@nhtio/adk 0.1.0-master-f0aa531d

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 (297) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +3 -0
  3. package/batteries/index.d.ts +28 -0
  4. package/batteries/llm/index.d.ts +11 -0
  5. package/batteries/llm/openai_chat_completions/adapter.cjs +916 -0
  6. package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -0
  7. package/batteries/llm/openai_chat_completions/adapter.d.ts +101 -0
  8. package/batteries/llm/openai_chat_completions/adapter.mjs +914 -0
  9. package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -0
  10. package/batteries/llm/openai_chat_completions/exceptions.cjs +89 -0
  11. package/batteries/llm/openai_chat_completions/exceptions.cjs.map +1 -0
  12. package/batteries/llm/openai_chat_completions/exceptions.d.ts +97 -0
  13. package/batteries/llm/openai_chat_completions/exceptions.mjs +81 -0
  14. package/batteries/llm/openai_chat_completions/exceptions.mjs.map +1 -0
  15. package/batteries/llm/openai_chat_completions/helpers.cjs +819 -0
  16. package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -0
  17. package/batteries/llm/openai_chat_completions/helpers.d.ts +233 -0
  18. package/batteries/llm/openai_chat_completions/helpers.mjs +783 -0
  19. package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -0
  20. package/batteries/llm/openai_chat_completions/index.d.ts +27 -0
  21. package/batteries/llm/openai_chat_completions/types.cjs +1 -0
  22. package/batteries/llm/openai_chat_completions/types.d.ts +524 -0
  23. package/batteries/llm/openai_chat_completions/types.mjs +0 -0
  24. package/batteries/llm/openai_chat_completions/validation.cjs +190 -0
  25. package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -0
  26. package/batteries/llm/openai_chat_completions/validation.d.ts +31 -0
  27. package/batteries/llm/openai_chat_completions/validation.mjs +187 -0
  28. package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -0
  29. package/batteries/llm/openai_chat_completions.cjs +51 -0
  30. package/batteries/llm/openai_chat_completions.mjs +5 -0
  31. package/batteries/llm/webllm_chat_completions/adapter.cjs +658 -0
  32. package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -0
  33. package/batteries/llm/webllm_chat_completions/adapter.d.ts +103 -0
  34. package/batteries/llm/webllm_chat_completions/adapter.mjs +656 -0
  35. package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -0
  36. package/batteries/llm/webllm_chat_completions/exceptions.cjs +70 -0
  37. package/batteries/llm/webllm_chat_completions/exceptions.cjs.map +1 -0
  38. package/batteries/llm/webllm_chat_completions/exceptions.d.ts +74 -0
  39. package/batteries/llm/webllm_chat_completions/exceptions.mjs +65 -0
  40. package/batteries/llm/webllm_chat_completions/exceptions.mjs.map +1 -0
  41. package/batteries/llm/webllm_chat_completions/helpers.cjs +38 -0
  42. package/batteries/llm/webllm_chat_completions/helpers.d.ts +6 -0
  43. package/batteries/llm/webllm_chat_completions/helpers.mjs +2 -0
  44. package/batteries/llm/webllm_chat_completions/index.d.ts +25 -0
  45. package/batteries/llm/webllm_chat_completions/types.d.ts +31 -0
  46. package/batteries/llm/webllm_chat_completions/validation.cjs +115 -0
  47. package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -0
  48. package/batteries/llm/webllm_chat_completions/validation.d.ts +8 -0
  49. package/batteries/llm/webllm_chat_completions/validation.mjs +112 -0
  50. package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -0
  51. package/batteries/llm/webllm_chat_completions.cjs +50 -0
  52. package/batteries/llm/webllm_chat_completions.mjs +6 -0
  53. package/batteries/llm.cjs +63 -0
  54. package/batteries/llm.mjs +10 -0
  55. package/batteries/storage/flydrive/index.d.ts +167 -0
  56. package/batteries/storage/flydrive.cjs +249 -0
  57. package/batteries/storage/flydrive.cjs.map +1 -0
  58. package/batteries/storage/flydrive.mjs +249 -0
  59. package/batteries/storage/flydrive.mjs.map +1 -0
  60. package/batteries/storage/in_memory/index.d.ts +106 -0
  61. package/batteries/storage/in_memory.cjs +121 -0
  62. package/batteries/storage/in_memory.cjs.map +1 -0
  63. package/batteries/storage/in_memory.mjs +119 -0
  64. package/batteries/storage/in_memory.mjs.map +1 -0
  65. package/batteries/storage/index.d.ts +18 -0
  66. package/batteries/storage/opfs/index.d.ts +299 -0
  67. package/batteries/storage/opfs.cjs +368 -0
  68. package/batteries/storage/opfs.cjs.map +1 -0
  69. package/batteries/storage/opfs.mjs +366 -0
  70. package/batteries/storage/opfs.mjs.map +1 -0
  71. package/batteries/storage.cjs +4 -0
  72. package/batteries/storage.mjs +2 -0
  73. package/batteries/tools/color/index.d.ts +37 -0
  74. package/batteries/tools/color.cjs +659 -0
  75. package/batteries/tools/color.cjs.map +1 -0
  76. package/batteries/tools/color.mjs +655 -0
  77. package/batteries/tools/color.mjs.map +1 -0
  78. package/batteries/tools/comparison/index.d.ts +29 -0
  79. package/batteries/tools/comparison.cjs +171 -0
  80. package/batteries/tools/comparison.cjs.map +1 -0
  81. package/batteries/tools/comparison.mjs +168 -0
  82. package/batteries/tools/comparison.mjs.map +1 -0
  83. package/batteries/tools/data_structure/index.d.ts +30 -0
  84. package/batteries/tools/data_structure.cjs +270 -0
  85. package/batteries/tools/data_structure.cjs.map +1 -0
  86. package/batteries/tools/data_structure.mjs +267 -0
  87. package/batteries/tools/data_structure.mjs.map +1 -0
  88. package/batteries/tools/datetime_extended/index.d.ts +51 -0
  89. package/batteries/tools/datetime_extended.cjs +309 -0
  90. package/batteries/tools/datetime_extended.cjs.map +1 -0
  91. package/batteries/tools/datetime_extended.mjs +302 -0
  92. package/batteries/tools/datetime_extended.mjs.map +1 -0
  93. package/batteries/tools/datetime_math/index.d.ts +36 -0
  94. package/batteries/tools/datetime_math.cjs +175 -0
  95. package/batteries/tools/datetime_math.cjs.map +1 -0
  96. package/batteries/tools/datetime_math.mjs +171 -0
  97. package/batteries/tools/datetime_math.mjs.map +1 -0
  98. package/batteries/tools/encoding/index.d.ts +36 -0
  99. package/batteries/tools/encoding.cjs +156 -0
  100. package/batteries/tools/encoding.cjs.map +1 -0
  101. package/batteries/tools/encoding.mjs +152 -0
  102. package/batteries/tools/encoding.mjs.map +1 -0
  103. package/batteries/tools/formatting/index.d.ts +28 -0
  104. package/batteries/tools/formatting.cjs +120 -0
  105. package/batteries/tools/formatting.cjs.map +1 -0
  106. package/batteries/tools/formatting.mjs +117 -0
  107. package/batteries/tools/formatting.mjs.map +1 -0
  108. package/batteries/tools/geo_basics/index.d.ts +33 -0
  109. package/batteries/tools/geo_basics.cjs +136 -0
  110. package/batteries/tools/geo_basics.cjs.map +1 -0
  111. package/batteries/tools/geo_basics.mjs +132 -0
  112. package/batteries/tools/geo_basics.mjs.map +1 -0
  113. package/batteries/tools/index.d.ts +32 -0
  114. package/batteries/tools/math/index.d.ts +37 -0
  115. package/batteries/tools/math.cjs +136 -0
  116. package/batteries/tools/math.cjs.map +1 -0
  117. package/batteries/tools/math.mjs +133 -0
  118. package/batteries/tools/math.mjs.map +1 -0
  119. package/batteries/tools/memory/index.d.ts +73 -0
  120. package/batteries/tools/memory.cjs +193 -0
  121. package/batteries/tools/memory.cjs.map +1 -0
  122. package/batteries/tools/memory.mjs +187 -0
  123. package/batteries/tools/memory.mjs.map +1 -0
  124. package/batteries/tools/parsing/index.d.ts +47 -0
  125. package/batteries/tools/parsing.cjs +191 -0
  126. package/batteries/tools/parsing.cjs.map +1 -0
  127. package/batteries/tools/parsing.mjs +185 -0
  128. package/batteries/tools/parsing.mjs.map +1 -0
  129. package/batteries/tools/retrievables/index.d.ts +81 -0
  130. package/batteries/tools/retrievables.cjs +215 -0
  131. package/batteries/tools/retrievables.cjs.map +1 -0
  132. package/batteries/tools/retrievables.mjs +209 -0
  133. package/batteries/tools/retrievables.mjs.map +1 -0
  134. package/batteries/tools/standing_instructions/index.d.ts +64 -0
  135. package/batteries/tools/standing_instructions.cjs +126 -0
  136. package/batteries/tools/standing_instructions.cjs.map +1 -0
  137. package/batteries/tools/standing_instructions.mjs +121 -0
  138. package/batteries/tools/standing_instructions.mjs.map +1 -0
  139. package/batteries/tools/statistics/index.d.ts +46 -0
  140. package/batteries/tools/statistics.cjs +253 -0
  141. package/batteries/tools/statistics.cjs.map +1 -0
  142. package/batteries/tools/statistics.mjs +248 -0
  143. package/batteries/tools/statistics.mjs.map +1 -0
  144. package/batteries/tools/string_processing/index.d.ts +29 -0
  145. package/batteries/tools/string_processing.cjs +154 -0
  146. package/batteries/tools/string_processing.cjs.map +1 -0
  147. package/batteries/tools/string_processing.mjs +151 -0
  148. package/batteries/tools/string_processing.mjs.map +1 -0
  149. package/batteries/tools/structured_data/index.d.ts +34 -0
  150. package/batteries/tools/structured_data.cjs +189 -0
  151. package/batteries/tools/structured_data.cjs.map +1 -0
  152. package/batteries/tools/structured_data.mjs +185 -0
  153. package/batteries/tools/structured_data.mjs.map +1 -0
  154. package/batteries/tools/text_analysis/index.d.ts +31 -0
  155. package/batteries/tools/text_analysis.cjs +120 -0
  156. package/batteries/tools/text_analysis.cjs.map +1 -0
  157. package/batteries/tools/text_analysis.mjs +117 -0
  158. package/batteries/tools/text_analysis.mjs.map +1 -0
  159. package/batteries/tools/text_comparison/index.d.ts +28 -0
  160. package/batteries/tools/text_comparison.cjs +96 -0
  161. package/batteries/tools/text_comparison.cjs.map +1 -0
  162. package/batteries/tools/text_comparison.mjs +93 -0
  163. package/batteries/tools/text_comparison.mjs.map +1 -0
  164. package/batteries/tools/time/index.d.ts +27 -0
  165. package/batteries/tools/time.cjs +63 -0
  166. package/batteries/tools/time.cjs.map +1 -0
  167. package/batteries/tools/time.mjs +60 -0
  168. package/batteries/tools/time.mjs.map +1 -0
  169. package/batteries/tools/unit_conversion/index.d.ts +19 -0
  170. package/batteries/tools/unit_conversion.cjs +452 -0
  171. package/batteries/tools/unit_conversion.cjs.map +1 -0
  172. package/batteries/tools/unit_conversion.mjs +450 -0
  173. package/batteries/tools/unit_conversion.mjs.map +1 -0
  174. package/batteries/tools.cjs +80 -0
  175. package/batteries/tools.mjs +21 -0
  176. package/batteries.cjs +142 -0
  177. package/batteries.mjs +30 -0
  178. package/chunk-KmRHZBOW.js +35 -0
  179. package/common-DeZaonK1.mjs +208 -0
  180. package/common-DeZaonK1.mjs.map +1 -0
  181. package/common-Od8edUXU.js +232 -0
  182. package/common-Od8edUXU.js.map +1 -0
  183. package/common.cjs +31 -0
  184. package/common.d.ts +108 -0
  185. package/common.mjs +8 -0
  186. package/dispatch_runner-9j6bXHL3.mjs +1609 -0
  187. package/dispatch_runner-9j6bXHL3.mjs.map +1 -0
  188. package/dispatch_runner-CsoH0nld.js +1627 -0
  189. package/dispatch_runner-CsoH0nld.js.map +1 -0
  190. package/dispatch_runner.cjs +3 -0
  191. package/dispatch_runner.d.ts +17 -0
  192. package/dispatch_runner.mjs +2 -0
  193. package/exceptions-D5YrO9Vm.js +280 -0
  194. package/exceptions-D5YrO9Vm.js.map +1 -0
  195. package/exceptions-NrzIHw_R.mjs +244 -0
  196. package/exceptions-NrzIHw_R.mjs.map +1 -0
  197. package/exceptions.cjs +33 -0
  198. package/exceptions.d.ts +52 -0
  199. package/exceptions.mjs +3 -0
  200. package/factories.cjs +4 -0
  201. package/factories.d.ts +39 -0
  202. package/factories.mjs +2 -0
  203. package/forge.cjs +9 -0
  204. package/forge.d.ts +49 -0
  205. package/forge.mjs +5 -0
  206. package/guards.cjs +96 -0
  207. package/guards.cjs.map +1 -0
  208. package/guards.d.ts +83 -0
  209. package/guards.mjs +72 -0
  210. package/guards.mjs.map +1 -0
  211. package/index.cjs +107 -0
  212. package/index.cjs.map +1 -0
  213. package/index.d.ts +18 -0
  214. package/index.mjs +31 -0
  215. package/index.mjs.map +1 -0
  216. package/lib/classes/artifact_tool.d.ts +129 -0
  217. package/lib/classes/base_exception.d.ts +83 -0
  218. package/lib/classes/identity.d.ts +71 -0
  219. package/lib/classes/media.d.ts +326 -0
  220. package/lib/classes/memory.d.ts +72 -0
  221. package/lib/classes/message.d.ts +137 -0
  222. package/lib/classes/registry.d.ts +79 -0
  223. package/lib/classes/retrievable.d.ts +100 -0
  224. package/lib/classes/spooled_artifact.d.ts +296 -0
  225. package/lib/classes/spooled_json_artifact.d.ts +158 -0
  226. package/lib/classes/spooled_markdown_artifact.d.ts +202 -0
  227. package/lib/classes/thought.d.ts +142 -0
  228. package/lib/classes/tokenizable.d.ts +124 -0
  229. package/lib/classes/tool.d.ts +228 -0
  230. package/lib/classes/tool_call.d.ts +190 -0
  231. package/lib/classes/tool_registry.d.ts +159 -0
  232. package/lib/classes/turn_gate.d.ts +109 -0
  233. package/lib/contracts/dispatch_context.d.ts +345 -0
  234. package/lib/contracts/media_reader.d.ts +60 -0
  235. package/lib/contracts/spool_reader.d.ts +80 -0
  236. package/lib/contracts/spooled_artifact_constructor.d.ts +38 -0
  237. package/lib/contracts/turn_runner_config.d.ts +101 -0
  238. package/lib/contracts/turn_runner_context.d.ts +267 -0
  239. package/lib/dispatch_runner.d.ts +98 -0
  240. package/lib/exceptions/runtime.d.ts +370 -0
  241. package/lib/helpers/media_readers.d.ts +39 -0
  242. package/lib/turn_runner.d.ts +144 -0
  243. package/lib/types/dispatch_context.d.ts +233 -0
  244. package/lib/types/dispatch_runner.d.ts +387 -0
  245. package/lib/types/turn_runner.d.ts +322 -0
  246. package/lib/utils/canonical_json.d.ts +18 -0
  247. package/lib/utils/exceptions.d.ts +78 -0
  248. package/lib/utils/guards.d.ts +32 -0
  249. package/lib/utils/validation.d.ts +77 -0
  250. package/package.json +334 -0
  251. package/runtime-BJVkrGQe.js +519 -0
  252. package/runtime-BJVkrGQe.js.map +1 -0
  253. package/runtime-CrEPIFgr.mjs +346 -0
  254. package/runtime-CrEPIFgr.mjs.map +1 -0
  255. package/skills/adk-assembly/SKILL.md +109 -0
  256. package/skills/adk-assembly/references/assembly-contract.md +66 -0
  257. package/skills/adk-assembly/references/executors-tools-pipelines-events.md +113 -0
  258. package/skills/adk-assembly/references/first-integration.md +93 -0
  259. package/skills/adk-assembly/references/storage-and-context.md +102 -0
  260. package/spooled_artifact-C5ZtGxuJ.mjs +544 -0
  261. package/spooled_artifact-C5ZtGxuJ.mjs.map +1 -0
  262. package/spooled_artifact-Cm9Te22K.js +568 -0
  263. package/spooled_artifact-Cm9Te22K.js.map +1 -0
  264. package/spooled_artifact.cjs +7 -0
  265. package/spooled_artifact.d.ts +40 -0
  266. package/spooled_artifact.mjs +3 -0
  267. package/spooled_markdown_artifact-BpUJol0W.mjs +771 -0
  268. package/spooled_markdown_artifact-BpUJol0W.mjs.map +1 -0
  269. package/spooled_markdown_artifact-RRB113sy.js +786 -0
  270. package/spooled_markdown_artifact-RRB113sy.js.map +1 -0
  271. package/thought-CDb457b4.mjs +470 -0
  272. package/thought-CDb457b4.mjs.map +1 -0
  273. package/thought-DuN2PgdO.js +494 -0
  274. package/thought-DuN2PgdO.js.map +1 -0
  275. package/tool-COSeH8I6.js +302 -0
  276. package/tool-COSeH8I6.js.map +1 -0
  277. package/tool-D2WB1EA1.mjs +296 -0
  278. package/tool-D2WB1EA1.mjs.map +1 -0
  279. package/tool_call-BKyyxGaZ.mjs +578 -0
  280. package/tool_call-BKyyxGaZ.mjs.map +1 -0
  281. package/tool_call-DFgzcVcU.js +608 -0
  282. package/tool_call-DFgzcVcU.js.map +1 -0
  283. package/tool_registry-Dkfprsck.js +641 -0
  284. package/tool_registry-Dkfprsck.js.map +1 -0
  285. package/tool_registry-DqLOyGyG.mjs +592 -0
  286. package/tool_registry-DqLOyGyG.mjs.map +1 -0
  287. package/turn_runner-CMm2BHdX.js +615 -0
  288. package/turn_runner-CMm2BHdX.js.map +1 -0
  289. package/turn_runner-y7eyEcJH.mjs +603 -0
  290. package/turn_runner-y7eyEcJH.mjs.map +1 -0
  291. package/turn_runner.cjs +3 -0
  292. package/turn_runner.d.ts +21 -0
  293. package/turn_runner.mjs +2 -0
  294. package/types.cjs +1 -0
  295. package/types.d.ts +56 -0
  296. package/types.mjs +0 -0
  297. package/vite-env.d.ts +23 -0
package/index.mjs ADDED
@@ -0,0 +1,31 @@
1
+ import { n as ValidationException } from "./exceptions-NrzIHw_R.mjs";
2
+ import { a as Tokenizable, c as isObject, i as TokenEncoding, o as isError, r as Registry, s as isInstanceOf, t as ToolRegistry } from "./tool_registry-DqLOyGyG.mjs";
3
+ import { C as E_NOT_A_SPOOL_READER, D as E_TOOL_DOWNSTREAM_ERROR, E as E_TOOL_ALREADY_REGISTERED, O as E_TURN_GATE_ABORTED, T as E_PIPELINE_SHORT_CIRCUITED, _ as E_INVALID_TURN_GATE_RESOLUTION, a as E_INVALID_INITIAL_MEMORY_VALUE, b as E_LLM_EXECUTION_EXECUTOR_ERROR, d as E_INVALID_INITIAL_TOOL_VALUE, f as E_INVALID_INITIAL_TURN_GATE_VALUE, g as E_INVALID_TURN_CONTEXT, h as E_INVALID_TOOL_ARGS, k as E_TURN_GATE_TIMEOUT, l as E_INVALID_INITIAL_THOUGHT_VALUE, m as E_INVALID_LLM_EXECUTION_CONTEXT, n as E_INPUT_PIPELINE_ERROR, o as E_INVALID_INITIAL_MESSAGE_VALUE, p as E_INVALID_LLM_DISPATCH_INPUT, r as E_INVALID_INITIAL_IDENTITY_VALUE, s as E_INVALID_INITIAL_REGISTRY_VALUE, t as E_DISPATCH_PIPELINE_ERROR, u as E_INVALID_INITIAL_TOOL_CALL_VALUE, v as E_INVALID_TURN_RUNNER_CONFIG, w as E_OUTPUT_PIPELINE_ERROR, x as E_LLM_EXECUTION_GATE_NOT_SUPPORTED, y as E_LLM_EXECUTION_ALREADY_SIGNALLED } from "./runtime-CrEPIFgr.mjs";
4
+ import { i as Identity, n as Message, r as Memory, t as Thought } from "./thought-CDb457b4.mjs";
5
+ import { i as Retrievable, n as fromWebFile, r as inMemoryMediaReader, t as fromFetch } from "./common-DeZaonK1.mjs";
6
+ import { a as mediaReaderSchema, i as implementsMediaReader, n as Media, r as isMedia, t as ToolCall } from "./tool_call-BKyyxGaZ.mjs";
7
+ import { t as Tool } from "./tool-D2WB1EA1.mjs";
8
+ import { i as ArtifactTool, r as implementsSpoolReader, t as SpooledArtifact } from "./spooled_artifact-C5ZtGxuJ.mjs";
9
+ import { n as SpooledJsonArtifact, t as SpooledMarkdownArtifact } from "./spooled_markdown_artifact-BpUJol0W.mjs";
10
+ import { t as DispatchRunner } from "./dispatch_runner-9j6bXHL3.mjs";
11
+ import "./dispatch_runner.mjs";
12
+ import "./exceptions.mjs";
13
+ import { t as TurnRunner } from "./turn_runner-y7eyEcJH.mjs";
14
+ import { isArtifactTool, isBaseException, isDispatchContext, isDispatchRunner, isIdentity, isMemory, isMessage, isRegistry, isSpooledArtifact, isSpooledArtifactConstructor, isSpooledJsonArtifact, isSpooledMarkdownArtifact, isThought, isTokenizable, isTool, isToolCall, isToolRegistry, isTurnContext, isTurnGate, isTurnRunner } from "./guards.mjs";
15
+ import "./turn_runner.mjs";
16
+ //#region src/index.ts
17
+ /**
18
+ * Root convenience barrel for the ADK's core runtime values and public TypeScript contracts.
19
+ *
20
+ * @module @nhtio/adk
21
+ */
22
+ /**
23
+ * The current version of the package.
24
+ *
25
+ * @tip This is a constant that is replaced during the build process with the actual version of the package.
26
+ */
27
+ var version = "0.1.0-master-f0aa531d";
28
+ //#endregion
29
+ export { ArtifactTool, DispatchRunner, E_DISPATCH_PIPELINE_ERROR, E_INPUT_PIPELINE_ERROR, E_INVALID_INITIAL_IDENTITY_VALUE, E_INVALID_INITIAL_MEMORY_VALUE, E_INVALID_INITIAL_MESSAGE_VALUE, E_INVALID_INITIAL_REGISTRY_VALUE, E_INVALID_INITIAL_THOUGHT_VALUE, E_INVALID_INITIAL_TOOL_CALL_VALUE, E_INVALID_INITIAL_TOOL_VALUE, E_INVALID_INITIAL_TURN_GATE_VALUE, E_INVALID_LLM_DISPATCH_INPUT, E_INVALID_LLM_EXECUTION_CONTEXT, E_INVALID_TOOL_ARGS, E_INVALID_TURN_CONTEXT, E_INVALID_TURN_GATE_RESOLUTION, E_INVALID_TURN_RUNNER_CONFIG, E_LLM_EXECUTION_ALREADY_SIGNALLED, E_LLM_EXECUTION_EXECUTOR_ERROR, E_LLM_EXECUTION_GATE_NOT_SUPPORTED, E_NOT_A_SPOOL_READER, E_OUTPUT_PIPELINE_ERROR, E_PIPELINE_SHORT_CIRCUITED, E_TOOL_ALREADY_REGISTERED, E_TOOL_DOWNSTREAM_ERROR, E_TURN_GATE_ABORTED, E_TURN_GATE_TIMEOUT, Identity, Media, Memory, Message, Registry, Retrievable, SpooledArtifact, SpooledJsonArtifact, SpooledMarkdownArtifact, Thought, TokenEncoding, Tokenizable, Tool, ToolCall, ToolRegistry, TurnRunner, ValidationException, fromFetch, fromWebFile, implementsMediaReader, implementsSpoolReader, inMemoryMediaReader, isArtifactTool, isBaseException, isDispatchContext, isDispatchRunner, isError, isIdentity, isInstanceOf, isMedia, isMemory, isMessage, isObject, isRegistry, isSpooledArtifact, isSpooledArtifactConstructor, isSpooledJsonArtifact, isSpooledMarkdownArtifact, isThought, isTokenizable, isTool, isToolCall, isToolRegistry, isTurnContext, isTurnGate, isTurnRunner, mediaReaderSchema, version };
30
+
31
+ //# sourceMappingURL=index.mjs.map
package/index.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * Root convenience barrel for the ADK's core runtime values and public TypeScript contracts.\n *\n * @module @nhtio/adk\n */\n\n/**\n * The current version of the package.\n *\n * @tip This is a constant that is replaced during the build process with the actual version of the package.\n */\nexport const version = __VERSION__\n\n// ── Data primitives (value classes + Raw* types) ──────────────────────────────\n\nexport {\n Tokenizable,\n TokenEncoding,\n Registry,\n Identity,\n Memory,\n Message,\n Retrievable,\n Thought,\n ToolCall,\n Tool,\n ArtifactTool,\n ToolRegistry,\n SpooledArtifact,\n SpooledJsonArtifact,\n SpooledMarkdownArtifact,\n implementsSpoolReader,\n Media,\n isMedia,\n implementsMediaReader,\n mediaReaderSchema,\n inMemoryMediaReader,\n fromFetch,\n fromWebFile,\n} from './common'\n\nexport type {\n RawMedia,\n SerializedMedia,\n MediaKind,\n MediaTrustTier,\n MediaModalityHazard,\n MediaStashEntry,\n MediaReader,\n} from './common'\n\n// ── Runners (the entry points for executing turns and dispatches) ─────────────\n\nexport { TurnRunner } from './turn_runner'\nexport { DispatchRunner } from './dispatch_runner'\n\n// ── Freestanding guards ───────────────────────────────────────────────────────\n\nexport {\n isInstanceOf,\n isError,\n isObject,\n isBaseException,\n isIdentity,\n isMemory,\n isMessage,\n isRegistry,\n isThought,\n isTokenizable,\n isTool,\n isArtifactTool,\n isToolCall,\n isToolRegistry,\n isTurnGate,\n isSpooledArtifact,\n isSpooledArtifactConstructor,\n isSpooledJsonArtifact,\n isSpooledMarkdownArtifact,\n isTurnContext,\n isTurnRunner,\n isDispatchContext,\n isDispatchRunner,\n} from './guards'\n\n// ── Exceptions ────────────────────────────────────────────────────────────────\n\nexport {\n ValidationException,\n E_INVALID_TURN_RUNNER_CONFIG,\n E_INVALID_TURN_CONTEXT,\n E_INPUT_PIPELINE_ERROR,\n E_OUTPUT_PIPELINE_ERROR,\n E_PIPELINE_SHORT_CIRCUITED,\n E_INVALID_INITIAL_REGISTRY_VALUE,\n E_INVALID_INITIAL_MEMORY_VALUE,\n E_INVALID_INITIAL_MESSAGE_VALUE,\n E_INVALID_INITIAL_IDENTITY_VALUE,\n E_INVALID_INITIAL_THOUGHT_VALUE,\n E_INVALID_INITIAL_TURN_GATE_VALUE,\n E_INVALID_TURN_GATE_RESOLUTION,\n E_TURN_GATE_TIMEOUT,\n E_TURN_GATE_ABORTED,\n E_NOT_A_SPOOL_READER,\n E_INVALID_INITIAL_TOOL_CALL_VALUE,\n E_INVALID_INITIAL_TOOL_VALUE,\n E_INVALID_TOOL_ARGS,\n E_TOOL_DOWNSTREAM_ERROR,\n E_TOOL_ALREADY_REGISTERED,\n E_INVALID_LLM_EXECUTION_CONTEXT,\n E_LLM_EXECUTION_GATE_NOT_SUPPORTED,\n E_LLM_EXECUTION_ALREADY_SIGNALLED,\n E_INVALID_LLM_DISPATCH_INPUT,\n E_DISPATCH_PIPELINE_ERROR,\n E_LLM_EXECUTION_EXECUTOR_ERROR,\n} from './exceptions'\n\n// ── Types (re-exported via `export type *` form) ──────────────────────────────\n\nexport type {\n BaseException,\n TurnContext,\n DispatchContext,\n TurnGate,\n RawIdentity,\n RawMemory,\n RawMessage,\n MessageRole,\n RawThought,\n RawToolCall,\n RawTool,\n ToolHandler,\n RawArtifactTool,\n ArtifactToolHandler,\n MergeOptions,\n SpooledArtifactConstructor,\n ToolMethodDescriptor,\n RawTurnGate,\n SpoolReader,\n JsonArtifactFormat,\n MarkdownHeadingEntry,\n MarkdownCodeEntry,\n MarkdownSection,\n RawTurnContext,\n ResolvedTurnContext,\n MemoryRetrievalFn,\n MessageRetrievalFn,\n ThoughtRetrievalFn,\n ToolCallRetrievalFn,\n ToolsRetrievalFn,\n RetrievableRetrievalFn,\n StandingInstructionsRefreshFn,\n StandingInstructionStoreFn,\n StandingInstructionMutateFn,\n StandingInstructionDeleteFn,\n MemoryStoreFn,\n MemoryMutateFn,\n MemoryDeleteFn,\n MessageStoreFn,\n MessageMutateFn,\n MessageDeleteFn,\n ThoughtStoreFn,\n ThoughtMutateFn,\n ThoughtDeleteFn,\n ToolCallStoreFn,\n ToolCallMutateFn,\n ToolCallDeleteFn,\n RetrievableStoreFn,\n RetrievableMutateFn,\n RetrievableDeleteFn,\n TurnRunnerConfig,\n ResolvedTurnRunnerConfig,\n TurnPipelineMiddlewareFn,\n TurnStreamableContent,\n TurnToolCallContent,\n TurnStartEvent,\n TurnEndEvent,\n TurnGateClosedEvent,\n ToolExecutionStartEvent,\n ToolExecutionEndEvent,\n EmitMessageFn,\n EmitThoughtFn,\n EmitToolCallFn,\n EmitToolExecutionStartFn,\n EmitToolExecutionEndFn,\n OpenGateFn,\n TurnEvents,\n TurnEvent,\n TurnEventListener,\n TurnObservabilityEvents,\n TurnObservabilityEvent,\n TurnObservabilityEventListener,\n RawDispatchContext,\n DispatchMemoryRetrievalFn,\n DispatchMessageRetrievalFn,\n DispatchThoughtRetrievalFn,\n DispatchToolCallRetrievalFn,\n DispatchToolsRetrievalFn,\n DispatchStandingInstructionsRefreshFn,\n DispatchStandingInstructionStoreFn,\n DispatchStandingInstructionMutateFn,\n DispatchStandingInstructionDeleteFn,\n DispatchMemoryStoreFn,\n DispatchMemoryMutateFn,\n DispatchMemoryDeleteFn,\n DispatchMessageStoreFn,\n DispatchMessageMutateFn,\n DispatchMessageDeleteFn,\n DispatchThoughtStoreFn,\n DispatchThoughtMutateFn,\n DispatchThoughtDeleteFn,\n DispatchToolCallStoreFn,\n DispatchToolCallMutateFn,\n DispatchToolCallDeleteFn,\n DispatchContextHooks,\n DispatchContextHookRegistrations,\n RawDispatchRunnerInput,\n DispatchPipelineMiddlewareFn,\n DispatchExecutorFn,\n DispatchExecutorHelpers,\n DispatchExecutorLogChannel,\n DispatchExecutorLogEntry,\n DispatchExecutorLogLevel,\n LogEvent,\n DispatchStartEvent,\n DispatchEndEvent,\n IterationStartEvent,\n IterationEndEvent,\n DispatchRunnerFunctionalHooks,\n DispatchRunnerObservabilityHooks,\n DispatchRunnerFunctionalHookRegistrations,\n DispatchRunnerObservabilityHookRegistrations,\n} from './types'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,IAAa,UAAA"}
@@ -0,0 +1,129 @@
1
+ import { Tool } from "./tool";
2
+ import type { Registry } from "./registry";
3
+ import type { Schema } from '@nhtio/validation';
4
+ import type { Tokenizable } from "./tokenizable";
5
+ import type { DispatchContext } from "../contracts/dispatch_context";
6
+ /**
7
+ * The execution function for an {@link ArtifactTool}.
8
+ *
9
+ * @remarks
10
+ * Identical to the base tool handler except the return type is narrowed to
11
+ * `string | Tokenizable | Promise<string | Tokenizable>`. Forged artifact-query tools emit
12
+ * model-visible strings — the ADK wraps a bare-string return into a {@link @nhtio/adk!Tokenizable}
13
+ * at the result-wrapping site so downstream code can rely on
14
+ * `ToolCall.results instanceof Tokenizable` for every `ArtifactTool` invocation.
15
+ */
16
+ export type ArtifactToolHandler = (args: unknown, ctx: DispatchContext, meta: Registry) => string | Tokenizable | Promise<string | Tokenizable>;
17
+ /**
18
+ * Plain input object supplied to {@link ArtifactTool} at construction time.
19
+ *
20
+ * @remarks
21
+ * Mirrors the base `RawTool` except `artifactConstructor` is forbidden — an `ArtifactTool`
22
+ * emits a {@link @nhtio/adk!Tokenizable} directly into `ToolCall.results` and explicitly opts out of
23
+ * `SpooledArtifact` wrapping. The forbidden field is enforced by {@link ArtifactTool.schema}
24
+ * at construction time.
25
+ */
26
+ export interface RawArtifactTool {
27
+ /** Unique identifier used in LLM tool definitions. Recommend lowercase snake_case. */
28
+ name: string;
29
+ /** Human-readable description passed to the model to explain what the tool does. */
30
+ description: string;
31
+ /** @nhtio/validation schema for the tool's input arguments. */
32
+ inputSchema: Schema;
33
+ /** Execution function. Returns a string or {@link @nhtio/adk!Tokenizable}; the ADK wraps a bare string into a `Tokenizable` at the result-wrapping site. */
34
+ handler: ArtifactToolHandler;
35
+ /** Optional arbitrary metadata for this tool. Defaults to `{}`. */
36
+ meta?: Record<string, unknown>;
37
+ /**
38
+ * When `true`, marks this tool as owned by a specific {@link @nhtio/adk!DispatchContext}.
39
+ *
40
+ * @remarks
41
+ * `ArtifactTool` instances produced by `SpooledArtifact.forgeTools(ctx)` set this to `true`
42
+ * so that `ToolRegistry.pruneEphemeral()` drops them at ctx-completion.
43
+ *
44
+ * @defaultValue `false`
45
+ */
46
+ ephemeral?: boolean;
47
+ /**
48
+ * When `true`, declares that this tool's output should be treated as **trusted developer/user
49
+ * intent** rather than as untrusted third-party text when surfaced to the model.
50
+ *
51
+ * @remarks
52
+ * Forged artifact-query tools default to `false` because their results are derived from
53
+ * spooled artifact bodies — which may themselves be untrusted upstream tool output. The
54
+ * trust signal does not promote handle-query results above the trust tier of the underlying
55
+ * artifact.
56
+ *
57
+ * @defaultValue `false`
58
+ */
59
+ trusted?: boolean;
60
+ /**
61
+ * Self-declared merge collision policy honoured by `ToolRegistry.merge`.
62
+ *
63
+ * @remarks
64
+ * Forged artifact-query tools set this to `'replace'` so that merging multiple
65
+ * `Subclass.forgeTools(ctx)` outputs (whose base-method tools overlap by name) resolves
66
+ * silently — the descriptors, snapshot, and handler behaviour are interchangeable across
67
+ * subclasses, so replacement is a behavioural no-op.
68
+ *
69
+ * @defaultValue `'throw'`
70
+ */
71
+ onCollision?: 'throw' | 'replace' | 'keep';
72
+ }
73
+ /**
74
+ * A {@link @nhtio/adk!Tool} subclass whose handler return value is wrapped directly in a
75
+ * {@link @nhtio/adk!Tokenizable} (not a {@link @nhtio/adk!SpooledArtifact}) when it
76
+ * lands on `ToolCall.results`.
77
+ *
78
+ * @remarks
79
+ * `ArtifactTool` is the canonical producer for **forged artifact-query tools** — the tools
80
+ * `SpooledArtifact.forgeTools(ctx)` emits so the model can `head`, `tail`, `grep`, `json_get`,
81
+ * `md_headings` (etc.) an artifact that is already in `ctx.turnToolCalls`.
82
+ *
83
+ * The difference from {@link @nhtio/adk!Tool} is structural, not stylistic:
84
+ *
85
+ * - A normal `Tool`'s handler returns bytes the ADK wraps in a fresh `SpooledArtifact`.
86
+ * The artifact lands in `ToolCall.results`, joins `ctx.turnToolCalls`, and is itself a
87
+ * first-class queryable artifact in the turn.
88
+ * - An `ArtifactTool`'s handler returns a string that is **already the model-visible answer**
89
+ * to a query against an existing artifact. The ADK wraps it in a `Tokenizable` rather
90
+ * than a `SpooledArtifact`; nothing new is queryable on its own. Subsequent
91
+ * `forgeTools(ctx)` calls exclude `ToolCall`s produced by an `ArtifactTool` from the
92
+ * `callId` enum (via the `ToolCall.fromArtifactTool` marker) — this is the structural fix
93
+ * that breaks the otherwise-recursive grep-on-the-grep-result loop.
94
+ *
95
+ * Consumers who want to build their own artifact-query tools (e.g. for a domain-specific
96
+ * spooled subclass not shipped by the ADK) should extend or instantiate this class.
97
+ */
98
+ export declare class ArtifactTool extends Tool {
99
+ /**
100
+ * Validator schema that accepts a {@link RawArtifactTool} object.
101
+ *
102
+ * @remarks
103
+ * Differs from {@link @nhtio/adk!Tool.schema} by forbidding `artifactConstructor` — wrapping is
104
+ * exactly the thing this class opts out of. Typed identically to {@link @nhtio/adk!Tool.schema} so the
105
+ * subclass relationship `class ArtifactTool extends Tool` remains structurally sound; the
106
+ * runtime validation rules still differ as declared by `rawArtifactToolSchema`.
107
+ */
108
+ static schema: typeof Tool.schema;
109
+ /**
110
+ * Returns `true` if `value` is an {@link ArtifactTool} instance.
111
+ *
112
+ * @remarks
113
+ * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
114
+ * created in a different module copy or VM context.
115
+ *
116
+ * @param value - The value to test.
117
+ * @returns `true` when `value` is an {@link ArtifactTool} instance.
118
+ */
119
+ static isArtifactTool(value: unknown): value is ArtifactTool;
120
+ /**
121
+ * @param raw - Raw tool input validated against {@link ArtifactTool.schema}.
122
+ *
123
+ * @throws {@link @nhtio/adk!E_INVALID_INITIAL_TOOL_VALUE} when `raw` does not satisfy
124
+ * {@link ArtifactTool.schema} (most commonly, when `artifactConstructor` is supplied — it is
125
+ * explicitly forbidden on this class) or when the base {@link @nhtio/adk!Tool} constructor rejects the
126
+ * input for any reason.
127
+ */
128
+ constructor(raw: RawArtifactTool);
129
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Base class for all structured exceptions in the ADK.
3
+ *
4
+ * @remarks
5
+ * Subclasses should declare static `code`, `status`, `fatal`, and optionally `help` to avoid
6
+ * repeating those values on every instance. Instance-level options always take precedence over
7
+ * static defaults, so a single exception class can still be thrown with per-site overrides when
8
+ * needed.
9
+ *
10
+ * The runtime cross-realm guard is inlined here rather than imported from `../utils/guards`
11
+ * to break a circular-import chain: `guards` depends on `validation`, which extends
12
+ * `BaseException`. Importing the shared `isInstanceOf` helper into this file would create a
13
+ * load-order cycle that leaves `BaseException` undefined when `ValidationException extends
14
+ * BaseException` evaluates.
15
+ */
16
+ export declare class BaseException extends Error {
17
+ /**
18
+ * Returns `true` if `value` is a {@link BaseException} instance.
19
+ *
20
+ * @remarks
21
+ * Performs cross-realm-safe detection: tries `instanceof`, then `Symbol.hasInstance`, then
22
+ * constructor-name comparison. The ADK does not export the `BaseException` class itself
23
+ * as a constructable value — use this guard plus the {@link BaseException} type for runtime
24
+ * detection and TypeScript narrowing.
25
+ *
26
+ * @param value - The value to test.
27
+ * @returns `true` when `value` is a {@link BaseException} instance.
28
+ */
29
+ static isBaseException(value: unknown): value is BaseException;
30
+ /**
31
+ * Default help text inherited by all instances unless overridden at the throw site.
32
+ */
33
+ static help?: string;
34
+ /**
35
+ * Default machine-readable error code inherited by all instances.
36
+ */
37
+ static code?: string;
38
+ /**
39
+ * Default HTTP status code inherited by all instances.
40
+ */
41
+ static status?: number;
42
+ /**
43
+ * Whether exceptions of this class are fatal by default.
44
+ */
45
+ static fatal?: boolean;
46
+ /**
47
+ * Default message used when no message is supplied to the constructor.
48
+ */
49
+ static message?: string;
50
+ /**
51
+ * Name of the class that raised the exception.
52
+ */
53
+ name: string;
54
+ /**
55
+ * Human-readable guidance for resolving or reporting this error.
56
+ */
57
+ help?: string;
58
+ /**
59
+ * Machine-readable error code for narrowing exception-handling logic.
60
+ */
61
+ code?: string;
62
+ /**
63
+ * HTTP status code associated with this error.
64
+ */
65
+ status?: number;
66
+ /**
67
+ * When `true`, the ADK treats this error as unrecoverable and should halt the agent loop.
68
+ */
69
+ fatal?: boolean;
70
+ /**
71
+ * @param message - Human-readable error message. Falls back to the static `message` on the
72
+ * subclass if omitted.
73
+ * @param options - Standard `ErrorOptions` extended with `code`, `status`, and `fatal`
74
+ * overrides. Static defaults on the subclass are used when these are absent.
75
+ */
76
+ constructor(message?: string, options?: ErrorOptions & {
77
+ code?: string;
78
+ status?: number;
79
+ fatal?: boolean;
80
+ });
81
+ get [Symbol.toStringTag](): string;
82
+ toString(): string;
83
+ }
@@ -0,0 +1,71 @@
1
+ import { Tokenizable } from "./tokenizable";
2
+ /**
3
+ * Plain input object supplied to {@link Identity} at construction time.
4
+ *
5
+ * @remarks
6
+ * Validated against `rawIdentitySchema` before the `Identity` instance is created.
7
+ */
8
+ export interface RawIdentity {
9
+ /**
10
+ * The system-facing identifier for this participant.
11
+ *
12
+ * @remarks
13
+ * Used internally to correlate messages to a specific participant — e.g. a database ID or
14
+ * a username. Never sent to the model directly; use `representation` for that.
15
+ */
16
+ identifier: string | number;
17
+ /**
18
+ * How this participant should be presented to the model.
19
+ *
20
+ * @remarks
21
+ * Accepts a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. This is what the model
22
+ * sees when it needs to distinguish between participants of the same role.
23
+ */
24
+ representation: string | Tokenizable;
25
+ }
26
+ /**
27
+ * An immutable, validated participant identity attached to a {@link @nhtio/adk!Message}.
28
+ *
29
+ * @remarks
30
+ * Carries two distinct representations of the same participant: `identifier` is the
31
+ * system-facing key (e.g. a database ID) used to correlate messages programmatically;
32
+ * `representation` is what the model sees when it needs to distinguish between participants
33
+ * sharing the same role. The `representation` is always a {@link @nhtio/adk!Tokenizable} so token cost
34
+ * can be estimated inline.
35
+ */
36
+ export declare class Identity {
37
+ #private;
38
+ /**
39
+ * Validator schema that accepts a {@link RawIdentity} object.
40
+ *
41
+ * @remarks
42
+ * Reusable fragment for any schema that needs to validate or nest an identity — for example,
43
+ * as a required field inside a message schema.
44
+ */
45
+ static schema: import("@nhtio/validation").ObjectSchema<RawIdentity>;
46
+ /**
47
+ * Returns `true` if `value` is an {@link Identity} instance.
48
+ *
49
+ * @remarks
50
+ * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
51
+ * created in a different module copy or VM context.
52
+ *
53
+ * @param value - The value to test.
54
+ * @returns `true` when `value` is an {@link Identity} instance.
55
+ */
56
+ static isIdentity(value: unknown): value is Identity;
57
+ /**
58
+ * The system-facing identifier for this participant — never sent to the model directly.
59
+ */
60
+ readonly identifier: string | number;
61
+ /**
62
+ * How this participant is presented to the model, as a {@link @nhtio/adk!Tokenizable} for inline
63
+ * token estimation.
64
+ */
65
+ readonly representation: Tokenizable;
66
+ /**
67
+ * @param raw - The raw identity input validated against `rawIdentitySchema`.
68
+ * @throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} when `raw` does not satisfy the schema.
69
+ */
70
+ constructor(raw: RawIdentity);
71
+ }
@@ -0,0 +1,326 @@
1
+ import { Registry } from "./registry";
2
+ import type { MediaReader } from "../contracts/media_reader";
3
+ /**
4
+ * The set of supported media kinds.
5
+ *
6
+ * @remarks
7
+ * Modality coverage is asymmetric across providers. The framework defines no
8
+ * `supportedModalities` field — how a battery handles a modality it cannot natively render is
9
+ * the battery author's call (see `unsupportedMediaPolicy` on the OpenAI Chat Completions
10
+ * battery).
11
+ */
12
+ export declare const MediaKind: readonly [
13
+ "image",
14
+ "audio",
15
+ "video",
16
+ "document"
17
+ ];
18
+ /**
19
+ * Union of all recognised media kind identifier strings.
20
+ */
21
+ export type MediaKind = (typeof MediaKind)[number];
22
+ /**
23
+ * Provenance axis. *Who is the framework willing to vouch for as the source of these bytes?*
24
+ *
25
+ * @remarks
26
+ * Mirrors `RetrievableTrustTier` deliberately — same vocabulary, same question:
27
+ * *did this content come from a place the agent should treat as authoritative?*
28
+ *
29
+ * - `'first-party'` — deployer-vetted bytes (tool output the operator authored, signed
30
+ * internal assets).
31
+ * - `'third-party-public'` — open-web fetches, public APIs, public corpora.
32
+ * - `'third-party-private'` — user uploads, partner APIs, private corpora.
33
+ */
34
+ export declare const MediaTrustTier: readonly [
35
+ "first-party",
36
+ "third-party-public",
37
+ "third-party-private"
38
+ ];
39
+ export type MediaTrustTier = (typeof MediaTrustTier)[number];
40
+ /**
41
+ * Modality-hazard axis. *How dangerous is it to let the model decode these bytes?*
42
+ *
43
+ * @remarks
44
+ * Orthogonal to provenance — a first-party trusted PDF can still carry hidden text layers; a
45
+ * third-party-public raw image can still be encoded as opaque pixels with adversarial
46
+ * perturbations.
47
+ *
48
+ * - `'inert'` — bytes the model never decodes as instructions (e.g. a handle that is never
49
+ * inlined into the prompt).
50
+ * - `'extractable-instructions'` — text-bearing media: PDFs, screenshots with UI text, documents.
51
+ * Hazard is OCR / embedded-text-layer reads.
52
+ * - `'opaque-perceptual'` — raw vision/audio/video the model encodes directly. Hazard is
53
+ * steganographic LSB prompts, adversarial perturbations, ultrasonic audio — invisible to any
54
+ * pre-screen.
55
+ *
56
+ * See `/the-loop/trust-tiers/media` and its research sub-page `/the-loop/trust-tiers/media/research`.
57
+ */
58
+ export declare const MediaModalityHazard: readonly [
59
+ "inert",
60
+ "extractable-instructions",
61
+ "opaque-perceptual"
62
+ ];
63
+ export type MediaModalityHazard = (typeof MediaModalityHazard)[number];
64
+ /**
65
+ * Per-entry shape stored in a {@link Media}'s `stash` register.
66
+ *
67
+ * @remarks
68
+ * Each entry carries its own trust tier so render code can route derived text (OCR, captions,
69
+ * transcripts) through its own envelope independent of the parent media. How a battery or
70
+ * middleware assigns those entry-level tiers is the implementor's call — the primitive contract
71
+ * does not enforce a "downgrade derived interpretation from possibly-adversarial bytes" policy.
72
+ */
73
+ export interface MediaStashEntry {
74
+ /** The value of the entry — any serialisable shape the consumer wants to store. */
75
+ value: unknown;
76
+ /** Trust tier for this specific entry; routed independently of the parent media. */
77
+ trustTier: MediaTrustTier;
78
+ /** Optional pointer to the parent Media id this entry was derived from. */
79
+ derivedFromMedia?: string;
80
+ }
81
+ /**
82
+ * Plain input object supplied to {@link Media} at construction time.
83
+ *
84
+ * @remarks
85
+ * Validated against `rawMediaSchema` before the `Media` instance is created.
86
+ */
87
+ export interface RawMedia {
88
+ /**
89
+ * Stable unique identifier for this media instance. Required for strict symmetry with
90
+ * `Message.id` and `ToolCall.id`. When omitted, a fresh UUIDv6 is assigned at construction
91
+ * time.
92
+ */
93
+ id?: string;
94
+ /** The media kind. See {@link MediaKind}. */
95
+ kind: MediaKind;
96
+ /** The MIME type of the underlying bytes. */
97
+ mimeType: string;
98
+ /** Filename used by providers that key on it (e.g. OpenAI `file.filename`). */
99
+ filename: string;
100
+ /** Re-openable byte source. See {@link @nhtio/adk!MediaReader}. */
101
+ reader: MediaReader;
102
+ /**
103
+ * Trust tier declared at construction time. Required — there is NO default.
104
+ * See {@link MediaTrustTier}.
105
+ */
106
+ trustTier: MediaTrustTier;
107
+ /**
108
+ * Modality hazard declared at construction time. Required — there is NO default.
109
+ * See {@link MediaModalityHazard}.
110
+ */
111
+ modalityHazard: MediaModalityHazard;
112
+ /** Optional provenance pointer (URL, tool name, etc.) for audit / events. */
113
+ source?: string;
114
+ /**
115
+ * Free-form per-instance metadata register. Middleware pipelines append to this — typically
116
+ * with a text description, transcript, caption, or alt-text — so downstream code that cannot
117
+ * consume the media natively has a model-readable fallback. No keys are reserved by the
118
+ * framework. Defaults to `{}`.
119
+ */
120
+ stash?: Record<string, MediaStashEntry>;
121
+ }
122
+ /**
123
+ * Shape returned by {@link Media.toJSON}. Metadata-only — bytes and the reader are stripped so
124
+ * naive event/log serialisation never materialises bytes.
125
+ */
126
+ export interface SerializedMedia {
127
+ id: string;
128
+ kind: MediaKind;
129
+ mimeType: string;
130
+ filename: string;
131
+ source?: string;
132
+ trustTier: MediaTrustTier;
133
+ modalityHazard: MediaModalityHazard;
134
+ stash: Record<string, MediaStashEntry>;
135
+ byteLength?: number;
136
+ }
137
+ /**
138
+ * Lazy, re-openable view over a binary asset (image, audio, video, document).
139
+ *
140
+ * @remarks
141
+ * Dual-peer to {@link @nhtio/adk!Tokenizable} (silo) and {@link @nhtio/adk!SpooledArtifact}
142
+ * (handle). Wraps a {@link @nhtio/adk!MediaReader} contract — the framework owns the contract, the
143
+ * implementor owns the storage backend. Bytes are reached only through the reader; the primitive
144
+ * itself never inlines bytes.
145
+ *
146
+ * Construction requires `trustTier` and `modalityHazard` — the framework refuses to guess
147
+ * provenance or decoding hazard. Ergonomic factories ({@link Media.userAttachment},
148
+ * {@link Media.toolGenerated}, {@link Media.retrievedPublic}, {@link Media.retrievedPrivate})
149
+ * force the labelling decision at the call site without becoming defaults on the bare
150
+ * constructor.
151
+ */
152
+ export declare class Media {
153
+ #private;
154
+ /**
155
+ * Validator schema that accepts a {@link RawMedia} object.
156
+ */
157
+ static schema: import("@nhtio/validation").ObjectSchema<RawMedia>;
158
+ /**
159
+ * The set of recognised media kinds. Exposed for downstream schemas that need to discriminate
160
+ * on `kind`.
161
+ */
162
+ static MediaKind: readonly [
163
+ "image",
164
+ "audio",
165
+ "video",
166
+ "document"
167
+ ];
168
+ /**
169
+ * The set of recognised trust tiers.
170
+ */
171
+ static MediaTrustTier: readonly [
172
+ "first-party",
173
+ "third-party-public",
174
+ "third-party-private"
175
+ ];
176
+ /**
177
+ * The set of recognised modality hazards.
178
+ */
179
+ static MediaModalityHazard: readonly [
180
+ "inert",
181
+ "extractable-instructions",
182
+ "opaque-perceptual"
183
+ ];
184
+ /**
185
+ * Returns `true` if `value` is a {@link Media} instance.
186
+ *
187
+ * @remarks
188
+ * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.
189
+ *
190
+ * @param value - The value to test.
191
+ * @returns `true` when `value` is a {@link Media} instance.
192
+ */
193
+ static isMedia(value: unknown): value is Media;
194
+ /** Stable unique identifier. */
195
+ readonly id: string;
196
+ /** Media kind. */
197
+ readonly kind: MediaKind;
198
+ /** MIME type of the underlying bytes. */
199
+ readonly mimeType: string;
200
+ /** Filename surfaced to providers that key on it. */
201
+ readonly filename: string;
202
+ /** Optional provenance pointer. */
203
+ readonly source: string | undefined;
204
+ /** Trust tier declared at construction time. */
205
+ readonly trustTier: MediaTrustTier;
206
+ /** Modality hazard declared at construction time. */
207
+ readonly modalityHazard: MediaModalityHazard;
208
+ /** Mutable per-instance metadata register; middleware pipelines append to this. */
209
+ readonly stash: Registry;
210
+ /**
211
+ * @param raw - The raw media input validated against `rawMediaSchema`.
212
+ * @throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_MEDIA_VALUE} when `raw` does not satisfy the schema.
213
+ * @throws {@link @nhtio/adk/exceptions!E_NOT_A_MEDIA_READER} when `raw.reader` does not implement {@link @nhtio/adk!MediaReader}.
214
+ */
215
+ constructor(raw: RawMedia);
216
+ /**
217
+ * Re-opens the underlying byte source and returns a fresh ReadableStream.
218
+ *
219
+ * @returns A drainable `ReadableStream` over the underlying bytes.
220
+ */
221
+ stream(): Promise<ReadableStream<Uint8Array>>;
222
+ /**
223
+ * Returns the total number of bytes in the underlying data, or `undefined` if unknown.
224
+ *
225
+ * @returns The byte length, or `undefined` when the underlying source cannot report it.
226
+ */
227
+ byteLength(): Promise<number | undefined>;
228
+ /**
229
+ * Drains the reader's stream and returns the underlying bytes as a single `Uint8Array`.
230
+ *
231
+ * @remarks
232
+ * Convenience for callers that need the full buffer (e.g. inline base64 encoding). Forces
233
+ * full materialisation — large assets should be piped through {@link Media.stream} instead.
234
+ */
235
+ asBytes(): Promise<Uint8Array>;
236
+ /**
237
+ * Drains the reader's stream and returns the underlying bytes as a base64 string.
238
+ *
239
+ * @remarks
240
+ * Cross-environment: prefers Node's `Buffer.from(buf).toString('base64')` when available;
241
+ * otherwise chunk-encodes through `btoa` with a 0x8000-byte window to avoid stack overflow
242
+ * on large buffers.
243
+ */
244
+ asBase64(): Promise<string>;
245
+ /**
246
+ * Returns the metadata-only serialisation of this Media. Bytes and the reader are stripped
247
+ * so naive event/log serialisation never materialises bytes.
248
+ *
249
+ * @remarks
250
+ * Implementations that have cheap, already-cached `byteLength` may opt to include it; this
251
+ * default implementation omits it to preserve the "lazy by default" invariant. Consumers that
252
+ * need byteLength on the serialised payload should call `await media.byteLength()` and merge
253
+ * the result.
254
+ */
255
+ toJSON(): SerializedMedia;
256
+ /**
257
+ * Factory: constructs a {@link Media} representing a user-supplied attachment.
258
+ *
259
+ * @remarks
260
+ * Pre-fills `trustTier: 'third-party-private'` and derives `modalityHazard` from `kind`
261
+ * (`document` → `'extractable-instructions'`; everything else → `'opaque-perceptual'`).
262
+ * Use the bare constructor when the conservative kind→hazard mapping is wrong for your case.
263
+ */
264
+ static userAttachment(args: {
265
+ id?: string;
266
+ kind: MediaKind;
267
+ mimeType: string;
268
+ filename: string;
269
+ reader: MediaReader;
270
+ source?: string;
271
+ stash?: Record<string, MediaStashEntry>;
272
+ }): Media;
273
+ /**
274
+ * Factory: constructs a {@link Media} produced by a first-party tool.
275
+ *
276
+ * @remarks
277
+ * Pre-fills `trustTier: 'first-party'` and derives `modalityHazard` from `kind`.
278
+ */
279
+ static toolGenerated(args: {
280
+ id?: string;
281
+ kind: MediaKind;
282
+ mimeType: string;
283
+ filename: string;
284
+ reader: MediaReader;
285
+ source?: string;
286
+ stash?: Record<string, MediaStashEntry>;
287
+ }): Media;
288
+ /**
289
+ * Factory: constructs a {@link Media} retrieved from a public third-party source.
290
+ *
291
+ * @remarks
292
+ * Pre-fills `trustTier: 'third-party-public'` and derives `modalityHazard` from `kind`.
293
+ */
294
+ static retrievedPublic(args: {
295
+ id?: string;
296
+ kind: MediaKind;
297
+ mimeType: string;
298
+ filename: string;
299
+ reader: MediaReader;
300
+ source?: string;
301
+ stash?: Record<string, MediaStashEntry>;
302
+ }): Media;
303
+ /**
304
+ * Factory: constructs a {@link Media} retrieved from a private third-party source.
305
+ *
306
+ * @remarks
307
+ * Pre-fills `trustTier: 'third-party-private'` and derives `modalityHazard` from `kind`.
308
+ */
309
+ static retrievedPrivate(args: {
310
+ id?: string;
311
+ kind: MediaKind;
312
+ mimeType: string;
313
+ filename: string;
314
+ reader: MediaReader;
315
+ source?: string;
316
+ stash?: Record<string, MediaStashEntry>;
317
+ }): Media;
318
+ }
319
+ /**
320
+ * Returns `true` if `value` is a {@link Media} instance.
321
+ *
322
+ * @remarks
323
+ * Module-level convenience alias for {@link Media.isMedia}. Uses {@link @nhtio/adk!isInstanceOf} for
324
+ * cross-realm safety.
325
+ */
326
+ export declare const isMedia: (value: unknown) => value is Media;