@warlock.js/core 4.8.0 → 4.8.1

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 (769) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/esm/connectors/ai-connector.mjs +1 -1
  3. package/package.json +12 -9
  4. package/esm/ai/src/agent/agent-input-builder.mjs +0 -133
  5. package/esm/ai/src/agent/agent-input-builder.mjs.map +0 -1
  6. package/esm/ai/src/agent/agent-log-event.mjs +0 -101
  7. package/esm/ai/src/agent/agent-log-event.mjs.map +0 -1
  8. package/esm/ai/src/agent/agent-stream.mjs +0 -82
  9. package/esm/ai/src/agent/agent-stream.mjs.map +0 -1
  10. package/esm/ai/src/agent/agent-to-stream-event.mjs +0 -86
  11. package/esm/ai/src/agent/agent-to-stream-event.mjs.map +0 -1
  12. package/esm/ai/src/agent/agent.mjs +0 -1276
  13. package/esm/ai/src/agent/agent.mjs.map +0 -1
  14. package/esm/ai/src/agent/index.mjs +0 -5
  15. package/esm/ai/src/agent/json-stream-guard.mjs +0 -400
  16. package/esm/ai/src/agent/json-stream-guard.mjs.map +0 -1
  17. package/esm/ai/src/agent/signature.mjs +0 -57
  18. package/esm/ai/src/agent/signature.mjs.map +0 -1
  19. package/esm/ai/src/agent/snapshot.mjs +0 -101
  20. package/esm/ai/src/agent/snapshot.mjs.map +0 -1
  21. package/esm/ai/src/agent/spawn-sub-agent.mjs +0 -68
  22. package/esm/ai/src/agent/spawn-sub-agent.mjs.map +0 -1
  23. package/esm/ai/src/ai.mjs +0 -191
  24. package/esm/ai/src/ai.mjs.map +0 -1
  25. package/esm/ai/src/batch/batch.mjs +0 -198
  26. package/esm/ai/src/batch/batch.mjs.map +0 -1
  27. package/esm/ai/src/batch/index.mjs +0 -3
  28. package/esm/ai/src/batch/run-batch-item.mjs +0 -100
  29. package/esm/ai/src/batch/run-batch-item.mjs.map +0 -1
  30. package/esm/ai/src/batch/run-with-concurrency.mjs +0 -39
  31. package/esm/ai/src/batch/run-with-concurrency.mjs.map +0 -1
  32. package/esm/ai/src/checkpoint/memory.mjs +0 -0
  33. package/esm/ai/src/checkpoint/memory.mjs.map +0 -1
  34. package/esm/ai/src/checkpoint/pg.mjs +0 -265
  35. package/esm/ai/src/checkpoint/pg.mjs.map +0 -1
  36. package/esm/ai/src/checkpoint/redis.mjs +0 -200
  37. package/esm/ai/src/checkpoint/redis.mjs.map +0 -1
  38. package/esm/ai/src/config.mjs +0 -59
  39. package/esm/ai/src/config.mjs.map +0 -1
  40. package/esm/ai/src/contracts/end.type.mjs +0 -47
  41. package/esm/ai/src/contracts/end.type.mjs.map +0 -1
  42. package/esm/ai/src/errors/agent-cancelled-error.mjs +0 -43
  43. package/esm/ai/src/errors/agent-cancelled-error.mjs.map +0 -1
  44. package/esm/ai/src/errors/agent-drift-error.mjs +0 -31
  45. package/esm/ai/src/errors/agent-drift-error.mjs.map +0 -1
  46. package/esm/ai/src/errors/agent-execution-error.mjs +0 -35
  47. package/esm/ai/src/errors/agent-execution-error.mjs.map +0 -1
  48. package/esm/ai/src/errors/agent-max-trips-error.mjs +0 -41
  49. package/esm/ai/src/errors/agent-max-trips-error.mjs.map +0 -1
  50. package/esm/ai/src/errors/ai-error.mjs +0 -68
  51. package/esm/ai/src/errors/ai-error.mjs.map +0 -1
  52. package/esm/ai/src/errors/budget-exceeded-error.mjs +0 -31
  53. package/esm/ai/src/errors/budget-exceeded-error.mjs.map +0 -1
  54. package/esm/ai/src/errors/content-filter-error.mjs +0 -28
  55. package/esm/ai/src/errors/content-filter-error.mjs.map +0 -1
  56. package/esm/ai/src/errors/context-length-exceeded-error.mjs +0 -31
  57. package/esm/ai/src/errors/context-length-exceeded-error.mjs.map +0 -1
  58. package/esm/ai/src/errors/guardrail-violation-error.mjs +0 -41
  59. package/esm/ai/src/errors/guardrail-violation-error.mjs.map +0 -1
  60. package/esm/ai/src/errors/index.mjs +0 -40
  61. package/esm/ai/src/errors/invalid-request-error.mjs +0 -31
  62. package/esm/ai/src/errors/invalid-request-error.mjs.map +0 -1
  63. package/esm/ai/src/errors/max-iterations-error.mjs +0 -32
  64. package/esm/ai/src/errors/max-iterations-error.mjs.map +0 -1
  65. package/esm/ai/src/errors/max-steps-exceeded-error.mjs +0 -21
  66. package/esm/ai/src/errors/max-steps-exceeded-error.mjs.map +0 -1
  67. package/esm/ai/src/errors/orchestrator-cancelled-error.mjs +0 -31
  68. package/esm/ai/src/errors/orchestrator-cancelled-error.mjs.map +0 -1
  69. package/esm/ai/src/errors/orchestrator-config-error.mjs +0 -30
  70. package/esm/ai/src/errors/orchestrator-config-error.mjs.map +0 -1
  71. package/esm/ai/src/errors/orchestrator-drift-error.mjs +0 -37
  72. package/esm/ai/src/errors/orchestrator-drift-error.mjs.map +0 -1
  73. package/esm/ai/src/errors/orchestrator-failed-error.mjs +0 -36
  74. package/esm/ai/src/errors/orchestrator-failed-error.mjs.map +0 -1
  75. package/esm/ai/src/errors/outbound-policy-error.mjs +0 -32
  76. package/esm/ai/src/errors/outbound-policy-error.mjs.map +0 -1
  77. package/esm/ai/src/errors/planner-cancelled-error.mjs +0 -29
  78. package/esm/ai/src/errors/planner-cancelled-error.mjs.map +0 -1
  79. package/esm/ai/src/errors/planner-drift-error.mjs +0 -33
  80. package/esm/ai/src/errors/planner-drift-error.mjs.map +0 -1
  81. package/esm/ai/src/errors/planner-failed-error.mjs +0 -37
  82. package/esm/ai/src/errors/planner-failed-error.mjs.map +0 -1
  83. package/esm/ai/src/errors/planner-plan-invalid-error.mjs +0 -25
  84. package/esm/ai/src/errors/planner-plan-invalid-error.mjs.map +0 -1
  85. package/esm/ai/src/errors/prompt-refinement-error.mjs +0 -27
  86. package/esm/ai/src/errors/prompt-refinement-error.mjs.map +0 -1
  87. package/esm/ai/src/errors/provider-auth-error.mjs +0 -26
  88. package/esm/ai/src/errors/provider-auth-error.mjs.map +0 -1
  89. package/esm/ai/src/errors/provider-error.mjs +0 -42
  90. package/esm/ai/src/errors/provider-error.mjs.map +0 -1
  91. package/esm/ai/src/errors/provider-rate-limit-error.mjs +0 -31
  92. package/esm/ai/src/errors/provider-rate-limit-error.mjs.map +0 -1
  93. package/esm/ai/src/errors/provider-timeout-error.mjs +0 -26
  94. package/esm/ai/src/errors/provider-timeout-error.mjs.map +0 -1
  95. package/esm/ai/src/errors/quota-exceeded-error.mjs +0 -40
  96. package/esm/ai/src/errors/quota-exceeded-error.mjs.map +0 -1
  97. package/esm/ai/src/errors/routing-error.mjs +0 -23
  98. package/esm/ai/src/errors/routing-error.mjs.map +0 -1
  99. package/esm/ai/src/errors/schema-validation-error.mjs +0 -37
  100. package/esm/ai/src/errors/schema-validation-error.mjs.map +0 -1
  101. package/esm/ai/src/errors/step-failed-error.mjs +0 -19
  102. package/esm/ai/src/errors/step-failed-error.mjs.map +0 -1
  103. package/esm/ai/src/errors/supervisor-cancelled-error.mjs +0 -29
  104. package/esm/ai/src/errors/supervisor-cancelled-error.mjs.map +0 -1
  105. package/esm/ai/src/errors/supervisor-drift-error.mjs +0 -30
  106. package/esm/ai/src/errors/supervisor-drift-error.mjs.map +0 -1
  107. package/esm/ai/src/errors/supervisor-failed-error.mjs +0 -43
  108. package/esm/ai/src/errors/supervisor-failed-error.mjs.map +0 -1
  109. package/esm/ai/src/errors/supervisor-routing-error.mjs +0 -39
  110. package/esm/ai/src/errors/supervisor-routing-error.mjs.map +0 -1
  111. package/esm/ai/src/errors/tool-execution-error.mjs +0 -32
  112. package/esm/ai/src/errors/tool-execution-error.mjs.map +0 -1
  113. package/esm/ai/src/errors/workflow-cancelled-error.mjs +0 -23
  114. package/esm/ai/src/errors/workflow-cancelled-error.mjs.map +0 -1
  115. package/esm/ai/src/errors/workflow-drift-error.mjs +0 -24
  116. package/esm/ai/src/errors/workflow-drift-error.mjs.map +0 -1
  117. package/esm/ai/src/errors/workflow-error.mjs +0 -18
  118. package/esm/ai/src/errors/workflow-error.mjs.map +0 -1
  119. package/esm/ai/src/eval/dataset.mjs +0 -112
  120. package/esm/ai/src/eval/dataset.mjs.map +0 -1
  121. package/esm/ai/src/eval/eval-runner.mjs +0 -135
  122. package/esm/ai/src/eval/eval-runner.mjs.map +0 -1
  123. package/esm/ai/src/eval/index.mjs +0 -48
  124. package/esm/ai/src/eval/index.mjs.map +0 -1
  125. package/esm/ai/src/eval/judge-scorer.mjs +0 -87
  126. package/esm/ai/src/eval/judge-scorer.mjs.map +0 -1
  127. package/esm/ai/src/eval/regression.mjs +0 -51
  128. package/esm/ai/src/eval/regression.mjs.map +0 -1
  129. package/esm/ai/src/eval/report-json.mjs +0 -33
  130. package/esm/ai/src/eval/report-json.mjs.map +0 -1
  131. package/esm/ai/src/eval/report-junit.mjs +0 -60
  132. package/esm/ai/src/eval/report-junit.mjs.map +0 -1
  133. package/esm/ai/src/eval/scorers.mjs +0 -101
  134. package/esm/ai/src/eval/scorers.mjs.map +0 -1
  135. package/esm/ai/src/guard/detectors/index.mjs +0 -6
  136. package/esm/ai/src/guard/detectors/injection.mjs +0 -254
  137. package/esm/ai/src/guard/detectors/injection.mjs.map +0 -1
  138. package/esm/ai/src/guard/detectors/moderation.mjs +0 -134
  139. package/esm/ai/src/guard/detectors/moderation.mjs.map +0 -1
  140. package/esm/ai/src/guard/detectors/pii.mjs +0 -199
  141. package/esm/ai/src/guard/detectors/pii.mjs.map +0 -1
  142. package/esm/ai/src/guard/detectors/topic.mjs +0 -99
  143. package/esm/ai/src/guard/detectors/topic.mjs.map +0 -1
  144. package/esm/ai/src/guard/errors.mjs +0 -18
  145. package/esm/ai/src/guard/errors.mjs.map +0 -1
  146. package/esm/ai/src/guard/guard.mjs +0 -209
  147. package/esm/ai/src/guard/guard.mjs.map +0 -1
  148. package/esm/ai/src/guard/guardrail.mjs +0 -22
  149. package/esm/ai/src/guard/guardrail.mjs.map +0 -1
  150. package/esm/ai/src/human/errors.mjs +0 -60
  151. package/esm/ai/src/human/errors.mjs.map +0 -1
  152. package/esm/ai/src/human/human-approval.mjs +0 -170
  153. package/esm/ai/src/human/human-approval.mjs.map +0 -1
  154. package/esm/ai/src/human/policy.mjs +0 -67
  155. package/esm/ai/src/human/policy.mjs.map +0 -1
  156. package/esm/ai/src/human/register.mjs +0 -37
  157. package/esm/ai/src/human/register.mjs.map +0 -1
  158. package/esm/ai/src/human/resume-seed.mjs +0 -53
  159. package/esm/ai/src/human/resume-seed.mjs.map +0 -1
  160. package/esm/ai/src/human/resume.mjs +0 -121
  161. package/esm/ai/src/human/resume.mjs.map +0 -1
  162. package/esm/ai/src/human/stores/index.mjs +0 -5
  163. package/esm/ai/src/human/stores/memory.mjs +0 -91
  164. package/esm/ai/src/human/stores/memory.mjs.map +0 -1
  165. package/esm/ai/src/human/stores/pg.mjs +0 -220
  166. package/esm/ai/src/human/stores/pg.mjs.map +0 -1
  167. package/esm/ai/src/human/stores/redis.mjs +0 -201
  168. package/esm/ai/src/human/stores/redis.mjs.map +0 -1
  169. package/esm/ai/src/image/image-cost.mjs +0 -55
  170. package/esm/ai/src/image/image-cost.mjs.map +0 -1
  171. package/esm/ai/src/image/image.mjs +0 -112
  172. package/esm/ai/src/image/image.mjs.map +0 -1
  173. package/esm/ai/src/image/index.mjs +0 -4
  174. package/esm/ai/src/index.mjs +0 -196
  175. package/esm/ai/src/memory/derive-id.mjs +0 -24
  176. package/esm/ai/src/memory/derive-id.mjs.map +0 -1
  177. package/esm/ai/src/memory/episodic-memory.mjs +0 -106
  178. package/esm/ai/src/memory/episodic-memory.mjs.map +0 -1
  179. package/esm/ai/src/memory/memory.mjs +0 -166
  180. package/esm/ai/src/memory/memory.mjs.map +0 -1
  181. package/esm/ai/src/memory/procedural-memory.mjs +0 -103
  182. package/esm/ai/src/memory/procedural-memory.mjs.map +0 -1
  183. package/esm/ai/src/memory/semantic-memory.mjs +0 -80
  184. package/esm/ai/src/memory/semantic-memory.mjs.map +0 -1
  185. package/esm/ai/src/memory/working-memory.mjs +0 -62
  186. package/esm/ai/src/memory/working-memory.mjs.map +0 -1
  187. package/esm/ai/src/middleware/builtins/budget.mjs +0 -219
  188. package/esm/ai/src/middleware/builtins/budget.mjs.map +0 -1
  189. package/esm/ai/src/middleware/builtins/guardrail.mjs +0 -76
  190. package/esm/ai/src/middleware/builtins/guardrail.mjs.map +0 -1
  191. package/esm/ai/src/middleware/builtins/semantic-cache.mjs +0 -149
  192. package/esm/ai/src/middleware/builtins/semantic-cache.mjs.map +0 -1
  193. package/esm/ai/src/middleware/helpers/compose.mjs +0 -52
  194. package/esm/ai/src/middleware/helpers/compose.mjs.map +0 -1
  195. package/esm/ai/src/middleware/helpers/for-tool.mjs +0 -80
  196. package/esm/ai/src/middleware/helpers/for-tool.mjs.map +0 -1
  197. package/esm/ai/src/middleware/index.mjs +0 -10
  198. package/esm/ai/src/middleware/pipeline.mjs +0 -100
  199. package/esm/ai/src/middleware/pipeline.mjs.map +0 -1
  200. package/esm/ai/src/middleware/utils/extract-user-text.mjs +0 -47
  201. package/esm/ai/src/middleware/utils/extract-user-text.mjs.map +0 -1
  202. package/esm/ai/src/middleware/utils/namespaced-state.mjs +0 -60
  203. package/esm/ai/src/middleware/utils/namespaced-state.mjs.map +0 -1
  204. package/esm/ai/src/mock/index.mjs +0 -4
  205. package/esm/ai/src/mock/mock-agent.mjs +0 -3
  206. package/esm/ai/src/mock/mock-router.mjs +0 -58
  207. package/esm/ai/src/mock/mock-router.mjs.map +0 -1
  208. package/esm/ai/src/model/fallback-model.mjs +0 -218
  209. package/esm/ai/src/model/fallback-model.mjs.map +0 -1
  210. package/esm/ai/src/model/index.mjs +0 -3
  211. package/esm/ai/src/object-stream/index.mjs +0 -4
  212. package/esm/ai/src/object-stream/parse-partial-json.mjs +0 -78
  213. package/esm/ai/src/object-stream/parse-partial-json.mjs.map +0 -1
  214. package/esm/ai/src/object-stream/stream-object.mjs +0 -97
  215. package/esm/ai/src/object-stream/stream-object.mjs.map +0 -1
  216. package/esm/ai/src/observe/index.mjs +0 -4
  217. package/esm/ai/src/observe/observer-registry.mjs +0 -35
  218. package/esm/ai/src/observe/observer-registry.mjs.map +0 -1
  219. package/esm/ai/src/observe/resolve-observers.mjs +0 -73
  220. package/esm/ai/src/observe/resolve-observers.mjs.map +0 -1
  221. package/esm/ai/src/orchestrator/as-tool.mjs +0 -98
  222. package/esm/ai/src/orchestrator/as-tool.mjs.map +0 -1
  223. package/esm/ai/src/orchestrator/checkpoint.mjs +0 -75
  224. package/esm/ai/src/orchestrator/checkpoint.mjs.map +0 -1
  225. package/esm/ai/src/orchestrator/commands.mjs +0 -34
  226. package/esm/ai/src/orchestrator/commands.mjs.map +0 -1
  227. package/esm/ai/src/orchestrator/compaction.mjs +0 -206
  228. package/esm/ai/src/orchestrator/compaction.mjs.map +0 -1
  229. package/esm/ai/src/orchestrator/dispatch.mjs +0 -171
  230. package/esm/ai/src/orchestrator/dispatch.mjs.map +0 -1
  231. package/esm/ai/src/orchestrator/emitter.mjs +0 -85
  232. package/esm/ai/src/orchestrator/emitter.mjs.map +0 -1
  233. package/esm/ai/src/orchestrator/execution.mjs +0 -395
  234. package/esm/ai/src/orchestrator/execution.mjs.map +0 -1
  235. package/esm/ai/src/orchestrator/index.mjs +0 -11
  236. package/esm/ai/src/orchestrator/load.mjs +0 -49
  237. package/esm/ai/src/orchestrator/load.mjs.map +0 -1
  238. package/esm/ai/src/orchestrator/lock.mjs +0 -75
  239. package/esm/ai/src/orchestrator/lock.mjs.map +0 -1
  240. package/esm/ai/src/orchestrator/memory.mjs +0 -141
  241. package/esm/ai/src/orchestrator/memory.mjs.map +0 -1
  242. package/esm/ai/src/orchestrator/orchestrator-stream.mjs +0 -98
  243. package/esm/ai/src/orchestrator/orchestrator-stream.mjs.map +0 -1
  244. package/esm/ai/src/orchestrator/orchestrator.mjs +0 -206
  245. package/esm/ai/src/orchestrator/orchestrator.mjs.map +0 -1
  246. package/esm/ai/src/orchestrator/resume.mjs +0 -74
  247. package/esm/ai/src/orchestrator/resume.mjs.map +0 -1
  248. package/esm/ai/src/orchestrator/session-lock.mjs +0 -83
  249. package/esm/ai/src/orchestrator/session-lock.mjs.map +0 -1
  250. package/esm/ai/src/orchestrator/signature.mjs +0 -120
  251. package/esm/ai/src/orchestrator/signature.mjs.map +0 -1
  252. package/esm/ai/src/orchestrator/window.mjs +0 -56
  253. package/esm/ai/src/orchestrator/window.mjs.map +0 -1
  254. package/esm/ai/src/planner/dag-scheduler.mjs +0 -97
  255. package/esm/ai/src/planner/dag-scheduler.mjs.map +0 -1
  256. package/esm/ai/src/planner/index.mjs +0 -6
  257. package/esm/ai/src/planner/plan-prompt.mjs +0 -31
  258. package/esm/ai/src/planner/plan-prompt.mjs.map +0 -1
  259. package/esm/ai/src/planner/plan-schema.mjs +0 -120
  260. package/esm/ai/src/planner/plan-schema.mjs.map +0 -1
  261. package/esm/ai/src/planner/planner-run.mjs +0 -769
  262. package/esm/ai/src/planner/planner-run.mjs.map +0 -1
  263. package/esm/ai/src/planner/planner.mjs +0 -144
  264. package/esm/ai/src/planner/planner.mjs.map +0 -1
  265. package/esm/ai/src/planner/signature.mjs +0 -27
  266. package/esm/ai/src/planner/signature.mjs.map +0 -1
  267. package/esm/ai/src/planner/snapshot.mjs +0 -95
  268. package/esm/ai/src/planner/snapshot.mjs.map +0 -1
  269. package/esm/ai/src/prompt/errors.mjs +0 -73
  270. package/esm/ai/src/prompt/errors.mjs.map +0 -1
  271. package/esm/ai/src/prompt/index.mjs +0 -4
  272. package/esm/ai/src/prompt/prompt-langfuse-sync.mjs +0 -104
  273. package/esm/ai/src/prompt/prompt-langfuse-sync.mjs.map +0 -1
  274. package/esm/ai/src/prompt/prompt-validate.mjs +0 -170
  275. package/esm/ai/src/prompt/prompt-validate.mjs.map +0 -1
  276. package/esm/ai/src/prompt/prompt.mjs +0 -218
  277. package/esm/ai/src/prompt/prompt.mjs.map +0 -1
  278. package/esm/ai/src/prompts/index.mjs +0 -3
  279. package/esm/ai/src/prompts/prompts-manager.mjs +0 -410
  280. package/esm/ai/src/prompts/prompts-manager.mjs.map +0 -1
  281. package/esm/ai/src/prompts/prompts-validate.mjs +0 -0
  282. package/esm/ai/src/prompts/prompts-validate.mjs.map +0 -1
  283. package/esm/ai/src/rag/as-tool.mjs +0 -48
  284. package/esm/ai/src/rag/as-tool.mjs.map +0 -1
  285. package/esm/ai/src/rag/chunk/chunk.mjs +0 -44
  286. package/esm/ai/src/rag/chunk/chunk.mjs.map +0 -1
  287. package/esm/ai/src/rag/chunk/fixed.mjs +0 -32
  288. package/esm/ai/src/rag/chunk/fixed.mjs.map +0 -1
  289. package/esm/ai/src/rag/chunk/markdown.mjs +0 -75
  290. package/esm/ai/src/rag/chunk/markdown.mjs.map +0 -1
  291. package/esm/ai/src/rag/chunk/recursive.mjs +0 -132
  292. package/esm/ai/src/rag/chunk/recursive.mjs.map +0 -1
  293. package/esm/ai/src/rag/chunk/sentence.mjs +0 -73
  294. package/esm/ai/src/rag/chunk/sentence.mjs.map +0 -1
  295. package/esm/ai/src/rag/hybrid/bm25.mjs +0 -51
  296. package/esm/ai/src/rag/hybrid/bm25.mjs.map +0 -1
  297. package/esm/ai/src/rag/hybrid/hybrid-rank.mjs +0 -29
  298. package/esm/ai/src/rag/hybrid/hybrid-rank.mjs.map +0 -1
  299. package/esm/ai/src/rag/hybrid/rrf.mjs +0 -30
  300. package/esm/ai/src/rag/hybrid/rrf.mjs.map +0 -1
  301. package/esm/ai/src/rag/index.mjs +0 -18
  302. package/esm/ai/src/rag/loaders/errors.mjs +0 -25
  303. package/esm/ai/src/rag/loaders/errors.mjs.map +0 -1
  304. package/esm/ai/src/rag/loaders/index.mjs +0 -7
  305. package/esm/ai/src/rag/loaders/load-html.mjs +0 -138
  306. package/esm/ai/src/rag/loaders/load-html.mjs.map +0 -1
  307. package/esm/ai/src/rag/loaders/load-pdf.mjs +0 -150
  308. package/esm/ai/src/rag/loaders/load-pdf.mjs.map +0 -1
  309. package/esm/ai/src/rag/loaders/load-text.mjs +0 -60
  310. package/esm/ai/src/rag/loaders/load-text.mjs.map +0 -1
  311. package/esm/ai/src/rag/loaders/load-web.mjs +0 -89
  312. package/esm/ai/src/rag/loaders/load-web.mjs.map +0 -1
  313. package/esm/ai/src/rag/rag.mjs +0 -126
  314. package/esm/ai/src/rag/rag.mjs.map +0 -1
  315. package/esm/ai/src/rag/rerank/keyword-reranker.mjs +0 -58
  316. package/esm/ai/src/rag/rerank/keyword-reranker.mjs.map +0 -1
  317. package/esm/ai/src/rag/rerank/llm-reranker.mjs +0 -85
  318. package/esm/ai/src/rag/rerank/llm-reranker.mjs.map +0 -1
  319. package/esm/ai/src/rag/retrieve.mjs +0 -68
  320. package/esm/ai/src/rag/retrieve.mjs.map +0 -1
  321. package/esm/ai/src/rag/store/cache-vector-store.mjs +0 -48
  322. package/esm/ai/src/rag/store/cache-vector-store.mjs.map +0 -1
  323. package/esm/ai/src/rag/store/pg-vector-store.mjs +0 -328
  324. package/esm/ai/src/rag/store/pg-vector-store.mjs.map +0 -1
  325. package/esm/ai/src/rag/transforms/multi-query.mjs +0 -41
  326. package/esm/ai/src/rag/transforms/multi-query.mjs.map +0 -1
  327. package/esm/ai/src/security/index.mjs +0 -5
  328. package/esm/ai/src/security/outbound-policy.mjs +0 -187
  329. package/esm/ai/src/security/outbound-policy.mjs.map +0 -1
  330. package/esm/ai/src/security/private-ip.mjs +0 -48
  331. package/esm/ai/src/security/private-ip.mjs.map +0 -1
  332. package/esm/ai/src/security/redact.mjs +0 -60
  333. package/esm/ai/src/security/redact.mjs.map +0 -1
  334. package/esm/ai/src/serve/serve.mjs +0 -90
  335. package/esm/ai/src/serve/serve.mjs.map +0 -1
  336. package/esm/ai/src/serve/sse.mjs +0 -25
  337. package/esm/ai/src/serve/sse.mjs.map +0 -1
  338. package/esm/ai/src/serve/stream-to-sse.mjs +0 -37
  339. package/esm/ai/src/serve/stream-to-sse.mjs.map +0 -1
  340. package/esm/ai/src/skills/catalog.mjs +0 -140
  341. package/esm/ai/src/skills/catalog.mjs.map +0 -1
  342. package/esm/ai/src/skills/index.mjs +0 -11
  343. package/esm/ai/src/skills/load-skill-tool.mjs +0 -65
  344. package/esm/ai/src/skills/load-skill-tool.mjs.map +0 -1
  345. package/esm/ai/src/skills/save-skill-tool.mjs +0 -65
  346. package/esm/ai/src/skills/save-skill-tool.mjs.map +0 -1
  347. package/esm/ai/src/skills/skills.mjs +0 -109
  348. package/esm/ai/src/skills/skills.mjs.map +0 -1
  349. package/esm/ai/src/skills/sources/directory-source.mjs +0 -108
  350. package/esm/ai/src/skills/sources/directory-source.mjs.map +0 -1
  351. package/esm/ai/src/skills/sources/index.mjs +0 -27
  352. package/esm/ai/src/skills/sources/index.mjs.map +0 -1
  353. package/esm/ai/src/skills/sources/parse-frontmatter.mjs +0 -46
  354. package/esm/ai/src/skills/sources/parse-frontmatter.mjs.map +0 -1
  355. package/esm/ai/src/skills/sources/store-source.mjs +0 -15
  356. package/esm/ai/src/skills/sources/store-source.mjs.map +0 -1
  357. package/esm/ai/src/skills/sources/url-source.mjs +0 -117
  358. package/esm/ai/src/skills/sources/url-source.mjs.map +0 -1
  359. package/esm/ai/src/snapshot/memory.mjs +0 -81
  360. package/esm/ai/src/snapshot/memory.mjs.map +0 -1
  361. package/esm/ai/src/snapshot/pg.mjs +0 -146
  362. package/esm/ai/src/snapshot/pg.mjs.map +0 -1
  363. package/esm/ai/src/snapshot/redis.mjs +0 -101
  364. package/esm/ai/src/snapshot/redis.mjs.map +0 -1
  365. package/esm/ai/src/speech/index.mjs +0 -3
  366. package/esm/ai/src/speech/speech.mjs +0 -122
  367. package/esm/ai/src/speech/speech.mjs.map +0 -1
  368. package/esm/ai/src/supervisor/as-tool.mjs +0 -74
  369. package/esm/ai/src/supervisor/as-tool.mjs.map +0 -1
  370. package/esm/ai/src/supervisor/cancellation.mjs +0 -22
  371. package/esm/ai/src/supervisor/cancellation.mjs.map +0 -1
  372. package/esm/ai/src/supervisor/decide.mjs +0 -272
  373. package/esm/ai/src/supervisor/decide.mjs.map +0 -1
  374. package/esm/ai/src/supervisor/emitter.mjs +0 -47
  375. package/esm/ai/src/supervisor/emitter.mjs.map +0 -1
  376. package/esm/ai/src/supervisor/entries.mjs +0 -206
  377. package/esm/ai/src/supervisor/entries.mjs.map +0 -1
  378. package/esm/ai/src/supervisor/execution.mjs +0 -1921
  379. package/esm/ai/src/supervisor/execution.mjs.map +0 -1
  380. package/esm/ai/src/supervisor/fan-out.mjs +0 -65
  381. package/esm/ai/src/supervisor/fan-out.mjs.map +0 -1
  382. package/esm/ai/src/supervisor/index.mjs +0 -14
  383. package/esm/ai/src/supervisor/router-factory.mjs +0 -141
  384. package/esm/ai/src/supervisor/router-factory.mjs.map +0 -1
  385. package/esm/ai/src/supervisor/router-prompt.mjs +0 -52
  386. package/esm/ai/src/supervisor/router-prompt.mjs.map +0 -1
  387. package/esm/ai/src/supervisor/signature.mjs +0 -89
  388. package/esm/ai/src/supervisor/signature.mjs.map +0 -1
  389. package/esm/ai/src/supervisor/snapshot.mjs +0 -69
  390. package/esm/ai/src/supervisor/snapshot.mjs.map +0 -1
  391. package/esm/ai/src/supervisor/supervisor-stream.mjs +0 -89
  392. package/esm/ai/src/supervisor/supervisor-stream.mjs.map +0 -1
  393. package/esm/ai/src/supervisor/supervisor.mjs +0 -144
  394. package/esm/ai/src/supervisor/supervisor.mjs.map +0 -1
  395. package/esm/ai/src/system-prompt/index.mjs +0 -7
  396. package/esm/ai/src/system-prompt/instruction.mjs +0 -57
  397. package/esm/ai/src/system-prompt/instruction.mjs.map +0 -1
  398. package/esm/ai/src/system-prompt/persona.mjs +0 -57
  399. package/esm/ai/src/system-prompt/persona.mjs.map +0 -1
  400. package/esm/ai/src/system-prompt/refined-system-prompt.mjs +0 -461
  401. package/esm/ai/src/system-prompt/refined-system-prompt.mjs.map +0 -1
  402. package/esm/ai/src/system-prompt/render-placeholders.mjs +0 -58
  403. package/esm/ai/src/system-prompt/render-placeholders.mjs.map +0 -1
  404. package/esm/ai/src/system-prompt/system-prompt.mjs +0 -286
  405. package/esm/ai/src/system-prompt/system-prompt.mjs.map +0 -1
  406. package/esm/ai/src/team/gates.mjs +0 -48
  407. package/esm/ai/src/team/gates.mjs.map +0 -1
  408. package/esm/ai/src/team/index.mjs +0 -3
  409. package/esm/ai/src/team/team.mjs +0 -94
  410. package/esm/ai/src/team/team.mjs.map +0 -1
  411. package/esm/ai/src/tool/executable-as-tool.mjs +0 -81
  412. package/esm/ai/src/tool/executable-as-tool.mjs.map +0 -1
  413. package/esm/ai/src/tool/index.mjs +0 -4
  414. package/esm/ai/src/tool/tool.mjs +0 -185
  415. package/esm/ai/src/tool/tool.mjs.map +0 -1
  416. package/esm/ai/src/transcribe/audio-input.mjs +0 -84
  417. package/esm/ai/src/transcribe/audio-input.mjs.map +0 -1
  418. package/esm/ai/src/transcribe/index.mjs +0 -4
  419. package/esm/ai/src/transcribe/transcribe.mjs +0 -127
  420. package/esm/ai/src/transcribe/transcribe.mjs.map +0 -1
  421. package/esm/ai/src/utils/compute-cost.mjs +0 -112
  422. package/esm/ai/src/utils/compute-cost.mjs.map +0 -1
  423. package/esm/ai/src/utils/extract-json-lenient.mjs +0 -97
  424. package/esm/ai/src/utils/extract-json-lenient.mjs.map +0 -1
  425. package/esm/ai/src/utils/extract-json-payload.mjs +0 -39
  426. package/esm/ai/src/utils/extract-json-payload.mjs.map +0 -1
  427. package/esm/ai/src/utils/generate-run-id.mjs +0 -23
  428. package/esm/ai/src/utils/generate-run-id.mjs.map +0 -1
  429. package/esm/ai/src/utils/index.mjs +0 -12
  430. package/esm/ai/src/utils/json-schema.mjs +0 -89
  431. package/esm/ai/src/utils/json-schema.mjs.map +0 -1
  432. package/esm/ai/src/utils/prepare-attachment-part.mjs +0 -232
  433. package/esm/ai/src/utils/prepare-attachment-part.mjs.map +0 -1
  434. package/esm/ai/src/utils/resolve-attachment.mjs +0 -74
  435. package/esm/ai/src/utils/resolve-attachment.mjs.map +0 -1
  436. package/esm/ai/src/utils/run-context.mjs +0 -89
  437. package/esm/ai/src/utils/run-context.mjs.map +0 -1
  438. package/esm/ai/src/utils/safe-json-parse.mjs +0 -22
  439. package/esm/ai/src/utils/safe-json-parse.mjs.map +0 -1
  440. package/esm/ai/src/utils/stamp-report-lineage.mjs +0 -45
  441. package/esm/ai/src/utils/stamp-report-lineage.mjs.map +0 -1
  442. package/esm/ai/src/vcr/cassette-io.mjs +0 -57
  443. package/esm/ai/src/vcr/cassette-io.mjs.map +0 -1
  444. package/esm/ai/src/vcr/errors.mjs +0 -37
  445. package/esm/ai/src/vcr/errors.mjs.map +0 -1
  446. package/esm/ai/src/vcr/hash-request.mjs +0 -118
  447. package/esm/ai/src/vcr/hash-request.mjs.map +0 -1
  448. package/esm/ai/src/vcr/index.mjs +0 -5
  449. package/esm/ai/src/vcr/vcr.mjs +0 -248
  450. package/esm/ai/src/vcr/vcr.mjs.map +0 -1
  451. package/esm/ai/src/workflow/as-tool.mjs +0 -49
  452. package/esm/ai/src/workflow/as-tool.mjs.map +0 -1
  453. package/esm/ai/src/workflow/cancellation.mjs +0 -44
  454. package/esm/ai/src/workflow/cancellation.mjs.map +0 -1
  455. package/esm/ai/src/workflow/emitter.mjs +0 -40
  456. package/esm/ai/src/workflow/emitter.mjs.map +0 -1
  457. package/esm/ai/src/workflow/engine.mjs +0 -363
  458. package/esm/ai/src/workflow/engine.mjs.map +0 -1
  459. package/esm/ai/src/workflow/index.mjs +0 -5
  460. package/esm/ai/src/workflow/retry.mjs +0 -32
  461. package/esm/ai/src/workflow/retry.mjs.map +0 -1
  462. package/esm/ai/src/workflow/router.mjs +0 -56
  463. package/esm/ai/src/workflow/router.mjs.map +0 -1
  464. package/esm/ai/src/workflow/run-scoped-emitter.mjs +0 -32
  465. package/esm/ai/src/workflow/run-scoped-emitter.mjs.map +0 -1
  466. package/esm/ai/src/workflow/signature.mjs +0 -34
  467. package/esm/ai/src/workflow/signature.mjs.map +0 -1
  468. package/esm/ai/src/workflow/snapshot.mjs +0 -77
  469. package/esm/ai/src/workflow/snapshot.mjs.map +0 -1
  470. package/esm/ai/src/workflow/state.mjs +0 -37
  471. package/esm/ai/src/workflow/state.mjs.map +0 -1
  472. package/esm/ai/src/workflow/step-runner.mjs +0 -370
  473. package/esm/ai/src/workflow/step-runner.mjs.map +0 -1
  474. package/esm/ai/src/workflow/step.mjs +0 -37
  475. package/esm/ai/src/workflow/step.mjs.map +0 -1
  476. package/esm/ai/src/workflow/workflow.mjs +0 -122
  477. package/esm/ai/src/workflow/workflow.mjs.map +0 -1
  478. package/esm/ai-openai/src/embedder.mjs +0 -4
  479. package/esm/ai-openai/src/image.mjs +0 -5
  480. package/esm/ai-openai/src/index.mjs +0 -7
  481. package/esm/ai-openai/src/model.mjs +0 -5
  482. package/esm/ai-openai/src/sdk.mjs +0 -9
  483. package/esm/ai-openai/src/speech.mjs +0 -5
  484. package/esm/ai-openai/src/transcription.mjs +0 -6
  485. package/esm/ai-openai/src/utils/index.mjs +0 -5
  486. package/esm/ai-openai/src/utils/to-openai-messages.mjs +0 -3
  487. package/esm/ai-openai/src/utils/to-openai-tools.mjs +0 -3
  488. package/esm/ai-openai/src/utils/wrap-openai-error.mjs +0 -4
  489. package/esm/node_modules/langfuse/lib/index.mjs +0 -1827
  490. package/esm/node_modules/langfuse/lib/index.mjs.map +0 -1
  491. package/esm/node_modules/langfuse-core/lib/index.mjs +0 -1770
  492. package/esm/node_modules/langfuse-core/lib/index.mjs.map +0 -1
  493. package/esm/node_modules/mustache/mustache.mjs +0 -587
  494. package/esm/node_modules/mustache/mustache.mjs.map +0 -1
  495. package/esm/node_modules/openai/_vendor/partial-json-parser/parser.mjs +0 -180
  496. package/esm/node_modules/openai/_vendor/partial-json-parser/parser.mjs.map +0 -1
  497. package/esm/node_modules/openai/auth/workload-identity-auth.mjs +0 -80
  498. package/esm/node_modules/openai/auth/workload-identity-auth.mjs.map +0 -1
  499. package/esm/node_modules/openai/azure.mjs +0 -82
  500. package/esm/node_modules/openai/azure.mjs.map +0 -1
  501. package/esm/node_modules/openai/client.mjs +0 -638
  502. package/esm/node_modules/openai/client.mjs.map +0 -1
  503. package/esm/node_modules/openai/core/api-promise.mjs +0 -75
  504. package/esm/node_modules/openai/core/api-promise.mjs.map +0 -1
  505. package/esm/node_modules/openai/core/error.mjs +0 -110
  506. package/esm/node_modules/openai/core/error.mjs.map +0 -1
  507. package/esm/node_modules/openai/core/pagination.mjs +0 -160
  508. package/esm/node_modules/openai/core/pagination.mjs.map +0 -1
  509. package/esm/node_modules/openai/core/resource.mjs +0 -10
  510. package/esm/node_modules/openai/core/resource.mjs.map +0 -1
  511. package/esm/node_modules/openai/core/streaming.mjs +0 -238
  512. package/esm/node_modules/openai/core/streaming.mjs.map +0 -1
  513. package/esm/node_modules/openai/index.mjs +0 -8
  514. package/esm/node_modules/openai/internal/decoders/line.mjs +0 -91
  515. package/esm/node_modules/openai/internal/decoders/line.mjs.map +0 -1
  516. package/esm/node_modules/openai/internal/detect-platform.mjs +0 -123
  517. package/esm/node_modules/openai/internal/detect-platform.mjs.map +0 -1
  518. package/esm/node_modules/openai/internal/errors.mjs +0 -26
  519. package/esm/node_modules/openai/internal/errors.mjs.map +0 -1
  520. package/esm/node_modules/openai/internal/headers.mjs +0 -65
  521. package/esm/node_modules/openai/internal/headers.mjs.map +0 -1
  522. package/esm/node_modules/openai/internal/parse.mjs +0 -41
  523. package/esm/node_modules/openai/internal/parse.mjs.map +0 -1
  524. package/esm/node_modules/openai/internal/qs/formats.mjs +0 -12
  525. package/esm/node_modules/openai/internal/qs/formats.mjs.map +0 -1
  526. package/esm/node_modules/openai/internal/qs/stringify.mjs +0 -179
  527. package/esm/node_modules/openai/internal/qs/stringify.mjs.map +0 -1
  528. package/esm/node_modules/openai/internal/qs/utils.mjs +0 -65
  529. package/esm/node_modules/openai/internal/qs/utils.mjs.map +0 -1
  530. package/esm/node_modules/openai/internal/request-options.mjs +0 -11
  531. package/esm/node_modules/openai/internal/request-options.mjs.map +0 -1
  532. package/esm/node_modules/openai/internal/shims.mjs +0 -77
  533. package/esm/node_modules/openai/internal/shims.mjs.map +0 -1
  534. package/esm/node_modules/openai/internal/to-file.mjs +0 -63
  535. package/esm/node_modules/openai/internal/to-file.mjs.map +0 -1
  536. package/esm/node_modules/openai/internal/tslib.mjs +0 -16
  537. package/esm/node_modules/openai/internal/tslib.mjs.map +0 -1
  538. package/esm/node_modules/openai/internal/uploads.mjs +0 -94
  539. package/esm/node_modules/openai/internal/uploads.mjs.map +0 -1
  540. package/esm/node_modules/openai/internal/utils/base64.mjs +0 -22
  541. package/esm/node_modules/openai/internal/utils/base64.mjs.map +0 -1
  542. package/esm/node_modules/openai/internal/utils/bytes.mjs +0 -26
  543. package/esm/node_modules/openai/internal/utils/bytes.mjs.map +0 -1
  544. package/esm/node_modules/openai/internal/utils/env.mjs +0 -16
  545. package/esm/node_modules/openai/internal/utils/env.mjs.map +0 -1
  546. package/esm/node_modules/openai/internal/utils/log.mjs +0 -58
  547. package/esm/node_modules/openai/internal/utils/log.mjs.map +0 -1
  548. package/esm/node_modules/openai/internal/utils/path.mjs +0 -62
  549. package/esm/node_modules/openai/internal/utils/path.mjs.map +0 -1
  550. package/esm/node_modules/openai/internal/utils/query.mjs +0 -10
  551. package/esm/node_modules/openai/internal/utils/query.mjs.map +0 -1
  552. package/esm/node_modules/openai/internal/utils/sleep.mjs +0 -6
  553. package/esm/node_modules/openai/internal/utils/sleep.mjs.map +0 -1
  554. package/esm/node_modules/openai/internal/utils/uuid.mjs +0 -18
  555. package/esm/node_modules/openai/internal/utils/uuid.mjs.map +0 -1
  556. package/esm/node_modules/openai/internal/utils/values.mjs +0 -41
  557. package/esm/node_modules/openai/internal/utils/values.mjs.map +0 -1
  558. package/esm/node_modules/openai/lib/AbstractChatCompletionRunner.mjs +0 -247
  559. package/esm/node_modules/openai/lib/AbstractChatCompletionRunner.mjs.map +0 -1
  560. package/esm/node_modules/openai/lib/AssistantStream.mjs +0 -472
  561. package/esm/node_modules/openai/lib/AssistantStream.mjs.map +0 -1
  562. package/esm/node_modules/openai/lib/ChatCompletionRunner.mjs +0 -26
  563. package/esm/node_modules/openai/lib/ChatCompletionRunner.mjs.map +0 -1
  564. package/esm/node_modules/openai/lib/ChatCompletionStream.mjs +0 -423
  565. package/esm/node_modules/openai/lib/ChatCompletionStream.mjs.map +0 -1
  566. package/esm/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs +0 -26
  567. package/esm/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs.map +0 -1
  568. package/esm/node_modules/openai/lib/EventStream.mjs +0 -163
  569. package/esm/node_modules/openai/lib/EventStream.mjs.map +0 -1
  570. package/esm/node_modules/openai/lib/ResponsesParser.mjs +0 -94
  571. package/esm/node_modules/openai/lib/ResponsesParser.mjs.map +0 -1
  572. package/esm/node_modules/openai/lib/RunnableFunction.mjs +0 -8
  573. package/esm/node_modules/openai/lib/RunnableFunction.mjs.map +0 -1
  574. package/esm/node_modules/openai/lib/Util.mjs +0 -19
  575. package/esm/node_modules/openai/lib/Util.mjs.map +0 -1
  576. package/esm/node_modules/openai/lib/chatCompletionUtils.mjs +0 -11
  577. package/esm/node_modules/openai/lib/chatCompletionUtils.mjs.map +0 -1
  578. package/esm/node_modules/openai/lib/parser.mjs +0 -88
  579. package/esm/node_modules/openai/lib/parser.mjs.map +0 -1
  580. package/esm/node_modules/openai/lib/responses/ResponseStream.mjs +0 -231
  581. package/esm/node_modules/openai/lib/responses/ResponseStream.mjs.map +0 -1
  582. package/esm/node_modules/openai/resources/admin/admin.mjs +0 -15
  583. package/esm/node_modules/openai/resources/admin/admin.mjs.map +0 -1
  584. package/esm/node_modules/openai/resources/admin/organization/admin-api-keys.mjs +0 -81
  585. package/esm/node_modules/openai/resources/admin/organization/admin-api-keys.mjs.map +0 -1
  586. package/esm/node_modules/openai/resources/admin/organization/audit-logs.mjs +0 -31
  587. package/esm/node_modules/openai/resources/admin/organization/audit-logs.mjs.map +0 -1
  588. package/esm/node_modules/openai/resources/admin/organization/certificates.mjs +0 -153
  589. package/esm/node_modules/openai/resources/admin/organization/certificates.mjs.map +0 -1
  590. package/esm/node_modules/openai/resources/admin/organization/data-retention.mjs +0 -42
  591. package/esm/node_modules/openai/resources/admin/organization/data-retention.mjs.map +0 -1
  592. package/esm/node_modules/openai/resources/admin/organization/groups/groups.mjs +0 -106
  593. package/esm/node_modules/openai/resources/admin/organization/groups/groups.mjs.map +0 -1
  594. package/esm/node_modules/openai/resources/admin/organization/groups/roles.mjs +0 -88
  595. package/esm/node_modules/openai/resources/admin/organization/groups/roles.mjs.map +0 -1
  596. package/esm/node_modules/openai/resources/admin/organization/groups/users.mjs +0 -88
  597. package/esm/node_modules/openai/resources/admin/organization/groups/users.mjs.map +0 -1
  598. package/esm/node_modules/openai/resources/admin/organization/invites.mjs +0 -83
  599. package/esm/node_modules/openai/resources/admin/organization/invites.mjs.map +0 -1
  600. package/esm/node_modules/openai/resources/admin/organization/organization.mjs +0 -45
  601. package/esm/node_modules/openai/resources/admin/organization/organization.mjs.map +0 -1
  602. package/esm/node_modules/openai/resources/admin/organization/projects/api-keys.mjs +0 -72
  603. package/esm/node_modules/openai/resources/admin/organization/projects/api-keys.mjs.map +0 -1
  604. package/esm/node_modules/openai/resources/admin/organization/projects/certificates.mjs +0 -78
  605. package/esm/node_modules/openai/resources/admin/organization/projects/certificates.mjs.map +0 -1
  606. package/esm/node_modules/openai/resources/admin/organization/projects/data-retention.mjs +0 -46
  607. package/esm/node_modules/openai/resources/admin/organization/projects/data-retention.mjs.map +0 -1
  608. package/esm/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs +0 -95
  609. package/esm/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs.map +0 -1
  610. package/esm/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs +0 -91
  611. package/esm/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs.map +0 -1
  612. package/esm/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs +0 -45
  613. package/esm/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs.map +0 -1
  614. package/esm/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs +0 -63
  615. package/esm/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs.map +0 -1
  616. package/esm/node_modules/openai/resources/admin/organization/projects/projects.mjs +0 -137
  617. package/esm/node_modules/openai/resources/admin/organization/projects/projects.mjs.map +0 -1
  618. package/esm/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs +0 -51
  619. package/esm/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs.map +0 -1
  620. package/esm/node_modules/openai/resources/admin/organization/projects/roles.mjs +0 -108
  621. package/esm/node_modules/openai/resources/admin/organization/projects/roles.mjs.map +0 -1
  622. package/esm/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs +0 -112
  623. package/esm/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs.map +0 -1
  624. package/esm/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs +0 -106
  625. package/esm/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs.map +0 -1
  626. package/esm/node_modules/openai/resources/admin/organization/projects/users/roles.mjs +0 -91
  627. package/esm/node_modules/openai/resources/admin/organization/projects/users/roles.mjs.map +0 -1
  628. package/esm/node_modules/openai/resources/admin/organization/projects/users/users.mjs +0 -118
  629. package/esm/node_modules/openai/resources/admin/organization/projects/users/users.mjs.map +0 -1
  630. package/esm/node_modules/openai/resources/admin/organization/roles.mjs +0 -96
  631. package/esm/node_modules/openai/resources/admin/organization/roles.mjs.map +0 -1
  632. package/esm/node_modules/openai/resources/admin/organization/spend-alerts.mjs +0 -97
  633. package/esm/node_modules/openai/resources/admin/organization/spend-alerts.mjs.map +0 -1
  634. package/esm/node_modules/openai/resources/admin/organization/usage.mjs +0 -207
  635. package/esm/node_modules/openai/resources/admin/organization/usage.mjs.map +0 -1
  636. package/esm/node_modules/openai/resources/admin/organization/users/roles.mjs +0 -88
  637. package/esm/node_modules/openai/resources/admin/organization/users/roles.mjs.map +0 -1
  638. package/esm/node_modules/openai/resources/admin/organization/users/users.mjs +0 -82
  639. package/esm/node_modules/openai/resources/admin/organization/users/users.mjs.map +0 -1
  640. package/esm/node_modules/openai/resources/audio/audio.mjs +0 -21
  641. package/esm/node_modules/openai/resources/audio/audio.mjs.map +0 -1
  642. package/esm/node_modules/openai/resources/audio/speech.mjs +0 -39
  643. package/esm/node_modules/openai/resources/audio/speech.mjs.map +0 -1
  644. package/esm/node_modules/openai/resources/audio/transcriptions.mjs +0 -22
  645. package/esm/node_modules/openai/resources/audio/transcriptions.mjs.map +0 -1
  646. package/esm/node_modules/openai/resources/audio/translations.mjs +0 -21
  647. package/esm/node_modules/openai/resources/audio/translations.mjs.map +0 -1
  648. package/esm/node_modules/openai/resources/batches.mjs +0 -54
  649. package/esm/node_modules/openai/resources/batches.mjs.map +0 -1
  650. package/esm/node_modules/openai/resources/beta/assistants.mjs +0 -78
  651. package/esm/node_modules/openai/resources/beta/assistants.mjs.map +0 -1
  652. package/esm/node_modules/openai/resources/beta/beta.mjs +0 -24
  653. package/esm/node_modules/openai/resources/beta/beta.mjs.map +0 -1
  654. package/esm/node_modules/openai/resources/beta/chatkit/chatkit.mjs +0 -18
  655. package/esm/node_modules/openai/resources/beta/chatkit/chatkit.mjs.map +0 -1
  656. package/esm/node_modules/openai/resources/beta/chatkit/sessions.mjs +0 -49
  657. package/esm/node_modules/openai/resources/beta/chatkit/sessions.mjs.map +0 -1
  658. package/esm/node_modules/openai/resources/beta/chatkit/threads.mjs +0 -85
  659. package/esm/node_modules/openai/resources/beta/chatkit/threads.mjs.map +0 -1
  660. package/esm/node_modules/openai/resources/beta/realtime/realtime.mjs +0 -21
  661. package/esm/node_modules/openai/resources/beta/realtime/realtime.mjs.map +0 -1
  662. package/esm/node_modules/openai/resources/beta/realtime/sessions.mjs +0 -33
  663. package/esm/node_modules/openai/resources/beta/realtime/sessions.mjs.map +0 -1
  664. package/esm/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs +0 -33
  665. package/esm/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs.map +0 -1
  666. package/esm/node_modules/openai/resources/beta/threads/messages.mjs +0 -83
  667. package/esm/node_modules/openai/resources/beta/threads/messages.mjs.map +0 -1
  668. package/esm/node_modules/openai/resources/beta/threads/runs/runs.mjs +0 -183
  669. package/esm/node_modules/openai/resources/beta/threads/runs/runs.mjs.map +0 -1
  670. package/esm/node_modules/openai/resources/beta/threads/runs/steps.mjs +0 -45
  671. package/esm/node_modules/openai/resources/beta/threads/runs/steps.mjs.map +0 -1
  672. package/esm/node_modules/openai/resources/beta/threads/threads.mjs +0 -101
  673. package/esm/node_modules/openai/resources/beta/threads/threads.mjs.map +0 -1
  674. package/esm/node_modules/openai/resources/chat/chat.mjs +0 -15
  675. package/esm/node_modules/openai/resources/chat/chat.mjs.map +0 -1
  676. package/esm/node_modules/openai/resources/chat/completions/completions.mjs +0 -123
  677. package/esm/node_modules/openai/resources/chat/completions/completions.mjs.map +0 -1
  678. package/esm/node_modules/openai/resources/chat/completions/index.mjs +0 -7
  679. package/esm/node_modules/openai/resources/chat/completions/messages.mjs +0 -35
  680. package/esm/node_modules/openai/resources/chat/completions/messages.mjs.map +0 -1
  681. package/esm/node_modules/openai/resources/chat/index.mjs +0 -5
  682. package/esm/node_modules/openai/resources/completions.mjs +0 -20
  683. package/esm/node_modules/openai/resources/completions.mjs.map +0 -1
  684. package/esm/node_modules/openai/resources/containers/containers.mjs +0 -57
  685. package/esm/node_modules/openai/resources/containers/containers.mjs.map +0 -1
  686. package/esm/node_modules/openai/resources/containers/files/content.mjs +0 -23
  687. package/esm/node_modules/openai/resources/containers/files/content.mjs.map +0 -1
  688. package/esm/node_modules/openai/resources/containers/files/files.mjs +0 -63
  689. package/esm/node_modules/openai/resources/containers/files/files.mjs.map +0 -1
  690. package/esm/node_modules/openai/resources/conversations/conversations.mjs +0 -57
  691. package/esm/node_modules/openai/resources/conversations/conversations.mjs.map +0 -1
  692. package/esm/node_modules/openai/resources/conversations/items.mjs +0 -57
  693. package/esm/node_modules/openai/resources/conversations/items.mjs.map +0 -1
  694. package/esm/node_modules/openai/resources/embeddings.mjs +0 -48
  695. package/esm/node_modules/openai/resources/embeddings.mjs.map +0 -1
  696. package/esm/node_modules/openai/resources/evals/evals.mjs +0 -73
  697. package/esm/node_modules/openai/resources/evals/evals.mjs.map +0 -1
  698. package/esm/node_modules/openai/resources/evals/runs/output-items.mjs +0 -35
  699. package/esm/node_modules/openai/resources/evals/runs/output-items.mjs.map +0 -1
  700. package/esm/node_modules/openai/resources/evals/runs/runs.mjs +0 -72
  701. package/esm/node_modules/openai/resources/evals/runs/runs.mjs.map +0 -1
  702. package/esm/node_modules/openai/resources/files.mjs +0 -111
  703. package/esm/node_modules/openai/resources/files.mjs.map +0 -1
  704. package/esm/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs +0 -15
  705. package/esm/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs.map +0 -1
  706. package/esm/node_modules/openai/resources/fine-tuning/alpha/graders.mjs +0 -60
  707. package/esm/node_modules/openai/resources/fine-tuning/alpha/graders.mjs.map +0 -1
  708. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs +0 -15
  709. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs.map +0 -1
  710. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs +0 -102
  711. package/esm/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs.map +0 -1
  712. package/esm/node_modules/openai/resources/fine-tuning/fine-tuning.mjs +0 -24
  713. package/esm/node_modules/openai/resources/fine-tuning/fine-tuning.mjs.map +0 -1
  714. package/esm/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs +0 -34
  715. package/esm/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs.map +0 -1
  716. package/esm/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs +0 -148
  717. package/esm/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs.map +0 -1
  718. package/esm/node_modules/openai/resources/fine-tuning/methods.mjs +0 -8
  719. package/esm/node_modules/openai/resources/fine-tuning/methods.mjs.map +0 -1
  720. package/esm/node_modules/openai/resources/graders/grader-models.mjs +0 -8
  721. package/esm/node_modules/openai/resources/graders/grader-models.mjs.map +0 -1
  722. package/esm/node_modules/openai/resources/graders/graders.mjs +0 -15
  723. package/esm/node_modules/openai/resources/graders/graders.mjs.map +0 -1
  724. package/esm/node_modules/openai/resources/images.mjs +0 -46
  725. package/esm/node_modules/openai/resources/images.mjs.map +0 -1
  726. package/esm/node_modules/openai/resources/index.mjs +0 -27
  727. package/esm/node_modules/openai/resources/models.mjs +0 -44
  728. package/esm/node_modules/openai/resources/models.mjs.map +0 -1
  729. package/esm/node_modules/openai/resources/moderations.mjs +0 -23
  730. package/esm/node_modules/openai/resources/moderations.mjs.map +0 -1
  731. package/esm/node_modules/openai/resources/realtime/calls.mjs +0 -79
  732. package/esm/node_modules/openai/resources/realtime/calls.mjs.map +0 -1
  733. package/esm/node_modules/openai/resources/realtime/client-secrets.mjs +0 -39
  734. package/esm/node_modules/openai/resources/realtime/client-secrets.mjs.map +0 -1
  735. package/esm/node_modules/openai/resources/realtime/realtime.mjs +0 -18
  736. package/esm/node_modules/openai/resources/realtime/realtime.mjs.map +0 -1
  737. package/esm/node_modules/openai/resources/responses/input-items.mjs +0 -31
  738. package/esm/node_modules/openai/resources/responses/input-items.mjs.map +0 -1
  739. package/esm/node_modules/openai/resources/responses/input-tokens.mjs +0 -27
  740. package/esm/node_modules/openai/resources/responses/input-tokens.mjs.map +0 -1
  741. package/esm/node_modules/openai/resources/responses/responses.mjs +0 -110
  742. package/esm/node_modules/openai/resources/responses/responses.mjs.map +0 -1
  743. package/esm/node_modules/openai/resources/skills/content.mjs +0 -22
  744. package/esm/node_modules/openai/resources/skills/content.mjs.map +0 -1
  745. package/esm/node_modules/openai/resources/skills/skills.mjs +0 -69
  746. package/esm/node_modules/openai/resources/skills/skills.mjs.map +0 -1
  747. package/esm/node_modules/openai/resources/skills/versions/content.mjs +0 -23
  748. package/esm/node_modules/openai/resources/skills/versions/content.mjs.map +0 -1
  749. package/esm/node_modules/openai/resources/skills/versions/versions.mjs +0 -58
  750. package/esm/node_modules/openai/resources/skills/versions/versions.mjs.map +0 -1
  751. package/esm/node_modules/openai/resources/uploads/parts.mjs +0 -34
  752. package/esm/node_modules/openai/resources/uploads/parts.mjs.map +0 -1
  753. package/esm/node_modules/openai/resources/uploads/uploads.mjs +0 -84
  754. package/esm/node_modules/openai/resources/uploads/uploads.mjs.map +0 -1
  755. package/esm/node_modules/openai/resources/vector-stores/file-batches.mjs +0 -126
  756. package/esm/node_modules/openai/resources/vector-stores/file-batches.mjs.map +0 -1
  757. package/esm/node_modules/openai/resources/vector-stores/files.mjs +0 -147
  758. package/esm/node_modules/openai/resources/vector-stores/files.mjs.map +0 -1
  759. package/esm/node_modules/openai/resources/vector-stores/vector-stores.mjs +0 -87
  760. package/esm/node_modules/openai/resources/vector-stores/vector-stores.mjs.map +0 -1
  761. package/esm/node_modules/openai/resources/videos.mjs +0 -115
  762. package/esm/node_modules/openai/resources/videos.mjs.map +0 -1
  763. package/esm/node_modules/openai/resources/webhooks/index.mjs +0 -3
  764. package/esm/node_modules/openai/resources/webhooks/webhooks.mjs +0 -69
  765. package/esm/node_modules/openai/resources/webhooks/webhooks.mjs.map +0 -1
  766. package/esm/node_modules/openai/resources/webhooks.mjs +0 -4
  767. package/esm/node_modules/openai/streaming.mjs +0 -3
  768. package/esm/node_modules/openai/version.mjs +0 -6
  769. package/esm/node_modules/openai/version.mjs.map +0 -1
@@ -1,138 +0,0 @@
1
- //#region ../@warlock.js/ai/src/rag/loaders/load-html.ts
2
- /** Default `id` when the caller supplies none. */
3
- const DEFAULT_ID = "document";
4
- /**
5
- * Elements whose *content* is not human-readable text and must be removed
6
- * wholesale (open tag → close tag → everything in between) before tags are
7
- * stripped. `script` / `style` would otherwise leak code into the chunked
8
- * text; `noscript` / `template` / `head` / `svg` are non-prose noise.
9
- */
10
- const STRIPPED_ELEMENTS = [
11
- "script",
12
- "style",
13
- "noscript",
14
- "template",
15
- "head",
16
- "svg"
17
- ];
18
- /**
19
- * Block-level tags that imply a line break in the readable text. Replacing
20
- * them with `\n` BEFORE the generic tag strip keeps paragraph / list / table
21
- * structure (so the recursive splitter still sees `\n\n` boundaries) instead
22
- * of collapsing the whole page onto one line.
23
- */
24
- const BLOCK_TAGS = /<\/?(?:p|div|section|article|header|footer|main|aside|nav|h[1-6]|ul|ol|li|table|tr|td|th|thead|tbody|blockquote|pre|hr|br)\b[^>]*>/gi;
25
- /** Named HTML entities common in prose. Numeric entities are decoded generically. */
26
- const NAMED_ENTITIES = {
27
- amp: "&",
28
- lt: "<",
29
- gt: ">",
30
- quot: "\"",
31
- apos: "'",
32
- nbsp: " ",
33
- copy: "©",
34
- reg: "®",
35
- trade: "™",
36
- hellip: "…",
37
- mdash: "—",
38
- ndash: "–",
39
- lsquo: "‘",
40
- rsquo: "’",
41
- ldquo: "“",
42
- rdquo: "”",
43
- laquo: "«",
44
- raquo: "»",
45
- middot: "·",
46
- bull: "•"
47
- };
48
- /**
49
- * Decode the HTML entities that survive tag stripping: named (`&amp;`),
50
- * decimal (`&#169;`), and hex (`&#xA9;`). Unknown named entities are left
51
- * verbatim rather than dropped, so unusual markup never silently loses text.
52
- */
53
- function decodeEntities(text) {
54
- return text.replace(/&(#x?[0-9a-f]+|[a-z][a-z0-9]*);/gi, (match, body) => {
55
- if (body[0] === "#") {
56
- const codePoint = body[1] === "x" || body[1] === "X" ? Number.parseInt(body.slice(2), 16) : Number.parseInt(body.slice(1), 10);
57
- if (Number.isNaN(codePoint) || codePoint < 0 || codePoint > 1114111) return match;
58
- try {
59
- return String.fromCodePoint(codePoint);
60
- } catch {
61
- return match;
62
- }
63
- }
64
- return NAMED_ENTITIES[body.toLowerCase()] ?? match;
65
- });
66
- }
67
- /**
68
- * Pull the `<title>` text out of the document, decoded and trimmed, or
69
- * `undefined` when there is none. Read BEFORE `<head>` is stripped.
70
- */
71
- function extractTitle(html) {
72
- const match = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);
73
- if (!match) return;
74
- const title = decodeEntities(match[1]).replace(/\s+/g, " ").trim();
75
- return title.length > 0 ? title : void 0;
76
- }
77
- /**
78
- * Strip HTML markup down to readable plain text — a lightweight,
79
- * dependency-free pass (no DOM parser): drop comments and non-prose elements
80
- * (`script` / `style` / `head` / `svg` / …) content-and-all, convert block
81
- * tags to line breaks to preserve paragraph structure, remove every
82
- * remaining tag, decode entities, then collapse runs of whitespace while
83
- * keeping blank-line paragraph separators.
84
- */
85
- function htmlToText(html) {
86
- let text = html;
87
- text = text.replace(/<!--[\s\S]*?-->/g, " ");
88
- for (const tag of STRIPPED_ELEMENTS) {
89
- const element = new RegExp(`<${tag}\\b[^>]*>[\\s\\S]*?<\\/${tag}>`, "gi");
90
- text = text.replace(element, " ");
91
- text = text.replace(new RegExp(`<\\/?${tag}\\b[^>]*>`, "gi"), " ");
92
- }
93
- text = text.replace(BLOCK_TAGS, "\n");
94
- text = text.replace(/<[^>]+>/g, "");
95
- text = decodeEntities(text);
96
- text = text.replace(/[^\S\n]+/g, " ").replace(/[ \t]*\n[ \t]*/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
97
- return text;
98
- }
99
- /**
100
- * Load an HTML string into a single {@link RagDocument} of readable text.
101
- * Scripts, styles, and other non-prose elements are dropped content-and-all,
102
- * block tags become line breaks (so paragraph structure survives for the
103
- * splitter), remaining tags are stripped, and HTML entities are decoded — a
104
- * lightweight regex pass, no heavy DOM dependency.
105
- *
106
- * The document's `metadata.title` is set from the page's `<title>` (unless
107
- * the caller overrode it), and `metadata.loader` is `"html"`. The output is
108
- * the exact shape `index()` consumes.
109
- *
110
- * @example
111
- * const kb = ai.rag({ embedder, store });
112
- * await kb.index(loadHtml(rawHtmlString, { id: "landing-page" }));
113
- *
114
- * @param html - The raw HTML markup.
115
- * @param options - Shared `id` / `metadata` / `tags` ({@link LoadHtmlOptions}).
116
- * @returns A {@link RagLoaderResult} (one document) ready for `rag.index()`.
117
- */
118
- function loadHtml(html, options = {}) {
119
- const id = options.id ?? DEFAULT_ID;
120
- const title = extractTitle(html);
121
- const text = htmlToText(html);
122
- if (text.length === 0) return [];
123
- return [{
124
- id,
125
- text,
126
- metadata: {
127
- source: id,
128
- loader: "html",
129
- ...title !== void 0 ? { title } : {},
130
- ...options.metadata
131
- },
132
- tags: options.tags
133
- }];
134
- }
135
-
136
- //#endregion
137
- export { extractTitle, htmlToText, loadHtml };
138
- //# sourceMappingURL=load-html.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"load-html.mjs","names":[],"sources":["../../../../../../../../../../@warlock.js/ai/src/rag/loaders/load-html.ts"],"sourcesContent":["import type { RagDocument } from \"../contracts/rag-document.type\";\nimport type { LoadHtmlOptions, RagLoaderResult } from \"./loader.type\";\n\n/** Default `id` when the caller supplies none. */\nconst DEFAULT_ID = \"document\";\n\n/**\n * Elements whose *content* is not human-readable text and must be removed\n * wholesale (open tag → close tag → everything in between) before tags are\n * stripped. `script` / `style` would otherwise leak code into the chunked\n * text; `noscript` / `template` / `head` / `svg` are non-prose noise.\n */\nconst STRIPPED_ELEMENTS = [\n \"script\",\n \"style\",\n \"noscript\",\n \"template\",\n \"head\",\n \"svg\",\n];\n\n/**\n * Block-level tags that imply a line break in the readable text. Replacing\n * them with `\\n` BEFORE the generic tag strip keeps paragraph / list / table\n * structure (so the recursive splitter still sees `\\n\\n` boundaries) instead\n * of collapsing the whole page onto one line.\n */\nconst BLOCK_TAGS =\n /<\\/?(?:p|div|section|article|header|footer|main|aside|nav|h[1-6]|ul|ol|li|table|tr|td|th|thead|tbody|blockquote|pre|hr|br)\\b[^>]*>/gi;\n\n/** Named HTML entities common in prose. Numeric entities are decoded generically. */\nconst NAMED_ENTITIES: Record<string, string> = {\n amp: \"&\",\n lt: \"<\",\n gt: \">\",\n quot: '\"',\n apos: \"'\",\n nbsp: \" \",\n copy: \"©\",\n reg: \"®\",\n trade: \"™\",\n hellip: \"…\",\n mdash: \"—\",\n ndash: \"–\",\n lsquo: \"‘\",\n rsquo: \"’\",\n ldquo: \"“\",\n rdquo: \"”\",\n laquo: \"«\",\n raquo: \"»\",\n middot: \"·\",\n bull: \"•\",\n};\n\n/**\n * Decode the HTML entities that survive tag stripping: named (`&amp;`),\n * decimal (`&#169;`), and hex (`&#xA9;`). Unknown named entities are left\n * verbatim rather than dropped, so unusual markup never silently loses text.\n */\nfunction decodeEntities(text: string): string {\n return text.replace(/&(#x?[0-9a-f]+|[a-z][a-z0-9]*);/gi, (match, body: string) => {\n if (body[0] === \"#\") {\n const codePoint =\n body[1] === \"x\" || body[1] === \"X\"\n ? Number.parseInt(body.slice(2), 16)\n : Number.parseInt(body.slice(1), 10);\n\n if (Number.isNaN(codePoint) || codePoint < 0 || codePoint > 0x10ffff) {\n return match;\n }\n\n try {\n return String.fromCodePoint(codePoint);\n } catch {\n return match;\n }\n }\n\n const named = NAMED_ENTITIES[body.toLowerCase()];\n\n return named ?? match;\n });\n}\n\n/**\n * Pull the `<title>` text out of the document, decoded and trimmed, or\n * `undefined` when there is none. Read BEFORE `<head>` is stripped.\n */\nfunction extractTitle(html: string): string | undefined {\n const match = /<title[^>]*>([\\s\\S]*?)<\\/title>/i.exec(html);\n\n if (!match) {\n return undefined;\n }\n\n const title = decodeEntities(match[1]).replace(/\\s+/g, \" \").trim();\n\n return title.length > 0 ? title : undefined;\n}\n\n/**\n * Strip HTML markup down to readable plain text — a lightweight,\n * dependency-free pass (no DOM parser): drop comments and non-prose elements\n * (`script` / `style` / `head` / `svg` / …) content-and-all, convert block\n * tags to line breaks to preserve paragraph structure, remove every\n * remaining tag, decode entities, then collapse runs of whitespace while\n * keeping blank-line paragraph separators.\n */\nfunction htmlToText(html: string): string {\n let text = html;\n\n // 1. Comments first — a commented-out `<script>` must not survive.\n text = text.replace(/<!--[\\s\\S]*?-->/g, \" \");\n\n // 2. Non-prose elements, content and all.\n for (const tag of STRIPPED_ELEMENTS) {\n const element = new RegExp(`<${tag}\\\\b[^>]*>[\\\\s\\\\S]*?<\\\\/${tag}>`, \"gi\");\n text = text.replace(element, \" \");\n // Defensively drop a self-closing / unterminated open tag too.\n text = text.replace(new RegExp(`<\\\\/?${tag}\\\\b[^>]*>`, \"gi\"), \" \");\n }\n\n // 3. Block tags → newlines, so paragraph / list structure survives.\n text = text.replace(BLOCK_TAGS, \"\\n\");\n\n // 4. Every remaining tag → gone.\n text = text.replace(/<[^>]+>/g, \"\");\n\n // 5. Entities → characters.\n text = decodeEntities(text);\n\n // 6. Normalize whitespace: trim each line, drop blank runs to a single\n // blank line (a paragraph separator the recursive splitter honors).\n text = text\n .replace(/[^\\S\\n]+/g, \" \")\n .replace(/[ \\t]*\\n[ \\t]*/g, \"\\n\")\n .replace(/\\n{3,}/g, \"\\n\\n\")\n .trim();\n\n return text;\n}\n\n/**\n * Load an HTML string into a single {@link RagDocument} of readable text.\n * Scripts, styles, and other non-prose elements are dropped content-and-all,\n * block tags become line breaks (so paragraph structure survives for the\n * splitter), remaining tags are stripped, and HTML entities are decoded — a\n * lightweight regex pass, no heavy DOM dependency.\n *\n * The document's `metadata.title` is set from the page's `<title>` (unless\n * the caller overrode it), and `metadata.loader` is `\"html\"`. The output is\n * the exact shape `index()` consumes.\n *\n * @example\n * const kb = ai.rag({ embedder, store });\n * await kb.index(loadHtml(rawHtmlString, { id: \"landing-page\" }));\n *\n * @param html - The raw HTML markup.\n * @param options - Shared `id` / `metadata` / `tags` ({@link LoadHtmlOptions}).\n * @returns A {@link RagLoaderResult} (one document) ready for `rag.index()`.\n */\nexport function loadHtml(\n html: string,\n options: LoadHtmlOptions = {},\n): RagLoaderResult {\n const id = options.id ?? DEFAULT_ID;\n const title = extractTitle(html);\n const text = htmlToText(html);\n\n // An all-markup / empty page strips to nothing; emit no document so\n // index() never receives a no-op record (matches loadText's behavior).\n if (text.length === 0) {\n return [];\n }\n\n // Derived keys (source, loader, title) sit UNDER the caller's metadata so\n // an explicit override always wins.\n const doc: RagDocument = {\n id,\n text,\n metadata: {\n source: id,\n loader: \"html\",\n ...(title !== undefined ? { title } : {}),\n ...options.metadata,\n },\n tags: options.tags,\n };\n\n return [doc];\n}\n\n/** Internal — exported for the web loader so it shares the exact strip pass. */\nexport { htmlToText, extractTitle };\n"],"mappings":";;AAIA,MAAM,aAAa;;;;;;;AAQnB,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;AAQA,MAAM,aACJ;;AAGF,MAAM,iBAAyC;CAC7C,KAAK;CACL,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,KAAK;CACL,OAAO;CACP,QAAQ;CACR,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,QAAQ;CACR,MAAM;AACR;;;;;;AAOA,SAAS,eAAe,MAAsB;CAC5C,OAAO,KAAK,QAAQ,sCAAsC,OAAO,SAAiB;EAChF,IAAI,KAAK,OAAO,KAAK;GACnB,MAAM,YACJ,KAAK,OAAO,OAAO,KAAK,OAAO,MAC3B,OAAO,SAAS,KAAK,MAAM,CAAC,GAAG,EAAE,IACjC,OAAO,SAAS,KAAK,MAAM,CAAC,GAAG,EAAE;GAEvC,IAAI,OAAO,MAAM,SAAS,KAAK,YAAY,KAAK,YAAY,SAC1D,OAAO;GAGT,IAAI;IACF,OAAO,OAAO,cAAc,SAAS;GACvC,QAAQ;IACN,OAAO;GACT;EACF;EAIA,OAFc,eAAe,KAAK,YAAY,MAE9B;CAClB,CAAC;AACH;;;;;AAMA,SAAS,aAAa,MAAkC;CACtD,MAAM,QAAQ,mCAAmC,KAAK,IAAI;CAE1D,IAAI,CAAC,OACH;CAGF,MAAM,QAAQ,eAAe,MAAM,EAAE,CAAC,CAAC,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;CAEjE,OAAO,MAAM,SAAS,IAAI,QAAQ;AACpC;;;;;;;;;AAUA,SAAS,WAAW,MAAsB;CACxC,IAAI,OAAO;CAGX,OAAO,KAAK,QAAQ,oBAAoB,GAAG;CAG3C,KAAK,MAAM,OAAO,mBAAmB;EACnC,MAAM,UAAU,IAAI,OAAO,IAAI,IAAI,yBAAyB,IAAI,IAAI,IAAI;EACxE,OAAO,KAAK,QAAQ,SAAS,GAAG;EAEhC,OAAO,KAAK,QAAQ,IAAI,OAAO,QAAQ,IAAI,YAAY,IAAI,GAAG,GAAG;CACnE;CAGA,OAAO,KAAK,QAAQ,YAAY,IAAI;CAGpC,OAAO,KAAK,QAAQ,YAAY,EAAE;CAGlC,OAAO,eAAe,IAAI;CAI1B,OAAO,KACJ,QAAQ,aAAa,GAAG,CAAC,CACzB,QAAQ,mBAAmB,IAAI,CAAC,CAChC,QAAQ,WAAW,MAAM,CAAC,CAC1B,KAAK;CAER,OAAO;AACT;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,SACd,MACA,UAA2B,CAAC,GACX;CACjB,MAAM,KAAK,QAAQ,MAAM;CACzB,MAAM,QAAQ,aAAa,IAAI;CAC/B,MAAM,OAAO,WAAW,IAAI;CAI5B,IAAI,KAAK,WAAW,GAClB,OAAO,CAAC;CAiBV,OAAO,CAAC;EAXN;EACA;EACA,UAAU;GACR,QAAQ;GACR,QAAQ;GACR,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;GACvC,GAAG,QAAQ;EACb;EACA,MAAM,QAAQ;CAGN,CAAC;AACb"}
@@ -1,150 +0,0 @@
1
- import { PDF_PARSE_INSTALL_INSTRUCTIONS } from "./errors.mjs";
2
-
3
- //#region ../@warlock.js/ai/src/rag/loaders/load-pdf.ts
4
- /** Default `id` when the caller supplies none. */
5
- const DEFAULT_ID = "document";
6
- let pdfParse;
7
- let isModuleExists;
8
- let loadingPromise;
9
- /**
10
- * Settle the lazy import of `pdf-parse` once, concurrency-safe. A bare
11
- * `catch` flips the flag to `false`; the curated
12
- * {@link PDF_PARSE_INSTALL_INSTRUCTIONS} surfaces at first
13
- * {@link loadPdf} call, never a raw module-resolution stack trace. Mirrors
14
- * the guard moderation detector's `loadOpenAi`.
15
- */
16
- function loadPdfParse() {
17
- if (isModuleExists !== void 0) return Promise.resolve();
18
- if (loadingPromise) return loadingPromise;
19
- loadingPromise = (async () => {
20
- try {
21
- const mod = await import("pdf-parse");
22
- pdfParse = mod.default ?? mod;
23
- isModuleExists = typeof pdfParse === "function";
24
- } catch {
25
- isModuleExists = false;
26
- }
27
- })();
28
- return loadingPromise;
29
- }
30
- /**
31
- * Coerce a {@link RagDocument}-compatible binary input into a `Buffer` for
32
- * `pdf-parse`. Accepts a Node `Buffer`, an `ArrayBuffer`, or a typed array
33
- * (`Uint8Array`) — the shapes a file read / fetch body hands back.
34
- */
35
- function toBuffer(input) {
36
- if (Buffer.isBuffer(input)) return input;
37
- if (input instanceof ArrayBuffer) return Buffer.from(input);
38
- return Buffer.from(input.buffer, input.byteOffset, input.byteLength);
39
- }
40
- /**
41
- * Load a PDF's bytes into {@link RagDocument}(s) via the OPTIONAL `pdf-parse`
42
- * peer. The peer is resolved lazily on the FIRST call (not at import) so
43
- * importing `@warlock.js/ai` never forces it to be installed; when it is
44
- * absent the curated {@link PDF_PARSE_INSTALL_INSTRUCTIONS} is thrown as a
45
- * plain `Error` (a missing optional peer is an infrastructure fault, not a
46
- * content problem).
47
- *
48
- * By default the whole PDF becomes a single document carrying
49
- * `metadata.pageCount`. With `perPage: true`, each page becomes its own
50
- * document (`id` suffixed `#p<n>`, `metadata.page` set) so citations stay
51
- * page-precise. Document `metadata.title` comes from the PDF info
52
- * dictionary's `Title` (unless overridden), and `metadata.loader` is
53
- * `"pdf"`. The output is the exact shape `index()` consumes.
54
- *
55
- * @example
56
- * import { readFile } from "node:fs/promises";
57
- * const kb = ai.rag({ embedder, store });
58
- * await kb.index(await loadPdf(await readFile("guide.pdf"), { id: "guide" }));
59
- *
60
- * @example
61
- * // One document per page for page-precise citations:
62
- * await kb.index(await loadPdf(bytes, { id: "manual", perPage: true }));
63
- *
64
- * @param input - The PDF bytes (`Buffer`, `ArrayBuffer`, or `Uint8Array`).
65
- * @param options - `perPage` plus shared `id` / `metadata` / `tags`
66
- * ({@link LoadPdfOptions}).
67
- * @returns A {@link RagLoaderResult} ready for `rag.index()`.
68
- * @throws {Error} carrying {@link PDF_PARSE_INSTALL_INSTRUCTIONS} when the
69
- * `pdf-parse` peer is not installed.
70
- */
71
- async function loadPdf(input, options = {}) {
72
- await loadPdfParse();
73
- if (!isModuleExists || !pdfParse) throw new Error(PDF_PARSE_INSTALL_INSTRUCTIONS);
74
- const id = options.id ?? DEFAULT_ID;
75
- if (options.perPage ?? false) return loadPerPage(input, id, options);
76
- const parsed = await pdfParse(toBuffer(input));
77
- const text = parsed.text.trim();
78
- const title = parsed.info?.Title?.trim();
79
- if (text.length === 0) return [];
80
- return [{
81
- id,
82
- text,
83
- metadata: {
84
- source: id,
85
- loader: "pdf",
86
- pageCount: parsed.numpages,
87
- ...title ? { title } : {},
88
- ...options.metadata
89
- },
90
- tags: options.tags
91
- }];
92
- }
93
- /**
94
- * Per-page variant: render each page separately via `pdf-parse`'s
95
- * `pagerender` hook, accumulating one document per non-empty page. Each
96
- * carries `metadata.page` (1-based) and `metadata.pageCount`, and its id is
97
- * the base id suffixed `#p<n>` so every page-document is distinctly
98
- * identified for citation.
99
- *
100
- * `pdf-parse` calls `pagerender` once per page in document order and
101
- * `await`s the returned string, so capturing each page's joined text content
102
- * here gives reliable page boundaries the concatenated `text` lacks.
103
- */
104
- async function loadPerPage(input, id, options) {
105
- const pages = [];
106
- const parsed = await pdfParse(toBuffer(input), { pagerender: async (page) => {
107
- const rendered = await renderPage(page);
108
- pages.push(rendered);
109
- return rendered;
110
- } });
111
- const title = parsed.info?.Title?.trim();
112
- const docs = [];
113
- pages.forEach((pageText, index) => {
114
- const text = pageText.trim();
115
- if (text.length === 0) return;
116
- const pageNumber = index + 1;
117
- docs.push({
118
- id: `${id}#p${pageNumber}`,
119
- text,
120
- metadata: {
121
- source: id,
122
- loader: "pdf",
123
- page: pageNumber,
124
- pageCount: parsed.numpages,
125
- ...title ? { title } : {},
126
- ...options.metadata
127
- },
128
- tags: options.tags
129
- });
130
- });
131
- return docs;
132
- }
133
- /**
134
- * Join a single page's text-layer items in reading order, inserting a space
135
- * between items so adjacent words do not run together. Mirrors the essence
136
- * of `pdf-parse`'s default renderer without depending on its internals, so
137
- * the per-page hook stays stable across `pdf-parse` versions. A page with no
138
- * text layer (scanned image) renders to an empty string and is dropped.
139
- */
140
- async function renderPage(page) {
141
- if (typeof page?.getTextContent !== "function") return "";
142
- return (await page.getTextContent({
143
- normalizeWhitespace: true,
144
- disableCombineTextItems: false
145
- })).items.map((item) => item.str).join(" ").replace(/\s+/g, " ").trim();
146
- }
147
-
148
- //#endregion
149
- export { loadPdf };
150
- //# sourceMappingURL=load-pdf.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"load-pdf.mjs","names":[],"sources":["../../../../../../../../../../@warlock.js/ai/src/rag/loaders/load-pdf.ts"],"sourcesContent":["import type { RagDocument } from \"../contracts/rag-document.type\";\nimport { PDF_PARSE_INSTALL_INSTRUCTIONS } from \"./errors\";\nimport type { LoadPdfOptions, RagLoaderResult } from \"./loader.type\";\n\n/** Default `id` when the caller supplies none. */\nconst DEFAULT_ID = \"document\";\n\n/**\n * The slice of `pdf-parse`'s result we consume. The peer returns more\n * (`info`, `metadata`, `version`); we only need the extracted `text` and\n * page count, so we type just those to keep the dependency at arm's length.\n */\ntype PdfParseResult = {\n /** Concatenated text of every page. */\n text: string;\n /** Number of pages in the document. */\n numpages: number;\n /** Document info dictionary — `Title` lifted into metadata when present. */\n info?: { Title?: string } & Record<string, unknown>;\n};\n\n/** The `pdf-parse` module's callable default export. */\ntype PdfParseFn = (\n data: Buffer | Uint8Array,\n options?: {\n /**\n * Per-page renderer `pdf-parse` calls once per page in document order and\n * `await`s — may return the page text synchronously or as a promise.\n */\n pagerender?: (page: unknown) => string | Promise<string>;\n },\n) => Promise<PdfParseResult>;\n\n// ============================================================\n// Lazily-loaded pdf-parse (OPTIONAL peer)\n// ============================================================\n\nlet pdfParse: PdfParseFn | undefined;\nlet isModuleExists: boolean | undefined;\nlet loadingPromise: Promise<void> | undefined;\n\n/**\n * Settle the lazy import of `pdf-parse` once, concurrency-safe. A bare\n * `catch` flips the flag to `false`; the curated\n * {@link PDF_PARSE_INSTALL_INSTRUCTIONS} surfaces at first\n * {@link loadPdf} call, never a raw module-resolution stack trace. Mirrors\n * the guard moderation detector's `loadOpenAi`.\n */\nfunction loadPdfParse(): Promise<void> {\n if (isModuleExists !== undefined) {\n return Promise.resolve();\n }\n\n if (loadingPromise) {\n return loadingPromise;\n }\n\n loadingPromise = (async () => {\n try {\n // Literal specifier so `vi.mock(\"pdf-parse\")` can intercept it in tests.\n // Typed via the ambient `pdf-parse` shim in this directory, so the bare\n // import resolves even though the OPTIONAL peer is not a dependency.\n const mod = (await import(\"pdf-parse\")) as {\n default?: PdfParseFn;\n } & Partial<PdfParseFn>;\n // pdf-parse ships CommonJS — the callable is `module.exports`, surfaced\n // as `default` under ESM interop. Fall back to the namespace itself for\n // bundlers that hoist the callable to the top level.\n pdfParse = mod.default ?? (mod as unknown as PdfParseFn);\n isModuleExists = typeof pdfParse === \"function\";\n } catch {\n isModuleExists = false;\n }\n })();\n\n return loadingPromise;\n}\n\n/**\n * Coerce a {@link RagDocument}-compatible binary input into a `Buffer` for\n * `pdf-parse`. Accepts a Node `Buffer`, an `ArrayBuffer`, or a typed array\n * (`Uint8Array`) — the shapes a file read / fetch body hands back.\n */\nfunction toBuffer(input: Buffer | ArrayBuffer | Uint8Array): Buffer {\n if (Buffer.isBuffer(input)) {\n return input;\n }\n\n if (input instanceof ArrayBuffer) {\n return Buffer.from(input);\n }\n\n return Buffer.from(input.buffer, input.byteOffset, input.byteLength);\n}\n\n/**\n * Load a PDF's bytes into {@link RagDocument}(s) via the OPTIONAL `pdf-parse`\n * peer. The peer is resolved lazily on the FIRST call (not at import) so\n * importing `@warlock.js/ai` never forces it to be installed; when it is\n * absent the curated {@link PDF_PARSE_INSTALL_INSTRUCTIONS} is thrown as a\n * plain `Error` (a missing optional peer is an infrastructure fault, not a\n * content problem).\n *\n * By default the whole PDF becomes a single document carrying\n * `metadata.pageCount`. With `perPage: true`, each page becomes its own\n * document (`id` suffixed `#p<n>`, `metadata.page` set) so citations stay\n * page-precise. Document `metadata.title` comes from the PDF info\n * dictionary's `Title` (unless overridden), and `metadata.loader` is\n * `\"pdf\"`. The output is the exact shape `index()` consumes.\n *\n * @example\n * import { readFile } from \"node:fs/promises\";\n * const kb = ai.rag({ embedder, store });\n * await kb.index(await loadPdf(await readFile(\"guide.pdf\"), { id: \"guide\" }));\n *\n * @example\n * // One document per page for page-precise citations:\n * await kb.index(await loadPdf(bytes, { id: \"manual\", perPage: true }));\n *\n * @param input - The PDF bytes (`Buffer`, `ArrayBuffer`, or `Uint8Array`).\n * @param options - `perPage` plus shared `id` / `metadata` / `tags`\n * ({@link LoadPdfOptions}).\n * @returns A {@link RagLoaderResult} ready for `rag.index()`.\n * @throws {Error} carrying {@link PDF_PARSE_INSTALL_INSTRUCTIONS} when the\n * `pdf-parse` peer is not installed.\n */\nexport async function loadPdf(\n input: Buffer | ArrayBuffer | Uint8Array,\n options: LoadPdfOptions = {},\n): Promise<RagLoaderResult> {\n await loadPdfParse();\n\n if (!isModuleExists || !pdfParse) {\n throw new Error(PDF_PARSE_INSTALL_INSTRUCTIONS);\n }\n\n const id = options.id ?? DEFAULT_ID;\n const perPage = options.perPage ?? false;\n\n if (perPage) {\n return loadPerPage(input, id, options);\n }\n\n const parsed = await pdfParse(toBuffer(input));\n const text = parsed.text.trim();\n const title = parsed.info?.Title?.trim();\n\n // An image-only / empty PDF extracts no text — emit nothing so index()\n // never receives a no-op record.\n if (text.length === 0) {\n return [];\n }\n\n const doc: RagDocument = {\n id,\n text,\n metadata: {\n source: id,\n loader: \"pdf\",\n pageCount: parsed.numpages,\n ...(title ? { title } : {}),\n ...options.metadata,\n },\n tags: options.tags,\n };\n\n return [doc];\n}\n\n/** One page of a parsed PDF — the text-layer item list `pagerender` sees. */\ntype PdfPage = {\n getTextContent: (\n options?: unknown,\n ) => Promise<{ items: { str: string }[] }>;\n};\n\n/**\n * Per-page variant: render each page separately via `pdf-parse`'s\n * `pagerender` hook, accumulating one document per non-empty page. Each\n * carries `metadata.page` (1-based) and `metadata.pageCount`, and its id is\n * the base id suffixed `#p<n>` so every page-document is distinctly\n * identified for citation.\n *\n * `pdf-parse` calls `pagerender` once per page in document order and\n * `await`s the returned string, so capturing each page's joined text content\n * here gives reliable page boundaries the concatenated `text` lacks.\n */\nasync function loadPerPage(\n input: Buffer | ArrayBuffer | Uint8Array,\n id: string,\n options: LoadPdfOptions,\n): Promise<RagDocument[]> {\n const pages: string[] = [];\n\n const parsed = await pdfParse!(toBuffer(input), {\n pagerender: async (page: unknown): Promise<string> => {\n const rendered = await renderPage(page as PdfPage);\n pages.push(rendered);\n return rendered;\n },\n });\n\n const title = parsed.info?.Title?.trim();\n const docs: RagDocument[] = [];\n\n pages.forEach((pageText, index) => {\n const text = pageText.trim();\n\n if (text.length === 0) {\n return;\n }\n\n const pageNumber = index + 1;\n\n docs.push({\n id: `${id}#p${pageNumber}`,\n text,\n metadata: {\n source: id,\n loader: \"pdf\",\n page: pageNumber,\n pageCount: parsed.numpages,\n ...(title ? { title } : {}),\n ...options.metadata,\n },\n tags: options.tags,\n });\n });\n\n return docs;\n}\n\n/**\n * Join a single page's text-layer items in reading order, inserting a space\n * between items so adjacent words do not run together. Mirrors the essence\n * of `pdf-parse`'s default renderer without depending on its internals, so\n * the per-page hook stays stable across `pdf-parse` versions. A page with no\n * text layer (scanned image) renders to an empty string and is dropped.\n */\nasync function renderPage(page: PdfPage): Promise<string> {\n if (typeof page?.getTextContent !== \"function\") {\n return \"\";\n }\n\n const content = await page.getTextContent({\n normalizeWhitespace: true,\n disableCombineTextItems: false,\n });\n\n return content.items\n .map((item) => item.str)\n .join(\" \")\n .replace(/\\s+/g, \" \")\n .trim();\n}\n"],"mappings":";;;;AAKA,MAAM,aAAa;AAgCnB,IAAI;AACJ,IAAI;AACJ,IAAI;;;;;;;;AASJ,SAAS,eAA8B;CACrC,IAAI,mBAAmB,QACrB,OAAO,QAAQ,QAAQ;CAGzB,IAAI,gBACF,OAAO;CAGT,kBAAkB,YAAY;EAC5B,IAAI;GAIF,MAAM,MAAO,MAAM,OAAO;GAM1B,WAAW,IAAI,WAAY;GAC3B,iBAAiB,OAAO,aAAa;EACvC,QAAQ;GACN,iBAAiB;EACnB;CACF,EAAC,CAAE;CAEH,OAAO;AACT;;;;;;AAOA,SAAS,SAAS,OAAkD;CAClE,IAAI,OAAO,SAAS,KAAK,GACvB,OAAO;CAGT,IAAI,iBAAiB,aACnB,OAAO,OAAO,KAAK,KAAK;CAG1B,OAAO,OAAO,KAAK,MAAM,QAAQ,MAAM,YAAY,MAAM,UAAU;AACrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,eAAsB,QACpB,OACA,UAA0B,CAAC,GACD;CAC1B,MAAM,aAAa;CAEnB,IAAI,CAAC,kBAAkB,CAAC,UACtB,MAAM,IAAI,MAAM,8BAA8B;CAGhD,MAAM,KAAK,QAAQ,MAAM;CAGzB,IAFgB,QAAQ,WAAW,OAGjC,OAAO,YAAY,OAAO,IAAI,OAAO;CAGvC,MAAM,SAAS,MAAM,SAAS,SAAS,KAAK,CAAC;CAC7C,MAAM,OAAO,OAAO,KAAK,KAAK;CAC9B,MAAM,QAAQ,OAAO,MAAM,OAAO,KAAK;CAIvC,IAAI,KAAK,WAAW,GAClB,OAAO,CAAC;CAgBV,OAAO,CAAC;EAZN;EACA;EACA,UAAU;GACR,QAAQ;GACR,QAAQ;GACR,WAAW,OAAO;GAClB,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;GACzB,GAAG,QAAQ;EACb;EACA,MAAM,QAAQ;CAGN,CAAC;AACb;;;;;;;;;;;;AAoBA,eAAe,YACb,OACA,IACA,SACwB;CACxB,MAAM,QAAkB,CAAC;CAEzB,MAAM,SAAS,MAAM,SAAU,SAAS,KAAK,GAAG,EAC9C,YAAY,OAAO,SAAmC;EACpD,MAAM,WAAW,MAAM,WAAW,IAAe;EACjD,MAAM,KAAK,QAAQ;EACnB,OAAO;CACT,EACF,CAAC;CAED,MAAM,QAAQ,OAAO,MAAM,OAAO,KAAK;CACvC,MAAM,OAAsB,CAAC;CAE7B,MAAM,SAAS,UAAU,UAAU;EACjC,MAAM,OAAO,SAAS,KAAK;EAE3B,IAAI,KAAK,WAAW,GAClB;EAGF,MAAM,aAAa,QAAQ;EAE3B,KAAK,KAAK;GACR,IAAI,GAAG,GAAG,IAAI;GACd;GACA,UAAU;IACR,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,WAAW,OAAO;IAClB,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;IACzB,GAAG,QAAQ;GACb;GACA,MAAM,QAAQ;EAChB,CAAC;CACH,CAAC;CAED,OAAO;AACT;;;;;;;;AASA,eAAe,WAAW,MAAgC;CACxD,IAAI,OAAO,MAAM,mBAAmB,YAClC,OAAO;CAQT,QAAO,MALe,KAAK,eAAe;EACxC,qBAAqB;EACrB,yBAAyB;CAC3B,CAAC,EAEa,CAAC,MACZ,KAAK,SAAS,KAAK,GAAG,CAAC,CACvB,KAAK,GAAG,CAAC,CACT,QAAQ,QAAQ,GAAG,CAAC,CACpB,KAAK;AACV"}
@@ -1,60 +0,0 @@
1
- //#region ../@warlock.js/ai/src/rag/loaders/load-text.ts
2
- /** Default `id` when the caller supplies neither `id` nor an item id. */
3
- const DEFAULT_ID = "document";
4
- /**
5
- * Load plain text into {@link RagDocument}(s) — the zero-dependency base
6
- * loader every other loader ultimately funnels into. Accepts a single
7
- * string, a single `{ id, text }` record, or an array mixing both; each
8
- * input becomes one document carrying `metadata.loader = "text"` plus a
9
- * `metadata.source` (the resolved id).
10
- *
11
- * Caller `metadata` always wins over the loader-derived keys, and per-item
12
- * `metadata` / `tags` (when an item is a record) layer on top of the shared
13
- * option values. Empty / whitespace-only items are dropped — they would
14
- * chunk to nothing anyway, so the result never carries a no-op document.
15
- *
16
- * The output is the exact shape `index()` consumes:
17
- *
18
- * @example
19
- * const kb = ai.rag({ embedder, store });
20
- * await kb.index(loadText("a long string of notes…"));
21
- *
22
- * @example
23
- * await kb.index(loadText([
24
- * { id: "faq-1", text: "…", metadata: { section: "billing" } },
25
- * { id: "faq-2", text: "…" },
26
- * ]));
27
- *
28
- * @param input - A string, a `{ id, text }` record, or an array of either.
29
- * @param options - Shared `id` / `metadata` / `tags` ({@link LoadTextOptions}).
30
- * @returns A {@link RagLoaderResult} ready to hand to `rag.index()`.
31
- */
32
- function loadText(input, options = {}) {
33
- const items = Array.isArray(input) ? input : [input];
34
- const baseId = options.id ?? DEFAULT_ID;
35
- const multiple = items.length > 1;
36
- const docs = [];
37
- items.forEach((item, index) => {
38
- const text = typeof item === "string" ? item : item.text;
39
- if (text.trim().length === 0) return;
40
- const id = (typeof item === "string" ? void 0 : item.id) ?? (multiple ? `${baseId}#${index}` : baseId);
41
- const itemMetadata = typeof item === "string" ? void 0 : item.metadata;
42
- const itemTags = typeof item === "string" ? void 0 : item.tags;
43
- docs.push({
44
- id,
45
- text,
46
- metadata: {
47
- source: id,
48
- loader: "text",
49
- ...options.metadata,
50
- ...itemMetadata
51
- },
52
- tags: itemTags ?? options.tags
53
- });
54
- });
55
- return docs;
56
- }
57
-
58
- //#endregion
59
- export { loadText };
60
- //# sourceMappingURL=load-text.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"load-text.mjs","names":[],"sources":["../../../../../../../../../../@warlock.js/ai/src/rag/loaders/load-text.ts"],"sourcesContent":["import type { RagDocument } from \"../contracts/rag-document.type\";\nimport type { LoadTextOptions, RagLoaderResult } from \"./loader.type\";\n\n/** Default `id` when the caller supplies neither `id` nor an item id. */\nconst DEFAULT_ID = \"document\";\n\n/**\n * One raw text item — a bare string, or a `{ id, text, … }` record giving the\n * item its own id / metadata / tags. Passing records lets a single\n * {@link loadText} call turn many strings into many distinctly-identified\n * {@link RagDocument}s.\n */\nexport type TextInput =\n | string\n | {\n /** Stable id for this item. Falls back to the option `id` + index. */\n id?: string;\n /** The text body. */\n text: string;\n /** Per-item metadata, merged under the shared option `metadata`. */\n metadata?: Record<string, unknown>;\n /** Per-item tags (override the shared option `tags` when present). */\n tags?: string[];\n };\n\n/**\n * Load plain text into {@link RagDocument}(s) — the zero-dependency base\n * loader every other loader ultimately funnels into. Accepts a single\n * string, a single `{ id, text }` record, or an array mixing both; each\n * input becomes one document carrying `metadata.loader = \"text\"` plus a\n * `metadata.source` (the resolved id).\n *\n * Caller `metadata` always wins over the loader-derived keys, and per-item\n * `metadata` / `tags` (when an item is a record) layer on top of the shared\n * option values. Empty / whitespace-only items are dropped — they would\n * chunk to nothing anyway, so the result never carries a no-op document.\n *\n * The output is the exact shape `index()` consumes:\n *\n * @example\n * const kb = ai.rag({ embedder, store });\n * await kb.index(loadText(\"a long string of notes…\"));\n *\n * @example\n * await kb.index(loadText([\n * { id: \"faq-1\", text: \"…\", metadata: { section: \"billing\" } },\n * { id: \"faq-2\", text: \"…\" },\n * ]));\n *\n * @param input - A string, a `{ id, text }` record, or an array of either.\n * @param options - Shared `id` / `metadata` / `tags` ({@link LoadTextOptions}).\n * @returns A {@link RagLoaderResult} ready to hand to `rag.index()`.\n */\nexport function loadText(\n input: TextInput | TextInput[],\n options: LoadTextOptions = {},\n): RagLoaderResult {\n const items = Array.isArray(input) ? input : [input];\n const baseId = options.id ?? DEFAULT_ID;\n const multiple = items.length > 1;\n\n const docs: RagDocument[] = [];\n\n items.forEach((item, index) => {\n const text = typeof item === \"string\" ? item : item.text;\n\n // Drop empties up front — they chunk to nothing, so emitting them would\n // only add a no-op document for index() to skip.\n if (text.trim().length === 0) {\n return;\n }\n\n const itemId =\n typeof item === \"string\" ? undefined : item.id;\n // A single input keeps the bare base id; multiple inputs are suffixed so\n // every emitted document has a distinct, stable id.\n const id = itemId ?? (multiple ? `${baseId}#${index}` : baseId);\n\n const itemMetadata =\n typeof item === \"string\" ? undefined : item.metadata;\n const itemTags = typeof item === \"string\" ? undefined : item.tags;\n\n docs.push({\n id,\n text,\n // Loader-derived keys first, then the shared option metadata, then the\n // per-item metadata — caller intent always overrides the derived keys.\n metadata: {\n source: id,\n loader: \"text\",\n ...options.metadata,\n ...itemMetadata,\n },\n tags: itemTags ?? options.tags,\n });\n });\n\n return docs;\n}\n"],"mappings":";;AAIA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDnB,SAAgB,SACd,OACA,UAA2B,CAAC,GACX;CACjB,MAAM,QAAQ,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;CACnD,MAAM,SAAS,QAAQ,MAAM;CAC7B,MAAM,WAAW,MAAM,SAAS;CAEhC,MAAM,OAAsB,CAAC;CAE7B,MAAM,SAAS,MAAM,UAAU;EAC7B,MAAM,OAAO,OAAO,SAAS,WAAW,OAAO,KAAK;EAIpD,IAAI,KAAK,KAAK,CAAC,CAAC,WAAW,GACzB;EAOF,MAAM,MAHJ,OAAO,SAAS,WAAW,SAAY,KAAK,QAGxB,WAAW,GAAG,OAAO,GAAG,UAAU;EAExD,MAAM,eACJ,OAAO,SAAS,WAAW,SAAY,KAAK;EAC9C,MAAM,WAAW,OAAO,SAAS,WAAW,SAAY,KAAK;EAE7D,KAAK,KAAK;GACR;GACA;GAGA,UAAU;IACR,QAAQ;IACR,QAAQ;IACR,GAAG,QAAQ;IACX,GAAG;GACL;GACA,MAAM,YAAY,QAAQ;EAC5B,CAAC;CACH,CAAC;CAED,OAAO;AACT"}
@@ -1,89 +0,0 @@
1
- import { OutboundPolicyError } from "../../errors/outbound-policy-error.mjs";
2
- import "../../errors/index.mjs";
3
- import { guardedFetch, readTextCapped, resolveOutboundPolicy } from "../../security/outbound-policy.mjs";
4
- import { extractTitle, htmlToText } from "./load-html.mjs";
5
-
6
- //#region ../@warlock.js/ai/src/rag/loaders/load-web.ts
7
- /** Browser-ish UA so servers that gate on it still return prose. */
8
- const DEFAULT_USER_AGENT = "warlock-ai-rag-loader/1.0 (+https://github.com/warlock-js)";
9
- /**
10
- * Whether a `content-type` header names an HTML document (so it is run
11
- * through the tag-strip pass) versus already-plain text (used verbatim).
12
- */
13
- function isHtmlContentType(contentType) {
14
- if (!contentType) return true;
15
- const lower = contentType.toLowerCase();
16
- return lower.includes("text/html") || lower.includes("application/xhtml");
17
- }
18
- /**
19
- * Fetch a URL through the SSRF-safe outbound policy and load it into a single
20
- * {@link RagDocument} of readable text. The fetch ALWAYS goes through
21
- * `guardedFetch` — never a raw `fetch` — so the scheme allowlist, host
22
- * allowlist, post-DNS private-IP guard, timeout, and response-size cap from
23
- * {@link LoadWebOptions.policy} (or the strict defaults) always apply.
24
- *
25
- * HTML responses are run through the same tag-strip pass as {@link loadHtml}
26
- * (scripts/styles dropped, entities decoded, paragraph structure kept);
27
- * non-HTML text responses (`text/plain`, markdown, …) are used verbatim.
28
- * The document's `metadata.source` is the resolved URL, `metadata.title` is
29
- * the page `<title>` (HTML only, unless overridden), `metadata.contentType`
30
- * is the server-reported type, and `metadata.loader` is `"web"`.
31
- *
32
- * The output is the exact shape `index()` consumes, so a load feeds straight
33
- * in:
34
- *
35
- * @example
36
- * const kb = ai.rag({ embedder, store });
37
- * await kb.index(await loadWeb("https://example.com/guide"));
38
- *
39
- * @example
40
- * // Tighten the SSRF policy to a single host:
41
- * await kb.index(await loadWeb(url, {
42
- * policy: { hostAllowlist: ["docs.example.com"], maxBytes: 2_000_000 },
43
- * tags: ["docs"],
44
- * }));
45
- *
46
- * @param url - The absolute URL to fetch. Validated by the outbound policy.
47
- * @param options - `policy` (the {@link OutboundPolicy}) plus shared
48
- * `id` / `metadata` / `tags` ({@link LoadWebOptions}).
49
- * @returns A {@link RagLoaderResult} (one document) ready for `rag.index()`.
50
- * @throws {OutboundPolicyError} when the policy blocks the URL, the request
51
- * times out, the body exceeds the cap, or the response is not OK.
52
- */
53
- async function loadWeb(url, options = {}) {
54
- const policy = resolveOutboundPolicy(options.policy);
55
- const response = await guardedFetch(url, policy, {
56
- headers: {
57
- "user-agent": DEFAULT_USER_AGENT,
58
- accept: "text/html,text/*"
59
- },
60
- redirect: "follow"
61
- });
62
- if (!response.ok) throw new OutboundPolicyError(`loadWeb: fetching "${url}" returned ${response.status} ${response.statusText}`, { context: {
63
- url,
64
- status: response.status
65
- } });
66
- const contentType = response.headers.get("content-type") ?? void 0;
67
- const raw = await readTextCapped(response, policy.maxBytes);
68
- const isHtml = isHtmlContentType(contentType);
69
- const text = isHtml ? htmlToText(raw) : raw.trim();
70
- const title = isHtml ? extractTitle(raw) : void 0;
71
- const id = options.id ?? url;
72
- if (text.length === 0) return [];
73
- return [{
74
- id,
75
- text,
76
- metadata: {
77
- source: url,
78
- loader: "web",
79
- ...title !== void 0 ? { title } : {},
80
- ...contentType !== void 0 ? { contentType } : {},
81
- ...options.metadata
82
- },
83
- tags: options.tags
84
- }];
85
- }
86
-
87
- //#endregion
88
- export { loadWeb };
89
- //# sourceMappingURL=load-web.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"load-web.mjs","names":[],"sources":["../../../../../../../../../../@warlock.js/ai/src/rag/loaders/load-web.ts"],"sourcesContent":["import {\n guardedFetch,\n readTextCapped,\n resolveOutboundPolicy,\n} from \"../../security/outbound-policy\";\nimport { OutboundPolicyError } from \"../../errors\";\nimport type { RagDocument } from \"../contracts/rag-document.type\";\nimport { htmlToText, extractTitle } from \"./load-html\";\nimport type { LoadWebOptions, RagLoaderResult } from \"./loader.type\";\n\n/** Browser-ish UA so servers that gate on it still return prose. */\nconst DEFAULT_USER_AGENT =\n \"warlock-ai-rag-loader/1.0 (+https://github.com/warlock-js)\";\n\n/**\n * Whether a `content-type` header names an HTML document (so it is run\n * through the tag-strip pass) versus already-plain text (used verbatim).\n */\nfunction isHtmlContentType(contentType: string | undefined): boolean {\n if (!contentType) {\n // No header — assume HTML, the common case for a fetched URL.\n return true;\n }\n\n const lower = contentType.toLowerCase();\n\n return lower.includes(\"text/html\") || lower.includes(\"application/xhtml\");\n}\n\n/**\n * Fetch a URL through the SSRF-safe outbound policy and load it into a single\n * {@link RagDocument} of readable text. The fetch ALWAYS goes through\n * `guardedFetch` — never a raw `fetch` — so the scheme allowlist, host\n * allowlist, post-DNS private-IP guard, timeout, and response-size cap from\n * {@link LoadWebOptions.policy} (or the strict defaults) always apply.\n *\n * HTML responses are run through the same tag-strip pass as {@link loadHtml}\n * (scripts/styles dropped, entities decoded, paragraph structure kept);\n * non-HTML text responses (`text/plain`, markdown, …) are used verbatim.\n * The document's `metadata.source` is the resolved URL, `metadata.title` is\n * the page `<title>` (HTML only, unless overridden), `metadata.contentType`\n * is the server-reported type, and `metadata.loader` is `\"web\"`.\n *\n * The output is the exact shape `index()` consumes, so a load feeds straight\n * in:\n *\n * @example\n * const kb = ai.rag({ embedder, store });\n * await kb.index(await loadWeb(\"https://example.com/guide\"));\n *\n * @example\n * // Tighten the SSRF policy to a single host:\n * await kb.index(await loadWeb(url, {\n * policy: { hostAllowlist: [\"docs.example.com\"], maxBytes: 2_000_000 },\n * tags: [\"docs\"],\n * }));\n *\n * @param url - The absolute URL to fetch. Validated by the outbound policy.\n * @param options - `policy` (the {@link OutboundPolicy}) plus shared\n * `id` / `metadata` / `tags` ({@link LoadWebOptions}).\n * @returns A {@link RagLoaderResult} (one document) ready for `rag.index()`.\n * @throws {OutboundPolicyError} when the policy blocks the URL, the request\n * times out, the body exceeds the cap, or the response is not OK.\n */\nexport async function loadWeb(\n url: string,\n options: LoadWebOptions = {},\n): Promise<RagLoaderResult> {\n const policy = resolveOutboundPolicy(options.policy);\n\n const response = await guardedFetch(url, policy, {\n headers: { \"user-agent\": DEFAULT_USER_AGENT, accept: \"text/html,text/*\" },\n redirect: \"follow\",\n });\n\n if (!response.ok) {\n throw new OutboundPolicyError(\n `loadWeb: fetching \"${url}\" returned ${response.status} ${response.statusText}`,\n { context: { url, status: response.status } },\n );\n }\n\n const contentType = response.headers.get(\"content-type\") ?? undefined;\n const raw = await readTextCapped(response, policy.maxBytes);\n\n const isHtml = isHtmlContentType(contentType);\n const text = isHtml ? htmlToText(raw) : raw.trim();\n const title = isHtml ? extractTitle(raw) : undefined;\n\n const id = options.id ?? url;\n\n // An empty body / all-markup page yields no document, so index() never\n // receives a no-op record.\n if (text.length === 0) {\n return [];\n }\n\n // Derived keys sit UNDER the caller's metadata so an explicit override wins.\n const doc: RagDocument = {\n id,\n text,\n metadata: {\n source: url,\n loader: \"web\",\n ...(title !== undefined ? { title } : {}),\n ...(contentType !== undefined ? { contentType } : {}),\n ...options.metadata,\n },\n tags: options.tags,\n };\n\n return [doc];\n}\n"],"mappings":";;;;;;;AAWA,MAAM,qBACJ;;;;;AAMF,SAAS,kBAAkB,aAA0C;CACnE,IAAI,CAAC,aAEH,OAAO;CAGT,MAAM,QAAQ,YAAY,YAAY;CAEtC,OAAO,MAAM,SAAS,WAAW,KAAK,MAAM,SAAS,mBAAmB;AAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,eAAsB,QACpB,KACA,UAA0B,CAAC,GACD;CAC1B,MAAM,SAAS,sBAAsB,QAAQ,MAAM;CAEnD,MAAM,WAAW,MAAM,aAAa,KAAK,QAAQ;EAC/C,SAAS;GAAE,cAAc;GAAoB,QAAQ;EAAmB;EACxE,UAAU;CACZ,CAAC;CAED,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,oBACR,sBAAsB,IAAI,aAAa,SAAS,OAAO,GAAG,SAAS,cACnE,EAAE,SAAS;EAAE;EAAK,QAAQ,SAAS;CAAO,EAAE,CAC9C;CAGF,MAAM,cAAc,SAAS,QAAQ,IAAI,cAAc,KAAK;CAC5D,MAAM,MAAM,MAAM,eAAe,UAAU,OAAO,QAAQ;CAE1D,MAAM,SAAS,kBAAkB,WAAW;CAC5C,MAAM,OAAO,SAAS,WAAW,GAAG,IAAI,IAAI,KAAK;CACjD,MAAM,QAAQ,SAAS,aAAa,GAAG,IAAI;CAE3C,MAAM,KAAK,QAAQ,MAAM;CAIzB,IAAI,KAAK,WAAW,GAClB,OAAO,CAAC;CAiBV,OAAO,CAAC;EAZN;EACA;EACA,UAAU;GACR,QAAQ;GACR,QAAQ;GACR,GAAI,UAAU,SAAY,EAAE,MAAM,IAAI,CAAC;GACvC,GAAI,gBAAgB,SAAY,EAAE,YAAY,IAAI,CAAC;GACnD,GAAG,QAAQ;EACb;EACA,MAAM,QAAQ;CAGN,CAAC;AACb"}
@@ -1,126 +0,0 @@
1
- import { resolveDefaultStore } from "../config.mjs";
2
- import { chunk } from "./chunk/chunk.mjs";
3
- import { ragAsTool } from "./as-tool.mjs";
4
- import { retrieve } from "./retrieve.mjs";
5
- import { cacheVectorStore } from "./store/cache-vector-store.mjs";
6
-
7
- //#region ../@warlock.js/ai/src/rag/rag.ts
8
- const DEFAULT_NAME = "rag";
9
- const DEFAULT_NAMESPACE_PREFIX = "ai.rag";
10
- /**
11
- * Max chunk texts embedded per `embedder.embedMany()` call. One call is
12
- * one provider request, so a giant document is sub-batched to stay under
13
- * the provider's per-request token cap (the design's "chunk larger than
14
- * provider per-request cap" guard).
15
- */
16
- const DEFAULT_MAX_BATCH = 96;
17
- /**
18
- * Create a RAG pipeline: **chunk → embed → vector store → retrieve →
19
- * rerank → cite**, reusing the app's `ai.embedder` for embedding, a
20
- * `@warlock.js/cache` `CacheDriver` as the vector store, and the
21
- * composite-as-tool engine to expose retrieval as a tool.
22
- *
23
- * Resolution is loud at construction (mirroring `memory()`):
24
- * - `embedder` is required — a provider with no embedder must be caught
25
- * here, not at first index.
26
- * - `store` falls back to `ai.config({ defaultStore })`; if neither
27
- * resolves, construction throws.
28
- *
29
- * `retrieve()` is return-only — it never auto-injects into a prompt; the
30
- * caller formats the cited chunks (or uses `asTool()` for the agent loop).
31
- * The reranker is OFF by default (cosine-only) unless `config.reranker`
32
- * is set.
33
- *
34
- * @example
35
- * import { ai } from "@warlock.js/ai";
36
- * import { MemoryCacheDriver } from "@warlock.js/cache";
37
- *
38
- * const kb = ai.rag({
39
- * name: "docs",
40
- * embedder: openai.embedder({ name: "text-embedding-3-small" }),
41
- * store: new MemoryCacheDriver(),
42
- * chunk: { type: "markdown", size: 800, overlap: 120 },
43
- * });
44
- *
45
- * await kb.index([{ id: "guide", text: longMarkdown, metadata: { url: "/guide" } }]);
46
- * const { chunks } = await kb.retrieve("how do I configure caching?", { topK: 4 });
47
- */
48
- function rag(config) {
49
- const name = config.name ?? DEFAULT_NAME;
50
- if (!config.embedder) throw new Error(`rag("${name}"): an \`embedder\` is required — pass one from a provider that supports embeddings (e.g. openai.embedder({ name: "text-embedding-3-small" }))`);
51
- const driver = config.store ?? resolveDefaultStore();
52
- if (!driver) throw new Error(`rag("${name}"): no store — pass \`store\` (a vector-capable @warlock.js/cache CacheDriver) or call \`ai.config({ defaultStore })\` at app boot before constructing the rag`);
53
- const store = cacheVectorStore(driver);
54
- const namespace = config.namespace ?? `${DEFAULT_NAMESPACE_PREFIX}.${name}`;
55
- const embedder = config.embedder;
56
- let indexedDimensions;
57
- const instance = {
58
- name,
59
- async index(docs, chunkOverride) {
60
- const chunkOptions = chunkOverride ?? config.chunk;
61
- const limits = config.limits;
62
- if (limits?.maxDocuments !== void 0 && docs.length > limits.maxDocuments) throw new Error(`rag("${name}"): index() received ${docs.length} documents, exceeding the configured maxDocuments of ${limits.maxDocuments}`);
63
- if (limits?.maxBytes !== void 0) {
64
- const totalBytes = docs.reduce((sum, doc) => sum + Buffer.byteLength(doc.text ?? ""), 0);
65
- if (totalBytes > limits.maxBytes) throw new Error(`rag("${name}"): index() received ${totalBytes} bytes of document text, exceeding the configured maxBytes of ${limits.maxBytes}`);
66
- }
67
- const records = [];
68
- for (const doc of docs) {
69
- const pieces = chunk(doc.text, chunkOptions);
70
- for (const piece of pieces) {
71
- const value = {
72
- sourceId: doc.id,
73
- chunkIndex: piece.index,
74
- span: piece.span,
75
- text: piece.text,
76
- metadata: doc.metadata
77
- };
78
- records.push({
79
- key: keyFor(namespace, doc.id, piece.index),
80
- value,
81
- text: piece.text,
82
- tags: doc.tags
83
- });
84
- }
85
- }
86
- if (records.length === 0) return { chunks: 0 };
87
- if (limits?.maxChunks !== void 0 && records.length > limits.maxChunks) throw new Error(`rag("${name}"): index() produced ${records.length} chunks, exceeding the configured maxChunks of ${limits.maxChunks}`);
88
- for (let offset = 0; offset < records.length; offset += DEFAULT_MAX_BATCH) {
89
- const batch = records.slice(offset, offset + DEFAULT_MAX_BATCH);
90
- const { vectors, dimensions } = await embedder.embedMany(batch.map((record) => record.text));
91
- if (indexedDimensions === void 0 && dimensions !== 0) indexedDimensions = dimensions;
92
- await Promise.all(batch.map((record, position) => store.upsert(record.key, record.value, vectors[position], record.tags)));
93
- }
94
- return { chunks: records.length };
95
- },
96
- async retrieve(query, options) {
97
- return retrieve(query, {
98
- embedder,
99
- store,
100
- namespace,
101
- reranker: config.reranker,
102
- defaults: config.retrieve,
103
- indexedDimensions
104
- }, options);
105
- },
106
- async clear() {
107
- await store.removeNamespace(namespace);
108
- },
109
- asTool(options) {
110
- return ragAsTool(name, (query, retrieveOptions) => instance.retrieve(query, retrieveOptions), options);
111
- }
112
- };
113
- return instance;
114
- }
115
- /**
116
- * Namespaced key for a stored chunk. Uses the `.` separator (matching
117
- * `SemanticMemory.keyFor`) so namespace-prefix filtering on the returned
118
- * `hit.key` stays aligned with the cache's `parseKey` normalization.
119
- */
120
- function keyFor(namespace, sourceId, chunkIndex) {
121
- return `${namespace}.${sourceId}.${chunkIndex}`;
122
- }
123
-
124
- //#endregion
125
- export { rag };
126
- //# sourceMappingURL=rag.mjs.map