@dexto/core 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (497) hide show
  1. package/README.md +36 -0
  2. package/dist/agent/DextoAgent.cjs +22 -3
  3. package/dist/agent/DextoAgent.d.ts +19 -2
  4. package/dist/agent/DextoAgent.d.ts.map +1 -1
  5. package/dist/agent/DextoAgent.js +23 -4
  6. package/dist/agent/index.cjs +4 -1
  7. package/dist/agent/index.d.ts +1 -1
  8. package/dist/agent/index.d.ts.map +1 -1
  9. package/dist/agent/index.js +5 -1
  10. package/dist/agent/schemas.cjs +90 -71
  11. package/dist/agent/schemas.d.ts +5911 -96
  12. package/dist/agent/schemas.d.ts.map +1 -1
  13. package/dist/agent/schemas.js +87 -66
  14. package/dist/approval/manager.cjs +165 -1
  15. package/dist/approval/manager.d.ts +91 -2
  16. package/dist/approval/manager.d.ts.map +1 -1
  17. package/dist/approval/manager.js +155 -1
  18. package/dist/approval/schemas.cjs +39 -3
  19. package/dist/approval/schemas.d.ts +238 -1
  20. package/dist/approval/schemas.d.ts.map +1 -1
  21. package/dist/approval/schemas.js +35 -3
  22. package/dist/approval/types.cjs +1 -0
  23. package/dist/approval/types.d.ts +26 -1
  24. package/dist/approval/types.d.ts.map +1 -1
  25. package/dist/approval/types.js +1 -0
  26. package/dist/context/compaction/factory.cjs +57 -0
  27. package/dist/context/compaction/factory.d.ts +17 -0
  28. package/dist/context/compaction/factory.d.ts.map +1 -0
  29. package/dist/context/compaction/factory.js +34 -0
  30. package/dist/context/compaction/index.cjs +49 -0
  31. package/dist/context/compaction/index.d.ts +11 -0
  32. package/dist/context/compaction/index.d.ts.map +1 -0
  33. package/dist/context/compaction/index.js +19 -0
  34. package/dist/context/{compression → compaction}/overflow.cjs +3 -3
  35. package/dist/context/{compression → compaction}/overflow.d.ts +4 -4
  36. package/dist/context/compaction/overflow.d.ts.map +1 -0
  37. package/dist/context/{compression → compaction}/overflow.js +2 -2
  38. package/dist/context/compaction/provider.cjs +16 -0
  39. package/dist/context/compaction/provider.d.ts +48 -0
  40. package/dist/context/compaction/provider.d.ts.map +1 -0
  41. package/dist/context/compaction/providers/noop-provider.cjs +48 -0
  42. package/dist/context/compaction/providers/noop-provider.d.ts +24 -0
  43. package/dist/context/compaction/providers/noop-provider.d.ts.map +1 -0
  44. package/dist/context/compaction/providers/noop-provider.js +24 -0
  45. package/dist/context/compaction/providers/reactive-overflow-provider.cjs +61 -0
  46. package/dist/context/compaction/providers/reactive-overflow-provider.d.ts +36 -0
  47. package/dist/context/compaction/providers/reactive-overflow-provider.d.ts.map +1 -0
  48. package/dist/context/compaction/providers/reactive-overflow-provider.js +37 -0
  49. package/dist/context/compaction/registry.cjs +39 -0
  50. package/dist/context/compaction/registry.d.ts +19 -0
  51. package/dist/context/compaction/registry.d.ts.map +1 -0
  52. package/dist/context/compaction/registry.js +16 -0
  53. package/dist/context/compaction/schemas.cjs +38 -0
  54. package/dist/context/compaction/schemas.d.ts +24 -0
  55. package/dist/context/compaction/schemas.d.ts.map +1 -0
  56. package/dist/context/compaction/schemas.js +14 -0
  57. package/dist/context/compaction/strategies/noop.cjs +36 -0
  58. package/dist/context/compaction/strategies/noop.d.ts +18 -0
  59. package/dist/context/compaction/strategies/noop.d.ts.map +1 -0
  60. package/dist/context/compaction/strategies/noop.js +13 -0
  61. package/dist/context/{compression → compaction/strategies}/reactive-overflow.cjs +3 -3
  62. package/dist/context/{compression → compaction/strategies}/reactive-overflow.d.ts +6 -6
  63. package/dist/context/compaction/strategies/reactive-overflow.d.ts.map +1 -0
  64. package/dist/context/{compression → compaction/strategies}/reactive-overflow.js +4 -4
  65. package/dist/context/{compression → compaction}/types.d.ts +4 -4
  66. package/dist/context/compaction/types.d.ts.map +1 -0
  67. package/dist/context/compaction/types.js +0 -0
  68. package/dist/context/error-codes.cjs +4 -0
  69. package/dist/context/error-codes.d.ts +4 -0
  70. package/dist/context/error-codes.d.ts.map +1 -1
  71. package/dist/context/error-codes.js +4 -0
  72. package/dist/context/errors.cjs +40 -0
  73. package/dist/context/errors.d.ts +14 -0
  74. package/dist/context/errors.d.ts.map +1 -1
  75. package/dist/context/errors.js +40 -0
  76. package/dist/context/index.cjs +3 -1
  77. package/dist/context/index.d.ts +1 -0
  78. package/dist/context/index.d.ts.map +1 -1
  79. package/dist/context/index.js +1 -0
  80. package/dist/context/types.d.ts +6 -0
  81. package/dist/context/types.d.ts.map +1 -1
  82. package/dist/context/utils.cjs +27 -7
  83. package/dist/context/utils.d.ts.map +1 -1
  84. package/dist/context/utils.js +27 -7
  85. package/dist/errors/result-bridge.cjs +2 -3
  86. package/dist/errors/result-bridge.d.ts.map +1 -1
  87. package/dist/errors/result-bridge.js +2 -3
  88. package/dist/events/index.cjs +2 -2
  89. package/dist/events/index.d.ts +16 -16
  90. package/dist/events/index.d.ts.map +1 -1
  91. package/dist/events/index.js +2 -2
  92. package/dist/filesystem/filesystem-service.cjs +39 -0
  93. package/dist/filesystem/filesystem-service.d.ts +32 -0
  94. package/dist/filesystem/filesystem-service.d.ts.map +1 -1
  95. package/dist/filesystem/filesystem-service.js +39 -0
  96. package/dist/filesystem/index.d.ts +1 -1
  97. package/dist/filesystem/index.d.ts.map +1 -1
  98. package/dist/filesystem/path-validator.cjs +69 -1
  99. package/dist/filesystem/path-validator.d.ts +43 -2
  100. package/dist/filesystem/path-validator.d.ts.map +1 -1
  101. package/dist/filesystem/path-validator.js +69 -1
  102. package/dist/image/define-image.cjs +146 -0
  103. package/dist/image/define-image.d.ts +71 -0
  104. package/dist/image/define-image.d.ts.map +1 -0
  105. package/dist/image/define-image.js +121 -0
  106. package/dist/image/index.cjs +32 -0
  107. package/dist/image/index.d.ts +53 -0
  108. package/dist/image/index.d.ts.map +1 -0
  109. package/dist/image/index.js +7 -0
  110. package/dist/image/types.cjs +16 -0
  111. package/dist/image/types.d.ts +231 -0
  112. package/dist/image/types.d.ts.map +1 -0
  113. package/dist/image/types.js +0 -0
  114. package/dist/index.cjs +5 -1
  115. package/dist/index.d.ts +2 -0
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +2 -0
  118. package/dist/llm/error-codes.cjs +1 -0
  119. package/dist/llm/error-codes.d.ts +1 -0
  120. package/dist/llm/error-codes.d.ts.map +1 -1
  121. package/dist/llm/error-codes.js +1 -0
  122. package/dist/llm/errors.cjs +24 -0
  123. package/dist/llm/errors.d.ts +19 -6
  124. package/dist/llm/errors.d.ts.map +1 -1
  125. package/dist/llm/errors.js +24 -0
  126. package/dist/llm/executor/stream-processor.cjs +11 -3
  127. package/dist/llm/executor/stream-processor.d.ts.map +1 -1
  128. package/dist/llm/executor/stream-processor.js +11 -3
  129. package/dist/llm/executor/turn-executor.cjs +50 -23
  130. package/dist/llm/executor/turn-executor.d.ts +6 -5
  131. package/dist/llm/executor/turn-executor.d.ts.map +1 -1
  132. package/dist/llm/executor/turn-executor.js +50 -23
  133. package/dist/llm/formatters/vercel.cjs +6 -2
  134. package/dist/llm/formatters/vercel.d.ts.map +1 -1
  135. package/dist/llm/formatters/vercel.js +6 -2
  136. package/dist/llm/index.cjs +18 -1
  137. package/dist/llm/index.d.ts +2 -0
  138. package/dist/llm/index.d.ts.map +1 -1
  139. package/dist/llm/index.js +14 -0
  140. package/dist/llm/providers/local/ai-sdk-adapter.cjs +308 -0
  141. package/dist/llm/providers/local/ai-sdk-adapter.d.ts +29 -0
  142. package/dist/llm/providers/local/ai-sdk-adapter.d.ts.map +1 -0
  143. package/dist/llm/providers/local/ai-sdk-adapter.js +278 -0
  144. package/dist/llm/providers/local/downloader.cjs +291 -0
  145. package/dist/llm/providers/local/downloader.d.ts +82 -0
  146. package/dist/llm/providers/local/downloader.d.ts.map +1 -0
  147. package/dist/llm/providers/local/downloader.js +251 -0
  148. package/dist/llm/providers/local/error-codes.cjs +57 -0
  149. package/dist/llm/providers/local/error-codes.d.ts +66 -0
  150. package/dist/llm/providers/local/error-codes.d.ts.map +1 -0
  151. package/dist/llm/providers/local/error-codes.js +34 -0
  152. package/dist/llm/providers/local/errors.cjs +240 -0
  153. package/dist/llm/providers/local/errors.d.ts +31 -0
  154. package/dist/llm/providers/local/errors.d.ts.map +1 -0
  155. package/dist/llm/providers/local/errors.js +217 -0
  156. package/dist/llm/providers/local/gpu-detector.cjs +214 -0
  157. package/dist/llm/providers/local/gpu-detector.d.ts +28 -0
  158. package/dist/llm/providers/local/gpu-detector.d.ts.map +1 -0
  159. package/dist/llm/providers/local/gpu-detector.js +178 -0
  160. package/dist/llm/providers/local/index.cjs +147 -0
  161. package/dist/llm/providers/local/index.d.ts +21 -0
  162. package/dist/llm/providers/local/index.d.ts.map +1 -0
  163. package/dist/llm/providers/local/index.js +126 -0
  164. package/dist/llm/providers/local/node-llama-provider.cjs +216 -0
  165. package/dist/llm/providers/local/node-llama-provider.d.ts +90 -0
  166. package/dist/llm/providers/local/node-llama-provider.d.ts.map +1 -0
  167. package/dist/llm/providers/local/node-llama-provider.js +176 -0
  168. package/dist/llm/providers/local/ollama-provider.cjs +230 -0
  169. package/dist/llm/providers/local/ollama-provider.d.ts +70 -0
  170. package/dist/llm/providers/local/ollama-provider.d.ts.map +1 -0
  171. package/dist/llm/providers/local/ollama-provider.js +198 -0
  172. package/dist/llm/providers/local/registry.cjs +343 -0
  173. package/dist/llm/providers/local/registry.d.ts +51 -0
  174. package/dist/llm/providers/local/registry.d.ts.map +1 -0
  175. package/dist/llm/providers/local/registry.js +312 -0
  176. package/dist/llm/providers/local/schemas.cjs +169 -0
  177. package/dist/llm/providers/local/schemas.d.ts +395 -0
  178. package/dist/llm/providers/local/schemas.d.ts.map +1 -0
  179. package/dist/llm/providers/local/schemas.js +133 -0
  180. package/dist/llm/providers/local/types.cjs +16 -0
  181. package/dist/llm/providers/local/types.d.ts +219 -0
  182. package/dist/llm/providers/local/types.d.ts.map +1 -0
  183. package/dist/llm/providers/local/types.js +0 -0
  184. package/dist/llm/providers/openrouter-model-registry.cjs +350 -0
  185. package/dist/llm/providers/openrouter-model-registry.d.ts +120 -0
  186. package/dist/llm/providers/openrouter-model-registry.d.ts.map +1 -0
  187. package/dist/llm/providers/openrouter-model-registry.js +309 -0
  188. package/dist/llm/registry.cjs +535 -9
  189. package/dist/llm/registry.d.ts +26 -0
  190. package/dist/llm/registry.d.ts.map +1 -1
  191. package/dist/llm/registry.js +532 -9
  192. package/dist/llm/resolver.cjs +63 -5
  193. package/dist/llm/resolver.d.ts +3 -3
  194. package/dist/llm/resolver.d.ts.map +1 -1
  195. package/dist/llm/resolver.js +69 -6
  196. package/dist/llm/schemas.cjs +90 -80
  197. package/dist/llm/schemas.d.ts +158 -22
  198. package/dist/llm/schemas.d.ts.map +1 -1
  199. package/dist/llm/schemas.js +90 -80
  200. package/dist/llm/services/factory.cjs +87 -13
  201. package/dist/llm/services/factory.d.ts +4 -1
  202. package/dist/llm/services/factory.d.ts.map +1 -1
  203. package/dist/llm/services/factory.js +85 -12
  204. package/dist/llm/services/test-utils.integration.cjs +22 -2
  205. package/dist/llm/services/test-utils.integration.d.ts +7 -1
  206. package/dist/llm/services/test-utils.integration.d.ts.map +1 -1
  207. package/dist/llm/services/test-utils.integration.js +26 -3
  208. package/dist/llm/services/vercel.cjs +5 -2
  209. package/dist/llm/services/vercel.d.ts +3 -2
  210. package/dist/llm/services/vercel.d.ts.map +1 -1
  211. package/dist/llm/services/vercel.js +5 -2
  212. package/dist/llm/types.cjs +11 -1
  213. package/dist/llm/types.d.ts +1 -1
  214. package/dist/llm/types.d.ts.map +1 -1
  215. package/dist/llm/types.js +11 -1
  216. package/dist/mcp/manager.cjs +8 -0
  217. package/dist/mcp/manager.d.ts +17 -0
  218. package/dist/mcp/manager.d.ts.map +1 -1
  219. package/dist/mcp/manager.js +8 -0
  220. package/dist/mcp/mcp-client.cjs +0 -3
  221. package/dist/mcp/mcp-client.d.ts.map +1 -1
  222. package/dist/mcp/mcp-client.js +0 -3
  223. package/dist/memory/schemas.d.ts +1 -1
  224. package/dist/plugins/error-codes.cjs +3 -0
  225. package/dist/plugins/error-codes.d.ts +7 -1
  226. package/dist/plugins/error-codes.d.ts.map +1 -1
  227. package/dist/plugins/error-codes.js +3 -0
  228. package/dist/plugins/index.cjs +7 -0
  229. package/dist/plugins/index.d.ts +4 -2
  230. package/dist/plugins/index.d.ts.map +1 -1
  231. package/dist/plugins/index.js +6 -1
  232. package/dist/plugins/manager.cjs +92 -7
  233. package/dist/plugins/manager.d.ts +10 -3
  234. package/dist/plugins/manager.d.ts.map +1 -1
  235. package/dist/plugins/manager.js +92 -7
  236. package/dist/plugins/registry.cjs +63 -0
  237. package/dist/plugins/registry.d.ts +101 -0
  238. package/dist/plugins/registry.d.ts.map +1 -0
  239. package/dist/plugins/registry.js +39 -0
  240. package/dist/plugins/schemas.cjs +17 -5
  241. package/dist/plugins/schemas.d.ts +62 -5
  242. package/dist/plugins/schemas.d.ts.map +1 -1
  243. package/dist/plugins/schemas.js +15 -4
  244. package/dist/providers/base-registry.cjs +147 -0
  245. package/dist/providers/base-registry.d.ts +147 -0
  246. package/dist/providers/base-registry.d.ts.map +1 -0
  247. package/dist/providers/base-registry.js +123 -0
  248. package/dist/providers/discovery.cjs +95 -0
  249. package/dist/providers/discovery.d.ts +94 -0
  250. package/dist/providers/discovery.d.ts.map +1 -0
  251. package/dist/providers/discovery.js +70 -0
  252. package/dist/providers/index.cjs +24 -0
  253. package/dist/providers/index.d.ts +32 -0
  254. package/dist/providers/index.d.ts.map +1 -0
  255. package/dist/providers/index.js +2 -0
  256. package/dist/resources/reference-parser.cjs +3 -3
  257. package/dist/resources/reference-parser.d.ts.map +1 -1
  258. package/dist/resources/reference-parser.js +3 -3
  259. package/dist/session/chat-session.cjs +20 -3
  260. package/dist/session/chat-session.d.ts.map +1 -1
  261. package/dist/session/chat-session.js +21 -4
  262. package/dist/storage/blob/factory.cjs +8 -11
  263. package/dist/storage/blob/factory.d.ts +32 -6
  264. package/dist/storage/blob/factory.d.ts.map +1 -1
  265. package/dist/storage/blob/factory.js +8 -11
  266. package/dist/storage/blob/index.cjs +56 -0
  267. package/dist/storage/blob/index.d.ts +45 -0
  268. package/dist/storage/blob/index.d.ts.map +1 -0
  269. package/dist/storage/blob/index.js +30 -0
  270. package/dist/storage/blob/provider.cjs +16 -0
  271. package/dist/storage/blob/provider.d.ts +50 -0
  272. package/dist/storage/blob/provider.d.ts.map +1 -0
  273. package/dist/storage/blob/provider.js +0 -0
  274. package/dist/storage/blob/providers/index.cjs +31 -0
  275. package/dist/storage/blob/providers/index.d.ts +8 -0
  276. package/dist/storage/blob/providers/index.d.ts.map +1 -0
  277. package/dist/storage/blob/providers/index.js +7 -0
  278. package/dist/storage/blob/providers/local.cjs +39 -0
  279. package/dist/storage/blob/providers/local.d.ts +17 -0
  280. package/dist/storage/blob/providers/local.d.ts.map +1 -0
  281. package/dist/storage/blob/providers/local.js +16 -0
  282. package/dist/storage/blob/providers/memory.cjs +39 -0
  283. package/dist/storage/blob/providers/memory.d.ts +17 -0
  284. package/dist/storage/blob/providers/memory.d.ts.map +1 -0
  285. package/dist/storage/blob/providers/memory.js +16 -0
  286. package/dist/storage/blob/registry.cjs +50 -0
  287. package/dist/storage/blob/registry.d.ts +42 -0
  288. package/dist/storage/blob/registry.d.ts.map +1 -0
  289. package/dist/storage/blob/registry.js +26 -0
  290. package/dist/storage/blob/schemas.cjs +9 -12
  291. package/dist/storage/blob/schemas.d.ts +39 -34
  292. package/dist/storage/blob/schemas.d.ts.map +1 -1
  293. package/dist/storage/blob/schemas.js +6 -11
  294. package/dist/storage/cache/factory.cjs +8 -36
  295. package/dist/storage/cache/factory.d.ts +32 -7
  296. package/dist/storage/cache/factory.d.ts.map +1 -1
  297. package/dist/storage/cache/factory.js +8 -26
  298. package/dist/storage/cache/index.cjs +53 -0
  299. package/dist/storage/cache/index.d.ts +44 -0
  300. package/dist/storage/cache/index.d.ts.map +1 -0
  301. package/dist/storage/cache/index.js +28 -0
  302. package/dist/storage/cache/provider.cjs +16 -0
  303. package/dist/storage/cache/provider.d.ts +56 -0
  304. package/dist/storage/cache/provider.d.ts.map +1 -0
  305. package/dist/storage/cache/provider.js +0 -0
  306. package/dist/storage/cache/providers/index.cjs +31 -0
  307. package/dist/storage/cache/providers/index.d.ts +8 -0
  308. package/dist/storage/cache/providers/index.d.ts.map +1 -0
  309. package/dist/storage/cache/providers/index.js +7 -0
  310. package/dist/storage/cache/providers/memory.cjs +40 -0
  311. package/dist/storage/cache/providers/memory.d.ts +17 -0
  312. package/dist/storage/cache/providers/memory.d.ts.map +1 -0
  313. package/dist/storage/cache/providers/memory.js +17 -0
  314. package/dist/storage/cache/providers/redis.cjs +66 -0
  315. package/dist/storage/cache/providers/redis.d.ts +20 -0
  316. package/dist/storage/cache/providers/redis.d.ts.map +1 -0
  317. package/dist/storage/cache/providers/redis.js +33 -0
  318. package/dist/storage/cache/registry.cjs +50 -0
  319. package/dist/storage/cache/registry.d.ts +42 -0
  320. package/dist/storage/cache/registry.d.ts.map +1 -0
  321. package/dist/storage/cache/registry.js +26 -0
  322. package/dist/storage/cache/schemas.cjs +6 -2
  323. package/dist/storage/cache/schemas.d.ts +2 -3
  324. package/dist/storage/cache/schemas.d.ts.map +1 -1
  325. package/dist/storage/cache/schemas.js +3 -1
  326. package/dist/storage/database/factory.cjs +8 -47
  327. package/dist/storage/database/factory.d.ts +34 -8
  328. package/dist/storage/database/factory.d.ts.map +1 -1
  329. package/dist/storage/database/factory.js +8 -37
  330. package/dist/storage/database/index.cjs +58 -0
  331. package/dist/storage/database/index.d.ts +45 -0
  332. package/dist/storage/database/index.d.ts.map +1 -0
  333. package/dist/storage/database/index.js +37 -0
  334. package/dist/storage/database/provider.cjs +16 -0
  335. package/dist/storage/database/provider.d.ts +56 -0
  336. package/dist/storage/database/provider.d.ts.map +1 -0
  337. package/dist/storage/database/provider.js +0 -0
  338. package/dist/storage/database/providers/index.cjs +34 -0
  339. package/dist/storage/database/providers/index.d.ts +9 -0
  340. package/dist/storage/database/providers/index.d.ts.map +1 -0
  341. package/dist/storage/database/providers/index.js +9 -0
  342. package/dist/storage/database/providers/memory.cjs +40 -0
  343. package/dist/storage/database/providers/memory.d.ts +16 -0
  344. package/dist/storage/database/providers/memory.d.ts.map +1 -0
  345. package/dist/storage/database/providers/memory.js +17 -0
  346. package/dist/storage/database/providers/postgres.cjs +62 -0
  347. package/dist/storage/database/providers/postgres.d.ts +19 -0
  348. package/dist/storage/database/providers/postgres.d.ts.map +1 -0
  349. package/dist/storage/database/providers/postgres.js +29 -0
  350. package/dist/storage/database/providers/sqlite.cjs +66 -0
  351. package/dist/storage/database/providers/sqlite.d.ts +20 -0
  352. package/dist/storage/database/providers/sqlite.d.ts.map +1 -0
  353. package/dist/storage/database/providers/sqlite.js +33 -0
  354. package/dist/storage/database/registry.cjs +50 -0
  355. package/dist/storage/database/registry.d.ts +42 -0
  356. package/dist/storage/database/registry.d.ts.map +1 -0
  357. package/dist/storage/database/registry.js +26 -0
  358. package/dist/storage/database/schemas.cjs +8 -2
  359. package/dist/storage/database/schemas.d.ts +3 -4
  360. package/dist/storage/database/schemas.d.ts.map +1 -1
  361. package/dist/storage/database/schemas.js +4 -1
  362. package/dist/storage/error-codes.cjs +6 -0
  363. package/dist/storage/error-codes.d.ts +7 -1
  364. package/dist/storage/error-codes.d.ts.map +1 -1
  365. package/dist/storage/error-codes.js +6 -0
  366. package/dist/storage/errors.cjs +80 -0
  367. package/dist/storage/errors.d.ts +24 -0
  368. package/dist/storage/errors.d.ts.map +1 -1
  369. package/dist/storage/errors.js +80 -0
  370. package/dist/storage/index.cjs +47 -4
  371. package/dist/storage/index.d.ts +34 -8
  372. package/dist/storage/index.d.ts.map +1 -1
  373. package/dist/storage/index.js +32 -3
  374. package/dist/storage/schemas.cjs +4 -0
  375. package/dist/storage/schemas.d.ts +17 -50
  376. package/dist/storage/schemas.d.ts.map +1 -1
  377. package/dist/storage/schemas.js +5 -1
  378. package/dist/storage/storage-manager.cjs +6 -6
  379. package/dist/storage/storage-manager.d.ts.map +1 -1
  380. package/dist/storage/storage-manager.js +3 -3
  381. package/dist/systemPrompt/in-built-prompts.cjs +7 -6
  382. package/dist/systemPrompt/in-built-prompts.d.ts +2 -2
  383. package/dist/systemPrompt/in-built-prompts.d.ts.map +1 -1
  384. package/dist/systemPrompt/in-built-prompts.js +6 -5
  385. package/dist/systemPrompt/registry.cjs +2 -2
  386. package/dist/systemPrompt/registry.d.ts +1 -1
  387. package/dist/systemPrompt/registry.d.ts.map +1 -1
  388. package/dist/systemPrompt/registry.js +2 -2
  389. package/dist/systemPrompt/schemas.cjs +2 -2
  390. package/dist/systemPrompt/schemas.d.ts +13 -13
  391. package/dist/systemPrompt/schemas.js +2 -2
  392. package/dist/tools/custom-tool-registry.cjs +64 -0
  393. package/dist/tools/custom-tool-registry.d.ts +120 -0
  394. package/dist/tools/custom-tool-registry.d.ts.map +1 -0
  395. package/dist/tools/custom-tool-registry.js +40 -0
  396. package/dist/tools/custom-tool-schema-registry.cjs +164 -0
  397. package/dist/tools/custom-tool-schema-registry.d.ts +86 -0
  398. package/dist/tools/custom-tool-schema-registry.d.ts.map +1 -0
  399. package/dist/tools/custom-tool-schema-registry.js +140 -0
  400. package/dist/tools/error-codes.cjs +3 -0
  401. package/dist/tools/error-codes.d.ts +4 -1
  402. package/dist/tools/error-codes.d.ts.map +1 -1
  403. package/dist/tools/error-codes.js +3 -0
  404. package/dist/tools/errors.cjs +41 -0
  405. package/dist/tools/errors.d.ts +17 -0
  406. package/dist/tools/errors.d.ts.map +1 -1
  407. package/dist/tools/errors.js +41 -0
  408. package/dist/tools/index.cjs +13 -1
  409. package/dist/tools/index.d.ts +4 -0
  410. package/dist/tools/index.d.ts.map +1 -1
  411. package/dist/tools/index.js +11 -1
  412. package/dist/tools/internal-tools/constants.cjs +3 -9
  413. package/dist/tools/internal-tools/constants.d.ts +1 -1
  414. package/dist/tools/internal-tools/constants.d.ts.map +1 -1
  415. package/dist/tools/internal-tools/constants.js +3 -9
  416. package/dist/tools/internal-tools/implementations/get-resource-tool.cjs +113 -0
  417. package/dist/tools/internal-tools/implementations/get-resource-tool.d.ts +30 -0
  418. package/dist/tools/internal-tools/implementations/get-resource-tool.d.ts.map +1 -0
  419. package/dist/tools/internal-tools/implementations/get-resource-tool.js +90 -0
  420. package/dist/tools/internal-tools/implementations/list-resources-tool.cjs +91 -0
  421. package/dist/tools/internal-tools/implementations/list-resources-tool.d.ts +24 -0
  422. package/dist/tools/internal-tools/implementations/list-resources-tool.d.ts.map +1 -0
  423. package/dist/tools/internal-tools/implementations/list-resources-tool.js +68 -0
  424. package/dist/tools/internal-tools/provider.cjs +150 -23
  425. package/dist/tools/internal-tools/provider.d.ts +55 -10
  426. package/dist/tools/internal-tools/provider.d.ts.map +1 -1
  427. package/dist/tools/internal-tools/provider.js +150 -23
  428. package/dist/tools/internal-tools/registry.cjs +18 -43
  429. package/dist/tools/internal-tools/registry.d.ts +4 -4
  430. package/dist/tools/internal-tools/registry.d.ts.map +1 -1
  431. package/dist/tools/internal-tools/registry.js +18 -43
  432. package/dist/tools/schemas.cjs +20 -0
  433. package/dist/tools/schemas.d.ts +43 -1
  434. package/dist/tools/schemas.d.ts.map +1 -1
  435. package/dist/tools/schemas.js +16 -0
  436. package/dist/tools/tool-manager.cjs +140 -13
  437. package/dist/tools/tool-manager.d.ts +22 -3
  438. package/dist/tools/tool-manager.d.ts.map +1 -1
  439. package/dist/tools/tool-manager.js +140 -13
  440. package/dist/tools/types.d.ts +43 -0
  441. package/dist/tools/types.d.ts.map +1 -1
  442. package/dist/utils/api-key-resolver.cjs +19 -1
  443. package/dist/utils/api-key-resolver.d.ts.map +1 -1
  444. package/dist/utils/api-key-resolver.js +19 -1
  445. package/dist/utils/index.cjs +0 -2
  446. package/dist/utils/index.d.ts +0 -1
  447. package/dist/utils/index.d.ts.map +1 -1
  448. package/dist/utils/index.js +0 -1
  449. package/dist/utils/redactor.cjs +18 -3
  450. package/dist/utils/redactor.d.ts +0 -7
  451. package/dist/utils/redactor.d.ts.map +1 -1
  452. package/dist/utils/redactor.js +18 -3
  453. package/dist/utils/service-initializer.cjs +9 -35
  454. package/dist/utils/service-initializer.d.ts.map +1 -1
  455. package/dist/utils/service-initializer.js +9 -35
  456. package/package.json +5 -2
  457. package/dist/context/compression/overflow.d.ts.map +0 -1
  458. package/dist/context/compression/reactive-overflow.d.ts.map +0 -1
  459. package/dist/context/compression/types.d.ts.map +0 -1
  460. package/dist/tools/internal-tools/implementations/bash-exec-tool.cjs +0 -130
  461. package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts +0 -13
  462. package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts.map +0 -1
  463. package/dist/tools/internal-tools/implementations/bash-exec-tool.js +0 -97
  464. package/dist/tools/internal-tools/implementations/bash-output-tool.cjs +0 -49
  465. package/dist/tools/internal-tools/implementations/bash-output-tool.d.ts +0 -12
  466. package/dist/tools/internal-tools/implementations/bash-output-tool.d.ts.map +0 -1
  467. package/dist/tools/internal-tools/implementations/bash-output-tool.js +0 -26
  468. package/dist/tools/internal-tools/implementations/edit-file-tool.cjs +0 -127
  469. package/dist/tools/internal-tools/implementations/edit-file-tool.d.ts +0 -12
  470. package/dist/tools/internal-tools/implementations/edit-file-tool.d.ts.map +0 -1
  471. package/dist/tools/internal-tools/implementations/edit-file-tool.js +0 -104
  472. package/dist/tools/internal-tools/implementations/glob-files-tool.cjs +0 -70
  473. package/dist/tools/internal-tools/implementations/glob-files-tool.d.ts +0 -12
  474. package/dist/tools/internal-tools/implementations/glob-files-tool.d.ts.map +0 -1
  475. package/dist/tools/internal-tools/implementations/glob-files-tool.js +0 -47
  476. package/dist/tools/internal-tools/implementations/grep-content-tool.cjs +0 -86
  477. package/dist/tools/internal-tools/implementations/grep-content-tool.d.ts +0 -12
  478. package/dist/tools/internal-tools/implementations/grep-content-tool.d.ts.map +0 -1
  479. package/dist/tools/internal-tools/implementations/grep-content-tool.js +0 -63
  480. package/dist/tools/internal-tools/implementations/kill-process-tool.cjs +0 -47
  481. package/dist/tools/internal-tools/implementations/kill-process-tool.d.ts +0 -12
  482. package/dist/tools/internal-tools/implementations/kill-process-tool.d.ts.map +0 -1
  483. package/dist/tools/internal-tools/implementations/kill-process-tool.js +0 -24
  484. package/dist/tools/internal-tools/implementations/read-file-tool.cjs +0 -63
  485. package/dist/tools/internal-tools/implementations/read-file-tool.d.ts +0 -12
  486. package/dist/tools/internal-tools/implementations/read-file-tool.d.ts.map +0 -1
  487. package/dist/tools/internal-tools/implementations/read-file-tool.js +0 -40
  488. package/dist/tools/internal-tools/implementations/write-file-tool.cjs +0 -124
  489. package/dist/tools/internal-tools/implementations/write-file-tool.d.ts +0 -12
  490. package/dist/tools/internal-tools/implementations/write-file-tool.d.ts.map +0 -1
  491. package/dist/tools/internal-tools/implementations/write-file-tool.js +0 -103
  492. package/dist/utils/env-file.cjs +0 -118
  493. package/dist/utils/env-file.d.ts +0 -5
  494. package/dist/utils/env-file.d.ts.map +0 -1
  495. package/dist/utils/env-file.js +0 -85
  496. /package/dist/context/{compression/types.js → compaction/provider.js} +0 -0
  497. /package/dist/context/{compression → compaction}/types.cjs +0 -0
@@ -0,0 +1,308 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var ai_sdk_adapter_exports = {};
30
+ __export(ai_sdk_adapter_exports, {
31
+ createLocalLanguageModel: () => createLocalLanguageModel
32
+ });
33
+ module.exports = __toCommonJS(ai_sdk_adapter_exports);
34
+ var import_node_llama_provider = require("./node-llama-provider.js");
35
+ var import_errors = require("./errors.js");
36
+ var import_registry = require("./registry.js");
37
+ var fs = __toESM(require("fs"), 1);
38
+ var path = __toESM(require("path"), 1);
39
+ var os = __toESM(require("os"), 1);
40
+ function getModelsDirectory() {
41
+ return path.join(os.homedir(), ".dexto", "models");
42
+ }
43
+ function getInstalledModelInfo(modelId) {
44
+ const stateFile = path.join(getModelsDirectory(), "state.json");
45
+ try {
46
+ if (!fs.existsSync(stateFile)) {
47
+ return null;
48
+ }
49
+ const content = fs.readFileSync(stateFile, "utf-8");
50
+ const state = JSON.parse(content);
51
+ return state.installed[modelId] ?? null;
52
+ } catch {
53
+ return null;
54
+ }
55
+ }
56
+ function getCustomModelFilePath(modelId) {
57
+ const customModelsFile = path.join(getModelsDirectory(), "custom-models.json");
58
+ try {
59
+ if (!fs.existsSync(customModelsFile)) {
60
+ return null;
61
+ }
62
+ const content = fs.readFileSync(customModelsFile, "utf-8");
63
+ const storage = JSON.parse(content);
64
+ const customModel = storage.models.find(
65
+ (m) => m.name === modelId && m.provider === "local" && m.filePath
66
+ );
67
+ return customModel?.filePath ?? null;
68
+ } catch {
69
+ return null;
70
+ }
71
+ }
72
+ function createLocalLanguageModel(config) {
73
+ return new LocalLanguageModel(config);
74
+ }
75
+ class LocalLanguageModel {
76
+ specificationVersion = "v2";
77
+ provider = "local";
78
+ modelId;
79
+ // Local models don't support URL-based content natively
80
+ supportedUrls = {};
81
+ config;
82
+ session = null;
83
+ loadedModel = null;
84
+ initPromise = null;
85
+ deviceName = "Local";
86
+ constructor(config) {
87
+ this.modelId = config.modelId;
88
+ this.config = config;
89
+ }
90
+ /**
91
+ * Initialize the model lazily on first use.
92
+ */
93
+ async ensureInitialized() {
94
+ if (this.session) {
95
+ return;
96
+ }
97
+ if (this.initPromise) {
98
+ return this.initPromise;
99
+ }
100
+ this.initPromise = this.initialize();
101
+ return this.initPromise;
102
+ }
103
+ async initialize() {
104
+ const {
105
+ modelId,
106
+ modelPath: directPath,
107
+ contextSize,
108
+ // Let node-llama-cpp default to "auto" if not specified
109
+ gpuLayers = -1,
110
+ threads
111
+ } = this.config;
112
+ const isInstalled = await (0, import_node_llama_provider.isNodeLlamaCppInstalled)();
113
+ if (!isInstalled) {
114
+ throw import_errors.LocalModelError.nodeLlamaNotInstalled();
115
+ }
116
+ let modelPath;
117
+ if (directPath) {
118
+ modelPath = directPath;
119
+ } else {
120
+ const installedModel = getInstalledModelInfo(modelId);
121
+ if (installedModel) {
122
+ modelPath = installedModel.filePath;
123
+ } else {
124
+ const customPath = getCustomModelFilePath(modelId);
125
+ if (customPath) {
126
+ modelPath = customPath;
127
+ } else {
128
+ const registryModel = (0, import_registry.getLocalModelById)(modelId);
129
+ if (!registryModel) {
130
+ throw import_errors.LocalModelError.modelNotFound(modelId);
131
+ }
132
+ throw import_errors.LocalModelError.modelNotDownloaded(modelId);
133
+ }
134
+ }
135
+ }
136
+ const loadConfig = {
137
+ modelPath,
138
+ gpuLayers
139
+ };
140
+ if (contextSize !== void 0) {
141
+ loadConfig.contextSize = contextSize;
142
+ }
143
+ if (threads !== void 0) {
144
+ loadConfig.threads = threads;
145
+ }
146
+ this.loadedModel = await (0, import_node_llama_provider.loadModel)(loadConfig);
147
+ this.deviceName = this.loadedModel.gpuInfo.deviceName || "Local";
148
+ this.session = await this.loadedModel.createSession();
149
+ }
150
+ /**
151
+ * Non-streaming text generation (V2 interface).
152
+ */
153
+ async doGenerate(options) {
154
+ await this.ensureInitialized();
155
+ const prompt = this.formatPrompt(options);
156
+ const maxTokens = options.maxOutputTokens ?? 1024;
157
+ const temperature = options.temperature ?? 0.7;
158
+ const promptOptions = {
159
+ maxTokens,
160
+ temperature
161
+ };
162
+ if (options.abortSignal) {
163
+ promptOptions.signal = options.abortSignal;
164
+ }
165
+ const response = await this.session.prompt(prompt, promptOptions);
166
+ const inputTokens = Math.ceil(prompt.length / 4);
167
+ const outputTokens = Math.ceil(response.length / 4);
168
+ const content = [{ type: "text", text: response }];
169
+ const finishReason = "stop";
170
+ const usage = {
171
+ inputTokens,
172
+ outputTokens,
173
+ totalTokens: inputTokens + outputTokens
174
+ };
175
+ const warnings = [];
176
+ return {
177
+ content,
178
+ finishReason,
179
+ usage,
180
+ providerMetadata: {
181
+ local: {
182
+ device: this.deviceName
183
+ }
184
+ },
185
+ warnings
186
+ };
187
+ }
188
+ /**
189
+ * Streaming text generation (V2 interface).
190
+ */
191
+ async doStream(options) {
192
+ await this.ensureInitialized();
193
+ const prompt = this.formatPrompt(options);
194
+ const maxTokens = options.maxOutputTokens ?? 1024;
195
+ const temperature = options.temperature ?? 0.7;
196
+ const inputTokens = Math.ceil(prompt.length / 4);
197
+ let outputTokens = 0;
198
+ const session = this.session;
199
+ const textId = "text-0";
200
+ const streamPromptOptions = {
201
+ maxTokens,
202
+ temperature,
203
+ onToken: (_token) => {
204
+ }
205
+ };
206
+ if (options.abortSignal) {
207
+ streamPromptOptions.signal = options.abortSignal;
208
+ }
209
+ let controller;
210
+ const stream = new ReadableStream({
211
+ async start(ctrl) {
212
+ controller = ctrl;
213
+ controller.enqueue({
214
+ type: "stream-start",
215
+ warnings: []
216
+ });
217
+ controller.enqueue({
218
+ type: "text-start",
219
+ id: textId
220
+ });
221
+ try {
222
+ streamPromptOptions.onToken = (token) => {
223
+ outputTokens += 1;
224
+ controller.enqueue({
225
+ type: "text-delta",
226
+ id: textId,
227
+ delta: token
228
+ });
229
+ };
230
+ await session.prompt(prompt, streamPromptOptions);
231
+ controller.enqueue({
232
+ type: "text-end",
233
+ id: textId
234
+ });
235
+ controller.enqueue({
236
+ type: "finish",
237
+ finishReason: "stop",
238
+ usage: {
239
+ inputTokens,
240
+ outputTokens,
241
+ totalTokens: inputTokens + outputTokens
242
+ }
243
+ });
244
+ controller.close();
245
+ } catch (error) {
246
+ if (error instanceof Error && error.name === "AbortError") {
247
+ controller.enqueue({
248
+ type: "text-end",
249
+ id: textId
250
+ });
251
+ controller.enqueue({
252
+ type: "finish",
253
+ finishReason: "stop",
254
+ usage: {
255
+ inputTokens,
256
+ outputTokens,
257
+ totalTokens: inputTokens + outputTokens
258
+ }
259
+ });
260
+ controller.close();
261
+ } else {
262
+ controller.enqueue({
263
+ type: "error",
264
+ error
265
+ });
266
+ controller.close();
267
+ }
268
+ }
269
+ }
270
+ });
271
+ return {
272
+ stream
273
+ };
274
+ }
275
+ /**
276
+ * Format the prompt from AI SDK message format.
277
+ */
278
+ formatPrompt(options) {
279
+ const parts = [];
280
+ if (options.prompt && Array.isArray(options.prompt)) {
281
+ for (const message of options.prompt) {
282
+ if (message.role === "system") {
283
+ parts.push(`System: ${message.content}`);
284
+ } else if (message.role === "user") {
285
+ if (Array.isArray(message.content)) {
286
+ const textParts = message.content.filter((p) => p.type === "text").map((p) => p.text);
287
+ if (textParts.length > 0) {
288
+ parts.push(`User: ${textParts.join("\n")}`);
289
+ }
290
+ }
291
+ } else if (message.role === "assistant") {
292
+ if (Array.isArray(message.content)) {
293
+ const textParts = message.content.filter((p) => p.type === "text").map((p) => p.text);
294
+ if (textParts.length > 0) {
295
+ parts.push(`Assistant: ${textParts.join("\n")}`);
296
+ }
297
+ }
298
+ }
299
+ }
300
+ }
301
+ parts.push("Assistant:");
302
+ return parts.join("\n\n");
303
+ }
304
+ }
305
+ // Annotate the CommonJS export names for ESM import in node:
306
+ 0 && (module.exports = {
307
+ createLocalLanguageModel
308
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Vercel AI SDK adapter for node-llama-cpp.
3
+ *
4
+ * This module creates a LanguageModelV2 implementation that wraps node-llama-cpp,
5
+ * allowing local GGUF models to be used with the Vercel AI SDK.
6
+ */
7
+ import type { LanguageModelV2 } from '@ai-sdk/provider';
8
+ /**
9
+ * Configuration for the local model AI SDK adapter.
10
+ */
11
+ export interface LocalModelAdapterConfig {
12
+ /** Model ID from the local registry */
13
+ modelId: string;
14
+ /** Direct path to model file (optional, overrides modelId lookup) */
15
+ modelPath?: string;
16
+ /** Context window size (default: 4096) */
17
+ contextSize?: number;
18
+ /** Number of GPU layers to offload (-1 = all, 0 = CPU only) */
19
+ gpuLayers?: number;
20
+ /** Number of CPU threads */
21
+ threads?: number;
22
+ }
23
+ /**
24
+ * Create a Vercel AI SDK compatible LanguageModelV2 from a local GGUF model.
25
+ * This is a synchronous function that returns a LanguageModel with lazy initialization.
26
+ * The actual model loading happens on first use.
27
+ */
28
+ export declare function createLocalLanguageModel(config: LocalModelAdapterConfig): LanguageModelV2;
29
+ //# sourceMappingURL=ai-sdk-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-sdk-adapter.d.ts","sourceRoot":"","sources":["../../../../src/llm/providers/local/ai-sdk-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EACR,eAAe,EAOlB,MAAM,kBAAkB,CAAC;AAa1B;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACpC,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AA+FD;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,uBAAuB,GAAG,eAAe,CAEzF"}
@@ -0,0 +1,278 @@
1
+ import "../../../chunk-PTJYTZNU.js";
2
+ import {
3
+ loadModel,
4
+ isNodeLlamaCppInstalled
5
+ } from "./node-llama-provider.js";
6
+ import { LocalModelError } from "./errors.js";
7
+ import { getLocalModelById } from "./registry.js";
8
+ import * as fs from "fs";
9
+ import * as path from "path";
10
+ import * as os from "os";
11
+ function getModelsDirectory() {
12
+ return path.join(os.homedir(), ".dexto", "models");
13
+ }
14
+ function getInstalledModelInfo(modelId) {
15
+ const stateFile = path.join(getModelsDirectory(), "state.json");
16
+ try {
17
+ if (!fs.existsSync(stateFile)) {
18
+ return null;
19
+ }
20
+ const content = fs.readFileSync(stateFile, "utf-8");
21
+ const state = JSON.parse(content);
22
+ return state.installed[modelId] ?? null;
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+ function getCustomModelFilePath(modelId) {
28
+ const customModelsFile = path.join(getModelsDirectory(), "custom-models.json");
29
+ try {
30
+ if (!fs.existsSync(customModelsFile)) {
31
+ return null;
32
+ }
33
+ const content = fs.readFileSync(customModelsFile, "utf-8");
34
+ const storage = JSON.parse(content);
35
+ const customModel = storage.models.find(
36
+ (m) => m.name === modelId && m.provider === "local" && m.filePath
37
+ );
38
+ return customModel?.filePath ?? null;
39
+ } catch {
40
+ return null;
41
+ }
42
+ }
43
+ function createLocalLanguageModel(config) {
44
+ return new LocalLanguageModel(config);
45
+ }
46
+ class LocalLanguageModel {
47
+ specificationVersion = "v2";
48
+ provider = "local";
49
+ modelId;
50
+ // Local models don't support URL-based content natively
51
+ supportedUrls = {};
52
+ config;
53
+ session = null;
54
+ loadedModel = null;
55
+ initPromise = null;
56
+ deviceName = "Local";
57
+ constructor(config) {
58
+ this.modelId = config.modelId;
59
+ this.config = config;
60
+ }
61
+ /**
62
+ * Initialize the model lazily on first use.
63
+ */
64
+ async ensureInitialized() {
65
+ if (this.session) {
66
+ return;
67
+ }
68
+ if (this.initPromise) {
69
+ return this.initPromise;
70
+ }
71
+ this.initPromise = this.initialize();
72
+ return this.initPromise;
73
+ }
74
+ async initialize() {
75
+ const {
76
+ modelId,
77
+ modelPath: directPath,
78
+ contextSize,
79
+ // Let node-llama-cpp default to "auto" if not specified
80
+ gpuLayers = -1,
81
+ threads
82
+ } = this.config;
83
+ const isInstalled = await isNodeLlamaCppInstalled();
84
+ if (!isInstalled) {
85
+ throw LocalModelError.nodeLlamaNotInstalled();
86
+ }
87
+ let modelPath;
88
+ if (directPath) {
89
+ modelPath = directPath;
90
+ } else {
91
+ const installedModel = getInstalledModelInfo(modelId);
92
+ if (installedModel) {
93
+ modelPath = installedModel.filePath;
94
+ } else {
95
+ const customPath = getCustomModelFilePath(modelId);
96
+ if (customPath) {
97
+ modelPath = customPath;
98
+ } else {
99
+ const registryModel = getLocalModelById(modelId);
100
+ if (!registryModel) {
101
+ throw LocalModelError.modelNotFound(modelId);
102
+ }
103
+ throw LocalModelError.modelNotDownloaded(modelId);
104
+ }
105
+ }
106
+ }
107
+ const loadConfig = {
108
+ modelPath,
109
+ gpuLayers
110
+ };
111
+ if (contextSize !== void 0) {
112
+ loadConfig.contextSize = contextSize;
113
+ }
114
+ if (threads !== void 0) {
115
+ loadConfig.threads = threads;
116
+ }
117
+ this.loadedModel = await loadModel(loadConfig);
118
+ this.deviceName = this.loadedModel.gpuInfo.deviceName || "Local";
119
+ this.session = await this.loadedModel.createSession();
120
+ }
121
+ /**
122
+ * Non-streaming text generation (V2 interface).
123
+ */
124
+ async doGenerate(options) {
125
+ await this.ensureInitialized();
126
+ const prompt = this.formatPrompt(options);
127
+ const maxTokens = options.maxOutputTokens ?? 1024;
128
+ const temperature = options.temperature ?? 0.7;
129
+ const promptOptions = {
130
+ maxTokens,
131
+ temperature
132
+ };
133
+ if (options.abortSignal) {
134
+ promptOptions.signal = options.abortSignal;
135
+ }
136
+ const response = await this.session.prompt(prompt, promptOptions);
137
+ const inputTokens = Math.ceil(prompt.length / 4);
138
+ const outputTokens = Math.ceil(response.length / 4);
139
+ const content = [{ type: "text", text: response }];
140
+ const finishReason = "stop";
141
+ const usage = {
142
+ inputTokens,
143
+ outputTokens,
144
+ totalTokens: inputTokens + outputTokens
145
+ };
146
+ const warnings = [];
147
+ return {
148
+ content,
149
+ finishReason,
150
+ usage,
151
+ providerMetadata: {
152
+ local: {
153
+ device: this.deviceName
154
+ }
155
+ },
156
+ warnings
157
+ };
158
+ }
159
+ /**
160
+ * Streaming text generation (V2 interface).
161
+ */
162
+ async doStream(options) {
163
+ await this.ensureInitialized();
164
+ const prompt = this.formatPrompt(options);
165
+ const maxTokens = options.maxOutputTokens ?? 1024;
166
+ const temperature = options.temperature ?? 0.7;
167
+ const inputTokens = Math.ceil(prompt.length / 4);
168
+ let outputTokens = 0;
169
+ const session = this.session;
170
+ const textId = "text-0";
171
+ const streamPromptOptions = {
172
+ maxTokens,
173
+ temperature,
174
+ onToken: (_token) => {
175
+ }
176
+ };
177
+ if (options.abortSignal) {
178
+ streamPromptOptions.signal = options.abortSignal;
179
+ }
180
+ let controller;
181
+ const stream = new ReadableStream({
182
+ async start(ctrl) {
183
+ controller = ctrl;
184
+ controller.enqueue({
185
+ type: "stream-start",
186
+ warnings: []
187
+ });
188
+ controller.enqueue({
189
+ type: "text-start",
190
+ id: textId
191
+ });
192
+ try {
193
+ streamPromptOptions.onToken = (token) => {
194
+ outputTokens += 1;
195
+ controller.enqueue({
196
+ type: "text-delta",
197
+ id: textId,
198
+ delta: token
199
+ });
200
+ };
201
+ await session.prompt(prompt, streamPromptOptions);
202
+ controller.enqueue({
203
+ type: "text-end",
204
+ id: textId
205
+ });
206
+ controller.enqueue({
207
+ type: "finish",
208
+ finishReason: "stop",
209
+ usage: {
210
+ inputTokens,
211
+ outputTokens,
212
+ totalTokens: inputTokens + outputTokens
213
+ }
214
+ });
215
+ controller.close();
216
+ } catch (error) {
217
+ if (error instanceof Error && error.name === "AbortError") {
218
+ controller.enqueue({
219
+ type: "text-end",
220
+ id: textId
221
+ });
222
+ controller.enqueue({
223
+ type: "finish",
224
+ finishReason: "stop",
225
+ usage: {
226
+ inputTokens,
227
+ outputTokens,
228
+ totalTokens: inputTokens + outputTokens
229
+ }
230
+ });
231
+ controller.close();
232
+ } else {
233
+ controller.enqueue({
234
+ type: "error",
235
+ error
236
+ });
237
+ controller.close();
238
+ }
239
+ }
240
+ }
241
+ });
242
+ return {
243
+ stream
244
+ };
245
+ }
246
+ /**
247
+ * Format the prompt from AI SDK message format.
248
+ */
249
+ formatPrompt(options) {
250
+ const parts = [];
251
+ if (options.prompt && Array.isArray(options.prompt)) {
252
+ for (const message of options.prompt) {
253
+ if (message.role === "system") {
254
+ parts.push(`System: ${message.content}`);
255
+ } else if (message.role === "user") {
256
+ if (Array.isArray(message.content)) {
257
+ const textParts = message.content.filter((p) => p.type === "text").map((p) => p.text);
258
+ if (textParts.length > 0) {
259
+ parts.push(`User: ${textParts.join("\n")}`);
260
+ }
261
+ }
262
+ } else if (message.role === "assistant") {
263
+ if (Array.isArray(message.content)) {
264
+ const textParts = message.content.filter((p) => p.type === "text").map((p) => p.text);
265
+ if (textParts.length > 0) {
266
+ parts.push(`Assistant: ${textParts.join("\n")}`);
267
+ }
268
+ }
269
+ }
270
+ }
271
+ }
272
+ parts.push("Assistant:");
273
+ return parts.join("\n\n");
274
+ }
275
+ }
276
+ export {
277
+ createLocalLanguageModel
278
+ };