@nhtio/adk 0.1.0-master-e068b986 → 0.1.0-master-0c6d984f

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 (210) hide show
  1. package/CHANGELOG.md +54 -9
  2. package/batteries/embeddings/openai/adapter.cjs +1 -1
  3. package/batteries/embeddings/openai/adapter.mjs +1 -1
  4. package/batteries/embeddings/webllm/adapter.cjs +1 -1
  5. package/batteries/embeddings/webllm/adapter.mjs +1 -1
  6. package/batteries/llm/ollama/adapter.cjs +5 -5
  7. package/batteries/llm/ollama/adapter.mjs +5 -5
  8. package/batteries/llm/ollama/helpers.cjs +2 -2
  9. package/batteries/llm/ollama/helpers.mjs +2 -2
  10. package/batteries/llm/ollama/validation.cjs +1 -1
  11. package/batteries/llm/ollama/validation.mjs +1 -1
  12. package/batteries/llm/openai_chat_completions/adapter.cjs +5 -5
  13. package/batteries/llm/openai_chat_completions/adapter.mjs +5 -5
  14. package/batteries/llm/openai_chat_completions/helpers.cjs +2 -2
  15. package/batteries/llm/openai_chat_completions/helpers.mjs +2 -2
  16. package/batteries/llm/openai_chat_completions/validation.cjs +1 -1
  17. package/batteries/llm/openai_chat_completions/validation.mjs +1 -1
  18. package/batteries/llm/webllm_chat_completions/adapter.cjs +5 -5
  19. package/batteries/llm/webllm_chat_completions/adapter.mjs +5 -5
  20. package/batteries/llm/webllm_chat_completions/validation.cjs +1 -1
  21. package/batteries/llm/webllm_chat_completions/validation.mjs +1 -1
  22. package/batteries/storage/flydrive.cjs +1 -1
  23. package/batteries/storage/flydrive.mjs +1 -1
  24. package/batteries/storage/in_memory.cjs +1 -1
  25. package/batteries/storage/in_memory.mjs +1 -1
  26. package/batteries/storage/opfs.cjs +1 -1
  27. package/batteries/storage/opfs.mjs +1 -1
  28. package/batteries/tools/_shared/index.d.ts +121 -0
  29. package/batteries/tools/_shared.cjs +157 -0
  30. package/batteries/tools/_shared.cjs.map +1 -0
  31. package/batteries/tools/_shared.mjs +149 -0
  32. package/batteries/tools/_shared.mjs.map +1 -0
  33. package/batteries/tools/color.cjs +2 -2
  34. package/batteries/tools/color.mjs +2 -2
  35. package/batteries/tools/comparison.cjs +3 -3
  36. package/batteries/tools/comparison.mjs +3 -3
  37. package/batteries/tools/data_structure.cjs +3 -3
  38. package/batteries/tools/data_structure.mjs +3 -3
  39. package/batteries/tools/datetime_extended.cjs +3 -3
  40. package/batteries/tools/datetime_extended.mjs +3 -3
  41. package/batteries/tools/datetime_math.cjs +3 -3
  42. package/batteries/tools/datetime_math.mjs +3 -3
  43. package/batteries/tools/encoding.cjs +3 -3
  44. package/batteries/tools/encoding.mjs +3 -3
  45. package/batteries/tools/formatting.cjs +3 -3
  46. package/batteries/tools/formatting.mjs +3 -3
  47. package/batteries/tools/geo_basics.cjs +2 -2
  48. package/batteries/tools/geo_basics.mjs +2 -2
  49. package/batteries/tools/index.d.ts +2 -0
  50. package/batteries/tools/math.cjs +3 -3
  51. package/batteries/tools/math.mjs +3 -3
  52. package/batteries/tools/memory.cjs +6 -6
  53. package/batteries/tools/memory.mjs +6 -6
  54. package/batteries/tools/parsing.cjs +4 -4
  55. package/batteries/tools/parsing.mjs +4 -4
  56. package/batteries/tools/retrievables.cjs +5 -5
  57. package/batteries/tools/retrievables.mjs +5 -5
  58. package/batteries/tools/scrapper/exceptions.d.ts +21 -0
  59. package/batteries/tools/scrapper/index.d.ts +172 -0
  60. package/batteries/tools/scrapper/shared.d.ts +139 -0
  61. package/batteries/tools/scrapper.cjs +8 -0
  62. package/batteries/tools/scrapper.mjs +2 -0
  63. package/batteries/tools/searxng/index.d.ts +47 -20
  64. package/batteries/tools/searxng.cjs +2 -1
  65. package/batteries/tools/searxng.mjs +2 -2
  66. package/batteries/tools/standing_instructions.cjs +4 -4
  67. package/batteries/tools/standing_instructions.mjs +4 -4
  68. package/batteries/tools/statistics.cjs +4 -4
  69. package/batteries/tools/statistics.mjs +4 -4
  70. package/batteries/tools/string_processing.cjs +3 -3
  71. package/batteries/tools/string_processing.mjs +3 -3
  72. package/batteries/tools/structured_data.cjs +3 -3
  73. package/batteries/tools/structured_data.mjs +3 -3
  74. package/batteries/tools/text_analysis.cjs +3 -3
  75. package/batteries/tools/text_analysis.mjs +3 -3
  76. package/batteries/tools/text_comparison.cjs +2 -2
  77. package/batteries/tools/text_comparison.mjs +2 -2
  78. package/batteries/tools/time.cjs +3 -3
  79. package/batteries/tools/time.mjs +3 -3
  80. package/batteries/tools/unit_conversion.cjs +2 -2
  81. package/batteries/tools/unit_conversion.mjs +2 -2
  82. package/batteries/tools/web_retrieval/index.d.ts +186 -0
  83. package/batteries/tools/web_retrieval.cjs +206 -0
  84. package/batteries/tools/web_retrieval.cjs.map +1 -0
  85. package/batteries/tools/web_retrieval.mjs +201 -0
  86. package/batteries/tools/web_retrieval.mjs.map +1 -0
  87. package/batteries/tools.cjs +13 -1
  88. package/batteries/tools.mjs +4 -2
  89. package/batteries/vector/arangodb.cjs +1 -1
  90. package/batteries/vector/arangodb.mjs +1 -1
  91. package/batteries/vector/clickhouse.cjs +1 -1
  92. package/batteries/vector/clickhouse.mjs +1 -1
  93. package/batteries/vector/cloudflare.cjs +1 -1
  94. package/batteries/vector/cloudflare.mjs +1 -1
  95. package/batteries/vector/couchbase.cjs +1 -1
  96. package/batteries/vector/couchbase.mjs +1 -1
  97. package/batteries/vector/duckdb.cjs +1 -1
  98. package/batteries/vector/duckdb.mjs +1 -1
  99. package/batteries/vector/elasticsearch.cjs +1 -1
  100. package/batteries/vector/elasticsearch.mjs +1 -1
  101. package/batteries/vector/filters.cjs +1 -1
  102. package/batteries/vector/filters.mjs +1 -1
  103. package/batteries/vector/hnswlib.cjs +1 -1
  104. package/batteries/vector/hnswlib.mjs +1 -1
  105. package/batteries/vector/lancedb.cjs +1 -1
  106. package/batteries/vector/lancedb.mjs +1 -1
  107. package/batteries/vector/mariadb.cjs +1 -1
  108. package/batteries/vector/mariadb.mjs +1 -1
  109. package/batteries/vector/meilisearch.cjs +1 -1
  110. package/batteries/vector/meilisearch.mjs +1 -1
  111. package/batteries/vector/migrate.cjs +1 -1
  112. package/batteries/vector/migrate.mjs +1 -1
  113. package/batteries/vector/mongodb.cjs +1 -1
  114. package/batteries/vector/mongodb.mjs +1 -1
  115. package/batteries/vector/neo4j.cjs +1 -1
  116. package/batteries/vector/neo4j.mjs +1 -1
  117. package/batteries/vector/opensearch.cjs +1 -1
  118. package/batteries/vector/opensearch.mjs +1 -1
  119. package/batteries/vector/oracle23ai.cjs +1 -1
  120. package/batteries/vector/oracle23ai.mjs +1 -1
  121. package/batteries/vector/pinecone.cjs +1 -1
  122. package/batteries/vector/pinecone.mjs +1 -1
  123. package/batteries/vector/redis.cjs +1 -1
  124. package/batteries/vector/redis.mjs +1 -1
  125. package/batteries/vector/retrievable.cjs +1 -1
  126. package/batteries/vector/retrievable.mjs +1 -1
  127. package/batteries/vector/s3vectors.cjs +1 -1
  128. package/batteries/vector/s3vectors.mjs +1 -1
  129. package/batteries/vector/solr.cjs +1 -1
  130. package/batteries/vector/solr.mjs +1 -1
  131. package/batteries/vector/surrealdb.cjs +1 -1
  132. package/batteries/vector/surrealdb.mjs +1 -1
  133. package/batteries/vector/typesense.cjs +1 -1
  134. package/batteries/vector/typesense.mjs +1 -1
  135. package/batteries/vector/vespa.cjs +1 -1
  136. package/batteries/vector/vespa.mjs +1 -1
  137. package/batteries/vector/weaviate.cjs +1 -1
  138. package/batteries/vector/weaviate.mjs +1 -1
  139. package/batteries.cjs +13 -1
  140. package/batteries.mjs +4 -2
  141. package/{common-DwyIhf5B.mjs → common-DYDUi99O.mjs} +7 -7
  142. package/{common-DwyIhf5B.mjs.map → common-DYDUi99O.mjs.map} +1 -1
  143. package/{common-Do0PmqEC.js → common-DZl3ADJs.js} +7 -7
  144. package/{common-Do0PmqEC.js.map → common-DZl3ADJs.js.map} +1 -1
  145. package/common.cjs +7 -7
  146. package/common.d.ts +1 -1
  147. package/common.mjs +7 -7
  148. package/{dispatch_runner-Bh12zRee.mjs → dispatch_runner--ZhdDWRZ.mjs} +3 -3
  149. package/{dispatch_runner-Bh12zRee.mjs.map → dispatch_runner--ZhdDWRZ.mjs.map} +1 -1
  150. package/{dispatch_runner-BCfDikZn.js → dispatch_runner-nHDKkxye.js} +3 -3
  151. package/{dispatch_runner-BCfDikZn.js.map → dispatch_runner-nHDKkxye.js.map} +1 -1
  152. package/dispatch_runner.cjs +1 -1
  153. package/dispatch_runner.mjs +1 -1
  154. package/eslint/rules.cjs +2 -2
  155. package/eslint/rules.mjs +2 -2
  156. package/eslint.cjs +3 -3
  157. package/eslint.mjs +3 -3
  158. package/forge.cjs +4 -4
  159. package/forge.mjs +4 -4
  160. package/guards.cjs +8 -8
  161. package/guards.mjs +8 -8
  162. package/index.cjs +10 -10
  163. package/index.mjs +10 -10
  164. package/mcp/adk-docs-corpus.json +1 -1
  165. package/package.json +202 -187
  166. package/scrapper-CR-MFDCm.js +462 -0
  167. package/scrapper-CR-MFDCm.js.map +1 -0
  168. package/scrapper-Djl6ga2K.mjs +432 -0
  169. package/scrapper-Djl6ga2K.mjs.map +1 -0
  170. package/{searxng-COD67eJC.js → searxng-CMhRD5xo.js} +84 -88
  171. package/searxng-CMhRD5xo.js.map +1 -0
  172. package/{searxng-oL3Z5Qo2.mjs → searxng-yWwuON_Y.mjs} +77 -87
  173. package/searxng-yWwuON_Y.mjs.map +1 -0
  174. package/skills/adk-assembly/SKILL.md +2 -2
  175. package/{spooled_artifact-BsM1EfRB.mjs → spooled_artifact-7eePq7JA.mjs} +3 -3
  176. package/{spooled_artifact-BsM1EfRB.mjs.map → spooled_artifact-7eePq7JA.mjs.map} +1 -1
  177. package/{spooled_artifact-B6XRZYFt.js → spooled_artifact-DX8LLyUX.js} +3 -3
  178. package/{spooled_artifact-B6XRZYFt.js.map → spooled_artifact-DX8LLyUX.js.map} +1 -1
  179. package/spooled_artifact.cjs +2 -2
  180. package/spooled_artifact.mjs +2 -2
  181. package/{spooled_markdown_artifact-DyevhaL6.js → spooled_markdown_artifact-ClX72lek.js} +3 -3
  182. package/{spooled_markdown_artifact-DyevhaL6.js.map → spooled_markdown_artifact-ClX72lek.js.map} +1 -1
  183. package/{spooled_markdown_artifact-DJnjD3Ti.mjs → spooled_markdown_artifact-wkrBF3oX.mjs} +3 -3
  184. package/{spooled_markdown_artifact-DJnjD3Ti.mjs.map → spooled_markdown_artifact-wkrBF3oX.mjs.map} +1 -1
  185. package/{thought-DzcSu2Y6.mjs → thought-B_vxAiKU.mjs} +3 -3
  186. package/{thought-DzcSu2Y6.mjs.map → thought-B_vxAiKU.mjs.map} +1 -1
  187. package/{thought-DhElxSkZ.js → thought-DLwpF7MI.js} +3 -3
  188. package/{thought-DhElxSkZ.js.map → thought-DLwpF7MI.js.map} +1 -1
  189. package/{tool-DjUJeSzk.js → tool-D5WGVIcI.js} +3 -3
  190. package/{tool-DjUJeSzk.js.map → tool-D5WGVIcI.js.map} +1 -1
  191. package/{tool-DMvZFz9h.mjs → tool-wMYMVl60.mjs} +3 -3
  192. package/{tool-DMvZFz9h.mjs.map → tool-wMYMVl60.mjs.map} +1 -1
  193. package/{tool_call-DhAW70EY.mjs → tool_call-B4-_-vjG.mjs} +4 -4
  194. package/{tool_call-DhAW70EY.mjs.map → tool_call-B4-_-vjG.mjs.map} +1 -1
  195. package/{tool_call-CGec5078.js → tool_call-DixVlW40.js} +4 -4
  196. package/{tool_call-CGec5078.js.map → tool_call-DixVlW40.js.map} +1 -1
  197. package/{tool_registry-BuMKln6b.mjs → tool_registry-791Vrjtf.mjs} +142 -142
  198. package/tool_registry-791Vrjtf.mjs.map +1 -0
  199. package/{tool_registry-C5wfDxaq.js → tool_registry-CKJPze3j.js} +141 -141
  200. package/tool_registry-CKJPze3j.js.map +1 -0
  201. package/{turn_runner-CfrZZ-ZJ.js → turn_runner-HXImLGIn.js} +5 -5
  202. package/{turn_runner-CfrZZ-ZJ.js.map → turn_runner-HXImLGIn.js.map} +1 -1
  203. package/{turn_runner-BQCupiHC.mjs → turn_runner-ZyYO-Kti.mjs} +5 -5
  204. package/{turn_runner-BQCupiHC.mjs.map → turn_runner-ZyYO-Kti.mjs.map} +1 -1
  205. package/turn_runner.cjs +1 -1
  206. package/turn_runner.mjs +1 -1
  207. package/searxng-COD67eJC.js.map +0 -1
  208. package/searxng-oL3Z5Qo2.mjs.map +0 -1
  209. package/tool_registry-BuMKln6b.mjs.map +0 -1
  210. package/tool_registry-C5wfDxaq.js.map +0 -1
@@ -1,6 +1,6 @@
1
- import { o as isError } from "../../tool_registry-BuMKln6b.mjs";
2
- import { t as Tool } from "../../tool-DMvZFz9h.mjs";
3
- import "../../common-DwyIhf5B.mjs";
1
+ import { o as isError } from "../../tool_registry-791Vrjtf.mjs";
2
+ import { t as Tool } from "../../tool-wMYMVl60.mjs";
3
+ import "../../common-DYDUi99O.mjs";
4
4
  import "../../guards.mjs";
5
5
  import { validator } from "@nhtio/validation";
6
6
  import { camelCase, capitalCase, kebabCase, pascalCase, snakeCase, trainCase } from "case-anything";
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../chunk-Ble4zEEl.js");
3
- const require_tool_registry = require("../../tool_registry-C5wfDxaq.js");
4
- const require_tool = require("../../tool-DjUJeSzk.js");
5
- require("../../common-Do0PmqEC.js");
3
+ const require_tool_registry = require("../../tool_registry-CKJPze3j.js");
4
+ const require_tool = require("../../tool-D5WGVIcI.js");
5
+ require("../../common-DZl3ADJs.js");
6
6
  require("../../guards.cjs");
7
7
  let _nhtio_validation = require("@nhtio/validation");
8
8
  //#region src/batteries/tools/structured_data/index.ts
@@ -1,6 +1,6 @@
1
- import { c as isObject, o as isError } from "../../tool_registry-BuMKln6b.mjs";
2
- import { t as Tool } from "../../tool-DMvZFz9h.mjs";
3
- import "../../common-DwyIhf5B.mjs";
1
+ import { c as isObject, o as isError } from "../../tool_registry-791Vrjtf.mjs";
2
+ import { t as Tool } from "../../tool-wMYMVl60.mjs";
3
+ import "../../common-DYDUi99O.mjs";
4
4
  import "../../guards.mjs";
5
5
  import { validator } from "@nhtio/validation";
6
6
  //#region src/batteries/tools/structured_data/index.ts
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../chunk-Ble4zEEl.js");
3
- const require_tool = require("../../tool-DjUJeSzk.js");
4
- require("../../common-Do0PmqEC.js");
5
- const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-DyevhaL6.js");
3
+ const require_tool = require("../../tool-D5WGVIcI.js");
4
+ require("../../common-DZl3ADJs.js");
5
+ const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-ClX72lek.js");
6
6
  let _nhtio_validation = require("@nhtio/validation");
7
7
  //#region src/batteries/tools/text_analysis/index.ts
8
8
  /**
@@ -1,6 +1,6 @@
1
- import { t as Tool } from "../../tool-DMvZFz9h.mjs";
2
- import "../../common-DwyIhf5B.mjs";
3
- import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-DJnjD3Ti.mjs";
1
+ import { t as Tool } from "../../tool-wMYMVl60.mjs";
2
+ import "../../common-DYDUi99O.mjs";
3
+ import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-wkrBF3oX.mjs";
4
4
  import { validator } from "@nhtio/validation";
5
5
  //#region src/batteries/tools/text_analysis/index.ts
6
6
  /**
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../chunk-Ble4zEEl.js");
3
- const require_tool = require("../../tool-DjUJeSzk.js");
4
- require("../../common-Do0PmqEC.js");
3
+ const require_tool = require("../../tool-D5WGVIcI.js");
4
+ require("../../common-DZl3ADJs.js");
5
5
  let _nhtio_validation = require("@nhtio/validation");
6
6
  let diff = require("diff");
7
7
  let fastest_levenshtein = require("fastest-levenshtein");
@@ -1,5 +1,5 @@
1
- import { t as Tool } from "../../tool-DMvZFz9h.mjs";
2
- import "../../common-DwyIhf5B.mjs";
1
+ import { t as Tool } from "../../tool-wMYMVl60.mjs";
2
+ import "../../common-DYDUi99O.mjs";
3
3
  import { validator } from "@nhtio/validation";
4
4
  import { diffLines, diffWords } from "diff";
5
5
  import { distance } from "fastest-levenshtein";
@@ -1,9 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../chunk-Ble4zEEl.js");
3
- const require_tool = require("../../tool-DjUJeSzk.js");
4
- require("../../common-Do0PmqEC.js");
5
- let luxon = require("luxon");
3
+ const require_tool = require("../../tool-D5WGVIcI.js");
4
+ require("../../common-DZl3ADJs.js");
6
5
  let _nhtio_validation = require("@nhtio/validation");
6
+ let luxon = require("luxon");
7
7
  //#region src/batteries/tools/time/index.ts
8
8
  /**
9
9
  * Pre-constructed tools for current time lookup and timezone-aware time formatting.
@@ -1,7 +1,7 @@
1
- import { t as Tool } from "../../tool-DMvZFz9h.mjs";
2
- import "../../common-DwyIhf5B.mjs";
3
- import { DateTime, IANAZone } from "luxon";
1
+ import { t as Tool } from "../../tool-wMYMVl60.mjs";
2
+ import "../../common-DYDUi99O.mjs";
4
3
  import { validator } from "@nhtio/validation";
4
+ import { DateTime, IANAZone } from "luxon";
5
5
  //#region src/batteries/tools/time/index.ts
6
6
  /**
7
7
  * Pre-constructed tools for current time lookup and timezone-aware time formatting.
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../../chunk-Ble4zEEl.js");
3
- const require_tool = require("../../tool-DjUJeSzk.js");
4
- require("../../common-Do0PmqEC.js");
3
+ const require_tool = require("../../tool-D5WGVIcI.js");
4
+ require("../../common-DZl3ADJs.js");
5
5
  const require_lib_helpers_bignum = require("../../lib/helpers/bignum.cjs");
6
6
  let _nhtio_validation = require("@nhtio/validation");
7
7
  //#region src/batteries/tools/unit_conversion/index.ts
@@ -1,5 +1,5 @@
1
- import { t as Tool } from "../../tool-DMvZFz9h.mjs";
2
- import "../../common-DwyIhf5B.mjs";
1
+ import { t as Tool } from "../../tool-wMYMVl60.mjs";
2
+ import "../../common-DYDUi99O.mjs";
3
3
  import { bigScale, formatBig } from "../../lib/helpers/bignum.mjs";
4
4
  import { validator } from "@nhtio/validation";
5
5
  //#region src/batteries/tools/unit_conversion/index.ts
@@ -0,0 +1,186 @@
1
+ /**
2
+ * RAG glue: turn web-search and web-scrape results into `Retrievable` records for a turn.
3
+ *
4
+ * @module @nhtio/adk/batteries/tools/web_retrieval
5
+ *
6
+ * @remarks
7
+ * The seam from "I searched / scraped something" to "it is in the turn as a `Retrievable`",
8
+ * shared by the SearXNG and Scrapper batteries. It is deliberately **decoupled** from the ADK
9
+ * core at runtime:
10
+ *
11
+ * - The converters are **pure** `(payload) => RawRetrievable[]` — they build plain data objects and
12
+ * never instantiate a core class, so the module's only core coupling is erased `import type`.
13
+ * - The recommended spool-artifact type travels as an **open resolver**
14
+ * ({@link @nhtio/adk/forge!ArtifactConstructorResolver}), never a closed string enum — a consumer's
15
+ * future YAML/HTML `SpooledArtifact` subclass works with no change here. The converter hands the
16
+ * recommendation to the caller's `spool` hook; the caller owns the actual class import.
17
+ * - The one helper that must construct a `Retrievable` ({@link storeRetrievables}) takes the
18
+ * constructor via a **resolver** (constructor / sync / async / dynamic-import), exactly like the
19
+ * vector battery's `createVectorStore` `client`.
20
+ *
21
+ * Web content is `'third-party-public'` by default — a definitional constant for open-web data
22
+ * (NOT inferred from the URL, which CONTRIBUTING Design Decision #12 forbids); override via
23
+ * `trustTier` when you know better.
24
+ */
25
+ import type { SpooledArtifact } from "../../../spooled_artifact";
26
+ import type { ArtifactConstructorResolver } from "../../../forge";
27
+ import type { RawRetrievable, Retrievable, RetrievableTrustTier } from "../../../common";
28
+ /** A constructor that builds a {@link @nhtio/adk!Retrievable} from a {@link @nhtio/adk!RawRetrievable}. */
29
+ export type RetrievableCtor = new (raw: RawRetrievable) => Retrievable;
30
+ /** A resolver of `T`: the value itself, or a (sync/async) thunk, optionally a module `{ default }`. */
31
+ export type Resolver<T> = T | (() => T | {
32
+ default: T;
33
+ }) | (() => Promise<T | {
34
+ default: T;
35
+ }>);
36
+ /**
37
+ * A reader-backed-artifact hook. Called by a converter for content that may be large; the
38
+ * converter passes the artifact constructor it **recommends** for this content (an open
39
+ * {@link @nhtio/adk/forge!ArtifactConstructorResolver}) so the caller can wrap with the right
40
+ * subclass — preserving its forged query tools — using the caller's own core import. Return a
41
+ * {@link @nhtio/adk!SpooledArtifact} to store the content reader-backed, or `undefined` to keep it
42
+ * inline as a string.
43
+ */
44
+ export type SpoolHook = (id: string, text: string, recommended: ArtifactConstructorResolver) => SpooledArtifact | undefined;
45
+ /** Options common to every converter. */
46
+ export interface ToRetrievableOptions {
47
+ /**
48
+ * Trust tier for the produced records. Default `'third-party-public'` (web content is
49
+ * third-party by definition — this is a constant, not URL inference).
50
+ */
51
+ trustTier?: RetrievableTrustTier;
52
+ /** Semantic `kind` label, e.g. `'web-search-result'`, `'web-article'`, `'web-links'`. */
53
+ kind?: string;
54
+ /** Prefix for the stable, hashed record id (namespacing across sources). */
55
+ idPrefix?: string;
56
+ /** Optional reader-backed-artifact hook for large content. See {@link SpoolHook}. */
57
+ spool?: SpoolHook;
58
+ }
59
+ /**
60
+ * The artifact-resolver recommendations a caller may supply so the glue names no concrete class
61
+ * itself. Each converter asks for the relevant key; if the caller omits it, content stays inline.
62
+ */
63
+ export interface ArtifactRecommendations {
64
+ /** Recommended for plain-text / HTML content (base `SpooledArtifact`). */
65
+ text?: ArtifactConstructorResolver;
66
+ /** Recommended for markdown content (`SpooledMarkdownArtifact`). */
67
+ markdown?: ArtifactConstructorResolver;
68
+ /** Recommended for JSON content (`SpooledJsonArtifact`). */
69
+ json?: ArtifactConstructorResolver;
70
+ }
71
+ /** Minimal structural shape of a SearXNG normalised result the converter reads. */
72
+ export interface SearxngResultLike {
73
+ /** Result URL (becomes the record's `source`). */
74
+ url?: string;
75
+ /** Result title (joined into the inline content). */
76
+ title?: string;
77
+ /** Result snippet (joined into the inline content). */
78
+ content?: string;
79
+ /** Relevance score (clamped to `[0,1]` on the record). */
80
+ score?: number;
81
+ }
82
+ /** Minimal structural shape of a SearXNG normalised payload. */
83
+ export interface SearxngPayloadLike {
84
+ /** The result list. */
85
+ results?: SearxngResultLike[];
86
+ }
87
+ /**
88
+ * Convert a SearXNG normalised payload into one {@link @nhtio/adk!RawRetrievable} per result.
89
+ *
90
+ * @remarks
91
+ * Snippets are short, so `content` stays an inline string (the `spool` hook, if any, is still
92
+ * offered the `text` recommendation). `source` is the result URL; `score` is clamped to `[0,1]`.
93
+ *
94
+ * @param payload - The SearXNG normalised payload (`{ results: [{ url, title, content, score }] }`).
95
+ * @param opts - Trust tier, kind, id prefix, optional spool hook.
96
+ * @param recommend - Optional artifact-resolver recommendations (the glue names no class itself).
97
+ * @returns One `RawRetrievable` per result.
98
+ */
99
+ export declare const searxngResultsToRetrievables: (payload: SearxngPayloadLike, opts?: ToRetrievableOptions, recommend?: ArtifactRecommendations) => RawRetrievable[];
100
+ /** Minimal structural shape of a Scrapper normalised article. */
101
+ export interface ScrapperArticleLike {
102
+ /** The page URL (becomes the record's `source`). */
103
+ url?: string;
104
+ /** Article title. */
105
+ title?: string;
106
+ /** Article text with HTML stripped (the default content source). */
107
+ textContent?: string;
108
+ /** Processed article HTML (the `'content'` content source). */
109
+ content?: string;
110
+ }
111
+ /** Which article text field to use as the record content. */
112
+ export type ArticleContentSource = 'textContent' | 'content';
113
+ /** Options for {@link scrapperArticleToRetrievable}. */
114
+ export interface ArticleToRetrievableOptions extends ToRetrievableOptions {
115
+ /** Which field to use as content (default `'textContent'`). `'content'` is HTML. */
116
+ contentSource?: ArticleContentSource;
117
+ /**
118
+ * Whether the chosen content is markdown (recommend `markdown`) rather than plain text.
119
+ * Default false. Use when an output pipeline rendered the article to markdown.
120
+ */
121
+ asMarkdown?: boolean;
122
+ }
123
+ /**
124
+ * Convert a Scrapper normalised article into a single {@link @nhtio/adk!RawRetrievable}.
125
+ *
126
+ * @remarks
127
+ * Long article text is exactly what a reader-backed {@link @nhtio/adk!SpooledArtifact} is for: pass a
128
+ * `spool` hook and the converter offers it the recommended artifact resolver (markdown when
129
+ * `asMarkdown`, else text/HTML) so the model gets the right forged query tools. Without a hook,
130
+ * content stays inline.
131
+ *
132
+ * @param article - The Scrapper normalised article.
133
+ * @param opts - Trust tier, kind, id prefix, content source, markdown flag, optional spool hook.
134
+ * @param recommend - Optional artifact-resolver recommendations.
135
+ * @returns A single `RawRetrievable`.
136
+ */
137
+ export declare const scrapperArticleToRetrievable: (article: ScrapperArticleLike, opts?: ArticleToRetrievableOptions, recommend?: ArtifactRecommendations) => RawRetrievable;
138
+ /** Minimal structural shape of a Scrapper normalised link. */
139
+ export interface ScrapperLinkLike {
140
+ /** The link's target URL (becomes the record's `source`). */
141
+ url?: string;
142
+ /** The link's anchor text (becomes the record's content). */
143
+ text?: string;
144
+ }
145
+ /** Minimal structural shape of a Scrapper normalised links payload. */
146
+ export interface ScrapperLinksLike {
147
+ /** The page URL the links were collected from. */
148
+ url?: string;
149
+ /** The collected links. */
150
+ links?: ScrapperLinkLike[];
151
+ }
152
+ /**
153
+ * Convert a Scrapper normalised links payload into one {@link @nhtio/adk!RawRetrievable} per link.
154
+ *
155
+ * @remarks
156
+ * Each link's `text` becomes the (inline) content and its `url` the `source`. Link text is short,
157
+ * so no spooling is applied.
158
+ *
159
+ * @param payload - The Scrapper normalised links payload (`{ links: [{ url, text }] }`).
160
+ * @param opts - Trust tier, kind, id prefix.
161
+ * @returns One `RawRetrievable` per link.
162
+ */
163
+ export declare const scrapperLinksToRetrievables: (payload: ScrapperLinksLike, opts?: ToRetrievableOptions) => RawRetrievable[];
164
+ /** The minimal context surface {@link storeRetrievables} needs. */
165
+ export interface RetrievableStoreCtx {
166
+ /** Persist a single `Retrievable` into the turn (a `DispatchContext` method, or a stub). */
167
+ storeRetrievable: (v: Retrievable) => unknown | Promise<unknown>;
168
+ }
169
+ /**
170
+ * Construct {@link @nhtio/adk!Retrievable}s from `RawRetrievable`s and store each via `ctx`.
171
+ *
172
+ * @remarks
173
+ * This is the only function here that touches a core class, and it does so through an injected
174
+ * **resolver** (`deps.retrievable`) so the glue itself never value-imports `Retrievable`. Each
175
+ * record's `RawRetrievable` validation (including the required `trustTier`) fires at construction.
176
+ * For reader-backed content, the caller's `spool` hook will typically have used
177
+ * `ctx.storeRetrievableBytes` already; this helper just persists the records into the turn.
178
+ *
179
+ * @param ctx - Anything with a `storeRetrievable` method (a `DispatchContext`, or a stub).
180
+ * @param raws - The plain records from the converters.
181
+ * @param deps - `{ retrievable }`: the `Retrievable` constructor or a resolver of it.
182
+ * @returns The constructed `Retrievable` instances, in input order.
183
+ */
184
+ export declare const storeRetrievables: (ctx: RetrievableStoreCtx, raws: RawRetrievable[], deps: {
185
+ retrievable: Resolver<RetrievableCtor>;
186
+ }) => Promise<Retrievable[]>;
@@ -0,0 +1,206 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../chunk-Ble4zEEl.js");
3
+ const require_tool_registry = require("../../tool_registry-CKJPze3j.js");
4
+ require("../../guards.cjs");
5
+ let js_sha256 = require("js-sha256");
6
+ //#region src/batteries/tools/web_retrieval/index.ts
7
+ /**
8
+ * RAG glue: turn web-search and web-scrape results into `Retrievable` records for a turn.
9
+ *
10
+ * @module @nhtio/adk/batteries/tools/web_retrieval
11
+ *
12
+ * @remarks
13
+ * The seam from "I searched / scraped something" to "it is in the turn as a `Retrievable`",
14
+ * shared by the SearXNG and Scrapper batteries. It is deliberately **decoupled** from the ADK
15
+ * core at runtime:
16
+ *
17
+ * - The converters are **pure** `(payload) => RawRetrievable[]` — they build plain data objects and
18
+ * never instantiate a core class, so the module's only core coupling is erased `import type`.
19
+ * - The recommended spool-artifact type travels as an **open resolver**
20
+ * ({@link @nhtio/adk/forge!ArtifactConstructorResolver}), never a closed string enum — a consumer's
21
+ * future YAML/HTML `SpooledArtifact` subclass works with no change here. The converter hands the
22
+ * recommendation to the caller's `spool` hook; the caller owns the actual class import.
23
+ * - The one helper that must construct a `Retrievable` ({@link storeRetrievables}) takes the
24
+ * constructor via a **resolver** (constructor / sync / async / dynamic-import), exactly like the
25
+ * vector battery's `createVectorStore` `client`.
26
+ *
27
+ * Web content is `'third-party-public'` by default — a definitional constant for open-web data
28
+ * (NOT inferred from the URL, which CONTRIBUTING Design Decision #12 forbids); override via
29
+ * `trustTier` when you know better.
30
+ */
31
+ var nowIso = () => (/* @__PURE__ */ new Date()).toISOString();
32
+ /** A stable, unguessable id derived from a source string (URL) plus an optional prefix. */
33
+ var stableId = (prefix, source) => {
34
+ const h = (0, js_sha256.sha256)(source);
35
+ return prefix ? `${prefix}:${h}` : h;
36
+ };
37
+ /** Clamp a possibly-unbounded score into `[0, 1]`; drop non-finite. */
38
+ var clampScore = (score) => {
39
+ if (typeof score !== "number" || !Number.isFinite(score)) return void 0;
40
+ if (score < 0) return 0;
41
+ if (score > 1) return 1;
42
+ return score;
43
+ };
44
+ /**
45
+ * Resolve content to either an inline string or a caller-provided {@link SpooledArtifact}. When a
46
+ * `spool` hook is supplied it is offered the recommended resolver; whatever it returns (artifact or
47
+ * `undefined`→inline) is used.
48
+ */
49
+ var resolveContent = (id, text, opts, recommended) => {
50
+ if (opts.spool) {
51
+ const artifact = opts.spool(id, text, recommended);
52
+ if (artifact) return artifact;
53
+ }
54
+ return text;
55
+ };
56
+ /**
57
+ * Convert a SearXNG normalised payload into one {@link @nhtio/adk!RawRetrievable} per result.
58
+ *
59
+ * @remarks
60
+ * Snippets are short, so `content` stays an inline string (the `spool` hook, if any, is still
61
+ * offered the `text` recommendation). `source` is the result URL; `score` is clamped to `[0,1]`.
62
+ *
63
+ * @param payload - The SearXNG normalised payload (`{ results: [{ url, title, content, score }] }`).
64
+ * @param opts - Trust tier, kind, id prefix, optional spool hook.
65
+ * @param recommend - Optional artifact-resolver recommendations (the glue names no class itself).
66
+ * @returns One `RawRetrievable` per result.
67
+ */
68
+ var searxngResultsToRetrievables = (payload, opts = {}, recommend = {}) => {
69
+ const trustTier = opts.trustTier ?? "third-party-public";
70
+ const kind = opts.kind ?? "web-search-result";
71
+ const created = nowIso();
72
+ return (payload.results ?? []).map((r, i) => {
73
+ const source = r.url ?? "";
74
+ const id = stableId(opts.idPrefix, source || `${kind}:${i}`);
75
+ const text = [r.title, r.content].filter((s) => typeof s === "string").join("\n");
76
+ const recommended = recommend.text ?? recommend.markdown ?? recommend.json;
77
+ const raw = {
78
+ id,
79
+ content: recommended ? resolveContent(id, text, opts, recommended) : text,
80
+ trustTier,
81
+ kind,
82
+ createdAt: created,
83
+ updatedAt: created
84
+ };
85
+ if (source) raw.source = source;
86
+ const score = clampScore(r.score);
87
+ if (score !== void 0) raw.score = score;
88
+ return raw;
89
+ });
90
+ };
91
+ /**
92
+ * Convert a Scrapper normalised article into a single {@link @nhtio/adk!RawRetrievable}.
93
+ *
94
+ * @remarks
95
+ * Long article text is exactly what a reader-backed {@link @nhtio/adk!SpooledArtifact} is for: pass a
96
+ * `spool` hook and the converter offers it the recommended artifact resolver (markdown when
97
+ * `asMarkdown`, else text/HTML) so the model gets the right forged query tools. Without a hook,
98
+ * content stays inline.
99
+ *
100
+ * @param article - The Scrapper normalised article.
101
+ * @param opts - Trust tier, kind, id prefix, content source, markdown flag, optional spool hook.
102
+ * @param recommend - Optional artifact-resolver recommendations.
103
+ * @returns A single `RawRetrievable`.
104
+ */
105
+ var scrapperArticleToRetrievable = (article, opts = {}, recommend = {}) => {
106
+ const trustTier = opts.trustTier ?? "third-party-public";
107
+ const kind = opts.kind ?? "web-article";
108
+ const created = nowIso();
109
+ const source = article.url ?? "";
110
+ const id = stableId(opts.idPrefix, source || kind);
111
+ const text = ((opts.contentSource ?? "textContent") === "content" ? article.content : article.textContent) ?? "";
112
+ const recommended = opts.asMarkdown ? recommend.markdown ?? recommend.text : recommend.text;
113
+ const raw = {
114
+ id,
115
+ content: recommended ? resolveContent(id, text, opts, recommended) : text,
116
+ trustTier,
117
+ kind,
118
+ createdAt: created,
119
+ updatedAt: created
120
+ };
121
+ if (source) raw.source = source;
122
+ return raw;
123
+ };
124
+ /**
125
+ * Convert a Scrapper normalised links payload into one {@link @nhtio/adk!RawRetrievable} per link.
126
+ *
127
+ * @remarks
128
+ * Each link's `text` becomes the (inline) content and its `url` the `source`. Link text is short,
129
+ * so no spooling is applied.
130
+ *
131
+ * @param payload - The Scrapper normalised links payload (`{ links: [{ url, text }] }`).
132
+ * @param opts - Trust tier, kind, id prefix.
133
+ * @returns One `RawRetrievable` per link.
134
+ */
135
+ var scrapperLinksToRetrievables = (payload, opts = {}) => {
136
+ const trustTier = opts.trustTier ?? "third-party-public";
137
+ const kind = opts.kind ?? "web-link";
138
+ const created = nowIso();
139
+ return (payload.links ?? []).map((l, i) => {
140
+ const source = l.url ?? "";
141
+ const raw = {
142
+ id: stableId(opts.idPrefix, source || `${kind}:${i}`),
143
+ content: l.text ?? source,
144
+ trustTier,
145
+ kind,
146
+ createdAt: created,
147
+ updatedAt: created
148
+ };
149
+ if (source) raw.source = source;
150
+ return raw;
151
+ });
152
+ };
153
+ /**
154
+ * Resolve a {@link Resolver} of the `Retrievable` constructor (sync / async / `{ default }`).
155
+ *
156
+ * @remarks
157
+ * Both a bare class and a resolver are `typeof 'function'`, and we hold `Retrievable` only as an
158
+ * `import type` (no runtime value to duck-type against). We disambiguate by behaviour: invoking a
159
+ * real ES class without `new` throws, so a bare constructor is caught and returned as-is; a resolver
160
+ * invokes cleanly and yields the constructor (possibly via a Promise and/or a `{ default }`).
161
+ */
162
+ var resolveRetrievableCtor = async (resolver) => {
163
+ if (typeof resolver !== "function") throw new TypeError("retrievable must be a constructor or a resolver returning one");
164
+ let resolved;
165
+ try {
166
+ resolved = resolver();
167
+ } catch {
168
+ return resolver;
169
+ }
170
+ if (require_tool_registry.isInstanceOf(resolved, "Promise", Promise)) resolved = await resolved;
171
+ if (resolved && typeof resolved === "object" && "default" in resolved) resolved = resolved.default;
172
+ if (typeof resolved === "function") return resolved;
173
+ return resolver;
174
+ };
175
+ /**
176
+ * Construct {@link @nhtio/adk!Retrievable}s from `RawRetrievable`s and store each via `ctx`.
177
+ *
178
+ * @remarks
179
+ * This is the only function here that touches a core class, and it does so through an injected
180
+ * **resolver** (`deps.retrievable`) so the glue itself never value-imports `Retrievable`. Each
181
+ * record's `RawRetrievable` validation (including the required `trustTier`) fires at construction.
182
+ * For reader-backed content, the caller's `spool` hook will typically have used
183
+ * `ctx.storeRetrievableBytes` already; this helper just persists the records into the turn.
184
+ *
185
+ * @param ctx - Anything with a `storeRetrievable` method (a `DispatchContext`, or a stub).
186
+ * @param raws - The plain records from the converters.
187
+ * @param deps - `{ retrievable }`: the `Retrievable` constructor or a resolver of it.
188
+ * @returns The constructed `Retrievable` instances, in input order.
189
+ */
190
+ var storeRetrievables = async (ctx, raws, deps) => {
191
+ const Ctor = await resolveRetrievableCtor(deps.retrievable);
192
+ const out = [];
193
+ for (const raw of raws) {
194
+ const record = new Ctor(raw);
195
+ await ctx.storeRetrievable(record);
196
+ out.push(record);
197
+ }
198
+ return out;
199
+ };
200
+ //#endregion
201
+ exports.scrapperArticleToRetrievable = scrapperArticleToRetrievable;
202
+ exports.scrapperLinksToRetrievables = scrapperLinksToRetrievables;
203
+ exports.searxngResultsToRetrievables = searxngResultsToRetrievables;
204
+ exports.storeRetrievables = storeRetrievables;
205
+
206
+ //# sourceMappingURL=web_retrieval.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web_retrieval.cjs","names":[],"sources":["../../../src/batteries/tools/web_retrieval/index.ts"],"sourcesContent":["/**\n * RAG glue: turn web-search and web-scrape results into `Retrievable` records for a turn.\n *\n * @module @nhtio/adk/batteries/tools/web_retrieval\n *\n * @remarks\n * The seam from \"I searched / scraped something\" to \"it is in the turn as a `Retrievable`\",\n * shared by the SearXNG and Scrapper batteries. It is deliberately **decoupled** from the ADK\n * core at runtime:\n *\n * - The converters are **pure** `(payload) => RawRetrievable[]` — they build plain data objects and\n * never instantiate a core class, so the module's only core coupling is erased `import type`.\n * - The recommended spool-artifact type travels as an **open resolver**\n * ({@link @nhtio/adk/forge!ArtifactConstructorResolver}), never a closed string enum — a consumer's\n * future YAML/HTML `SpooledArtifact` subclass works with no change here. The converter hands the\n * recommendation to the caller's `spool` hook; the caller owns the actual class import.\n * - The one helper that must construct a `Retrievable` ({@link storeRetrievables}) takes the\n * constructor via a **resolver** (constructor / sync / async / dynamic-import), exactly like the\n * vector battery's `createVectorStore` `client`.\n *\n * Web content is `'third-party-public'` by default — a definitional constant for open-web data\n * (NOT inferred from the URL, which CONTRIBUTING Design Decision #12 forbids); override via\n * `trustTier` when you know better.\n */\n\nimport { sha256 } from 'js-sha256'\nimport { isInstanceOf } from '@nhtio/adk/guards'\nimport type { SpooledArtifact } from '@nhtio/adk/spooled_artifact'\nimport type { ArtifactConstructorResolver } from '@nhtio/adk/forge'\nimport type { RawRetrievable, Retrievable, RetrievableTrustTier } from '@nhtio/adk/common'\n\n/** A constructor that builds a {@link @nhtio/adk!Retrievable} from a {@link @nhtio/adk!RawRetrievable}. */\nexport type RetrievableCtor = new (raw: RawRetrievable) => Retrievable\n\n/** A resolver of `T`: the value itself, or a (sync/async) thunk, optionally a module `{ default }`. */\nexport type Resolver<T> = T | (() => T | { default: T }) | (() => Promise<T | { default: T }>)\n\n/**\n * A reader-backed-artifact hook. Called by a converter for content that may be large; the\n * converter passes the artifact constructor it **recommends** for this content (an open\n * {@link @nhtio/adk/forge!ArtifactConstructorResolver}) so the caller can wrap with the right\n * subclass — preserving its forged query tools — using the caller's own core import. Return a\n * {@link @nhtio/adk!SpooledArtifact} to store the content reader-backed, or `undefined` to keep it\n * inline as a string.\n */\nexport type SpoolHook = (\n id: string,\n text: string,\n recommended: ArtifactConstructorResolver\n) => SpooledArtifact | undefined\n\n/** Options common to every converter. */\nexport interface ToRetrievableOptions {\n /**\n * Trust tier for the produced records. Default `'third-party-public'` (web content is\n * third-party by definition — this is a constant, not URL inference).\n */\n trustTier?: RetrievableTrustTier\n /** Semantic `kind` label, e.g. `'web-search-result'`, `'web-article'`, `'web-links'`. */\n kind?: string\n /** Prefix for the stable, hashed record id (namespacing across sources). */\n idPrefix?: string\n /** Optional reader-backed-artifact hook for large content. See {@link SpoolHook}. */\n spool?: SpoolHook\n}\n\n/**\n * The artifact-resolver recommendations a caller may supply so the glue names no concrete class\n * itself. Each converter asks for the relevant key; if the caller omits it, content stays inline.\n */\nexport interface ArtifactRecommendations {\n /** Recommended for plain-text / HTML content (base `SpooledArtifact`). */\n text?: ArtifactConstructorResolver\n /** Recommended for markdown content (`SpooledMarkdownArtifact`). */\n markdown?: ArtifactConstructorResolver\n /** Recommended for JSON content (`SpooledJsonArtifact`). */\n json?: ArtifactConstructorResolver\n}\n\nconst nowIso = (): string => new Date().toISOString()\n\n/** A stable, unguessable id derived from a source string (URL) plus an optional prefix. */\nconst stableId = (prefix: string | undefined, source: string): string => {\n const h = sha256(source)\n return prefix ? `${prefix}:${h}` : h\n}\n\n/** Clamp a possibly-unbounded score into `[0, 1]`; drop non-finite. */\nconst clampScore = (score: unknown): number | undefined => {\n if (typeof score !== 'number' || !Number.isFinite(score)) return undefined\n if (score < 0) return 0\n if (score > 1) return 1\n return score\n}\n\n/**\n * Resolve content to either an inline string or a caller-provided {@link SpooledArtifact}. When a\n * `spool` hook is supplied it is offered the recommended resolver; whatever it returns (artifact or\n * `undefined`→inline) is used.\n */\nconst resolveContent = (\n id: string,\n text: string,\n opts: ToRetrievableOptions,\n recommended: ArtifactConstructorResolver\n): string | SpooledArtifact => {\n if (opts.spool) {\n const artifact = opts.spool(id, text, recommended)\n if (artifact) return artifact\n }\n return text\n}\n\n// ── SearXNG ──────────────────────────────────────────────────────────────────\n\n/** Minimal structural shape of a SearXNG normalised result the converter reads. */\nexport interface SearxngResultLike {\n /** Result URL (becomes the record's `source`). */\n url?: string\n /** Result title (joined into the inline content). */\n title?: string\n /** Result snippet (joined into the inline content). */\n content?: string\n /** Relevance score (clamped to `[0,1]` on the record). */\n score?: number\n}\n/** Minimal structural shape of a SearXNG normalised payload. */\nexport interface SearxngPayloadLike {\n /** The result list. */\n results?: SearxngResultLike[]\n}\n\n/**\n * Convert a SearXNG normalised payload into one {@link @nhtio/adk!RawRetrievable} per result.\n *\n * @remarks\n * Snippets are short, so `content` stays an inline string (the `spool` hook, if any, is still\n * offered the `text` recommendation). `source` is the result URL; `score` is clamped to `[0,1]`.\n *\n * @param payload - The SearXNG normalised payload (`{ results: [{ url, title, content, score }] }`).\n * @param opts - Trust tier, kind, id prefix, optional spool hook.\n * @param recommend - Optional artifact-resolver recommendations (the glue names no class itself).\n * @returns One `RawRetrievable` per result.\n */\nexport const searxngResultsToRetrievables = (\n payload: SearxngPayloadLike,\n opts: ToRetrievableOptions = {},\n recommend: ArtifactRecommendations = {}\n): RawRetrievable[] => {\n const trustTier: RetrievableTrustTier = opts.trustTier ?? 'third-party-public'\n const kind = opts.kind ?? 'web-search-result'\n const created = nowIso()\n const results = payload.results ?? []\n return results.map((r, i) => {\n const source = r.url ?? ''\n const id = stableId(opts.idPrefix, source || `${kind}:${i}`)\n const text = [r.title, r.content].filter((s): s is string => typeof s === 'string').join('\\n')\n const recommended = recommend.text ?? recommend.markdown ?? recommend.json\n const content = recommended ? resolveContent(id, text, opts, recommended) : text\n const raw: RawRetrievable = {\n id,\n content,\n trustTier,\n kind,\n createdAt: created,\n updatedAt: created,\n }\n if (source) raw.source = source\n const score = clampScore(r.score)\n if (score !== undefined) raw.score = score\n return raw\n })\n}\n\n// ── Scrapper: article ──────────────────────────────────────────────────────────\n\n/** Minimal structural shape of a Scrapper normalised article. */\nexport interface ScrapperArticleLike {\n /** The page URL (becomes the record's `source`). */\n url?: string\n /** Article title. */\n title?: string\n /** Article text with HTML stripped (the default content source). */\n textContent?: string\n /** Processed article HTML (the `'content'` content source). */\n content?: string\n}\n\n/** Which article text field to use as the record content. */\nexport type ArticleContentSource = 'textContent' | 'content'\n\n/** Options for {@link scrapperArticleToRetrievable}. */\nexport interface ArticleToRetrievableOptions extends ToRetrievableOptions {\n /** Which field to use as content (default `'textContent'`). `'content'` is HTML. */\n contentSource?: ArticleContentSource\n /**\n * Whether the chosen content is markdown (recommend `markdown`) rather than plain text.\n * Default false. Use when an output pipeline rendered the article to markdown.\n */\n asMarkdown?: boolean\n}\n\n/**\n * Convert a Scrapper normalised article into a single {@link @nhtio/adk!RawRetrievable}.\n *\n * @remarks\n * Long article text is exactly what a reader-backed {@link @nhtio/adk!SpooledArtifact} is for: pass a\n * `spool` hook and the converter offers it the recommended artifact resolver (markdown when\n * `asMarkdown`, else text/HTML) so the model gets the right forged query tools. Without a hook,\n * content stays inline.\n *\n * @param article - The Scrapper normalised article.\n * @param opts - Trust tier, kind, id prefix, content source, markdown flag, optional spool hook.\n * @param recommend - Optional artifact-resolver recommendations.\n * @returns A single `RawRetrievable`.\n */\nexport const scrapperArticleToRetrievable = (\n article: ScrapperArticleLike,\n opts: ArticleToRetrievableOptions = {},\n recommend: ArtifactRecommendations = {}\n): RawRetrievable => {\n const trustTier: RetrievableTrustTier = opts.trustTier ?? 'third-party-public'\n const kind = opts.kind ?? 'web-article'\n const created = nowIso()\n const source = article.url ?? ''\n const id = stableId(opts.idPrefix, source || kind)\n const field = opts.contentSource ?? 'textContent'\n const text = (field === 'content' ? article.content : article.textContent) ?? ''\n const recommended = opts.asMarkdown ? (recommend.markdown ?? recommend.text) : recommend.text\n const content = recommended ? resolveContent(id, text, opts, recommended) : text\n const raw: RawRetrievable = {\n id,\n content,\n trustTier,\n kind,\n createdAt: created,\n updatedAt: created,\n }\n if (source) raw.source = source\n return raw\n}\n\n// ── Scrapper: links ──────────────────────────────────────────────────────────\n\n/** Minimal structural shape of a Scrapper normalised link. */\nexport interface ScrapperLinkLike {\n /** The link's target URL (becomes the record's `source`). */\n url?: string\n /** The link's anchor text (becomes the record's content). */\n text?: string\n}\n/** Minimal structural shape of a Scrapper normalised links payload. */\nexport interface ScrapperLinksLike {\n /** The page URL the links were collected from. */\n url?: string\n /** The collected links. */\n links?: ScrapperLinkLike[]\n}\n\n/**\n * Convert a Scrapper normalised links payload into one {@link @nhtio/adk!RawRetrievable} per link.\n *\n * @remarks\n * Each link's `text` becomes the (inline) content and its `url` the `source`. Link text is short,\n * so no spooling is applied.\n *\n * @param payload - The Scrapper normalised links payload (`{ links: [{ url, text }] }`).\n * @param opts - Trust tier, kind, id prefix.\n * @returns One `RawRetrievable` per link.\n */\nexport const scrapperLinksToRetrievables = (\n payload: ScrapperLinksLike,\n opts: ToRetrievableOptions = {}\n): RawRetrievable[] => {\n const trustTier: RetrievableTrustTier = opts.trustTier ?? 'third-party-public'\n const kind = opts.kind ?? 'web-link'\n const created = nowIso()\n const links = payload.links ?? []\n return links.map((l, i) => {\n const source = l.url ?? ''\n const id = stableId(opts.idPrefix, source || `${kind}:${i}`)\n const raw: RawRetrievable = {\n id,\n content: l.text ?? source,\n trustTier,\n kind,\n createdAt: created,\n updatedAt: created,\n }\n if (source) raw.source = source\n return raw\n })\n}\n\n// ── Store helper (the single core-touching function) ─────────────────────────\n\n/** The minimal context surface {@link storeRetrievables} needs. */\nexport interface RetrievableStoreCtx {\n /** Persist a single `Retrievable` into the turn (a `DispatchContext` method, or a stub). */\n storeRetrievable: (v: Retrievable) => unknown | Promise<unknown>\n}\n\n/**\n * Resolve a {@link Resolver} of the `Retrievable` constructor (sync / async / `{ default }`).\n *\n * @remarks\n * Both a bare class and a resolver are `typeof 'function'`, and we hold `Retrievable` only as an\n * `import type` (no runtime value to duck-type against). We disambiguate by behaviour: invoking a\n * real ES class without `new` throws, so a bare constructor is caught and returned as-is; a resolver\n * invokes cleanly and yields the constructor (possibly via a Promise and/or a `{ default }`).\n */\nconst resolveRetrievableCtor = async (\n resolver: Resolver<RetrievableCtor>\n): Promise<RetrievableCtor> => {\n if (typeof resolver !== 'function') {\n throw new TypeError('retrievable must be a constructor or a resolver returning one')\n }\n let resolved: unknown\n try {\n resolved = (resolver as () => unknown)()\n } catch {\n return resolver as RetrievableCtor // bare class: threw on no-`new` invocation\n }\n if (isInstanceOf(resolved, 'Promise', Promise)) resolved = await resolved\n if (resolved && typeof resolved === 'object' && 'default' in resolved) {\n resolved = (resolved as { default?: unknown }).default\n }\n if (typeof resolved === 'function') return resolved as RetrievableCtor\n return resolver as RetrievableCtor // resolver returned a non-function: it was itself the ctor\n}\n\n/**\n * Construct {@link @nhtio/adk!Retrievable}s from `RawRetrievable`s and store each via `ctx`.\n *\n * @remarks\n * This is the only function here that touches a core class, and it does so through an injected\n * **resolver** (`deps.retrievable`) so the glue itself never value-imports `Retrievable`. Each\n * record's `RawRetrievable` validation (including the required `trustTier`) fires at construction.\n * For reader-backed content, the caller's `spool` hook will typically have used\n * `ctx.storeRetrievableBytes` already; this helper just persists the records into the turn.\n *\n * @param ctx - Anything with a `storeRetrievable` method (a `DispatchContext`, or a stub).\n * @param raws - The plain records from the converters.\n * @param deps - `{ retrievable }`: the `Retrievable` constructor or a resolver of it.\n * @returns The constructed `Retrievable` instances, in input order.\n */\nexport const storeRetrievables = async (\n ctx: RetrievableStoreCtx,\n raws: RawRetrievable[],\n deps: { retrievable: Resolver<RetrievableCtor> }\n): Promise<Retrievable[]> => {\n const Ctor = await resolveRetrievableCtor(deps.retrievable)\n const out: Retrievable[] = []\n for (const raw of raws) {\n const record = new Ctor(raw)\n await ctx.storeRetrievable(record)\n out.push(record)\n }\n return out\n}\n"],"mappings":"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"}