@nhtio/adk 1.20260924.0 → 1.20260928.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/artifact_methods-Cg0go7Q4.mjs +1 -0
  3. package/artifact_methods-CxeKTocm.cjs +1 -0
  4. package/batteries/artifacts/ecmascript.cjs +1 -1
  5. package/batteries/artifacts/ecmascript.mjs +1 -1
  6. package/batteries/artifacts/toon.cjs +1 -1
  7. package/batteries/artifacts/toon.mjs +1 -1
  8. package/batteries/artifacts/xml.cjs +1 -1
  9. package/batteries/artifacts/xml.mjs +1 -1
  10. package/batteries/artifacts/yaml.cjs +1 -1
  11. package/batteries/artifacts/yaml.mjs +1 -1
  12. package/batteries/artifacts.cjs +4 -4
  13. package/batteries/artifacts.mjs +4 -4
  14. package/batteries/dev-tools/forge.cjs +3 -3
  15. package/batteries/dev-tools/forge.mjs +3 -3
  16. package/batteries/dev-tools.cjs +3 -3
  17. package/batteries/dev-tools.mjs +3 -3
  18. package/batteries/encoding.cjs +7 -7
  19. package/batteries/encoding.mjs +7 -7
  20. package/batteries/generation/gemini/adapter.cjs +1 -1
  21. package/batteries/generation/gemini/adapter.mjs +1 -1
  22. package/batteries/generation/local_diffusion/adapter.cjs +1 -1
  23. package/batteries/generation/local_diffusion/adapter.mjs +1 -1
  24. package/batteries/generation/openai/adapter.cjs +1 -1
  25. package/batteries/generation/openai/adapter.mjs +1 -1
  26. package/batteries/llm/anthropic_messages/adapter.cjs +6 -6
  27. package/batteries/llm/anthropic_messages/adapter.mjs +6 -6
  28. package/batteries/llm/anthropic_messages/count_tokens.cjs +1 -1
  29. package/batteries/llm/anthropic_messages/count_tokens.mjs +1 -1
  30. package/batteries/llm/anthropic_messages/helpers.cjs +3 -3
  31. package/batteries/llm/anthropic_messages/helpers.mjs +3 -3
  32. package/batteries/llm/anthropic_messages/validation.cjs +2 -2
  33. package/batteries/llm/anthropic_messages/validation.mjs +2 -2
  34. package/batteries/llm/anthropic_messages.cjs +2 -2
  35. package/batteries/llm/anthropic_messages.mjs +2 -2
  36. package/batteries/llm/bedrock_converse/adapter.cjs +162 -21
  37. package/batteries/llm/bedrock_converse/adapter.cjs.map +1 -1
  38. package/batteries/llm/bedrock_converse/adapter.mjs +162 -21
  39. package/batteries/llm/bedrock_converse/adapter.mjs.map +1 -1
  40. package/batteries/llm/bedrock_converse/helpers.cjs +1 -1
  41. package/batteries/llm/bedrock_converse/helpers.mjs +1 -1
  42. package/batteries/llm/bedrock_converse/validation.cjs +2 -2
  43. package/batteries/llm/bedrock_converse/validation.mjs +2 -2
  44. package/batteries/llm/bedrock_converse.cjs +2 -2
  45. package/batteries/llm/bedrock_converse.mjs +2 -2
  46. package/batteries/llm/claude_code_cli/adapter.cjs +66 -25
  47. package/batteries/llm/claude_code_cli/adapter.cjs.map +1 -1
  48. package/batteries/llm/claude_code_cli/adapter.mjs +66 -25
  49. package/batteries/llm/claude_code_cli/adapter.mjs.map +1 -1
  50. package/batteries/llm/claude_code_cli/helpers.cjs +3 -3
  51. package/batteries/llm/claude_code_cli/helpers.mjs +3 -3
  52. package/batteries/llm/claude_code_cli/line_queue.d.ts +39 -0
  53. package/batteries/llm/claude_code_cli/message_id_state.d.ts +48 -0
  54. package/batteries/llm/claude_code_cli/types.d.ts +76 -0
  55. package/batteries/llm/claude_code_cli/validation.cjs +5 -2
  56. package/batteries/llm/claude_code_cli/validation.cjs.map +1 -1
  57. package/batteries/llm/claude_code_cli/validation.mjs +5 -2
  58. package/batteries/llm/claude_code_cli/validation.mjs.map +1 -1
  59. package/batteries/llm/claude_code_cli/wire.cjs.map +1 -1
  60. package/batteries/llm/claude_code_cli/wire.d.ts +45 -1
  61. package/batteries/llm/claude_code_cli/wire.mjs.map +1 -1
  62. package/batteries/llm/claude_code_cli/wrapper.d.ts +5 -4
  63. package/batteries/llm/claude_code_cli.cjs +2 -2
  64. package/batteries/llm/claude_code_cli.mjs +2 -2
  65. package/batteries/llm/gemini_generate_content/adapter.cjs +160 -19
  66. package/batteries/llm/gemini_generate_content/adapter.cjs.map +1 -1
  67. package/batteries/llm/gemini_generate_content/adapter.mjs +160 -19
  68. package/batteries/llm/gemini_generate_content/adapter.mjs.map +1 -1
  69. package/batteries/llm/gemini_generate_content/helpers.cjs +1 -1
  70. package/batteries/llm/gemini_generate_content/helpers.mjs +1 -1
  71. package/batteries/llm/gemini_generate_content/validation.cjs +2 -2
  72. package/batteries/llm/gemini_generate_content/validation.mjs +2 -2
  73. package/batteries/llm/gemini_generate_content.cjs +1 -1
  74. package/batteries/llm/gemini_generate_content.mjs +1 -1
  75. package/batteries/llm/litert_lm/adapter.cjs +6 -6
  76. package/batteries/llm/litert_lm/adapter.mjs +6 -6
  77. package/batteries/llm/litert_lm/helpers.cjs +3 -3
  78. package/batteries/llm/litert_lm/helpers.mjs +3 -3
  79. package/batteries/llm/litert_lm/validation.cjs +2 -2
  80. package/batteries/llm/litert_lm/validation.mjs +2 -2
  81. package/batteries/llm/litert_lm.cjs +1 -1
  82. package/batteries/llm/litert_lm.mjs +1 -1
  83. package/batteries/llm/ollama/adapter.cjs +6 -6
  84. package/batteries/llm/ollama/adapter.mjs +6 -6
  85. package/batteries/llm/ollama/helpers.cjs +4 -4
  86. package/batteries/llm/ollama/helpers.mjs +4 -4
  87. package/batteries/llm/ollama/validation.cjs +2 -2
  88. package/batteries/llm/ollama/validation.mjs +2 -2
  89. package/batteries/llm/ollama.cjs +2 -2
  90. package/batteries/llm/ollama.mjs +2 -2
  91. package/batteries/llm/openai_chat_completions/adapter.cjs +6 -6
  92. package/batteries/llm/openai_chat_completions/adapter.mjs +6 -6
  93. package/batteries/llm/openai_chat_completions/helpers.cjs +4 -4
  94. package/batteries/llm/openai_chat_completions/helpers.mjs +4 -4
  95. package/batteries/llm/openai_chat_completions/validation.cjs +2 -2
  96. package/batteries/llm/openai_chat_completions/validation.mjs +2 -2
  97. package/batteries/llm/openai_chat_completions.cjs +2 -2
  98. package/batteries/llm/openai_chat_completions.mjs +2 -2
  99. package/batteries/llm/openai_responses/adapter.cjs +6 -6
  100. package/batteries/llm/openai_responses/adapter.mjs +6 -6
  101. package/batteries/llm/openai_responses/helpers.cjs +3 -3
  102. package/batteries/llm/openai_responses/helpers.mjs +3 -3
  103. package/batteries/llm/openai_responses/validation.cjs +2 -2
  104. package/batteries/llm/openai_responses/validation.mjs +2 -2
  105. package/batteries/llm/openai_responses.cjs +2 -2
  106. package/batteries/llm/openai_responses.mjs +2 -2
  107. package/batteries/llm/transformers_js/adapter.cjs +6 -6
  108. package/batteries/llm/transformers_js/adapter.mjs +6 -6
  109. package/batteries/llm/transformers_js/helpers.cjs +3 -3
  110. package/batteries/llm/transformers_js/helpers.mjs +3 -3
  111. package/batteries/llm/transformers_js/validation.cjs +2 -2
  112. package/batteries/llm/transformers_js/validation.mjs +2 -2
  113. package/batteries/llm/transformers_js.cjs +1 -1
  114. package/batteries/llm/transformers_js.mjs +1 -1
  115. package/batteries/llm/webllm_chat_completions/adapter.cjs +6 -6
  116. package/batteries/llm/webllm_chat_completions/adapter.mjs +6 -6
  117. package/batteries/llm/webllm_chat_completions/helpers.cjs +1 -1
  118. package/batteries/llm/webllm_chat_completions/helpers.mjs +1 -1
  119. package/batteries/llm/webllm_chat_completions/validation.cjs +2 -2
  120. package/batteries/llm/webllm_chat_completions/validation.mjs +2 -2
  121. package/batteries/llm/webllm_chat_completions.cjs +2 -2
  122. package/batteries/llm/webllm_chat_completions.mjs +2 -2
  123. package/batteries/llm.cjs +2 -2
  124. package/batteries/llm.mjs +2 -2
  125. package/batteries/media/forge.cjs +4 -4
  126. package/batteries/media/forge.mjs +4 -4
  127. package/batteries/media/lint.cjs +1 -1
  128. package/batteries/media/lint.mjs +1 -1
  129. package/batteries/orchestration/dispatch_reasoner.cjs +4 -4
  130. package/batteries/orchestration/dispatch_reasoner.mjs +4 -4
  131. package/batteries/orchestration/executor.cjs +2 -2
  132. package/batteries/orchestration/executor.mjs +2 -2
  133. package/batteries/orchestration/forge.cjs +4 -4
  134. package/batteries/orchestration/forge.mjs +4 -4
  135. package/batteries/orchestration/validation.cjs +2 -2
  136. package/batteries/orchestration/validation.mjs +2 -2
  137. package/batteries/orchestration.cjs +4 -4
  138. package/batteries/orchestration.mjs +4 -4
  139. package/batteries/sandbox/js.cjs +1 -1
  140. package/batteries/sandbox/js.mjs +1 -1
  141. package/batteries/sandbox/tools.cjs +1 -1
  142. package/batteries/sandbox/tools.mjs +1 -1
  143. package/batteries/sandbox.cjs +3 -3
  144. package/batteries/sandbox.mjs +3 -3
  145. package/batteries/skills.cjs +9 -9
  146. package/batteries/skills.mjs +9 -9
  147. package/batteries/tools/_shared.cjs +1 -1
  148. package/batteries/tools/_shared.mjs +1 -1
  149. package/batteries/tools/color.cjs +2 -2
  150. package/batteries/tools/color.mjs +2 -2
  151. package/batteries/tools/comparison.cjs +2 -2
  152. package/batteries/tools/comparison.mjs +2 -2
  153. package/batteries/tools/data_structure.cjs +2 -2
  154. package/batteries/tools/data_structure.mjs +2 -2
  155. package/batteries/tools/datetime_extended.cjs +3 -3
  156. package/batteries/tools/datetime_extended.mjs +3 -3
  157. package/batteries/tools/datetime_math.cjs +3 -3
  158. package/batteries/tools/datetime_math.mjs +3 -3
  159. package/batteries/tools/encoding.cjs +2 -2
  160. package/batteries/tools/encoding.mjs +2 -2
  161. package/batteries/tools/formatting.cjs +2 -2
  162. package/batteries/tools/formatting.mjs +2 -2
  163. package/batteries/tools/geo_basics.cjs +2 -2
  164. package/batteries/tools/geo_basics.mjs +2 -2
  165. package/batteries/tools/math.cjs +2 -2
  166. package/batteries/tools/math.mjs +2 -2
  167. package/batteries/tools/memory.cjs +5 -5
  168. package/batteries/tools/memory.mjs +5 -5
  169. package/batteries/tools/parsing.cjs +3 -3
  170. package/batteries/tools/parsing.mjs +3 -3
  171. package/batteries/tools/retrievables.cjs +5 -5
  172. package/batteries/tools/retrievables.mjs +5 -5
  173. package/batteries/tools/scrapper.cjs +1 -1
  174. package/batteries/tools/scrapper.mjs +1 -1
  175. package/batteries/tools/searxng.cjs +1 -1
  176. package/batteries/tools/searxng.mjs +1 -1
  177. package/batteries/tools/standing_instructions.cjs +3 -3
  178. package/batteries/tools/standing_instructions.mjs +3 -3
  179. package/batteries/tools/statistics.cjs +3 -3
  180. package/batteries/tools/statistics.mjs +3 -3
  181. package/batteries/tools/string_processing.cjs +2 -2
  182. package/batteries/tools/string_processing.mjs +2 -2
  183. package/batteries/tools/structured_data.cjs +2 -2
  184. package/batteries/tools/structured_data.mjs +2 -2
  185. package/batteries/tools/text_analysis.cjs +3 -3
  186. package/batteries/tools/text_analysis.mjs +3 -3
  187. package/batteries/tools/text_comparison.cjs +2 -2
  188. package/batteries/tools/text_comparison.mjs +2 -2
  189. package/batteries/tools/time.cjs +3 -3
  190. package/batteries/tools/time.mjs +3 -3
  191. package/batteries/tools/unit_conversion.cjs +2 -2
  192. package/batteries/tools/unit_conversion.mjs +2 -2
  193. package/batteries/tools.cjs +2 -2
  194. package/batteries/tools.mjs +2 -2
  195. package/batteries/validation.cjs +4 -4
  196. package/batteries/validation.mjs +4 -4
  197. package/batteries/vector/conformance.cjs +59 -0
  198. package/batteries/vector/conformance.cjs.map +1 -1
  199. package/batteries/vector/conformance.mjs +59 -0
  200. package/batteries/vector/conformance.mjs.map +1 -1
  201. package/batteries/vector/lancedb.cjs +1 -1
  202. package/batteries/vector/lancedb.cjs.map +1 -1
  203. package/batteries/vector/lancedb.mjs +1 -1
  204. package/batteries/vector/lancedb.mjs.map +1 -1
  205. package/batteries/vector/retrievable.cjs +1 -1
  206. package/batteries/vector/retrievable.mjs +1 -1
  207. package/batteries/vector/sqlite_vec/index.d.ts +1 -1
  208. package/batteries/vector/sqlite_vec.cjs +19 -30
  209. package/batteries/vector/sqlite_vec.cjs.map +1 -1
  210. package/batteries/vector/sqlite_vec.mjs +20 -31
  211. package/batteries/vector/sqlite_vec.mjs.map +1 -1
  212. package/batteries.cjs +4 -4
  213. package/batteries.mjs +4 -4
  214. package/{chat_common-B7fvGTKv.cjs → chat_common-CNayzS1V.cjs} +2 -2
  215. package/{chat_common-B7fvGTKv.cjs.map → chat_common-CNayzS1V.cjs.map} +1 -1
  216. package/{chat_common-CeoHwSsz.mjs → chat_common-DKw8FDol.mjs} +2 -2
  217. package/{chat_common-CeoHwSsz.mjs.map → chat_common-DKw8FDol.mjs.map} +1 -1
  218. package/claude-code-cli-wrapper.cjs +104 -22
  219. package/claude-code-cli-wrapper.cjs.map +1 -1
  220. package/claude-code-cli-wrapper.mjs +104 -22
  221. package/claude-code-cli-wrapper.mjs.map +1 -1
  222. package/{common-7gCR3zQu.cjs → common-CqetsItm.cjs} +7 -7
  223. package/{common-7gCR3zQu.cjs.map → common-CqetsItm.cjs.map} +1 -1
  224. package/{common-B5maOoF_.mjs → common-oI1niK9Z.mjs} +7 -7
  225. package/{common-B5maOoF_.mjs.map → common-oI1niK9Z.mjs.map} +1 -1
  226. package/common.cjs +7 -7
  227. package/common.mjs +7 -7
  228. package/{dispatch_runner-DO7jo_gl.mjs → dispatch_runner-BZDXUe0G.mjs} +5 -5
  229. package/{dispatch_runner-DO7jo_gl.mjs.map → dispatch_runner-BZDXUe0G.mjs.map} +1 -1
  230. package/{dispatch_runner-FlriTyoq.cjs → dispatch_runner-DDUxXJC3.cjs} +5 -5
  231. package/{dispatch_runner-FlriTyoq.cjs.map → dispatch_runner-DDUxXJC3.cjs.map} +1 -1
  232. package/dispatch_runner.cjs +1 -1
  233. package/dispatch_runner.mjs +1 -1
  234. package/{ecmascript-bgwVyZG1.mjs → ecmascript-B9Z2C24U.mjs} +3 -3
  235. package/{ecmascript-bgwVyZG1.mjs.map → ecmascript-B9Z2C24U.mjs.map} +1 -1
  236. package/{ecmascript-BydSB03Y.cjs → ecmascript-BYfmjg7y.cjs} +3 -3
  237. package/{ecmascript-BydSB03Y.cjs.map → ecmascript-BYfmjg7y.cjs.map} +1 -1
  238. package/eslint/rules.cjs +1 -1
  239. package/eslint/rules.mjs +1 -1
  240. package/eslint.cjs +2 -2
  241. package/eslint.mjs +2 -2
  242. package/exceptions.cjs +1 -1
  243. package/exceptions.mjs +1 -1
  244. package/forge.cjs +2 -2
  245. package/forge.mjs +2 -2
  246. package/guards.cjs +7 -7
  247. package/guards.mjs +7 -7
  248. package/{helpers-Dcp4CrOz.cjs → helpers-DPlh_7Bn.cjs} +3 -3
  249. package/{helpers-Dcp4CrOz.cjs.map → helpers-DPlh_7Bn.cjs.map} +1 -1
  250. package/{helpers-C1T0DV8Q.mjs → helpers-mbn_EsDV.mjs} +3 -3
  251. package/{helpers-C1T0DV8Q.mjs.map → helpers-mbn_EsDV.mjs.map} +1 -1
  252. package/index.cjs +11 -11
  253. package/index.mjs +11 -11
  254. package/mcp/adk-docs-corpus.json +2 -2
  255. package/package.json +425 -425
  256. package/{retrievable-BBwiACtw.cjs → retrievable-Bq-O3k6r.cjs} +3 -3
  257. package/{retrievable-BBwiACtw.cjs.map → retrievable-Bq-O3k6r.cjs.map} +1 -1
  258. package/{retrievable-CrGKx4sc.mjs → retrievable-CXTAUuuv.mjs} +3 -3
  259. package/{retrievable-CrGKx4sc.mjs.map → retrievable-CXTAUuuv.mjs.map} +1 -1
  260. package/{scrapper-BibKj8qE.cjs → scrapper-B8xG9lTD.cjs} +4 -4
  261. package/{scrapper-BibKj8qE.cjs.map → scrapper-B8xG9lTD.cjs.map} +1 -1
  262. package/{scrapper-_JzgbLG5.mjs → scrapper-DiQ5FfDL.mjs} +4 -4
  263. package/{scrapper-_JzgbLG5.mjs.map → scrapper-DiQ5FfDL.mjs.map} +1 -1
  264. package/{searxng-D-nA2gEI.mjs → searxng-BFTJ6rTE.mjs} +4 -4
  265. package/{searxng-D-nA2gEI.mjs.map → searxng-BFTJ6rTE.mjs.map} +1 -1
  266. package/{searxng-C6xrLW-v.cjs → searxng-EJhWRnIE.cjs} +4 -4
  267. package/{searxng-C6xrLW-v.cjs.map → searxng-EJhWRnIE.cjs.map} +1 -1
  268. package/server.json +2 -2
  269. package/skills/adk-assembly/SKILL.md +2 -2
  270. package/{spooled_artifact-BLgbGT8b.cjs → spooled_artifact---DmicFW.cjs} +384 -384
  271. package/spooled_artifact---DmicFW.cjs.map +1 -0
  272. package/{spooled_artifact-BkOe4-j-.mjs → spooled_artifact-Bw_7swIp.mjs} +385 -385
  273. package/spooled_artifact-Bw_7swIp.mjs.map +1 -0
  274. package/spooled_artifact.cjs +2 -2
  275. package/spooled_artifact.mjs +2 -2
  276. package/{spooled_markdown_artifact-8zdejfcJ.cjs → spooled_markdown_artifact-Rjzj-kyh.cjs} +3 -3
  277. package/{spooled_markdown_artifact-8zdejfcJ.cjs.map → spooled_markdown_artifact-Rjzj-kyh.cjs.map} +1 -1
  278. package/{spooled_markdown_artifact-Dnl-lCGv.mjs → spooled_markdown_artifact-vd6eNtIP.mjs} +3 -3
  279. package/{spooled_markdown_artifact-Dnl-lCGv.mjs.map → spooled_markdown_artifact-vd6eNtIP.mjs.map} +1 -1
  280. package/{thought-BrQt6HAb.mjs → thought-CxSaF6Xf.mjs} +3 -3
  281. package/{thought-BrQt6HAb.mjs.map → thought-CxSaF6Xf.mjs.map} +1 -1
  282. package/{thought-COeZTQ-B.cjs → thought-Dp3sMWW6.cjs} +3 -3
  283. package/{thought-COeZTQ-B.cjs.map → thought-Dp3sMWW6.cjs.map} +1 -1
  284. package/{tokenizable-DDIdXbJN.cjs → tokenizable-BcodRtoW.cjs} +29 -29
  285. package/{tokenizable-DDIdXbJN.cjs.map → tokenizable-BcodRtoW.cjs.map} +1 -1
  286. package/{tokenizable-xPXj1AQX.mjs → tokenizable-VB4Av8GF.mjs} +30 -30
  287. package/{tokenizable-xPXj1AQX.mjs.map → tokenizable-VB4Av8GF.mjs.map} +1 -1
  288. package/{tool_call-JbjeUpRK.cjs → tool_call-B9px4W9k.cjs} +4 -4
  289. package/{tool_call-JbjeUpRK.cjs.map → tool_call-B9px4W9k.cjs.map} +1 -1
  290. package/{tool_call-8crmZsO8.mjs → tool_call-Cfaj-6zK.mjs} +4 -4
  291. package/{tool_call-8crmZsO8.mjs.map → tool_call-Cfaj-6zK.mjs.map} +1 -1
  292. package/{tools-BC4NJqZD.mjs → tools-D0MBDh2R.mjs} +6 -6
  293. package/{tools-BC4NJqZD.mjs.map → tools-D0MBDh2R.mjs.map} +1 -1
  294. package/{tools-D4mdzi0a.cjs → tools-aNbi6JyA.cjs} +6 -6
  295. package/{tools-D4mdzi0a.cjs.map → tools-aNbi6JyA.cjs.map} +1 -1
  296. package/{toon-BA9Q7NHG.mjs → toon-BSTQnHed.mjs} +5 -5
  297. package/{toon-BA9Q7NHG.mjs.map → toon-BSTQnHed.mjs.map} +1 -1
  298. package/{toon-b-0pFKZ8.cjs → toon-DmLwZ6H1.cjs} +5 -5
  299. package/{toon-b-0pFKZ8.cjs.map → toon-DmLwZ6H1.cjs.map} +1 -1
  300. package/{turn_runner-BmVXcBZ2.mjs → turn_runner-BHHD6h77.mjs} +5 -5
  301. package/{turn_runner-BmVXcBZ2.mjs.map → turn_runner-BHHD6h77.mjs.map} +1 -1
  302. package/{turn_runner-DX-3s3ih.cjs → turn_runner-Dj7JsUTQ.cjs} +5 -5
  303. package/{turn_runner-DX-3s3ih.cjs.map → turn_runner-Dj7JsUTQ.cjs.map} +1 -1
  304. package/turn_runner.cjs +1 -1
  305. package/turn_runner.mjs +1 -1
  306. package/{xml-B1JIGLpU.mjs → xml-CYseDztH.mjs} +5 -5
  307. package/{xml-B1JIGLpU.mjs.map → xml-CYseDztH.mjs.map} +1 -1
  308. package/{xml-fvwTsoRv.cjs → xml-zJul8jMQ.cjs} +5 -5
  309. package/{xml-fvwTsoRv.cjs.map → xml-zJul8jMQ.cjs.map} +1 -1
  310. package/{yaml-1mP4uxdf.mjs → yaml-BPBoiOjx.mjs} +5 -5
  311. package/{yaml-1mP4uxdf.mjs.map → yaml-BPBoiOjx.mjs.map} +1 -1
  312. package/{yaml-DPUTumla.cjs → yaml-D0PzoRAr.cjs} +5 -5
  313. package/{yaml-DPUTumla.cjs.map → yaml-D0PzoRAr.cjs.map} +1 -1
  314. package/artifact_methods-7KatxCSd.cjs +0 -1
  315. package/artifact_methods-q52ETLwI.mjs +0 -1
  316. package/spooled_artifact-BLgbGT8b.cjs.map +0 -1
  317. package/spooled_artifact-BkOe4-j-.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"thought-BrQt6HAb.mjs","names":["#identifier","#representation","#id","#content","#confidence","#importance","#createdAt","#updatedAt","#id","#role","#content","#attachments","#identity","#createdAt","#updatedAt","#id","#content","#identity","#payload","#replayCompatibility","#createdAt","#updatedAt"],"sources":["../src/lib/classes/identity.ts","../src/lib/classes/memory.ts","../src/lib/classes/message.ts","../src/lib/classes/thought.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError, isObject } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_IDENTITY_VALUE } from '../exceptions/runtime'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Identity} at construction time.\n *\n * @remarks\n * Validated against `rawIdentitySchema` before the `Identity` instance is created.\n */\nexport interface RawIdentity {\n /**\n * The system-facing identifier for this participant.\n *\n * @remarks\n * Used internally to correlate messages to a specific participant — e.g. a database ID or\n * a username. Never sent to the model directly; use `representation` for that.\n */\n identifier: string | number\n /**\n * How this participant should be presented to the model.\n *\n * @remarks\n * Accepts a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. This is what the model\n * sees when it needs to distinguish between participants of the same role.\n */\n representation: string | Tokenizable\n}\n\n/**\n * A fully-resolved {@link RawIdentity} where `representation` has been normalised to a\n * {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Used internally by the {@link Identity} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedIdentity {\n identifier: string | number\n representation: Tokenizable\n}\n\n/**\n * Validator schema used to validate a {@link RawIdentity} before constructing an {@link Identity}.\n *\n * @remarks\n * Validates both fields of {@link RawIdentity}:\n * - `identifier` — required string or number.\n * - `representation` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} (via the {@link Identity} constructor) when\n * validation fails.\n */\nconst rawIdentitySchema = validator.object<RawIdentity>({\n identifier: validator.alternatives(validator.string(), validator.number()).required(),\n representation: Tokenizable.schema.required(),\n})\n\n/**\n * Registry of every {@link Identity} genuinely constructed by this module, in this realm.\n *\n * @remarks\n * The brand that {@link identityOrRawIdentitySchema} trusts to bypass raw-object validation. A\n * {@link WeakSet} keyed by the instance is unforgeable (unlike {@link Identity.isIdentity}, which\n * falls back to a `constructor.name` comparison for cross-realm reach and therefore also accepts a\n * hand-rolled look-alike) and holds no strong reference. Every instance adds itself in the\n * constructor; membership means the instance carries real, intact private fields.\n */\nconst liveIdentities = new WeakSet<object>()\n\n/**\n * Public schema fragment that accepts either a plain {@link RawIdentity} object or an existing\n * {@link Identity} instance.\n *\n * @remarks\n * A genuinely-constructed live {@link Identity} passes through the custom branch UNCHANGED — mirroring\n * {@link @nhtio/adk!Tokenizable.schema}. This matters because Joi's object schema *clones* any value it\n * validates, and cloning an `Identity` produces a look-alike with the right prototype but no private\n * `#identifier` / `#representation` fields (the constructor never ran), which then throws on\n * `[ENCODE_METHOD]`. Returning the live instance verbatim keeps its private state intact so it encodes\n * and re-wraps losslessly.\n *\n * Only a **branded** instance (one this module actually constructed — see {@link liveIdentities})\n * bypasses validation. A bare `constructor.name === 'Identity'` is NOT enough: a look-alike or a\n * cross-realm instance is not in the brand set, so it falls through to {@link rawIdentitySchema},\n * which validates its fields (rejecting a malformed `representation`) rather than retaining an\n * unvalidated husk that would later produce invalid serialized state. Plain {@link RawIdentity}\n * objects fall through the same way.\n */\nconst identityOrRawIdentitySchema = validator\n .alternatives(\n validator.custom((value, helpers) => {\n if (isObject(value) && liveIdentities.has(value)) {\n return value\n }\n return helpers.error('any.invalid')\n }),\n rawIdentitySchema\n )\n .custom((value) => {\n // A genuinely-branded live instance passes through the first alternative untouched. Anything\n // else — a plain RawIdentity, a hand-rolled look-alike, or a FOREIGN/cross-realm `Identity`\n // (a second copy of the package in the dependency tree) — arrives here as the field-validated\n // output of `rawIdentitySchema`. Joi cloned it, so a foreign instance is now a husk that still\n // carries an `Identity`-named prototype but has NO private fields; `Identity.isIdentity` accepts\n // it (name/prototype fallback) yet `[ENCODE_METHOD]` throws reading the missing privates.\n // Rebuild any non-branded value into a genuine LOCAL Identity so every consumer stores real,\n // encodable private state regardless of where the value originated.\n if (isObject(value) && liveIdentities.has(value)) {\n return value\n }\n return new Identity(value as RawIdentity)\n })\n\n/**\n * An immutable, validated participant identity attached to a {@link @nhtio/adk!Message}.\n *\n * @remarks\n * Carries two distinct representations of the same participant: `identifier` is the\n * system-facing key (e.g. a database ID) used to correlate messages programmatically;\n * `representation` is what the model sees when it needs to distinguish between participants\n * sharing the same role. The `representation` is always a {@link @nhtio/adk!Tokenizable} so token cost\n * can be estimated inline.\n */\nexport class Identity {\n /**\n * Validator schema that accepts a {@link RawIdentity} object OR an existing {@link Identity} instance.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest an identity — for example,\n * as a required field inside a message schema. A locally branded {@link Identity} passes through\n * unchanged (its private state is preserved, so it still encodes losslessly); foreign/cross-realm\n * identities and plain {@link RawIdentity} values are validated field-by-field and rebuilt locally.\n * See {@link identityOrRawIdentitySchema}.\n */\n public static schema = identityOrRawIdentitySchema\n\n /**\n * Returns `true` if `value` is an {@link Identity} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is an {@link Identity} instance.\n */\n public static isIdentity(value: unknown): value is Identity {\n return isInstanceOf(value, 'Identity', Identity)\n }\n\n /**\n * The system-facing identifier for this participant — never sent to the model directly.\n */\n declare readonly identifier: string | number\n\n /**\n * How this participant is presented to the model, as a {@link @nhtio/adk!Tokenizable} for inline\n * token estimation.\n */\n declare readonly representation: Tokenizable\n\n #identifier: string | number\n #representation: Tokenizable\n\n /**\n * @param raw - The raw identity input validated against `rawIdentitySchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawIdentity) {\n let resolved: ResolvedIdentity\n try {\n resolved = validateOrThrow<ResolvedIdentity>(rawIdentitySchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_IDENTITY_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#identifier = resolved.identifier\n this.#representation = Tokenizable.isTokenizable(resolved.representation)\n ? resolved.representation\n : new Tokenizable(resolved.representation)\n\n Object.defineProperties(this, {\n identifier: {\n get: () => this.#identifier,\n enumerable: true,\n configurable: false,\n },\n representation: {\n get: () => this.#representation,\n enumerable: true,\n configurable: false,\n },\n })\n\n // Brand this genuinely-constructed instance so `identityOrRawIdentitySchema` can trust it to\n // bypass raw-object validation. A look-alike or cross-realm object is never in this set.\n liveIdentities.add(this)\n }\n\n /**\n * Serialise this Identity into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawIdentity}-shaped object; `representation` is the live {@link @nhtio/adk!Tokenizable}\n * instance (the encoder recurses into it). Round-trips via {@link Identity.[DECODE_METHOD]}, which\n * re-validates through the constructor.\n *\n * @returns A {@link RawIdentity}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n identifier: this.#identifier,\n representation: this.#representation,\n }\n }\n\n /**\n * Reconstruct an {@link Identity} from an {@link Identity.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Identity.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Identity}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Identity {\n return new Identity(data as RawIdentity)\n }\n}\n","import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_MEMORY_VALUE } from '../exceptions/runtime'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport type { DateTime } from 'luxon'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Memory} at construction time.\n *\n * @remarks\n * Validated against `rawMemorySchema` before the `Memory` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawMemory {\n /** Stable unique identifier for this memory entry. */\n id: string\n /** The memory content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. */\n content: string | Tokenizable\n /** Confidence score in the range `[0, 1]` — how certain the agent is that this memory is accurate. */\n confidence: number\n /** Importance score in the range `[0, 1]` — how much weight this memory should carry during retrieval. */\n importance: number\n /** When this memory was first recorded. */\n createdAt: string | number | Date | DateTime\n /** When this memory was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawMemory} where all fields have been validated and temporal values\n * normalised to Luxon `DateTime` instances.\n *\n * @remarks\n * This is the shape returned by `rawMemorySchema` after validation — used internally by the\n * {@link Memory} constructor to assign private fields with guaranteed types.\n */\ninterface ResolvedMemory {\n id: string\n content: Tokenizable\n confidence: number\n importance: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawMemory} before constructing a {@link Memory}.\n *\n * @remarks\n * Validates all six fields of {@link RawMemory}:\n * - `id` — required non-empty string.\n * - `content` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n * - `confidence` — required number in `[0, 1]`.\n * - `importance` — required number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} (via the {@link Memory} constructor) when\n * validation fails.\n */\nconst rawMemorySchema = validator.object<RawMemory>({\n id: validator.string().required(),\n content: Tokenizable.schema.required(),\n confidence: validator.number().min(0).max(1).required(),\n importance: validator.number().min(0).max(1).required(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated memory entry held by the agent.\n *\n * @remarks\n * Constructed from a {@link RawMemory} via `rawMemorySchema`. All temporal fields are\n * normalised to Luxon `DateTime` instances at construction time. The `content` field is\n * always a {@link @nhtio/adk!Tokenizable} so callers can estimate token cost without an additional\n * wrapping step.\n */\nexport class Memory {\n /**\n * Validator schema that accepts a {@link RawMemory} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a memory entry — for\n * example, a collection schema that holds an array of memories.\n */\n public static schema = rawMemorySchema\n\n /**\n * Returns `true` if `value` is a {@link Memory} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Memory} instance.\n */\n public static isMemory(value: unknown): value is Memory {\n return isInstanceOf(value, 'Memory', Memory)\n }\n /** Stable unique identifier for this memory entry. */\n declare readonly id: string\n /** The memory content as a {@link @nhtio/adk!Tokenizable} for inline token estimation. */\n declare readonly content: Tokenizable\n /** Confidence score in the range `[0, 1]`. */\n declare readonly confidence: number\n /** Importance score in the range `[0, 1]`. */\n declare readonly importance: number\n /** When this memory was first recorded. */\n declare readonly createdAt: DateTime\n /** When this memory was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable\n #confidence: number\n #importance: number\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw memory input validated against `rawMemorySchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawMemory) {\n let resolved: ResolvedMemory\n try {\n resolved = validateOrThrow<ResolvedMemory>(rawMemorySchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_MEMORY_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content = Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#confidence = resolved.confidence\n this.#importance = resolved.importance\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n confidence: {\n get: () => this.#confidence,\n enumerable: true,\n configurable: false,\n },\n importance: {\n get: () => this.#importance,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Memory into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawMemory}-shaped object; `content` is the live {@link @nhtio/adk!Tokenizable} and the\n * temporal fields are live Luxon `DateTime` instances (the encoder recurses into both). Round-trips\n * via {@link Memory.[DECODE_METHOD]}, which re-validates through the constructor.\n *\n * @returns A {@link RawMemory}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n content: this.#content,\n confidence: this.#confidence,\n importance: this.#importance,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Memory} from a {@link Memory.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Memory.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Memory}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Memory {\n return new Memory(data as RawMemory)\n }\n}\n","import { Media } from './media'\nimport { Identity } from './identity'\nimport { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_MESSAGE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { RawIdentity } from './identity'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * The roles a {@link Message} author can hold.\n *\n * @remarks\n * Restricted to `user` and `assistant` — system instructions, developer directives, and\n * tool results are handled separately and never appear in the persisted message history.\n */\nexport type MessageRole = 'user' | 'assistant'\n\n/**\n * Plain input object supplied to {@link Message} at construction time.\n *\n * @remarks\n * Validated against `rawMessageSchema` before the `Message` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n *\n * At least one of `content` or `attachments` (non-empty) must be present — a message with\n * neither throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE}.\n */\nexport interface RawMessage {\n /** Stable unique identifier for this message. */\n id: string\n /** Whether this message is from the human participant or the model. */\n role: MessageRole\n /**\n * The message content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Optional — but required when `attachments` is absent or empty. The cross-field rule on\n * `rawMessageSchema` enforces that at least one of `content` or `attachments` is present.\n */\n content?: string | Tokenizable\n /**\n * Media attachments carried by this message — images, audio, video, documents.\n *\n * @remarks\n * Optional and symmetric across roles: both `user` and `assistant` messages may carry\n * attachments. Each attachment carries its own `trustTier` and `modalityHazard`, which the\n * renderer uses to wrap the asset in its own trust envelope independent of the message\n * envelope. How a renderer orders text vs attachments in the on-the-wire content array is\n * a renderer-policy concern, not a contract of {@link Message}.\n */\n attachments?: Media[]\n /**\n * The identity of the participant who authored this message.\n *\n * @remarks\n * Optional. When omitted, the `role` value is used as both the system-facing `identifier`\n * and the model-facing `representation`. Three accepted forms when provided:\n * - A plain `string` — used as both `identifier` and `representation`.\n * - A {@link @nhtio/adk!RawIdentity} object — validated and wrapped into an {@link @nhtio/adk!Identity}.\n * - An existing {@link @nhtio/adk!Identity} instance — passed through unchanged.\n */\n identity?: string | RawIdentity | Identity\n /** When this message was created. */\n createdAt: string | number | Date | DateTime\n /** When this message was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawMessage} where temporal fields have been normalised to Luxon\n * `DateTime` instances and `identity` is a validated {@link @nhtio/adk!Identity}.\n *\n * @remarks\n * Used internally by the {@link Message} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedMessage {\n id: string\n role: MessageRole\n content?: Tokenizable\n attachments: Media[]\n identity: string | RawIdentity | Identity\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawMessage} before constructing a {@link Message}.\n *\n * @remarks\n * Validates all fields of {@link RawMessage}:\n * - `id` — required non-empty string.\n * - `role` — required; must be `'user'` or `'assistant'`.\n * - `content` — optional string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n * - `attachments` — optional array of {@link @nhtio/adk!Media} instances. Defaults to `[]`.\n * - At least one of `content` or `attachments` must be present and non-empty; a message with\n * neither is invalid.\n * - `identity` — required string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; a plain string is\n * mapped to both `identifier` and `representation` automatically.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} (via the {@link Message} constructor) when\n * validation fails.\n */\nconst rawMessageSchema = validator\n .object<RawMessage>({\n id: validator.string().required(),\n role: validator.string().valid('user', 'assistant').required(),\n content: Tokenizable.schema.optional(),\n attachments: validator\n .array()\n .items(\n validator\n .any()\n .required()\n .custom((value, helpers) => {\n if (Media.isMedia(value)) return value\n return helpers.error('any.invalid')\n })\n )\n .default([]),\n identity: validator\n .alternatives(validator.string(), Identity.schema)\n .default(validator.ref('role')),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n })\n .custom((value, helpers) => {\n const resolved = value as ResolvedMessage\n const hasContent = resolved.content !== undefined && resolved.content !== null\n const hasAttachments = Array.isArray(resolved.attachments) && resolved.attachments.length > 0\n if (!hasContent && !hasAttachments) {\n return helpers.error('any.invalid')\n }\n return resolved\n })\n\n/**\n * An immutable, validated conversation message from a human participant or the model.\n *\n * @remarks\n * Covers only `user` and `assistant` roles — system instructions, developer directives, and\n * tool results are not represented here. Constructed from a {@link RawMessage} via\n * `rawMessageSchema`. Temporal fields are normalised to Luxon `DateTime` instances at\n * construction time. Both `content` and `identity.representation` are {@link @nhtio/adk!Tokenizable} so\n * token cost can be estimated inline.\n *\n * A message may carry `content` (text), `attachments` (media), or both. The cross-field rule\n * on `rawMessageSchema` enforces that at least one is present. Downstream code that reaches\n * for `message.content` must handle the attachments-only case where `content` is `undefined`.\n */\nexport class Message {\n /**\n * Validator schema that accepts a {@link RawMessage} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a message entry — for\n * example, a collection schema that holds an array of messages.\n */\n public static schema = rawMessageSchema\n\n /**\n * Returns `true` if `value` is a {@link Message} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Message} instance.\n */\n public static isMessage(value: unknown): value is Message {\n return isInstanceOf(value, 'Message', Message)\n }\n\n /** Stable unique identifier for this message. */\n declare readonly id: string\n /** Whether this message is from the human participant or the model. */\n declare readonly role: MessageRole\n /**\n * The message content as a {@link @nhtio/adk!Tokenizable} for inline token estimation, or `undefined`\n * for attachments-only messages.\n *\n * @remarks\n * `undefined` when the message was constructed with only `attachments`. Render code that\n * needs the text portion must guard for the missing case rather than blindly calling\n * `message.content.toString()`.\n */\n declare readonly content: Tokenizable | undefined\n /**\n * Media attachments carried by this message.\n *\n * @remarks\n * Always defined as a frozen array — empty when the message has no attachments. Both\n * `user` and `assistant` messages may carry attachments. Each entry carries its own\n * `trustTier` and `modalityHazard`; the renderer wraps each in its own trust envelope\n * independent of the message envelope.\n */\n declare readonly attachments: ReadonlyArray<Media>\n /** The identity of the participant who authored this message. */\n declare readonly identity: Identity\n /** When this message was created. */\n declare readonly createdAt: DateTime\n /** When this message was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #role: MessageRole\n #content: Tokenizable | undefined\n #attachments: ReadonlyArray<Media>\n #identity: Identity\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw message input validated against `rawMessageSchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} when `raw` does not satisfy the schema —\n * including the cross-field rule that at least one of `content` or `attachments` must be\n * present and non-empty.\n */\n constructor(raw: RawMessage) {\n let resolved: ResolvedMessage\n try {\n resolved = validateOrThrow<ResolvedMessage>(rawMessageSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_MESSAGE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#role = resolved.role\n this.#content =\n resolved.content === undefined || resolved.content === null\n ? undefined\n : Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#attachments = Object.freeze([...(resolved.attachments ?? [])])\n const rawIdentity = resolved.identity\n this.#identity = Identity.isIdentity(rawIdentity)\n ? rawIdentity\n : typeof rawIdentity === 'string'\n ? new Identity({ identifier: rawIdentity, representation: rawIdentity })\n : new Identity(rawIdentity)\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n role: {\n get: () => this.#role,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n attachments: {\n get: () => this.#attachments,\n enumerable: true,\n configurable: false,\n },\n identity: {\n get: () => this.#identity,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Message into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawMessage}-shaped object holding the live nested primitives — `content`\n * ({@link @nhtio/adk!Tokenizable}), `attachments` ({@link @nhtio/adk!Media}[]), `identity`\n * ({@link @nhtio/adk!Identity}), and Luxon temporal fields — which the encoder recurses into. A\n * text-only message round-trips trivially; a message carrying {@link @nhtio/adk!Media} round-trips only\n * if each attachment's reader is describable (a `fromWebFile`-backed attachment throws\n * {@link @nhtio/adk!E_READER_NOT_DESCRIBABLE} at encode). The frozen attachments array is copied to a\n * plain array for the snapshot. Round-trips via {@link Message.[DECODE_METHOD]}.\n *\n * @returns A {@link RawMessage}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n role: this.#role,\n content: this.#content,\n // Omit when empty: the schema's cross-field rule treats a present-but-empty `attachments`\n // array as invalid (it must contain ≥1 entry when supplied). A text-only message has none.\n ...(this.#attachments.length > 0 ? { attachments: [...this.#attachments] } : {}),\n identity: this.#identity,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Message} from a {@link Message.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Message.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Message}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Message {\n return new Message(data as RawMessage)\n }\n}\n","import { Identity } from './identity'\nimport { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_THOUGHT_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { RawIdentity } from './identity'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Thought} at construction time.\n *\n * @remarks\n * Validated against `rawThoughtSchema` before the `Thought` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawThought {\n /** Stable unique identifier for this thought. */\n id: string\n /**\n * The reasoning content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Required and non-empty in plain-text mode. In opaque mode ({@link RawThought.payload} present) it\n * may be empty or omitted — the payload carries the meaning — and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}. `Thought.content` is therefore ALWAYS a `Tokenizable`, never\n * `undefined`, so readers need no guard.\n */\n content?: string | Tokenizable\n /**\n * The identity of the agent who produced this thought.\n *\n * @remarks\n * Required in multi-agent conversations to attribute reasoning traces to a specific agent.\n * Three accepted forms when provided:\n * - A plain `string` — used as both `identifier` and `representation`.\n * - A {@link @nhtio/adk!RawIdentity} object — validated and wrapped into an {@link @nhtio/adk!Identity}.\n * - An existing {@link @nhtio/adk!Identity} instance — passed through unchanged.\n *\n * When omitted, defaults to `'assistant'` (both `identifier` and `representation`).\n */\n identity?: string | RawIdentity | Identity\n /**\n * Optional vendor-opaque payload that round-trips back to a matching model wire.\n *\n * @remarks\n * Carries anything the ADK cannot interpret but a specific provider can — for example,\n * an Anthropic Messages thinking-block `signature`, an OpenAI Responses\n * `ResponseReasoningItem.encrypted_content` blob, a DeepSeek server-side reasoning handle,\n * or an MCP-mediated reasoning item.\n *\n * When present, an LLM battery MUST treat the thought as **opaque-mode**: do NOT inline\n * `content` through the plain `<thought>` envelope; serialise `payload` back to the wire in\n * whichever shape the matching {@link RawThought.replayCompatibility} identifier specifies.\n * The plain-text `content` is kept alongside for token-accounting and human/observer\n * inspection — it is not the thing the model sees.\n *\n * Cross-field invariant: a present `payload` REQUIRES a present {@link RawThought.replayCompatibility}.\n * A `payload` without `replayCompatibility` is malformed (the ADK has no way to know\n * which adapter can consume it) and {@link Thought.schema} rejects with\n * {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE}.\n *\n * @defaultValue `undefined`\n */\n payload?: unknown\n /**\n * Optional free-form identifier describing which adapter wire-shape this thought can be\n * safely replayed into.\n *\n * @remarks\n * Examples (none of these are reserved by the ADK — they are consumer conventions):\n * - `'plain-text'` — replayable into every LLM battery\n * - `'anthropic-messages-thinking-v1'`\n * - `'openai-responses-reasoning-item-v1'`\n * - `'deepseek-reasoning-handle-v1'`\n *\n * LLM batteries declare via constructor option which tags they can safely replay; matching\n * opaque thoughts are routed to the wire's typed reasoning channel where it exists, or to a\n * documented side-channel key on the request body where the wire has none. Non-matching\n * opaque thoughts are elided from the current dispatch but NOT removed from\n * `ctx.turnThoughts` — they remain in context so a subsequent dispatch to a different\n * adapter that DOES declare the matching tag can pick them up.\n *\n * Plain-text thoughts (`payload === undefined` AND `replayCompatibility === undefined`, or\n * explicit `replayCompatibility: 'plain-text'`) are always replayable.\n *\n * A `replayCompatibility` without a `payload` is allowed — it documents intent (\"this\n * plain-text thought is only meaningful to a specific fine-tuned variant\") without\n * requiring an opaque blob.\n *\n * @defaultValue `undefined`\n */\n replayCompatibility?: string\n /** When this thought was recorded. */\n createdAt: string | number | Date | DateTime\n /** When this thought was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawThought} where temporal fields have been normalised to Luxon\n * `DateTime` instances.\n *\n * @remarks\n * Used internally by the {@link Thought} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedThought {\n id: string\n content?: string | Tokenizable\n identity: string | RawIdentity | Identity\n payload?: unknown\n replayCompatibility?: string\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawThought} before constructing a {@link Thought}.\n *\n * @remarks\n * Validates all fields of {@link RawThought}:\n * - `id` — required non-empty string.\n * - `content` — string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.emptyableSchema}.\n * Required and non-empty in plain-text mode; may be empty or omitted in opaque mode (see the\n * content-OR-payload rule below).\n * - `identity` — optional string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; defaults to\n * `'assistant'` when omitted.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Cross-field rule — a thought must carry meaning through EITHER its prose OR an opaque replay\n * `payload`. A NULLISH payload (`undefined` or `null`) carries no replay data and so counts as ABSENT\n * for both halves of the rule:\n * - `payload` ABSENT (plain-text mode) — `content` is REQUIRED and must be non-empty. The prose is\n * the only thing the thought has; an empty one is indistinguishable from a bug.\n * - `payload` PRESENT (opaque mode) — `content` may be empty or omitted, and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}. The payload is what round-trips to the wire; `content` is kept only\n * for token-accounting and human/observer inspection (see {@link RawThought.payload}), so a\n * signed-but-textless provider thinking block is legitimate. Rejecting it would discard the\n * payload's replay data — strictly worse than storing a thought with no prose.\n *\n * A present `payload` additionally REQUIRES a present `replayCompatibility`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} (via the {@link Thought} constructor) when\n * validation fails.\n */\nconst rawThoughtSchema = validator\n .object<RawThought>({\n id: validator.string().required(),\n // Emptiness is adjudicated by the cross-field rule below, which needs to see `payload` to decide.\n content: Tokenizable.emptyableSchema.optional(),\n identity: validator.alternatives(validator.string(), Identity.schema).default('assistant'),\n payload: validator.any().optional(),\n replayCompatibility: validator.string().min(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n })\n .custom((value, helpers) => {\n const v = value as RawThought\n // A NULLISH payload carries no replay data, so it is opaque mode in NEITHER rule below. `null`\n // reaches here easily — JSON round-tripping, a serializer normalising absent fields, a provider\n // mapper assigning a nullish thinking block — and treating it as \"present\" would both demand a\n // pointless `replayCompatibility` and, worse, waive the content requirement for a thought that has\n // no prose AND no payload: the exact state the either-or exists to forbid.\n const hasPayload = v.payload !== undefined && v.payload !== null\n if (hasPayload && (v.replayCompatibility === undefined || v.replayCompatibility === null)) {\n return helpers.error('any.invalid')\n }\n // content-OR-payload: only an opaque thought may go without prose. A Tokenizable counts as\n // present without being unwrapped — a dynamic one would evaluate its callback just to be measured,\n // and its emptiness is not knowable until prompt-assembly anyway.\n if (!hasPayload) {\n const hasContent = Tokenizable.isTokenizable(v.content)\n ? true\n : typeof v.content === 'string' && v.content.length > 0\n if (!hasContent) {\n return helpers.error('any.invalid')\n }\n }\n return value\n })\n\n/**\n * An immutable, validated internal reasoning trace produced by an agent.\n *\n * @remarks\n * Represents an agent's internal thinking — distinct from {@link @nhtio/adk!Message} (which is part of\n * the visible conversation) and never shown to end users directly. Carries an `identity` so\n * reasoning traces can be attributed to a specific agent in multi-agent conversations.\n * Constructed from a {@link RawThought} via `rawThoughtSchema`. The `content` field is always\n * a {@link @nhtio/adk!Tokenizable} so token cost can be estimated inline — including when the raw input\n * omitted it or supplied `''`, which is legal in opaque-replay mode and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}.\n */\nexport class Thought {\n /**\n * Validator schema that accepts a {@link RawThought} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a thought entry.\n */\n public static schema = rawThoughtSchema\n\n /**\n * Returns `true` if `value` is a {@link Thought} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Thought} instance.\n */\n public static isThought(value: unknown): value is Thought {\n return isInstanceOf(value, 'Thought', Thought)\n }\n\n /** Stable unique identifier for this thought. */\n declare readonly id: string\n /**\n * The reasoning content as a {@link @nhtio/adk!Tokenizable} for inline token estimation.\n *\n * @remarks\n * Never `undefined` — an opaque thought constructed without prose carries an empty\n * {@link @nhtio/adk!Tokenizable} here, so readers need no presence guard.\n */\n declare readonly content: Tokenizable\n /** The identity of the agent who produced this thought. */\n declare readonly identity: Identity\n /**\n * Optional vendor-opaque payload that round-trips back to a matching model wire.\n * See {@link RawThought.payload}.\n */\n declare readonly payload: unknown\n /**\n * Optional wire-shape identifier describing which adapter can safely replay this thought.\n * See {@link RawThought.replayCompatibility}.\n */\n declare readonly replayCompatibility: string | undefined\n /** When this thought was recorded. */\n declare readonly createdAt: DateTime\n /** When this thought was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable\n #identity: Identity\n #payload: unknown\n #replayCompatibility: string | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw thought input validated against `rawThoughtSchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawThought) {\n let resolved: ResolvedThought\n try {\n resolved = validateOrThrow<ResolvedThought>(rawThoughtSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_THOUGHT_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n // Absent content is legal only in opaque mode (enforced by rawThoughtSchema). Resolve it to an\n // EMPTY Tokenizable rather than leaving it undefined so `content` stays a total field — every\n // reader can call `.toString()` / measure it without a guard.\n this.#content = Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content ?? '')\n const rawIdentity = resolved.identity\n this.#identity = Identity.isIdentity(rawIdentity)\n ? rawIdentity\n : typeof rawIdentity === 'string'\n ? new Identity({ identifier: rawIdentity, representation: rawIdentity })\n : new Identity(rawIdentity)\n this.#payload = resolved.payload\n this.#replayCompatibility = resolved.replayCompatibility\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n identity: {\n get: () => this.#identity,\n enumerable: true,\n configurable: false,\n },\n payload: {\n get: () => this.#payload,\n enumerable: true,\n configurable: false,\n },\n replayCompatibility: {\n get: () => this.#replayCompatibility,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Thought into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawThought}-shaped object; `content` is the live {@link @nhtio/adk!Tokenizable},\n * `identity` the live {@link @nhtio/adk!Identity}, and the temporal fields live Luxon `DateTime`s (the\n * encoder recurses into each). The vendor-opaque `payload` is passed through as-is — if it holds a\n * value the encoder cannot serialise, encode throws (standard encoder behaviour). Round-trips via\n * {@link Thought.[DECODE_METHOD]}, which re-validates through the constructor.\n *\n * @returns A {@link RawThought}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n content: this.#content,\n identity: this.#identity,\n payload: this.#payload,\n replayCompatibility: this.#replayCompatibility,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Thought} from a {@link Thought.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Thought.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Thought}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Thought {\n return new Thought(data as RawThought)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyDA,IAAM,oBAAoB,UAAU,OAAoB;CACtD,YAAY,UAAU,aAAa,UAAU,OAAO,GAAG,UAAU,OAAO,CAAC,EAAE,SAAS;CACpF,gBAAgB,YAAY,OAAO,SAAS;AAC9C,CAAC;;;;;;;;;;;AAYD,IAAM,iCA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AAW,KAAKC;GAChB,WAAW,KAAKC;EAClB;CACF;;;;;;;CAQA,QAAQ,eAAe,MAAqC;EAC1D,OAAO,IAAI,QAAQ,IAAkB;CACvC;AACF"}
1
+ {"version":3,"file":"thought-CxSaF6Xf.mjs","names":["#identifier","#representation","#id","#content","#confidence","#importance","#createdAt","#updatedAt","#id","#role","#content","#attachments","#identity","#createdAt","#updatedAt","#id","#content","#identity","#payload","#replayCompatibility","#createdAt","#updatedAt"],"sources":["../src/lib/classes/identity.ts","../src/lib/classes/memory.ts","../src/lib/classes/message.ts","../src/lib/classes/thought.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError, isObject } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_IDENTITY_VALUE } from '../exceptions/runtime'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Identity} at construction time.\n *\n * @remarks\n * Validated against `rawIdentitySchema` before the `Identity` instance is created.\n */\nexport interface RawIdentity {\n /**\n * The system-facing identifier for this participant.\n *\n * @remarks\n * Used internally to correlate messages to a specific participant — e.g. a database ID or\n * a username. Never sent to the model directly; use `representation` for that.\n */\n identifier: string | number\n /**\n * How this participant should be presented to the model.\n *\n * @remarks\n * Accepts a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. This is what the model\n * sees when it needs to distinguish between participants of the same role.\n */\n representation: string | Tokenizable\n}\n\n/**\n * A fully-resolved {@link RawIdentity} where `representation` has been normalised to a\n * {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Used internally by the {@link Identity} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedIdentity {\n identifier: string | number\n representation: Tokenizable\n}\n\n/**\n * Validator schema used to validate a {@link RawIdentity} before constructing an {@link Identity}.\n *\n * @remarks\n * Validates both fields of {@link RawIdentity}:\n * - `identifier` — required string or number.\n * - `representation` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} (via the {@link Identity} constructor) when\n * validation fails.\n */\nconst rawIdentitySchema = validator.object<RawIdentity>({\n identifier: validator.alternatives(validator.string(), validator.number()).required(),\n representation: Tokenizable.schema.required(),\n})\n\n/**\n * Registry of every {@link Identity} genuinely constructed by this module, in this realm.\n *\n * @remarks\n * The brand that {@link identityOrRawIdentitySchema} trusts to bypass raw-object validation. A\n * {@link WeakSet} keyed by the instance is unforgeable (unlike {@link Identity.isIdentity}, which\n * falls back to a `constructor.name` comparison for cross-realm reach and therefore also accepts a\n * hand-rolled look-alike) and holds no strong reference. Every instance adds itself in the\n * constructor; membership means the instance carries real, intact private fields.\n */\nconst liveIdentities = new WeakSet<object>()\n\n/**\n * Public schema fragment that accepts either a plain {@link RawIdentity} object or an existing\n * {@link Identity} instance.\n *\n * @remarks\n * A genuinely-constructed live {@link Identity} passes through the custom branch UNCHANGED — mirroring\n * {@link @nhtio/adk!Tokenizable.schema}. This matters because Joi's object schema *clones* any value it\n * validates, and cloning an `Identity` produces a look-alike with the right prototype but no private\n * `#identifier` / `#representation` fields (the constructor never ran), which then throws on\n * `[ENCODE_METHOD]`. Returning the live instance verbatim keeps its private state intact so it encodes\n * and re-wraps losslessly.\n *\n * Only a **branded** instance (one this module actually constructed — see {@link liveIdentities})\n * bypasses validation. A bare `constructor.name === 'Identity'` is NOT enough: a look-alike or a\n * cross-realm instance is not in the brand set, so it falls through to {@link rawIdentitySchema},\n * which validates its fields (rejecting a malformed `representation`) rather than retaining an\n * unvalidated husk that would later produce invalid serialized state. Plain {@link RawIdentity}\n * objects fall through the same way.\n */\nconst identityOrRawIdentitySchema = validator\n .alternatives(\n validator.custom((value, helpers) => {\n if (isObject(value) && liveIdentities.has(value)) {\n return value\n }\n return helpers.error('any.invalid')\n }),\n rawIdentitySchema\n )\n .custom((value) => {\n // A genuinely-branded live instance passes through the first alternative untouched. Anything\n // else — a plain RawIdentity, a hand-rolled look-alike, or a FOREIGN/cross-realm `Identity`\n // (a second copy of the package in the dependency tree) — arrives here as the field-validated\n // output of `rawIdentitySchema`. Joi cloned it, so a foreign instance is now a husk that still\n // carries an `Identity`-named prototype but has NO private fields; `Identity.isIdentity` accepts\n // it (name/prototype fallback) yet `[ENCODE_METHOD]` throws reading the missing privates.\n // Rebuild any non-branded value into a genuine LOCAL Identity so every consumer stores real,\n // encodable private state regardless of where the value originated.\n if (isObject(value) && liveIdentities.has(value)) {\n return value\n }\n return new Identity(value as RawIdentity)\n })\n\n/**\n * An immutable, validated participant identity attached to a {@link @nhtio/adk!Message}.\n *\n * @remarks\n * Carries two distinct representations of the same participant: `identifier` is the\n * system-facing key (e.g. a database ID) used to correlate messages programmatically;\n * `representation` is what the model sees when it needs to distinguish between participants\n * sharing the same role. The `representation` is always a {@link @nhtio/adk!Tokenizable} so token cost\n * can be estimated inline.\n */\nexport class Identity {\n /**\n * Validator schema that accepts a {@link RawIdentity} object OR an existing {@link Identity} instance.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest an identity — for example,\n * as a required field inside a message schema. A locally branded {@link Identity} passes through\n * unchanged (its private state is preserved, so it still encodes losslessly); foreign/cross-realm\n * identities and plain {@link RawIdentity} values are validated field-by-field and rebuilt locally.\n * See {@link identityOrRawIdentitySchema}.\n */\n public static schema = identityOrRawIdentitySchema\n\n /**\n * Returns `true` if `value` is an {@link Identity} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is an {@link Identity} instance.\n */\n public static isIdentity(value: unknown): value is Identity {\n return isInstanceOf(value, 'Identity', Identity)\n }\n\n /**\n * The system-facing identifier for this participant — never sent to the model directly.\n */\n declare readonly identifier: string | number\n\n /**\n * How this participant is presented to the model, as a {@link @nhtio/adk!Tokenizable} for inline\n * token estimation.\n */\n declare readonly representation: Tokenizable\n\n #identifier: string | number\n #representation: Tokenizable\n\n /**\n * @param raw - The raw identity input validated against `rawIdentitySchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawIdentity) {\n let resolved: ResolvedIdentity\n try {\n resolved = validateOrThrow<ResolvedIdentity>(rawIdentitySchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_IDENTITY_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#identifier = resolved.identifier\n this.#representation = Tokenizable.isTokenizable(resolved.representation)\n ? resolved.representation\n : new Tokenizable(resolved.representation)\n\n Object.defineProperties(this, {\n identifier: {\n get: () => this.#identifier,\n enumerable: true,\n configurable: false,\n },\n representation: {\n get: () => this.#representation,\n enumerable: true,\n configurable: false,\n },\n })\n\n // Brand this genuinely-constructed instance so `identityOrRawIdentitySchema` can trust it to\n // bypass raw-object validation. A look-alike or cross-realm object is never in this set.\n liveIdentities.add(this)\n }\n\n /**\n * Serialise this Identity into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawIdentity}-shaped object; `representation` is the live {@link @nhtio/adk!Tokenizable}\n * instance (the encoder recurses into it). Round-trips via {@link Identity.[DECODE_METHOD]}, which\n * re-validates through the constructor.\n *\n * @returns A {@link RawIdentity}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n identifier: this.#identifier,\n representation: this.#representation,\n }\n }\n\n /**\n * Reconstruct an {@link Identity} from an {@link Identity.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Identity.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Identity}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Identity {\n return new Identity(data as RawIdentity)\n }\n}\n","import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_MEMORY_VALUE } from '../exceptions/runtime'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport type { DateTime } from 'luxon'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Memory} at construction time.\n *\n * @remarks\n * Validated against `rawMemorySchema` before the `Memory` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawMemory {\n /** Stable unique identifier for this memory entry. */\n id: string\n /** The memory content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. */\n content: string | Tokenizable\n /** Confidence score in the range `[0, 1]` — how certain the agent is that this memory is accurate. */\n confidence: number\n /** Importance score in the range `[0, 1]` — how much weight this memory should carry during retrieval. */\n importance: number\n /** When this memory was first recorded. */\n createdAt: string | number | Date | DateTime\n /** When this memory was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawMemory} where all fields have been validated and temporal values\n * normalised to Luxon `DateTime` instances.\n *\n * @remarks\n * This is the shape returned by `rawMemorySchema` after validation — used internally by the\n * {@link Memory} constructor to assign private fields with guaranteed types.\n */\ninterface ResolvedMemory {\n id: string\n content: Tokenizable\n confidence: number\n importance: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawMemory} before constructing a {@link Memory}.\n *\n * @remarks\n * Validates all six fields of {@link RawMemory}:\n * - `id` — required non-empty string.\n * - `content` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n * - `confidence` — required number in `[0, 1]`.\n * - `importance` — required number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} (via the {@link Memory} constructor) when\n * validation fails.\n */\nconst rawMemorySchema = validator.object<RawMemory>({\n id: validator.string().required(),\n content: Tokenizable.schema.required(),\n confidence: validator.number().min(0).max(1).required(),\n importance: validator.number().min(0).max(1).required(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated memory entry held by the agent.\n *\n * @remarks\n * Constructed from a {@link RawMemory} via `rawMemorySchema`. All temporal fields are\n * normalised to Luxon `DateTime` instances at construction time. The `content` field is\n * always a {@link @nhtio/adk!Tokenizable} so callers can estimate token cost without an additional\n * wrapping step.\n */\nexport class Memory {\n /**\n * Validator schema that accepts a {@link RawMemory} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a memory entry — for\n * example, a collection schema that holds an array of memories.\n */\n public static schema = rawMemorySchema\n\n /**\n * Returns `true` if `value` is a {@link Memory} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Memory} instance.\n */\n public static isMemory(value: unknown): value is Memory {\n return isInstanceOf(value, 'Memory', Memory)\n }\n /** Stable unique identifier for this memory entry. */\n declare readonly id: string\n /** The memory content as a {@link @nhtio/adk!Tokenizable} for inline token estimation. */\n declare readonly content: Tokenizable\n /** Confidence score in the range `[0, 1]`. */\n declare readonly confidence: number\n /** Importance score in the range `[0, 1]`. */\n declare readonly importance: number\n /** When this memory was first recorded. */\n declare readonly createdAt: DateTime\n /** When this memory was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable\n #confidence: number\n #importance: number\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw memory input validated against `rawMemorySchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawMemory) {\n let resolved: ResolvedMemory\n try {\n resolved = validateOrThrow<ResolvedMemory>(rawMemorySchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_MEMORY_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content = Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#confidence = resolved.confidence\n this.#importance = resolved.importance\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n confidence: {\n get: () => this.#confidence,\n enumerable: true,\n configurable: false,\n },\n importance: {\n get: () => this.#importance,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Memory into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawMemory}-shaped object; `content` is the live {@link @nhtio/adk!Tokenizable} and the\n * temporal fields are live Luxon `DateTime` instances (the encoder recurses into both). Round-trips\n * via {@link Memory.[DECODE_METHOD]}, which re-validates through the constructor.\n *\n * @returns A {@link RawMemory}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n content: this.#content,\n confidence: this.#confidence,\n importance: this.#importance,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Memory} from a {@link Memory.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Memory.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Memory}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Memory {\n return new Memory(data as RawMemory)\n }\n}\n","import { Media } from './media'\nimport { Identity } from './identity'\nimport { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_MESSAGE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { RawIdentity } from './identity'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * The roles a {@link Message} author can hold.\n *\n * @remarks\n * Restricted to `user` and `assistant` — system instructions, developer directives, and\n * tool results are handled separately and never appear in the persisted message history.\n */\nexport type MessageRole = 'user' | 'assistant'\n\n/**\n * Plain input object supplied to {@link Message} at construction time.\n *\n * @remarks\n * Validated against `rawMessageSchema` before the `Message` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n *\n * At least one of `content` or `attachments` (non-empty) must be present — a message with\n * neither throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE}.\n */\nexport interface RawMessage {\n /** Stable unique identifier for this message. */\n id: string\n /** Whether this message is from the human participant or the model. */\n role: MessageRole\n /**\n * The message content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Optional — but required when `attachments` is absent or empty. The cross-field rule on\n * `rawMessageSchema` enforces that at least one of `content` or `attachments` is present.\n */\n content?: string | Tokenizable\n /**\n * Media attachments carried by this message — images, audio, video, documents.\n *\n * @remarks\n * Optional and symmetric across roles: both `user` and `assistant` messages may carry\n * attachments. Each attachment carries its own `trustTier` and `modalityHazard`, which the\n * renderer uses to wrap the asset in its own trust envelope independent of the message\n * envelope. How a renderer orders text vs attachments in the on-the-wire content array is\n * a renderer-policy concern, not a contract of {@link Message}.\n */\n attachments?: Media[]\n /**\n * The identity of the participant who authored this message.\n *\n * @remarks\n * Optional. When omitted, the `role` value is used as both the system-facing `identifier`\n * and the model-facing `representation`. Three accepted forms when provided:\n * - A plain `string` — used as both `identifier` and `representation`.\n * - A {@link @nhtio/adk!RawIdentity} object — validated and wrapped into an {@link @nhtio/adk!Identity}.\n * - An existing {@link @nhtio/adk!Identity} instance — passed through unchanged.\n */\n identity?: string | RawIdentity | Identity\n /** When this message was created. */\n createdAt: string | number | Date | DateTime\n /** When this message was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawMessage} where temporal fields have been normalised to Luxon\n * `DateTime` instances and `identity` is a validated {@link @nhtio/adk!Identity}.\n *\n * @remarks\n * Used internally by the {@link Message} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedMessage {\n id: string\n role: MessageRole\n content?: Tokenizable\n attachments: Media[]\n identity: string | RawIdentity | Identity\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawMessage} before constructing a {@link Message}.\n *\n * @remarks\n * Validates all fields of {@link RawMessage}:\n * - `id` — required non-empty string.\n * - `role` — required; must be `'user'` or `'assistant'`.\n * - `content` — optional string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n * - `attachments` — optional array of {@link @nhtio/adk!Media} instances. Defaults to `[]`.\n * - At least one of `content` or `attachments` must be present and non-empty; a message with\n * neither is invalid.\n * - `identity` — required string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; a plain string is\n * mapped to both `identifier` and `representation` automatically.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} (via the {@link Message} constructor) when\n * validation fails.\n */\nconst rawMessageSchema = validator\n .object<RawMessage>({\n id: validator.string().required(),\n role: validator.string().valid('user', 'assistant').required(),\n content: Tokenizable.schema.optional(),\n attachments: validator\n .array()\n .items(\n validator\n .any()\n .required()\n .custom((value, helpers) => {\n if (Media.isMedia(value)) return value\n return helpers.error('any.invalid')\n })\n )\n .default([]),\n identity: validator\n .alternatives(validator.string(), Identity.schema)\n .default(validator.ref('role')),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n })\n .custom((value, helpers) => {\n const resolved = value as ResolvedMessage\n const hasContent = resolved.content !== undefined && resolved.content !== null\n const hasAttachments = Array.isArray(resolved.attachments) && resolved.attachments.length > 0\n if (!hasContent && !hasAttachments) {\n return helpers.error('any.invalid')\n }\n return resolved\n })\n\n/**\n * An immutable, validated conversation message from a human participant or the model.\n *\n * @remarks\n * Covers only `user` and `assistant` roles — system instructions, developer directives, and\n * tool results are not represented here. Constructed from a {@link RawMessage} via\n * `rawMessageSchema`. Temporal fields are normalised to Luxon `DateTime` instances at\n * construction time. Both `content` and `identity.representation` are {@link @nhtio/adk!Tokenizable} so\n * token cost can be estimated inline.\n *\n * A message may carry `content` (text), `attachments` (media), or both. The cross-field rule\n * on `rawMessageSchema` enforces that at least one is present. Downstream code that reaches\n * for `message.content` must handle the attachments-only case where `content` is `undefined`.\n */\nexport class Message {\n /**\n * Validator schema that accepts a {@link RawMessage} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a message entry — for\n * example, a collection schema that holds an array of messages.\n */\n public static schema = rawMessageSchema\n\n /**\n * Returns `true` if `value` is a {@link Message} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Message} instance.\n */\n public static isMessage(value: unknown): value is Message {\n return isInstanceOf(value, 'Message', Message)\n }\n\n /** Stable unique identifier for this message. */\n declare readonly id: string\n /** Whether this message is from the human participant or the model. */\n declare readonly role: MessageRole\n /**\n * The message content as a {@link @nhtio/adk!Tokenizable} for inline token estimation, or `undefined`\n * for attachments-only messages.\n *\n * @remarks\n * `undefined` when the message was constructed with only `attachments`. Render code that\n * needs the text portion must guard for the missing case rather than blindly calling\n * `message.content.toString()`.\n */\n declare readonly content: Tokenizable | undefined\n /**\n * Media attachments carried by this message.\n *\n * @remarks\n * Always defined as a frozen array — empty when the message has no attachments. Both\n * `user` and `assistant` messages may carry attachments. Each entry carries its own\n * `trustTier` and `modalityHazard`; the renderer wraps each in its own trust envelope\n * independent of the message envelope.\n */\n declare readonly attachments: ReadonlyArray<Media>\n /** The identity of the participant who authored this message. */\n declare readonly identity: Identity\n /** When this message was created. */\n declare readonly createdAt: DateTime\n /** When this message was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #role: MessageRole\n #content: Tokenizable | undefined\n #attachments: ReadonlyArray<Media>\n #identity: Identity\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw message input validated against `rawMessageSchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} when `raw` does not satisfy the schema —\n * including the cross-field rule that at least one of `content` or `attachments` must be\n * present and non-empty.\n */\n constructor(raw: RawMessage) {\n let resolved: ResolvedMessage\n try {\n resolved = validateOrThrow<ResolvedMessage>(rawMessageSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_MESSAGE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#role = resolved.role\n this.#content =\n resolved.content === undefined || resolved.content === null\n ? undefined\n : Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#attachments = Object.freeze([...(resolved.attachments ?? [])])\n const rawIdentity = resolved.identity\n this.#identity = Identity.isIdentity(rawIdentity)\n ? rawIdentity\n : typeof rawIdentity === 'string'\n ? new Identity({ identifier: rawIdentity, representation: rawIdentity })\n : new Identity(rawIdentity)\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n role: {\n get: () => this.#role,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n attachments: {\n get: () => this.#attachments,\n enumerable: true,\n configurable: false,\n },\n identity: {\n get: () => this.#identity,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Message into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawMessage}-shaped object holding the live nested primitives — `content`\n * ({@link @nhtio/adk!Tokenizable}), `attachments` ({@link @nhtio/adk!Media}[]), `identity`\n * ({@link @nhtio/adk!Identity}), and Luxon temporal fields — which the encoder recurses into. A\n * text-only message round-trips trivially; a message carrying {@link @nhtio/adk!Media} round-trips only\n * if each attachment's reader is describable (a `fromWebFile`-backed attachment throws\n * {@link @nhtio/adk!E_READER_NOT_DESCRIBABLE} at encode). The frozen attachments array is copied to a\n * plain array for the snapshot. Round-trips via {@link Message.[DECODE_METHOD]}.\n *\n * @returns A {@link RawMessage}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n role: this.#role,\n content: this.#content,\n // Omit when empty: the schema's cross-field rule treats a present-but-empty `attachments`\n // array as invalid (it must contain ≥1 entry when supplied). A text-only message has none.\n ...(this.#attachments.length > 0 ? { attachments: [...this.#attachments] } : {}),\n identity: this.#identity,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Message} from a {@link Message.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Message.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Message}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Message {\n return new Message(data as RawMessage)\n }\n}\n","import { Identity } from './identity'\nimport { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_THOUGHT_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { RawIdentity } from './identity'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Thought} at construction time.\n *\n * @remarks\n * Validated against `rawThoughtSchema` before the `Thought` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawThought {\n /** Stable unique identifier for this thought. */\n id: string\n /**\n * The reasoning content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Required and non-empty in plain-text mode. In opaque mode ({@link RawThought.payload} present) it\n * may be empty or omitted — the payload carries the meaning — and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}. `Thought.content` is therefore ALWAYS a `Tokenizable`, never\n * `undefined`, so readers need no guard.\n */\n content?: string | Tokenizable\n /**\n * The identity of the agent who produced this thought.\n *\n * @remarks\n * Required in multi-agent conversations to attribute reasoning traces to a specific agent.\n * Three accepted forms when provided:\n * - A plain `string` — used as both `identifier` and `representation`.\n * - A {@link @nhtio/adk!RawIdentity} object — validated and wrapped into an {@link @nhtio/adk!Identity}.\n * - An existing {@link @nhtio/adk!Identity} instance — passed through unchanged.\n *\n * When omitted, defaults to `'assistant'` (both `identifier` and `representation`).\n */\n identity?: string | RawIdentity | Identity\n /**\n * Optional vendor-opaque payload that round-trips back to a matching model wire.\n *\n * @remarks\n * Carries anything the ADK cannot interpret but a specific provider can — for example,\n * an Anthropic Messages thinking-block `signature`, an OpenAI Responses\n * `ResponseReasoningItem.encrypted_content` blob, a DeepSeek server-side reasoning handle,\n * or an MCP-mediated reasoning item.\n *\n * When present, an LLM battery MUST treat the thought as **opaque-mode**: do NOT inline\n * `content` through the plain `<thought>` envelope; serialise `payload` back to the wire in\n * whichever shape the matching {@link RawThought.replayCompatibility} identifier specifies.\n * The plain-text `content` is kept alongside for token-accounting and human/observer\n * inspection — it is not the thing the model sees.\n *\n * Cross-field invariant: a present `payload` REQUIRES a present {@link RawThought.replayCompatibility}.\n * A `payload` without `replayCompatibility` is malformed (the ADK has no way to know\n * which adapter can consume it) and {@link Thought.schema} rejects with\n * {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE}.\n *\n * @defaultValue `undefined`\n */\n payload?: unknown\n /**\n * Optional free-form identifier describing which adapter wire-shape this thought can be\n * safely replayed into.\n *\n * @remarks\n * Examples (none of these are reserved by the ADK — they are consumer conventions):\n * - `'plain-text'` — replayable into every LLM battery\n * - `'anthropic-messages-thinking-v1'`\n * - `'openai-responses-reasoning-item-v1'`\n * - `'deepseek-reasoning-handle-v1'`\n *\n * LLM batteries declare via constructor option which tags they can safely replay; matching\n * opaque thoughts are routed to the wire's typed reasoning channel where it exists, or to a\n * documented side-channel key on the request body where the wire has none. Non-matching\n * opaque thoughts are elided from the current dispatch but NOT removed from\n * `ctx.turnThoughts` — they remain in context so a subsequent dispatch to a different\n * adapter that DOES declare the matching tag can pick them up.\n *\n * Plain-text thoughts (`payload === undefined` AND `replayCompatibility === undefined`, or\n * explicit `replayCompatibility: 'plain-text'`) are always replayable.\n *\n * A `replayCompatibility` without a `payload` is allowed — it documents intent (\"this\n * plain-text thought is only meaningful to a specific fine-tuned variant\") without\n * requiring an opaque blob.\n *\n * @defaultValue `undefined`\n */\n replayCompatibility?: string\n /** When this thought was recorded. */\n createdAt: string | number | Date | DateTime\n /** When this thought was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawThought} where temporal fields have been normalised to Luxon\n * `DateTime` instances.\n *\n * @remarks\n * Used internally by the {@link Thought} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedThought {\n id: string\n content?: string | Tokenizable\n identity: string | RawIdentity | Identity\n payload?: unknown\n replayCompatibility?: string\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawThought} before constructing a {@link Thought}.\n *\n * @remarks\n * Validates all fields of {@link RawThought}:\n * - `id` — required non-empty string.\n * - `content` — string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.emptyableSchema}.\n * Required and non-empty in plain-text mode; may be empty or omitted in opaque mode (see the\n * content-OR-payload rule below).\n * - `identity` — optional string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; defaults to\n * `'assistant'` when omitted.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Cross-field rule — a thought must carry meaning through EITHER its prose OR an opaque replay\n * `payload`. A NULLISH payload (`undefined` or `null`) carries no replay data and so counts as ABSENT\n * for both halves of the rule:\n * - `payload` ABSENT (plain-text mode) — `content` is REQUIRED and must be non-empty. The prose is\n * the only thing the thought has; an empty one is indistinguishable from a bug.\n * - `payload` PRESENT (opaque mode) — `content` may be empty or omitted, and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}. The payload is what round-trips to the wire; `content` is kept only\n * for token-accounting and human/observer inspection (see {@link RawThought.payload}), so a\n * signed-but-textless provider thinking block is legitimate. Rejecting it would discard the\n * payload's replay data — strictly worse than storing a thought with no prose.\n *\n * A present `payload` additionally REQUIRES a present `replayCompatibility`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} (via the {@link Thought} constructor) when\n * validation fails.\n */\nconst rawThoughtSchema = validator\n .object<RawThought>({\n id: validator.string().required(),\n // Emptiness is adjudicated by the cross-field rule below, which needs to see `payload` to decide.\n content: Tokenizable.emptyableSchema.optional(),\n identity: validator.alternatives(validator.string(), Identity.schema).default('assistant'),\n payload: validator.any().optional(),\n replayCompatibility: validator.string().min(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n })\n .custom((value, helpers) => {\n const v = value as RawThought\n // A NULLISH payload carries no replay data, so it is opaque mode in NEITHER rule below. `null`\n // reaches here easily — JSON round-tripping, a serializer normalising absent fields, a provider\n // mapper assigning a nullish thinking block — and treating it as \"present\" would both demand a\n // pointless `replayCompatibility` and, worse, waive the content requirement for a thought that has\n // no prose AND no payload: the exact state the either-or exists to forbid.\n const hasPayload = v.payload !== undefined && v.payload !== null\n if (hasPayload && (v.replayCompatibility === undefined || v.replayCompatibility === null)) {\n return helpers.error('any.invalid')\n }\n // content-OR-payload: only an opaque thought may go without prose. A Tokenizable counts as\n // present without being unwrapped — a dynamic one would evaluate its callback just to be measured,\n // and its emptiness is not knowable until prompt-assembly anyway.\n if (!hasPayload) {\n const hasContent = Tokenizable.isTokenizable(v.content)\n ? true\n : typeof v.content === 'string' && v.content.length > 0\n if (!hasContent) {\n return helpers.error('any.invalid')\n }\n }\n return value\n })\n\n/**\n * An immutable, validated internal reasoning trace produced by an agent.\n *\n * @remarks\n * Represents an agent's internal thinking — distinct from {@link @nhtio/adk!Message} (which is part of\n * the visible conversation) and never shown to end users directly. Carries an `identity` so\n * reasoning traces can be attributed to a specific agent in multi-agent conversations.\n * Constructed from a {@link RawThought} via `rawThoughtSchema`. The `content` field is always\n * a {@link @nhtio/adk!Tokenizable} so token cost can be estimated inline — including when the raw input\n * omitted it or supplied `''`, which is legal in opaque-replay mode and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}.\n */\nexport class Thought {\n /**\n * Validator schema that accepts a {@link RawThought} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a thought entry.\n */\n public static schema = rawThoughtSchema\n\n /**\n * Returns `true` if `value` is a {@link Thought} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Thought} instance.\n */\n public static isThought(value: unknown): value is Thought {\n return isInstanceOf(value, 'Thought', Thought)\n }\n\n /** Stable unique identifier for this thought. */\n declare readonly id: string\n /**\n * The reasoning content as a {@link @nhtio/adk!Tokenizable} for inline token estimation.\n *\n * @remarks\n * Never `undefined` — an opaque thought constructed without prose carries an empty\n * {@link @nhtio/adk!Tokenizable} here, so readers need no presence guard.\n */\n declare readonly content: Tokenizable\n /** The identity of the agent who produced this thought. */\n declare readonly identity: Identity\n /**\n * Optional vendor-opaque payload that round-trips back to a matching model wire.\n * See {@link RawThought.payload}.\n */\n declare readonly payload: unknown\n /**\n * Optional wire-shape identifier describing which adapter can safely replay this thought.\n * See {@link RawThought.replayCompatibility}.\n */\n declare readonly replayCompatibility: string | undefined\n /** When this thought was recorded. */\n declare readonly createdAt: DateTime\n /** When this thought was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable\n #identity: Identity\n #payload: unknown\n #replayCompatibility: string | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw thought input validated against `rawThoughtSchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawThought) {\n let resolved: ResolvedThought\n try {\n resolved = validateOrThrow<ResolvedThought>(rawThoughtSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_THOUGHT_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n // Absent content is legal only in opaque mode (enforced by rawThoughtSchema). Resolve it to an\n // EMPTY Tokenizable rather than leaving it undefined so `content` stays a total field — every\n // reader can call `.toString()` / measure it without a guard.\n this.#content = Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content ?? '')\n const rawIdentity = resolved.identity\n this.#identity = Identity.isIdentity(rawIdentity)\n ? rawIdentity\n : typeof rawIdentity === 'string'\n ? new Identity({ identifier: rawIdentity, representation: rawIdentity })\n : new Identity(rawIdentity)\n this.#payload = resolved.payload\n this.#replayCompatibility = resolved.replayCompatibility\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n identity: {\n get: () => this.#identity,\n enumerable: true,\n configurable: false,\n },\n payload: {\n get: () => this.#payload,\n enumerable: true,\n configurable: false,\n },\n replayCompatibility: {\n get: () => this.#replayCompatibility,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Thought into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawThought}-shaped object; `content` is the live {@link @nhtio/adk!Tokenizable},\n * `identity` the live {@link @nhtio/adk!Identity}, and the temporal fields live Luxon `DateTime`s (the\n * encoder recurses into each). The vendor-opaque `payload` is passed through as-is — if it holds a\n * value the encoder cannot serialise, encode throws (standard encoder behaviour). Round-trips via\n * {@link Thought.[DECODE_METHOD]}, which re-validates through the constructor.\n *\n * @returns A {@link RawThought}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n content: this.#content,\n identity: this.#identity,\n payload: this.#payload,\n replayCompatibility: this.#replayCompatibility,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Thought} from a {@link Thought.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Thought.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Thought}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Thought {\n return new Thought(data as RawThought)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyDA,IAAM,oBAAoB,UAAU,OAAoB;CACtD,YAAY,UAAU,aAAa,UAAU,OAAO,GAAG,UAAU,OAAO,CAAC,EAAE,SAAS;CACpF,gBAAgB,YAAY,OAAO,SAAS;AAC9C,CAAC;;;;;;;;;;;AAYD,IAAM,iCAAiB,IAAI,QAAgB;;;;;;;;;;;;;;;;;;;;AAqB3C,IAAM,8BAA8B,UACjC,aACC,UAAU,QAAQ,OAAO,YAA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AQ,IAAkB;CACvC;AACF"}
@@ -1,7 +1,7 @@
1
1
  const require_exceptions = require("./exceptions-DrHnAGQz.cjs");
2
2
  const require_guards = require("./guards-5-XmJgD2.cjs");
3
- const require_tokenizable = require("./tokenizable-DDIdXbJN.cjs");
4
- const require_tool_call = require("./tool_call-JbjeUpRK.cjs");
3
+ const require_tokenizable = require("./tokenizable-BcodRtoW.cjs");
4
+ const require_tool_call = require("./tool_call-B9px4W9k.cjs");
5
5
  let _nhtio_validation = require("@nhtio/validation");
6
6
  //#region src/lib/classes/identity.ts
7
7
  /**
@@ -672,4 +672,4 @@ Object.defineProperty(exports, "Thought", {
672
672
  }
673
673
  });
674
674
 
675
- //# sourceMappingURL=thought-COeZTQ-B.cjs.map
675
+ //# sourceMappingURL=thought-Dp3sMWW6.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"thought-COeZTQ-B.cjs","names":["#identifier","#representation","#id","#content","#confidence","#importance","#createdAt","#updatedAt","#id","#role","#content","#attachments","#identity","#createdAt","#updatedAt","#id","#content","#identity","#payload","#replayCompatibility","#createdAt","#updatedAt"],"sources":["../src/lib/classes/identity.ts","../src/lib/classes/memory.ts","../src/lib/classes/message.ts","../src/lib/classes/thought.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError, isObject } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_IDENTITY_VALUE } from '../exceptions/runtime'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Identity} at construction time.\n *\n * @remarks\n * Validated against `rawIdentitySchema` before the `Identity` instance is created.\n */\nexport interface RawIdentity {\n /**\n * The system-facing identifier for this participant.\n *\n * @remarks\n * Used internally to correlate messages to a specific participant — e.g. a database ID or\n * a username. Never sent to the model directly; use `representation` for that.\n */\n identifier: string | number\n /**\n * How this participant should be presented to the model.\n *\n * @remarks\n * Accepts a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. This is what the model\n * sees when it needs to distinguish between participants of the same role.\n */\n representation: string | Tokenizable\n}\n\n/**\n * A fully-resolved {@link RawIdentity} where `representation` has been normalised to a\n * {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Used internally by the {@link Identity} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedIdentity {\n identifier: string | number\n representation: Tokenizable\n}\n\n/**\n * Validator schema used to validate a {@link RawIdentity} before constructing an {@link Identity}.\n *\n * @remarks\n * Validates both fields of {@link RawIdentity}:\n * - `identifier` — required string or number.\n * - `representation` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} (via the {@link Identity} constructor) when\n * validation fails.\n */\nconst rawIdentitySchema = validator.object<RawIdentity>({\n identifier: validator.alternatives(validator.string(), validator.number()).required(),\n representation: Tokenizable.schema.required(),\n})\n\n/**\n * Registry of every {@link Identity} genuinely constructed by this module, in this realm.\n *\n * @remarks\n * The brand that {@link identityOrRawIdentitySchema} trusts to bypass raw-object validation. A\n * {@link WeakSet} keyed by the instance is unforgeable (unlike {@link Identity.isIdentity}, which\n * falls back to a `constructor.name` comparison for cross-realm reach and therefore also accepts a\n * hand-rolled look-alike) and holds no strong reference. Every instance adds itself in the\n * constructor; membership means the instance carries real, intact private fields.\n */\nconst liveIdentities = new WeakSet<object>()\n\n/**\n * Public schema fragment that accepts either a plain {@link RawIdentity} object or an existing\n * {@link Identity} instance.\n *\n * @remarks\n * A genuinely-constructed live {@link Identity} passes through the custom branch UNCHANGED — mirroring\n * {@link @nhtio/adk!Tokenizable.schema}. This matters because Joi's object schema *clones* any value it\n * validates, and cloning an `Identity` produces a look-alike with the right prototype but no private\n * `#identifier` / `#representation` fields (the constructor never ran), which then throws on\n * `[ENCODE_METHOD]`. Returning the live instance verbatim keeps its private state intact so it encodes\n * and re-wraps losslessly.\n *\n * Only a **branded** instance (one this module actually constructed — see {@link liveIdentities})\n * bypasses validation. A bare `constructor.name === 'Identity'` is NOT enough: a look-alike or a\n * cross-realm instance is not in the brand set, so it falls through to {@link rawIdentitySchema},\n * which validates its fields (rejecting a malformed `representation`) rather than retaining an\n * unvalidated husk that would later produce invalid serialized state. Plain {@link RawIdentity}\n * objects fall through the same way.\n */\nconst identityOrRawIdentitySchema = validator\n .alternatives(\n validator.custom((value, helpers) => {\n if (isObject(value) && liveIdentities.has(value)) {\n return value\n }\n return helpers.error('any.invalid')\n }),\n rawIdentitySchema\n )\n .custom((value) => {\n // A genuinely-branded live instance passes through the first alternative untouched. Anything\n // else — a plain RawIdentity, a hand-rolled look-alike, or a FOREIGN/cross-realm `Identity`\n // (a second copy of the package in the dependency tree) — arrives here as the field-validated\n // output of `rawIdentitySchema`. Joi cloned it, so a foreign instance is now a husk that still\n // carries an `Identity`-named prototype but has NO private fields; `Identity.isIdentity` accepts\n // it (name/prototype fallback) yet `[ENCODE_METHOD]` throws reading the missing privates.\n // Rebuild any non-branded value into a genuine LOCAL Identity so every consumer stores real,\n // encodable private state regardless of where the value originated.\n if (isObject(value) && liveIdentities.has(value)) {\n return value\n }\n return new Identity(value as RawIdentity)\n })\n\n/**\n * An immutable, validated participant identity attached to a {@link @nhtio/adk!Message}.\n *\n * @remarks\n * Carries two distinct representations of the same participant: `identifier` is the\n * system-facing key (e.g. a database ID) used to correlate messages programmatically;\n * `representation` is what the model sees when it needs to distinguish between participants\n * sharing the same role. The `representation` is always a {@link @nhtio/adk!Tokenizable} so token cost\n * can be estimated inline.\n */\nexport class Identity {\n /**\n * Validator schema that accepts a {@link RawIdentity} object OR an existing {@link Identity} instance.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest an identity — for example,\n * as a required field inside a message schema. A locally branded {@link Identity} passes through\n * unchanged (its private state is preserved, so it still encodes losslessly); foreign/cross-realm\n * identities and plain {@link RawIdentity} values are validated field-by-field and rebuilt locally.\n * See {@link identityOrRawIdentitySchema}.\n */\n public static schema = identityOrRawIdentitySchema\n\n /**\n * Returns `true` if `value` is an {@link Identity} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is an {@link Identity} instance.\n */\n public static isIdentity(value: unknown): value is Identity {\n return isInstanceOf(value, 'Identity', Identity)\n }\n\n /**\n * The system-facing identifier for this participant — never sent to the model directly.\n */\n declare readonly identifier: string | number\n\n /**\n * How this participant is presented to the model, as a {@link @nhtio/adk!Tokenizable} for inline\n * token estimation.\n */\n declare readonly representation: Tokenizable\n\n #identifier: string | number\n #representation: Tokenizable\n\n /**\n * @param raw - The raw identity input validated against `rawIdentitySchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawIdentity) {\n let resolved: ResolvedIdentity\n try {\n resolved = validateOrThrow<ResolvedIdentity>(rawIdentitySchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_IDENTITY_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#identifier = resolved.identifier\n this.#representation = Tokenizable.isTokenizable(resolved.representation)\n ? resolved.representation\n : new Tokenizable(resolved.representation)\n\n Object.defineProperties(this, {\n identifier: {\n get: () => this.#identifier,\n enumerable: true,\n configurable: false,\n },\n representation: {\n get: () => this.#representation,\n enumerable: true,\n configurable: false,\n },\n })\n\n // Brand this genuinely-constructed instance so `identityOrRawIdentitySchema` can trust it to\n // bypass raw-object validation. A look-alike or cross-realm object is never in this set.\n liveIdentities.add(this)\n }\n\n /**\n * Serialise this Identity into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawIdentity}-shaped object; `representation` is the live {@link @nhtio/adk!Tokenizable}\n * instance (the encoder recurses into it). Round-trips via {@link Identity.[DECODE_METHOD]}, which\n * re-validates through the constructor.\n *\n * @returns A {@link RawIdentity}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n identifier: this.#identifier,\n representation: this.#representation,\n }\n }\n\n /**\n * Reconstruct an {@link Identity} from an {@link Identity.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Identity.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Identity}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Identity {\n return new Identity(data as RawIdentity)\n }\n}\n","import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_MEMORY_VALUE } from '../exceptions/runtime'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport type { DateTime } from 'luxon'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Memory} at construction time.\n *\n * @remarks\n * Validated against `rawMemorySchema` before the `Memory` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawMemory {\n /** Stable unique identifier for this memory entry. */\n id: string\n /** The memory content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. */\n content: string | Tokenizable\n /** Confidence score in the range `[0, 1]` — how certain the agent is that this memory is accurate. */\n confidence: number\n /** Importance score in the range `[0, 1]` — how much weight this memory should carry during retrieval. */\n importance: number\n /** When this memory was first recorded. */\n createdAt: string | number | Date | DateTime\n /** When this memory was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawMemory} where all fields have been validated and temporal values\n * normalised to Luxon `DateTime` instances.\n *\n * @remarks\n * This is the shape returned by `rawMemorySchema` after validation — used internally by the\n * {@link Memory} constructor to assign private fields with guaranteed types.\n */\ninterface ResolvedMemory {\n id: string\n content: Tokenizable\n confidence: number\n importance: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawMemory} before constructing a {@link Memory}.\n *\n * @remarks\n * Validates all six fields of {@link RawMemory}:\n * - `id` — required non-empty string.\n * - `content` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n * - `confidence` — required number in `[0, 1]`.\n * - `importance` — required number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} (via the {@link Memory} constructor) when\n * validation fails.\n */\nconst rawMemorySchema = validator.object<RawMemory>({\n id: validator.string().required(),\n content: Tokenizable.schema.required(),\n confidence: validator.number().min(0).max(1).required(),\n importance: validator.number().min(0).max(1).required(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated memory entry held by the agent.\n *\n * @remarks\n * Constructed from a {@link RawMemory} via `rawMemorySchema`. All temporal fields are\n * normalised to Luxon `DateTime` instances at construction time. The `content` field is\n * always a {@link @nhtio/adk!Tokenizable} so callers can estimate token cost without an additional\n * wrapping step.\n */\nexport class Memory {\n /**\n * Validator schema that accepts a {@link RawMemory} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a memory entry — for\n * example, a collection schema that holds an array of memories.\n */\n public static schema = rawMemorySchema\n\n /**\n * Returns `true` if `value` is a {@link Memory} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Memory} instance.\n */\n public static isMemory(value: unknown): value is Memory {\n return isInstanceOf(value, 'Memory', Memory)\n }\n /** Stable unique identifier for this memory entry. */\n declare readonly id: string\n /** The memory content as a {@link @nhtio/adk!Tokenizable} for inline token estimation. */\n declare readonly content: Tokenizable\n /** Confidence score in the range `[0, 1]`. */\n declare readonly confidence: number\n /** Importance score in the range `[0, 1]`. */\n declare readonly importance: number\n /** When this memory was first recorded. */\n declare readonly createdAt: DateTime\n /** When this memory was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable\n #confidence: number\n #importance: number\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw memory input validated against `rawMemorySchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawMemory) {\n let resolved: ResolvedMemory\n try {\n resolved = validateOrThrow<ResolvedMemory>(rawMemorySchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_MEMORY_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content = Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#confidence = resolved.confidence\n this.#importance = resolved.importance\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n confidence: {\n get: () => this.#confidence,\n enumerable: true,\n configurable: false,\n },\n importance: {\n get: () => this.#importance,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Memory into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawMemory}-shaped object; `content` is the live {@link @nhtio/adk!Tokenizable} and the\n * temporal fields are live Luxon `DateTime` instances (the encoder recurses into both). Round-trips\n * via {@link Memory.[DECODE_METHOD]}, which re-validates through the constructor.\n *\n * @returns A {@link RawMemory}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n content: this.#content,\n confidence: this.#confidence,\n importance: this.#importance,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Memory} from a {@link Memory.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Memory.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Memory}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Memory {\n return new Memory(data as RawMemory)\n }\n}\n","import { Media } from './media'\nimport { Identity } from './identity'\nimport { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_MESSAGE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { RawIdentity } from './identity'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * The roles a {@link Message} author can hold.\n *\n * @remarks\n * Restricted to `user` and `assistant` — system instructions, developer directives, and\n * tool results are handled separately and never appear in the persisted message history.\n */\nexport type MessageRole = 'user' | 'assistant'\n\n/**\n * Plain input object supplied to {@link Message} at construction time.\n *\n * @remarks\n * Validated against `rawMessageSchema` before the `Message` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n *\n * At least one of `content` or `attachments` (non-empty) must be present — a message with\n * neither throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE}.\n */\nexport interface RawMessage {\n /** Stable unique identifier for this message. */\n id: string\n /** Whether this message is from the human participant or the model. */\n role: MessageRole\n /**\n * The message content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Optional — but required when `attachments` is absent or empty. The cross-field rule on\n * `rawMessageSchema` enforces that at least one of `content` or `attachments` is present.\n */\n content?: string | Tokenizable\n /**\n * Media attachments carried by this message — images, audio, video, documents.\n *\n * @remarks\n * Optional and symmetric across roles: both `user` and `assistant` messages may carry\n * attachments. Each attachment carries its own `trustTier` and `modalityHazard`, which the\n * renderer uses to wrap the asset in its own trust envelope independent of the message\n * envelope. How a renderer orders text vs attachments in the on-the-wire content array is\n * a renderer-policy concern, not a contract of {@link Message}.\n */\n attachments?: Media[]\n /**\n * The identity of the participant who authored this message.\n *\n * @remarks\n * Optional. When omitted, the `role` value is used as both the system-facing `identifier`\n * and the model-facing `representation`. Three accepted forms when provided:\n * - A plain `string` — used as both `identifier` and `representation`.\n * - A {@link @nhtio/adk!RawIdentity} object — validated and wrapped into an {@link @nhtio/adk!Identity}.\n * - An existing {@link @nhtio/adk!Identity} instance — passed through unchanged.\n */\n identity?: string | RawIdentity | Identity\n /** When this message was created. */\n createdAt: string | number | Date | DateTime\n /** When this message was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawMessage} where temporal fields have been normalised to Luxon\n * `DateTime` instances and `identity` is a validated {@link @nhtio/adk!Identity}.\n *\n * @remarks\n * Used internally by the {@link Message} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedMessage {\n id: string\n role: MessageRole\n content?: Tokenizable\n attachments: Media[]\n identity: string | RawIdentity | Identity\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawMessage} before constructing a {@link Message}.\n *\n * @remarks\n * Validates all fields of {@link RawMessage}:\n * - `id` — required non-empty string.\n * - `role` — required; must be `'user'` or `'assistant'`.\n * - `content` — optional string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n * - `attachments` — optional array of {@link @nhtio/adk!Media} instances. Defaults to `[]`.\n * - At least one of `content` or `attachments` must be present and non-empty; a message with\n * neither is invalid.\n * - `identity` — required string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; a plain string is\n * mapped to both `identifier` and `representation` automatically.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} (via the {@link Message} constructor) when\n * validation fails.\n */\nconst rawMessageSchema = validator\n .object<RawMessage>({\n id: validator.string().required(),\n role: validator.string().valid('user', 'assistant').required(),\n content: Tokenizable.schema.optional(),\n attachments: validator\n .array()\n .items(\n validator\n .any()\n .required()\n .custom((value, helpers) => {\n if (Media.isMedia(value)) return value\n return helpers.error('any.invalid')\n })\n )\n .default([]),\n identity: validator\n .alternatives(validator.string(), Identity.schema)\n .default(validator.ref('role')),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n })\n .custom((value, helpers) => {\n const resolved = value as ResolvedMessage\n const hasContent = resolved.content !== undefined && resolved.content !== null\n const hasAttachments = Array.isArray(resolved.attachments) && resolved.attachments.length > 0\n if (!hasContent && !hasAttachments) {\n return helpers.error('any.invalid')\n }\n return resolved\n })\n\n/**\n * An immutable, validated conversation message from a human participant or the model.\n *\n * @remarks\n * Covers only `user` and `assistant` roles — system instructions, developer directives, and\n * tool results are not represented here. Constructed from a {@link RawMessage} via\n * `rawMessageSchema`. Temporal fields are normalised to Luxon `DateTime` instances at\n * construction time. Both `content` and `identity.representation` are {@link @nhtio/adk!Tokenizable} so\n * token cost can be estimated inline.\n *\n * A message may carry `content` (text), `attachments` (media), or both. The cross-field rule\n * on `rawMessageSchema` enforces that at least one is present. Downstream code that reaches\n * for `message.content` must handle the attachments-only case where `content` is `undefined`.\n */\nexport class Message {\n /**\n * Validator schema that accepts a {@link RawMessage} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a message entry — for\n * example, a collection schema that holds an array of messages.\n */\n public static schema = rawMessageSchema\n\n /**\n * Returns `true` if `value` is a {@link Message} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Message} instance.\n */\n public static isMessage(value: unknown): value is Message {\n return isInstanceOf(value, 'Message', Message)\n }\n\n /** Stable unique identifier for this message. */\n declare readonly id: string\n /** Whether this message is from the human participant or the model. */\n declare readonly role: MessageRole\n /**\n * The message content as a {@link @nhtio/adk!Tokenizable} for inline token estimation, or `undefined`\n * for attachments-only messages.\n *\n * @remarks\n * `undefined` when the message was constructed with only `attachments`. Render code that\n * needs the text portion must guard for the missing case rather than blindly calling\n * `message.content.toString()`.\n */\n declare readonly content: Tokenizable | undefined\n /**\n * Media attachments carried by this message.\n *\n * @remarks\n * Always defined as a frozen array — empty when the message has no attachments. Both\n * `user` and `assistant` messages may carry attachments. Each entry carries its own\n * `trustTier` and `modalityHazard`; the renderer wraps each in its own trust envelope\n * independent of the message envelope.\n */\n declare readonly attachments: ReadonlyArray<Media>\n /** The identity of the participant who authored this message. */\n declare readonly identity: Identity\n /** When this message was created. */\n declare readonly createdAt: DateTime\n /** When this message was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #role: MessageRole\n #content: Tokenizable | undefined\n #attachments: ReadonlyArray<Media>\n #identity: Identity\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw message input validated against `rawMessageSchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} when `raw` does not satisfy the schema —\n * including the cross-field rule that at least one of `content` or `attachments` must be\n * present and non-empty.\n */\n constructor(raw: RawMessage) {\n let resolved: ResolvedMessage\n try {\n resolved = validateOrThrow<ResolvedMessage>(rawMessageSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_MESSAGE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#role = resolved.role\n this.#content =\n resolved.content === undefined || resolved.content === null\n ? undefined\n : Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#attachments = Object.freeze([...(resolved.attachments ?? [])])\n const rawIdentity = resolved.identity\n this.#identity = Identity.isIdentity(rawIdentity)\n ? rawIdentity\n : typeof rawIdentity === 'string'\n ? new Identity({ identifier: rawIdentity, representation: rawIdentity })\n : new Identity(rawIdentity)\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n role: {\n get: () => this.#role,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n attachments: {\n get: () => this.#attachments,\n enumerable: true,\n configurable: false,\n },\n identity: {\n get: () => this.#identity,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Message into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawMessage}-shaped object holding the live nested primitives — `content`\n * ({@link @nhtio/adk!Tokenizable}), `attachments` ({@link @nhtio/adk!Media}[]), `identity`\n * ({@link @nhtio/adk!Identity}), and Luxon temporal fields — which the encoder recurses into. A\n * text-only message round-trips trivially; a message carrying {@link @nhtio/adk!Media} round-trips only\n * if each attachment's reader is describable (a `fromWebFile`-backed attachment throws\n * {@link @nhtio/adk!E_READER_NOT_DESCRIBABLE} at encode). The frozen attachments array is copied to a\n * plain array for the snapshot. Round-trips via {@link Message.[DECODE_METHOD]}.\n *\n * @returns A {@link RawMessage}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n role: this.#role,\n content: this.#content,\n // Omit when empty: the schema's cross-field rule treats a present-but-empty `attachments`\n // array as invalid (it must contain ≥1 entry when supplied). A text-only message has none.\n ...(this.#attachments.length > 0 ? { attachments: [...this.#attachments] } : {}),\n identity: this.#identity,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Message} from a {@link Message.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Message.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Message}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Message {\n return new Message(data as RawMessage)\n }\n}\n","import { Identity } from './identity'\nimport { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_THOUGHT_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { RawIdentity } from './identity'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Thought} at construction time.\n *\n * @remarks\n * Validated against `rawThoughtSchema` before the `Thought` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawThought {\n /** Stable unique identifier for this thought. */\n id: string\n /**\n * The reasoning content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Required and non-empty in plain-text mode. In opaque mode ({@link RawThought.payload} present) it\n * may be empty or omitted — the payload carries the meaning — and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}. `Thought.content` is therefore ALWAYS a `Tokenizable`, never\n * `undefined`, so readers need no guard.\n */\n content?: string | Tokenizable\n /**\n * The identity of the agent who produced this thought.\n *\n * @remarks\n * Required in multi-agent conversations to attribute reasoning traces to a specific agent.\n * Three accepted forms when provided:\n * - A plain `string` — used as both `identifier` and `representation`.\n * - A {@link @nhtio/adk!RawIdentity} object — validated and wrapped into an {@link @nhtio/adk!Identity}.\n * - An existing {@link @nhtio/adk!Identity} instance — passed through unchanged.\n *\n * When omitted, defaults to `'assistant'` (both `identifier` and `representation`).\n */\n identity?: string | RawIdentity | Identity\n /**\n * Optional vendor-opaque payload that round-trips back to a matching model wire.\n *\n * @remarks\n * Carries anything the ADK cannot interpret but a specific provider can — for example,\n * an Anthropic Messages thinking-block `signature`, an OpenAI Responses\n * `ResponseReasoningItem.encrypted_content` blob, a DeepSeek server-side reasoning handle,\n * or an MCP-mediated reasoning item.\n *\n * When present, an LLM battery MUST treat the thought as **opaque-mode**: do NOT inline\n * `content` through the plain `<thought>` envelope; serialise `payload` back to the wire in\n * whichever shape the matching {@link RawThought.replayCompatibility} identifier specifies.\n * The plain-text `content` is kept alongside for token-accounting and human/observer\n * inspection — it is not the thing the model sees.\n *\n * Cross-field invariant: a present `payload` REQUIRES a present {@link RawThought.replayCompatibility}.\n * A `payload` without `replayCompatibility` is malformed (the ADK has no way to know\n * which adapter can consume it) and {@link Thought.schema} rejects with\n * {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE}.\n *\n * @defaultValue `undefined`\n */\n payload?: unknown\n /**\n * Optional free-form identifier describing which adapter wire-shape this thought can be\n * safely replayed into.\n *\n * @remarks\n * Examples (none of these are reserved by the ADK — they are consumer conventions):\n * - `'plain-text'` — replayable into every LLM battery\n * - `'anthropic-messages-thinking-v1'`\n * - `'openai-responses-reasoning-item-v1'`\n * - `'deepseek-reasoning-handle-v1'`\n *\n * LLM batteries declare via constructor option which tags they can safely replay; matching\n * opaque thoughts are routed to the wire's typed reasoning channel where it exists, or to a\n * documented side-channel key on the request body where the wire has none. Non-matching\n * opaque thoughts are elided from the current dispatch but NOT removed from\n * `ctx.turnThoughts` — they remain in context so a subsequent dispatch to a different\n * adapter that DOES declare the matching tag can pick them up.\n *\n * Plain-text thoughts (`payload === undefined` AND `replayCompatibility === undefined`, or\n * explicit `replayCompatibility: 'plain-text'`) are always replayable.\n *\n * A `replayCompatibility` without a `payload` is allowed — it documents intent (\"this\n * plain-text thought is only meaningful to a specific fine-tuned variant\") without\n * requiring an opaque blob.\n *\n * @defaultValue `undefined`\n */\n replayCompatibility?: string\n /** When this thought was recorded. */\n createdAt: string | number | Date | DateTime\n /** When this thought was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawThought} where temporal fields have been normalised to Luxon\n * `DateTime` instances.\n *\n * @remarks\n * Used internally by the {@link Thought} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedThought {\n id: string\n content?: string | Tokenizable\n identity: string | RawIdentity | Identity\n payload?: unknown\n replayCompatibility?: string\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawThought} before constructing a {@link Thought}.\n *\n * @remarks\n * Validates all fields of {@link RawThought}:\n * - `id` — required non-empty string.\n * - `content` — string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.emptyableSchema}.\n * Required and non-empty in plain-text mode; may be empty or omitted in opaque mode (see the\n * content-OR-payload rule below).\n * - `identity` — optional string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; defaults to\n * `'assistant'` when omitted.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Cross-field rule — a thought must carry meaning through EITHER its prose OR an opaque replay\n * `payload`. A NULLISH payload (`undefined` or `null`) carries no replay data and so counts as ABSENT\n * for both halves of the rule:\n * - `payload` ABSENT (plain-text mode) — `content` is REQUIRED and must be non-empty. The prose is\n * the only thing the thought has; an empty one is indistinguishable from a bug.\n * - `payload` PRESENT (opaque mode) — `content` may be empty or omitted, and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}. The payload is what round-trips to the wire; `content` is kept only\n * for token-accounting and human/observer inspection (see {@link RawThought.payload}), so a\n * signed-but-textless provider thinking block is legitimate. Rejecting it would discard the\n * payload's replay data — strictly worse than storing a thought with no prose.\n *\n * A present `payload` additionally REQUIRES a present `replayCompatibility`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} (via the {@link Thought} constructor) when\n * validation fails.\n */\nconst rawThoughtSchema = validator\n .object<RawThought>({\n id: validator.string().required(),\n // Emptiness is adjudicated by the cross-field rule below, which needs to see `payload` to decide.\n content: Tokenizable.emptyableSchema.optional(),\n identity: validator.alternatives(validator.string(), Identity.schema).default('assistant'),\n payload: validator.any().optional(),\n replayCompatibility: validator.string().min(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n })\n .custom((value, helpers) => {\n const v = value as RawThought\n // A NULLISH payload carries no replay data, so it is opaque mode in NEITHER rule below. `null`\n // reaches here easily — JSON round-tripping, a serializer normalising absent fields, a provider\n // mapper assigning a nullish thinking block — and treating it as \"present\" would both demand a\n // pointless `replayCompatibility` and, worse, waive the content requirement for a thought that has\n // no prose AND no payload: the exact state the either-or exists to forbid.\n const hasPayload = v.payload !== undefined && v.payload !== null\n if (hasPayload && (v.replayCompatibility === undefined || v.replayCompatibility === null)) {\n return helpers.error('any.invalid')\n }\n // content-OR-payload: only an opaque thought may go without prose. A Tokenizable counts as\n // present without being unwrapped — a dynamic one would evaluate its callback just to be measured,\n // and its emptiness is not knowable until prompt-assembly anyway.\n if (!hasPayload) {\n const hasContent = Tokenizable.isTokenizable(v.content)\n ? true\n : typeof v.content === 'string' && v.content.length > 0\n if (!hasContent) {\n return helpers.error('any.invalid')\n }\n }\n return value\n })\n\n/**\n * An immutable, validated internal reasoning trace produced by an agent.\n *\n * @remarks\n * Represents an agent's internal thinking — distinct from {@link @nhtio/adk!Message} (which is part of\n * the visible conversation) and never shown to end users directly. Carries an `identity` so\n * reasoning traces can be attributed to a specific agent in multi-agent conversations.\n * Constructed from a {@link RawThought} via `rawThoughtSchema`. The `content` field is always\n * a {@link @nhtio/adk!Tokenizable} so token cost can be estimated inline — including when the raw input\n * omitted it or supplied `''`, which is legal in opaque-replay mode and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}.\n */\nexport class Thought {\n /**\n * Validator schema that accepts a {@link RawThought} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a thought entry.\n */\n public static schema = rawThoughtSchema\n\n /**\n * Returns `true` if `value` is a {@link Thought} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Thought} instance.\n */\n public static isThought(value: unknown): value is Thought {\n return isInstanceOf(value, 'Thought', Thought)\n }\n\n /** Stable unique identifier for this thought. */\n declare readonly id: string\n /**\n * The reasoning content as a {@link @nhtio/adk!Tokenizable} for inline token estimation.\n *\n * @remarks\n * Never `undefined` — an opaque thought constructed without prose carries an empty\n * {@link @nhtio/adk!Tokenizable} here, so readers need no presence guard.\n */\n declare readonly content: Tokenizable\n /** The identity of the agent who produced this thought. */\n declare readonly identity: Identity\n /**\n * Optional vendor-opaque payload that round-trips back to a matching model wire.\n * See {@link RawThought.payload}.\n */\n declare readonly payload: unknown\n /**\n * Optional wire-shape identifier describing which adapter can safely replay this thought.\n * See {@link RawThought.replayCompatibility}.\n */\n declare readonly replayCompatibility: string | undefined\n /** When this thought was recorded. */\n declare readonly createdAt: DateTime\n /** When this thought was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable\n #identity: Identity\n #payload: unknown\n #replayCompatibility: string | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw thought input validated against `rawThoughtSchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawThought) {\n let resolved: ResolvedThought\n try {\n resolved = validateOrThrow<ResolvedThought>(rawThoughtSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_THOUGHT_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n // Absent content is legal only in opaque mode (enforced by rawThoughtSchema). Resolve it to an\n // EMPTY Tokenizable rather than leaving it undefined so `content` stays a total field — every\n // reader can call `.toString()` / measure it without a guard.\n this.#content = Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content ?? '')\n const rawIdentity = resolved.identity\n this.#identity = Identity.isIdentity(rawIdentity)\n ? rawIdentity\n : typeof rawIdentity === 'string'\n ? new Identity({ identifier: rawIdentity, representation: rawIdentity })\n : new Identity(rawIdentity)\n this.#payload = resolved.payload\n this.#replayCompatibility = resolved.replayCompatibility\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n identity: {\n get: () => this.#identity,\n enumerable: true,\n configurable: false,\n },\n payload: {\n get: () => this.#payload,\n enumerable: true,\n configurable: false,\n },\n replayCompatibility: {\n get: () => this.#replayCompatibility,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Thought into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawThought}-shaped object; `content` is the live {@link @nhtio/adk!Tokenizable},\n * `identity` the live {@link @nhtio/adk!Identity}, and the temporal fields live Luxon `DateTime`s (the\n * encoder recurses into each). The vendor-opaque `payload` is passed through as-is — if it holds a\n * value the encoder cannot serialise, encode throws (standard encoder behaviour). Round-trips via\n * {@link Thought.[DECODE_METHOD]}, which re-validates through the constructor.\n *\n * @returns A {@link RawThought}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n content: this.#content,\n identity: this.#identity,\n payload: this.#payload,\n replayCompatibility: this.#replayCompatibility,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Thought} from a {@link Thought.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Thought.[ENCODE_METHOD]}.\n * @returns A fully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YAAY;GAAa,gBAAgB;EAAY,CAAC,IACrE,IAAI,SAAS,WAAW;EAC9B,KAAKC,WAAW,SAAS;EACzB,KAAKC,uBAAuB,SAAS;EACrC,KAAKC,aAAa,SAAS;EAC3B,KAAKC,aAAa,SAAS;EAE3B,OAAO,iBAAiB,MAAM;GAC5B,IAAI;IACF,WAAW,KAAKN;IAChB,YAAY;IACZ,cAAc;GAChB;GACA,SAAS;IACP,WAAW,KAAKC;IAChB,YAAY;IACZ,cAAc;GAChB;GACA,UAAU;IACR,WAAW,KAAKC;IAChB,YAAY;IACZ,cAAc;GAChB;GACA,SAAS;IACP,WAAW,KAAKC;IAChB,YAAY;IACZ,cAAc;GAChB;GACA,qBAAqB;IACnB,WAAW,KAAKC;IAChB,YAAY;IACZ,cAAc;GAChB;GACA,WAAW;IACT,WAAW,KAAKC;IAChB,YAAY;IACZ,cAAc;GAChB;GACA,WAAW;IACT,WAAW,KAAKC;IAChB,YAAY;IACZ,cAAc;GAChB;EACF,CAAC;CACH;;;;;;;;;;;;;CAcA,CAAC,oBAAA,iBAAuC;EACtC,OAAO;GACL,IAAI,KAAKN;GACT,SAAS,KAAKC;GACd,UAAU,KAAKC;GACf,SAAS,KAAKC;GACd,qBAAqB,KAAKC;GAC1B,WAAW,KAAKC;GAChB,WAAW,KAAKC;EAClB;CACF;;;;;;;CAQA,QAAQ,oBAAA,eAAe,MAAqC;EAC1D,OAAO,IAAI,QAAQ,IAAkB;CACvC;AACF"}
1
+ {"version":3,"file":"thought-Dp3sMWW6.cjs","names":["#identifier","#representation","#id","#content","#confidence","#importance","#createdAt","#updatedAt","#id","#role","#content","#attachments","#identity","#createdAt","#updatedAt","#id","#content","#identity","#payload","#replayCompatibility","#createdAt","#updatedAt"],"sources":["../src/lib/classes/identity.ts","../src/lib/classes/memory.ts","../src/lib/classes/message.ts","../src/lib/classes/thought.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError, isObject } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_IDENTITY_VALUE } from '../exceptions/runtime'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Identity} at construction time.\n *\n * @remarks\n * Validated against `rawIdentitySchema` before the `Identity` instance is created.\n */\nexport interface RawIdentity {\n /**\n * The system-facing identifier for this participant.\n *\n * @remarks\n * Used internally to correlate messages to a specific participant — e.g. a database ID or\n * a username. Never sent to the model directly; use `representation` for that.\n */\n identifier: string | number\n /**\n * How this participant should be presented to the model.\n *\n * @remarks\n * Accepts a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. This is what the model\n * sees when it needs to distinguish between participants of the same role.\n */\n representation: string | Tokenizable\n}\n\n/**\n * A fully-resolved {@link RawIdentity} where `representation` has been normalised to a\n * {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Used internally by the {@link Identity} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedIdentity {\n identifier: string | number\n representation: Tokenizable\n}\n\n/**\n * Validator schema used to validate a {@link RawIdentity} before constructing an {@link Identity}.\n *\n * @remarks\n * Validates both fields of {@link RawIdentity}:\n * - `identifier` — required string or number.\n * - `representation` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} (via the {@link Identity} constructor) when\n * validation fails.\n */\nconst rawIdentitySchema = validator.object<RawIdentity>({\n identifier: validator.alternatives(validator.string(), validator.number()).required(),\n representation: Tokenizable.schema.required(),\n})\n\n/**\n * Registry of every {@link Identity} genuinely constructed by this module, in this realm.\n *\n * @remarks\n * The brand that {@link identityOrRawIdentitySchema} trusts to bypass raw-object validation. A\n * {@link WeakSet} keyed by the instance is unforgeable (unlike {@link Identity.isIdentity}, which\n * falls back to a `constructor.name` comparison for cross-realm reach and therefore also accepts a\n * hand-rolled look-alike) and holds no strong reference. Every instance adds itself in the\n * constructor; membership means the instance carries real, intact private fields.\n */\nconst liveIdentities = new WeakSet<object>()\n\n/**\n * Public schema fragment that accepts either a plain {@link RawIdentity} object or an existing\n * {@link Identity} instance.\n *\n * @remarks\n * A genuinely-constructed live {@link Identity} passes through the custom branch UNCHANGED — mirroring\n * {@link @nhtio/adk!Tokenizable.schema}. This matters because Joi's object schema *clones* any value it\n * validates, and cloning an `Identity` produces a look-alike with the right prototype but no private\n * `#identifier` / `#representation` fields (the constructor never ran), which then throws on\n * `[ENCODE_METHOD]`. Returning the live instance verbatim keeps its private state intact so it encodes\n * and re-wraps losslessly.\n *\n * Only a **branded** instance (one this module actually constructed — see {@link liveIdentities})\n * bypasses validation. A bare `constructor.name === 'Identity'` is NOT enough: a look-alike or a\n * cross-realm instance is not in the brand set, so it falls through to {@link rawIdentitySchema},\n * which validates its fields (rejecting a malformed `representation`) rather than retaining an\n * unvalidated husk that would later produce invalid serialized state. Plain {@link RawIdentity}\n * objects fall through the same way.\n */\nconst identityOrRawIdentitySchema = validator\n .alternatives(\n validator.custom((value, helpers) => {\n if (isObject(value) && liveIdentities.has(value)) {\n return value\n }\n return helpers.error('any.invalid')\n }),\n rawIdentitySchema\n )\n .custom((value) => {\n // A genuinely-branded live instance passes through the first alternative untouched. Anything\n // else — a plain RawIdentity, a hand-rolled look-alike, or a FOREIGN/cross-realm `Identity`\n // (a second copy of the package in the dependency tree) — arrives here as the field-validated\n // output of `rawIdentitySchema`. Joi cloned it, so a foreign instance is now a husk that still\n // carries an `Identity`-named prototype but has NO private fields; `Identity.isIdentity` accepts\n // it (name/prototype fallback) yet `[ENCODE_METHOD]` throws reading the missing privates.\n // Rebuild any non-branded value into a genuine LOCAL Identity so every consumer stores real,\n // encodable private state regardless of where the value originated.\n if (isObject(value) && liveIdentities.has(value)) {\n return value\n }\n return new Identity(value as RawIdentity)\n })\n\n/**\n * An immutable, validated participant identity attached to a {@link @nhtio/adk!Message}.\n *\n * @remarks\n * Carries two distinct representations of the same participant: `identifier` is the\n * system-facing key (e.g. a database ID) used to correlate messages programmatically;\n * `representation` is what the model sees when it needs to distinguish between participants\n * sharing the same role. The `representation` is always a {@link @nhtio/adk!Tokenizable} so token cost\n * can be estimated inline.\n */\nexport class Identity {\n /**\n * Validator schema that accepts a {@link RawIdentity} object OR an existing {@link Identity} instance.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest an identity — for example,\n * as a required field inside a message schema. A locally branded {@link Identity} passes through\n * unchanged (its private state is preserved, so it still encodes losslessly); foreign/cross-realm\n * identities and plain {@link RawIdentity} values are validated field-by-field and rebuilt locally.\n * See {@link identityOrRawIdentitySchema}.\n */\n public static schema = identityOrRawIdentitySchema\n\n /**\n * Returns `true` if `value` is an {@link Identity} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is an {@link Identity} instance.\n */\n public static isIdentity(value: unknown): value is Identity {\n return isInstanceOf(value, 'Identity', Identity)\n }\n\n /**\n * The system-facing identifier for this participant — never sent to the model directly.\n */\n declare readonly identifier: string | number\n\n /**\n * How this participant is presented to the model, as a {@link @nhtio/adk!Tokenizable} for inline\n * token estimation.\n */\n declare readonly representation: Tokenizable\n\n #identifier: string | number\n #representation: Tokenizable\n\n /**\n * @param raw - The raw identity input validated against `rawIdentitySchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawIdentity) {\n let resolved: ResolvedIdentity\n try {\n resolved = validateOrThrow<ResolvedIdentity>(rawIdentitySchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_IDENTITY_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#identifier = resolved.identifier\n this.#representation = Tokenizable.isTokenizable(resolved.representation)\n ? resolved.representation\n : new Tokenizable(resolved.representation)\n\n Object.defineProperties(this, {\n identifier: {\n get: () => this.#identifier,\n enumerable: true,\n configurable: false,\n },\n representation: {\n get: () => this.#representation,\n enumerable: true,\n configurable: false,\n },\n })\n\n // Brand this genuinely-constructed instance so `identityOrRawIdentitySchema` can trust it to\n // bypass raw-object validation. A look-alike or cross-realm object is never in this set.\n liveIdentities.add(this)\n }\n\n /**\n * Serialise this Identity into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawIdentity}-shaped object; `representation` is the live {@link @nhtio/adk!Tokenizable}\n * instance (the encoder recurses into it). Round-trips via {@link Identity.[DECODE_METHOD]}, which\n * re-validates through the constructor.\n *\n * @returns A {@link RawIdentity}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n identifier: this.#identifier,\n representation: this.#representation,\n }\n }\n\n /**\n * Reconstruct an {@link Identity} from an {@link Identity.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Identity.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Identity}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Identity {\n return new Identity(data as RawIdentity)\n }\n}\n","import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_MEMORY_VALUE } from '../exceptions/runtime'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport type { DateTime } from 'luxon'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Memory} at construction time.\n *\n * @remarks\n * Validated against `rawMemorySchema` before the `Memory` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawMemory {\n /** Stable unique identifier for this memory entry. */\n id: string\n /** The memory content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. */\n content: string | Tokenizable\n /** Confidence score in the range `[0, 1]` — how certain the agent is that this memory is accurate. */\n confidence: number\n /** Importance score in the range `[0, 1]` — how much weight this memory should carry during retrieval. */\n importance: number\n /** When this memory was first recorded. */\n createdAt: string | number | Date | DateTime\n /** When this memory was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawMemory} where all fields have been validated and temporal values\n * normalised to Luxon `DateTime` instances.\n *\n * @remarks\n * This is the shape returned by `rawMemorySchema` after validation — used internally by the\n * {@link Memory} constructor to assign private fields with guaranteed types.\n */\ninterface ResolvedMemory {\n id: string\n content: Tokenizable\n confidence: number\n importance: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawMemory} before constructing a {@link Memory}.\n *\n * @remarks\n * Validates all six fields of {@link RawMemory}:\n * - `id` — required non-empty string.\n * - `content` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n * - `confidence` — required number in `[0, 1]`.\n * - `importance` — required number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} (via the {@link Memory} constructor) when\n * validation fails.\n */\nconst rawMemorySchema = validator.object<RawMemory>({\n id: validator.string().required(),\n content: Tokenizable.schema.required(),\n confidence: validator.number().min(0).max(1).required(),\n importance: validator.number().min(0).max(1).required(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated memory entry held by the agent.\n *\n * @remarks\n * Constructed from a {@link RawMemory} via `rawMemorySchema`. All temporal fields are\n * normalised to Luxon `DateTime` instances at construction time. The `content` field is\n * always a {@link @nhtio/adk!Tokenizable} so callers can estimate token cost without an additional\n * wrapping step.\n */\nexport class Memory {\n /**\n * Validator schema that accepts a {@link RawMemory} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a memory entry — for\n * example, a collection schema that holds an array of memories.\n */\n public static schema = rawMemorySchema\n\n /**\n * Returns `true` if `value` is a {@link Memory} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Memory} instance.\n */\n public static isMemory(value: unknown): value is Memory {\n return isInstanceOf(value, 'Memory', Memory)\n }\n /** Stable unique identifier for this memory entry. */\n declare readonly id: string\n /** The memory content as a {@link @nhtio/adk!Tokenizable} for inline token estimation. */\n declare readonly content: Tokenizable\n /** Confidence score in the range `[0, 1]`. */\n declare readonly confidence: number\n /** Importance score in the range `[0, 1]`. */\n declare readonly importance: number\n /** When this memory was first recorded. */\n declare readonly createdAt: DateTime\n /** When this memory was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable\n #confidence: number\n #importance: number\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw memory input validated against `rawMemorySchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawMemory) {\n let resolved: ResolvedMemory\n try {\n resolved = validateOrThrow<ResolvedMemory>(rawMemorySchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_MEMORY_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content = Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#confidence = resolved.confidence\n this.#importance = resolved.importance\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n confidence: {\n get: () => this.#confidence,\n enumerable: true,\n configurable: false,\n },\n importance: {\n get: () => this.#importance,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Memory into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawMemory}-shaped object; `content` is the live {@link @nhtio/adk!Tokenizable} and the\n * temporal fields are live Luxon `DateTime` instances (the encoder recurses into both). Round-trips\n * via {@link Memory.[DECODE_METHOD]}, which re-validates through the constructor.\n *\n * @returns A {@link RawMemory}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n content: this.#content,\n confidence: this.#confidence,\n importance: this.#importance,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Memory} from a {@link Memory.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Memory.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Memory}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Memory {\n return new Memory(data as RawMemory)\n }\n}\n","import { Media } from './media'\nimport { Identity } from './identity'\nimport { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_MESSAGE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { RawIdentity } from './identity'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * The roles a {@link Message} author can hold.\n *\n * @remarks\n * Restricted to `user` and `assistant` — system instructions, developer directives, and\n * tool results are handled separately and never appear in the persisted message history.\n */\nexport type MessageRole = 'user' | 'assistant'\n\n/**\n * Plain input object supplied to {@link Message} at construction time.\n *\n * @remarks\n * Validated against `rawMessageSchema` before the `Message` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n *\n * At least one of `content` or `attachments` (non-empty) must be present — a message with\n * neither throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE}.\n */\nexport interface RawMessage {\n /** Stable unique identifier for this message. */\n id: string\n /** Whether this message is from the human participant or the model. */\n role: MessageRole\n /**\n * The message content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Optional — but required when `attachments` is absent or empty. The cross-field rule on\n * `rawMessageSchema` enforces that at least one of `content` or `attachments` is present.\n */\n content?: string | Tokenizable\n /**\n * Media attachments carried by this message — images, audio, video, documents.\n *\n * @remarks\n * Optional and symmetric across roles: both `user` and `assistant` messages may carry\n * attachments. Each attachment carries its own `trustTier` and `modalityHazard`, which the\n * renderer uses to wrap the asset in its own trust envelope independent of the message\n * envelope. How a renderer orders text vs attachments in the on-the-wire content array is\n * a renderer-policy concern, not a contract of {@link Message}.\n */\n attachments?: Media[]\n /**\n * The identity of the participant who authored this message.\n *\n * @remarks\n * Optional. When omitted, the `role` value is used as both the system-facing `identifier`\n * and the model-facing `representation`. Three accepted forms when provided:\n * - A plain `string` — used as both `identifier` and `representation`.\n * - A {@link @nhtio/adk!RawIdentity} object — validated and wrapped into an {@link @nhtio/adk!Identity}.\n * - An existing {@link @nhtio/adk!Identity} instance — passed through unchanged.\n */\n identity?: string | RawIdentity | Identity\n /** When this message was created. */\n createdAt: string | number | Date | DateTime\n /** When this message was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawMessage} where temporal fields have been normalised to Luxon\n * `DateTime` instances and `identity` is a validated {@link @nhtio/adk!Identity}.\n *\n * @remarks\n * Used internally by the {@link Message} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedMessage {\n id: string\n role: MessageRole\n content?: Tokenizable\n attachments: Media[]\n identity: string | RawIdentity | Identity\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawMessage} before constructing a {@link Message}.\n *\n * @remarks\n * Validates all fields of {@link RawMessage}:\n * - `id` — required non-empty string.\n * - `role` — required; must be `'user'` or `'assistant'`.\n * - `content` — optional string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n * - `attachments` — optional array of {@link @nhtio/adk!Media} instances. Defaults to `[]`.\n * - At least one of `content` or `attachments` must be present and non-empty; a message with\n * neither is invalid.\n * - `identity` — required string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; a plain string is\n * mapped to both `identifier` and `representation` automatically.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} (via the {@link Message} constructor) when\n * validation fails.\n */\nconst rawMessageSchema = validator\n .object<RawMessage>({\n id: validator.string().required(),\n role: validator.string().valid('user', 'assistant').required(),\n content: Tokenizable.schema.optional(),\n attachments: validator\n .array()\n .items(\n validator\n .any()\n .required()\n .custom((value, helpers) => {\n if (Media.isMedia(value)) return value\n return helpers.error('any.invalid')\n })\n )\n .default([]),\n identity: validator\n .alternatives(validator.string(), Identity.schema)\n .default(validator.ref('role')),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n })\n .custom((value, helpers) => {\n const resolved = value as ResolvedMessage\n const hasContent = resolved.content !== undefined && resolved.content !== null\n const hasAttachments = Array.isArray(resolved.attachments) && resolved.attachments.length > 0\n if (!hasContent && !hasAttachments) {\n return helpers.error('any.invalid')\n }\n return resolved\n })\n\n/**\n * An immutable, validated conversation message from a human participant or the model.\n *\n * @remarks\n * Covers only `user` and `assistant` roles — system instructions, developer directives, and\n * tool results are not represented here. Constructed from a {@link RawMessage} via\n * `rawMessageSchema`. Temporal fields are normalised to Luxon `DateTime` instances at\n * construction time. Both `content` and `identity.representation` are {@link @nhtio/adk!Tokenizable} so\n * token cost can be estimated inline.\n *\n * A message may carry `content` (text), `attachments` (media), or both. The cross-field rule\n * on `rawMessageSchema` enforces that at least one is present. Downstream code that reaches\n * for `message.content` must handle the attachments-only case where `content` is `undefined`.\n */\nexport class Message {\n /**\n * Validator schema that accepts a {@link RawMessage} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a message entry — for\n * example, a collection schema that holds an array of messages.\n */\n public static schema = rawMessageSchema\n\n /**\n * Returns `true` if `value` is a {@link Message} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Message} instance.\n */\n public static isMessage(value: unknown): value is Message {\n return isInstanceOf(value, 'Message', Message)\n }\n\n /** Stable unique identifier for this message. */\n declare readonly id: string\n /** Whether this message is from the human participant or the model. */\n declare readonly role: MessageRole\n /**\n * The message content as a {@link @nhtio/adk!Tokenizable} for inline token estimation, or `undefined`\n * for attachments-only messages.\n *\n * @remarks\n * `undefined` when the message was constructed with only `attachments`. Render code that\n * needs the text portion must guard for the missing case rather than blindly calling\n * `message.content.toString()`.\n */\n declare readonly content: Tokenizable | undefined\n /**\n * Media attachments carried by this message.\n *\n * @remarks\n * Always defined as a frozen array — empty when the message has no attachments. Both\n * `user` and `assistant` messages may carry attachments. Each entry carries its own\n * `trustTier` and `modalityHazard`; the renderer wraps each in its own trust envelope\n * independent of the message envelope.\n */\n declare readonly attachments: ReadonlyArray<Media>\n /** The identity of the participant who authored this message. */\n declare readonly identity: Identity\n /** When this message was created. */\n declare readonly createdAt: DateTime\n /** When this message was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #role: MessageRole\n #content: Tokenizable | undefined\n #attachments: ReadonlyArray<Media>\n #identity: Identity\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw message input validated against `rawMessageSchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} when `raw` does not satisfy the schema —\n * including the cross-field rule that at least one of `content` or `attachments` must be\n * present and non-empty.\n */\n constructor(raw: RawMessage) {\n let resolved: ResolvedMessage\n try {\n resolved = validateOrThrow<ResolvedMessage>(rawMessageSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_MESSAGE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#role = resolved.role\n this.#content =\n resolved.content === undefined || resolved.content === null\n ? undefined\n : Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#attachments = Object.freeze([...(resolved.attachments ?? [])])\n const rawIdentity = resolved.identity\n this.#identity = Identity.isIdentity(rawIdentity)\n ? rawIdentity\n : typeof rawIdentity === 'string'\n ? new Identity({ identifier: rawIdentity, representation: rawIdentity })\n : new Identity(rawIdentity)\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n role: {\n get: () => this.#role,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n attachments: {\n get: () => this.#attachments,\n enumerable: true,\n configurable: false,\n },\n identity: {\n get: () => this.#identity,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Message into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawMessage}-shaped object holding the live nested primitives — `content`\n * ({@link @nhtio/adk!Tokenizable}), `attachments` ({@link @nhtio/adk!Media}[]), `identity`\n * ({@link @nhtio/adk!Identity}), and Luxon temporal fields — which the encoder recurses into. A\n * text-only message round-trips trivially; a message carrying {@link @nhtio/adk!Media} round-trips only\n * if each attachment's reader is describable (a `fromWebFile`-backed attachment throws\n * {@link @nhtio/adk!E_READER_NOT_DESCRIBABLE} at encode). The frozen attachments array is copied to a\n * plain array for the snapshot. Round-trips via {@link Message.[DECODE_METHOD]}.\n *\n * @returns A {@link RawMessage}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n role: this.#role,\n content: this.#content,\n // Omit when empty: the schema's cross-field rule treats a present-but-empty `attachments`\n // array as invalid (it must contain ≥1 entry when supplied). A text-only message has none.\n ...(this.#attachments.length > 0 ? { attachments: [...this.#attachments] } : {}),\n identity: this.#identity,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Message} from a {@link Message.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Message.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Message}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Message {\n return new Message(data as RawMessage)\n }\n}\n","import { Identity } from './identity'\nimport { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { ENCODE_METHOD, DECODE_METHOD } from '../utils/encoder_symbols'\nimport { E_INVALID_INITIAL_THOUGHT_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { RawIdentity } from './identity'\nimport type { AdkEncodableSnapshot } from './encodable'\n\n/**\n * Plain input object supplied to {@link Thought} at construction time.\n *\n * @remarks\n * Validated against `rawThoughtSchema` before the `Thought` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawThought {\n /** Stable unique identifier for this thought. */\n id: string\n /**\n * The reasoning content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Required and non-empty in plain-text mode. In opaque mode ({@link RawThought.payload} present) it\n * may be empty or omitted — the payload carries the meaning — and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}. `Thought.content` is therefore ALWAYS a `Tokenizable`, never\n * `undefined`, so readers need no guard.\n */\n content?: string | Tokenizable\n /**\n * The identity of the agent who produced this thought.\n *\n * @remarks\n * Required in multi-agent conversations to attribute reasoning traces to a specific agent.\n * Three accepted forms when provided:\n * - A plain `string` — used as both `identifier` and `representation`.\n * - A {@link @nhtio/adk!RawIdentity} object — validated and wrapped into an {@link @nhtio/adk!Identity}.\n * - An existing {@link @nhtio/adk!Identity} instance — passed through unchanged.\n *\n * When omitted, defaults to `'assistant'` (both `identifier` and `representation`).\n */\n identity?: string | RawIdentity | Identity\n /**\n * Optional vendor-opaque payload that round-trips back to a matching model wire.\n *\n * @remarks\n * Carries anything the ADK cannot interpret but a specific provider can — for example,\n * an Anthropic Messages thinking-block `signature`, an OpenAI Responses\n * `ResponseReasoningItem.encrypted_content` blob, a DeepSeek server-side reasoning handle,\n * or an MCP-mediated reasoning item.\n *\n * When present, an LLM battery MUST treat the thought as **opaque-mode**: do NOT inline\n * `content` through the plain `<thought>` envelope; serialise `payload` back to the wire in\n * whichever shape the matching {@link RawThought.replayCompatibility} identifier specifies.\n * The plain-text `content` is kept alongside for token-accounting and human/observer\n * inspection — it is not the thing the model sees.\n *\n * Cross-field invariant: a present `payload` REQUIRES a present {@link RawThought.replayCompatibility}.\n * A `payload` without `replayCompatibility` is malformed (the ADK has no way to know\n * which adapter can consume it) and {@link Thought.schema} rejects with\n * {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE}.\n *\n * @defaultValue `undefined`\n */\n payload?: unknown\n /**\n * Optional free-form identifier describing which adapter wire-shape this thought can be\n * safely replayed into.\n *\n * @remarks\n * Examples (none of these are reserved by the ADK — they are consumer conventions):\n * - `'plain-text'` — replayable into every LLM battery\n * - `'anthropic-messages-thinking-v1'`\n * - `'openai-responses-reasoning-item-v1'`\n * - `'deepseek-reasoning-handle-v1'`\n *\n * LLM batteries declare via constructor option which tags they can safely replay; matching\n * opaque thoughts are routed to the wire's typed reasoning channel where it exists, or to a\n * documented side-channel key on the request body where the wire has none. Non-matching\n * opaque thoughts are elided from the current dispatch but NOT removed from\n * `ctx.turnThoughts` — they remain in context so a subsequent dispatch to a different\n * adapter that DOES declare the matching tag can pick them up.\n *\n * Plain-text thoughts (`payload === undefined` AND `replayCompatibility === undefined`, or\n * explicit `replayCompatibility: 'plain-text'`) are always replayable.\n *\n * A `replayCompatibility` without a `payload` is allowed — it documents intent (\"this\n * plain-text thought is only meaningful to a specific fine-tuned variant\") without\n * requiring an opaque blob.\n *\n * @defaultValue `undefined`\n */\n replayCompatibility?: string\n /** When this thought was recorded. */\n createdAt: string | number | Date | DateTime\n /** When this thought was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawThought} where temporal fields have been normalised to Luxon\n * `DateTime` instances.\n *\n * @remarks\n * Used internally by the {@link Thought} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedThought {\n id: string\n content?: string | Tokenizable\n identity: string | RawIdentity | Identity\n payload?: unknown\n replayCompatibility?: string\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawThought} before constructing a {@link Thought}.\n *\n * @remarks\n * Validates all fields of {@link RawThought}:\n * - `id` — required non-empty string.\n * - `content` — string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.emptyableSchema}.\n * Required and non-empty in plain-text mode; may be empty or omitted in opaque mode (see the\n * content-OR-payload rule below).\n * - `identity` — optional string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; defaults to\n * `'assistant'` when omitted.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Cross-field rule — a thought must carry meaning through EITHER its prose OR an opaque replay\n * `payload`. A NULLISH payload (`undefined` or `null`) carries no replay data and so counts as ABSENT\n * for both halves of the rule:\n * - `payload` ABSENT (plain-text mode) — `content` is REQUIRED and must be non-empty. The prose is\n * the only thing the thought has; an empty one is indistinguishable from a bug.\n * - `payload` PRESENT (opaque mode) — `content` may be empty or omitted, and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}. The payload is what round-trips to the wire; `content` is kept only\n * for token-accounting and human/observer inspection (see {@link RawThought.payload}), so a\n * signed-but-textless provider thinking block is legitimate. Rejecting it would discard the\n * payload's replay data — strictly worse than storing a thought with no prose.\n *\n * A present `payload` additionally REQUIRES a present `replayCompatibility`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} (via the {@link Thought} constructor) when\n * validation fails.\n */\nconst rawThoughtSchema = validator\n .object<RawThought>({\n id: validator.string().required(),\n // Emptiness is adjudicated by the cross-field rule below, which needs to see `payload` to decide.\n content: Tokenizable.emptyableSchema.optional(),\n identity: validator.alternatives(validator.string(), Identity.schema).default('assistant'),\n payload: validator.any().optional(),\n replayCompatibility: validator.string().min(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n })\n .custom((value, helpers) => {\n const v = value as RawThought\n // A NULLISH payload carries no replay data, so it is opaque mode in NEITHER rule below. `null`\n // reaches here easily — JSON round-tripping, a serializer normalising absent fields, a provider\n // mapper assigning a nullish thinking block — and treating it as \"present\" would both demand a\n // pointless `replayCompatibility` and, worse, waive the content requirement for a thought that has\n // no prose AND no payload: the exact state the either-or exists to forbid.\n const hasPayload = v.payload !== undefined && v.payload !== null\n if (hasPayload && (v.replayCompatibility === undefined || v.replayCompatibility === null)) {\n return helpers.error('any.invalid')\n }\n // content-OR-payload: only an opaque thought may go without prose. A Tokenizable counts as\n // present without being unwrapped — a dynamic one would evaluate its callback just to be measured,\n // and its emptiness is not knowable until prompt-assembly anyway.\n if (!hasPayload) {\n const hasContent = Tokenizable.isTokenizable(v.content)\n ? true\n : typeof v.content === 'string' && v.content.length > 0\n if (!hasContent) {\n return helpers.error('any.invalid')\n }\n }\n return value\n })\n\n/**\n * An immutable, validated internal reasoning trace produced by an agent.\n *\n * @remarks\n * Represents an agent's internal thinking — distinct from {@link @nhtio/adk!Message} (which is part of\n * the visible conversation) and never shown to end users directly. Carries an `identity` so\n * reasoning traces can be attributed to a specific agent in multi-agent conversations.\n * Constructed from a {@link RawThought} via `rawThoughtSchema`. The `content` field is always\n * a {@link @nhtio/adk!Tokenizable} so token cost can be estimated inline — including when the raw input\n * omitted it or supplied `''`, which is legal in opaque-replay mode and resolves to an empty\n * {@link @nhtio/adk!Tokenizable}.\n */\nexport class Thought {\n /**\n * Validator schema that accepts a {@link RawThought} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a thought entry.\n */\n public static schema = rawThoughtSchema\n\n /**\n * Returns `true` if `value` is a {@link Thought} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Thought} instance.\n */\n public static isThought(value: unknown): value is Thought {\n return isInstanceOf(value, 'Thought', Thought)\n }\n\n /** Stable unique identifier for this thought. */\n declare readonly id: string\n /**\n * The reasoning content as a {@link @nhtio/adk!Tokenizable} for inline token estimation.\n *\n * @remarks\n * Never `undefined` — an opaque thought constructed without prose carries an empty\n * {@link @nhtio/adk!Tokenizable} here, so readers need no presence guard.\n */\n declare readonly content: Tokenizable\n /** The identity of the agent who produced this thought. */\n declare readonly identity: Identity\n /**\n * Optional vendor-opaque payload that round-trips back to a matching model wire.\n * See {@link RawThought.payload}.\n */\n declare readonly payload: unknown\n /**\n * Optional wire-shape identifier describing which adapter can safely replay this thought.\n * See {@link RawThought.replayCompatibility}.\n */\n declare readonly replayCompatibility: string | undefined\n /** When this thought was recorded. */\n declare readonly createdAt: DateTime\n /** When this thought was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable\n #identity: Identity\n #payload: unknown\n #replayCompatibility: string | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw thought input validated against `rawThoughtSchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawThought) {\n let resolved: ResolvedThought\n try {\n resolved = validateOrThrow<ResolvedThought>(rawThoughtSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_THOUGHT_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n // Absent content is legal only in opaque mode (enforced by rawThoughtSchema). Resolve it to an\n // EMPTY Tokenizable rather than leaving it undefined so `content` stays a total field — every\n // reader can call `.toString()` / measure it without a guard.\n this.#content = Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content ?? '')\n const rawIdentity = resolved.identity\n this.#identity = Identity.isIdentity(rawIdentity)\n ? rawIdentity\n : typeof rawIdentity === 'string'\n ? new Identity({ identifier: rawIdentity, representation: rawIdentity })\n : new Identity(rawIdentity)\n this.#payload = resolved.payload\n this.#replayCompatibility = resolved.replayCompatibility\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n identity: {\n get: () => this.#identity,\n enumerable: true,\n configurable: false,\n },\n payload: {\n get: () => this.#payload,\n enumerable: true,\n configurable: false,\n },\n replayCompatibility: {\n get: () => this.#replayCompatibility,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Serialise this Thought into an `@nhtio/encoder` snapshot.\n *\n * @remarks\n * Emits a {@link RawThought}-shaped object; `content` is the live {@link @nhtio/adk!Tokenizable},\n * `identity` the live {@link @nhtio/adk!Identity}, and the temporal fields live Luxon `DateTime`s (the\n * encoder recurses into each). The vendor-opaque `payload` is passed through as-is — if it holds a\n * value the encoder cannot serialise, encode throws (standard encoder behaviour). Round-trips via\n * {@link Thought.[DECODE_METHOD]}, which re-validates through the constructor.\n *\n * @returns A {@link RawThought}-shaped snapshot.\n */\n [ENCODE_METHOD](): AdkEncodableSnapshot {\n return {\n id: this.#id,\n content: this.#content,\n identity: this.#identity,\n payload: this.#payload,\n replayCompatibility: this.#replayCompatibility,\n createdAt: this.#createdAt,\n updatedAt: this.#updatedAt,\n }\n }\n\n /**\n * Reconstruct a {@link Thought} from a {@link Thought.[ENCODE_METHOD]} snapshot.\n *\n * @param data - The snapshot produced by {@link Thought.[ENCODE_METHOD]}.\n * @returns A fully-validated {@link Thought}.\n */\n static [DECODE_METHOD](data: AdkEncodableSnapshot): Thought {\n return new Thought(data as RawThought)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyDA,IAAM,oBAAoB,kBAAA,UAAU,OAAoB;CACtD,YAAY,kBAAA,UAAU,aAAa,kBAAA,UAAU,OAAO,GAAG,kBAAA,UAAU,OAAO,CAAC,EAAE,SAAS;CACpF,gBAAgB,oBAAA,YAAY,OAAO,SAAS;AAC9C,CAAC;;;;;;;;;;;AAYD,IAAM,iCAAiB,IAAI,QAAgB;;;;;;;;;;;;;;;;;;;;AAqB3C,IAAM,8BAA8B,kBAAA,UACjC,aACC,kBAAA,UAAU,QAAQ,OAAO,YAAY;CACnC,IAAI,eAAA,SAAS,KAAK,KAAK,eAAe,IAAI,KAAK,GAC7C,OAAO;CAET,OAAO,QAAQ,MAAM,aAAa;AACpC,CAAC,GACD,iBACF,EACC,QAAQ,UAAU;CASjB,IAAI,eAAA,SAAS,KAAK,KAAK,eAAe,IAAI,KAAK,GAC7C,OAAO;CAET,OAAO,IAAI,SAAS,KAAoB;AAC1C,CAAC;;;;;;;;;;;AAYH,IAAa,WAAb,MAAa,SAAS;;;;;;;;;;;CAWpB,OAAc,SAAS;;;;;;;;;;;CAYvB,OAAc,WAAW,OAAmC;EAC1D,OAAO,eAAA,aAAa,OAAO,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