@nhtio/adk 0.1.0-master-f0aa531d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +3 -0
  3. package/batteries/index.d.ts +28 -0
  4. package/batteries/llm/index.d.ts +11 -0
  5. package/batteries/llm/openai_chat_completions/adapter.cjs +916 -0
  6. package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -0
  7. package/batteries/llm/openai_chat_completions/adapter.d.ts +101 -0
  8. package/batteries/llm/openai_chat_completions/adapter.mjs +914 -0
  9. package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -0
  10. package/batteries/llm/openai_chat_completions/exceptions.cjs +89 -0
  11. package/batteries/llm/openai_chat_completions/exceptions.cjs.map +1 -0
  12. package/batteries/llm/openai_chat_completions/exceptions.d.ts +97 -0
  13. package/batteries/llm/openai_chat_completions/exceptions.mjs +81 -0
  14. package/batteries/llm/openai_chat_completions/exceptions.mjs.map +1 -0
  15. package/batteries/llm/openai_chat_completions/helpers.cjs +819 -0
  16. package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -0
  17. package/batteries/llm/openai_chat_completions/helpers.d.ts +233 -0
  18. package/batteries/llm/openai_chat_completions/helpers.mjs +783 -0
  19. package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -0
  20. package/batteries/llm/openai_chat_completions/index.d.ts +27 -0
  21. package/batteries/llm/openai_chat_completions/types.cjs +1 -0
  22. package/batteries/llm/openai_chat_completions/types.d.ts +524 -0
  23. package/batteries/llm/openai_chat_completions/types.mjs +0 -0
  24. package/batteries/llm/openai_chat_completions/validation.cjs +190 -0
  25. package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -0
  26. package/batteries/llm/openai_chat_completions/validation.d.ts +31 -0
  27. package/batteries/llm/openai_chat_completions/validation.mjs +187 -0
  28. package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -0
  29. package/batteries/llm/openai_chat_completions.cjs +51 -0
  30. package/batteries/llm/openai_chat_completions.mjs +5 -0
  31. package/batteries/llm/webllm_chat_completions/adapter.cjs +658 -0
  32. package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -0
  33. package/batteries/llm/webllm_chat_completions/adapter.d.ts +103 -0
  34. package/batteries/llm/webllm_chat_completions/adapter.mjs +656 -0
  35. package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -0
  36. package/batteries/llm/webllm_chat_completions/exceptions.cjs +70 -0
  37. package/batteries/llm/webllm_chat_completions/exceptions.cjs.map +1 -0
  38. package/batteries/llm/webllm_chat_completions/exceptions.d.ts +74 -0
  39. package/batteries/llm/webllm_chat_completions/exceptions.mjs +65 -0
  40. package/batteries/llm/webllm_chat_completions/exceptions.mjs.map +1 -0
  41. package/batteries/llm/webllm_chat_completions/helpers.cjs +38 -0
  42. package/batteries/llm/webllm_chat_completions/helpers.d.ts +6 -0
  43. package/batteries/llm/webllm_chat_completions/helpers.mjs +2 -0
  44. package/batteries/llm/webllm_chat_completions/index.d.ts +25 -0
  45. package/batteries/llm/webllm_chat_completions/types.d.ts +31 -0
  46. package/batteries/llm/webllm_chat_completions/validation.cjs +115 -0
  47. package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -0
  48. package/batteries/llm/webllm_chat_completions/validation.d.ts +8 -0
  49. package/batteries/llm/webllm_chat_completions/validation.mjs +112 -0
  50. package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -0
  51. package/batteries/llm/webllm_chat_completions.cjs +50 -0
  52. package/batteries/llm/webllm_chat_completions.mjs +6 -0
  53. package/batteries/llm.cjs +63 -0
  54. package/batteries/llm.mjs +10 -0
  55. package/batteries/storage/flydrive/index.d.ts +167 -0
  56. package/batteries/storage/flydrive.cjs +249 -0
  57. package/batteries/storage/flydrive.cjs.map +1 -0
  58. package/batteries/storage/flydrive.mjs +249 -0
  59. package/batteries/storage/flydrive.mjs.map +1 -0
  60. package/batteries/storage/in_memory/index.d.ts +106 -0
  61. package/batteries/storage/in_memory.cjs +121 -0
  62. package/batteries/storage/in_memory.cjs.map +1 -0
  63. package/batteries/storage/in_memory.mjs +119 -0
  64. package/batteries/storage/in_memory.mjs.map +1 -0
  65. package/batteries/storage/index.d.ts +18 -0
  66. package/batteries/storage/opfs/index.d.ts +299 -0
  67. package/batteries/storage/opfs.cjs +368 -0
  68. package/batteries/storage/opfs.cjs.map +1 -0
  69. package/batteries/storage/opfs.mjs +366 -0
  70. package/batteries/storage/opfs.mjs.map +1 -0
  71. package/batteries/storage.cjs +4 -0
  72. package/batteries/storage.mjs +2 -0
  73. package/batteries/tools/color/index.d.ts +37 -0
  74. package/batteries/tools/color.cjs +659 -0
  75. package/batteries/tools/color.cjs.map +1 -0
  76. package/batteries/tools/color.mjs +655 -0
  77. package/batteries/tools/color.mjs.map +1 -0
  78. package/batteries/tools/comparison/index.d.ts +29 -0
  79. package/batteries/tools/comparison.cjs +171 -0
  80. package/batteries/tools/comparison.cjs.map +1 -0
  81. package/batteries/tools/comparison.mjs +168 -0
  82. package/batteries/tools/comparison.mjs.map +1 -0
  83. package/batteries/tools/data_structure/index.d.ts +30 -0
  84. package/batteries/tools/data_structure.cjs +270 -0
  85. package/batteries/tools/data_structure.cjs.map +1 -0
  86. package/batteries/tools/data_structure.mjs +267 -0
  87. package/batteries/tools/data_structure.mjs.map +1 -0
  88. package/batteries/tools/datetime_extended/index.d.ts +51 -0
  89. package/batteries/tools/datetime_extended.cjs +309 -0
  90. package/batteries/tools/datetime_extended.cjs.map +1 -0
  91. package/batteries/tools/datetime_extended.mjs +302 -0
  92. package/batteries/tools/datetime_extended.mjs.map +1 -0
  93. package/batteries/tools/datetime_math/index.d.ts +36 -0
  94. package/batteries/tools/datetime_math.cjs +175 -0
  95. package/batteries/tools/datetime_math.cjs.map +1 -0
  96. package/batteries/tools/datetime_math.mjs +171 -0
  97. package/batteries/tools/datetime_math.mjs.map +1 -0
  98. package/batteries/tools/encoding/index.d.ts +36 -0
  99. package/batteries/tools/encoding.cjs +156 -0
  100. package/batteries/tools/encoding.cjs.map +1 -0
  101. package/batteries/tools/encoding.mjs +152 -0
  102. package/batteries/tools/encoding.mjs.map +1 -0
  103. package/batteries/tools/formatting/index.d.ts +28 -0
  104. package/batteries/tools/formatting.cjs +120 -0
  105. package/batteries/tools/formatting.cjs.map +1 -0
  106. package/batteries/tools/formatting.mjs +117 -0
  107. package/batteries/tools/formatting.mjs.map +1 -0
  108. package/batteries/tools/geo_basics/index.d.ts +33 -0
  109. package/batteries/tools/geo_basics.cjs +136 -0
  110. package/batteries/tools/geo_basics.cjs.map +1 -0
  111. package/batteries/tools/geo_basics.mjs +132 -0
  112. package/batteries/tools/geo_basics.mjs.map +1 -0
  113. package/batteries/tools/index.d.ts +32 -0
  114. package/batteries/tools/math/index.d.ts +37 -0
  115. package/batteries/tools/math.cjs +136 -0
  116. package/batteries/tools/math.cjs.map +1 -0
  117. package/batteries/tools/math.mjs +133 -0
  118. package/batteries/tools/math.mjs.map +1 -0
  119. package/batteries/tools/memory/index.d.ts +73 -0
  120. package/batteries/tools/memory.cjs +193 -0
  121. package/batteries/tools/memory.cjs.map +1 -0
  122. package/batteries/tools/memory.mjs +187 -0
  123. package/batteries/tools/memory.mjs.map +1 -0
  124. package/batteries/tools/parsing/index.d.ts +47 -0
  125. package/batteries/tools/parsing.cjs +191 -0
  126. package/batteries/tools/parsing.cjs.map +1 -0
  127. package/batteries/tools/parsing.mjs +185 -0
  128. package/batteries/tools/parsing.mjs.map +1 -0
  129. package/batteries/tools/retrievables/index.d.ts +81 -0
  130. package/batteries/tools/retrievables.cjs +215 -0
  131. package/batteries/tools/retrievables.cjs.map +1 -0
  132. package/batteries/tools/retrievables.mjs +209 -0
  133. package/batteries/tools/retrievables.mjs.map +1 -0
  134. package/batteries/tools/standing_instructions/index.d.ts +64 -0
  135. package/batteries/tools/standing_instructions.cjs +126 -0
  136. package/batteries/tools/standing_instructions.cjs.map +1 -0
  137. package/batteries/tools/standing_instructions.mjs +121 -0
  138. package/batteries/tools/standing_instructions.mjs.map +1 -0
  139. package/batteries/tools/statistics/index.d.ts +46 -0
  140. package/batteries/tools/statistics.cjs +253 -0
  141. package/batteries/tools/statistics.cjs.map +1 -0
  142. package/batteries/tools/statistics.mjs +248 -0
  143. package/batteries/tools/statistics.mjs.map +1 -0
  144. package/batteries/tools/string_processing/index.d.ts +29 -0
  145. package/batteries/tools/string_processing.cjs +154 -0
  146. package/batteries/tools/string_processing.cjs.map +1 -0
  147. package/batteries/tools/string_processing.mjs +151 -0
  148. package/batteries/tools/string_processing.mjs.map +1 -0
  149. package/batteries/tools/structured_data/index.d.ts +34 -0
  150. package/batteries/tools/structured_data.cjs +189 -0
  151. package/batteries/tools/structured_data.cjs.map +1 -0
  152. package/batteries/tools/structured_data.mjs +185 -0
  153. package/batteries/tools/structured_data.mjs.map +1 -0
  154. package/batteries/tools/text_analysis/index.d.ts +31 -0
  155. package/batteries/tools/text_analysis.cjs +120 -0
  156. package/batteries/tools/text_analysis.cjs.map +1 -0
  157. package/batteries/tools/text_analysis.mjs +117 -0
  158. package/batteries/tools/text_analysis.mjs.map +1 -0
  159. package/batteries/tools/text_comparison/index.d.ts +28 -0
  160. package/batteries/tools/text_comparison.cjs +96 -0
  161. package/batteries/tools/text_comparison.cjs.map +1 -0
  162. package/batteries/tools/text_comparison.mjs +93 -0
  163. package/batteries/tools/text_comparison.mjs.map +1 -0
  164. package/batteries/tools/time/index.d.ts +27 -0
  165. package/batteries/tools/time.cjs +63 -0
  166. package/batteries/tools/time.cjs.map +1 -0
  167. package/batteries/tools/time.mjs +60 -0
  168. package/batteries/tools/time.mjs.map +1 -0
  169. package/batteries/tools/unit_conversion/index.d.ts +19 -0
  170. package/batteries/tools/unit_conversion.cjs +452 -0
  171. package/batteries/tools/unit_conversion.cjs.map +1 -0
  172. package/batteries/tools/unit_conversion.mjs +450 -0
  173. package/batteries/tools/unit_conversion.mjs.map +1 -0
  174. package/batteries/tools.cjs +80 -0
  175. package/batteries/tools.mjs +21 -0
  176. package/batteries.cjs +142 -0
  177. package/batteries.mjs +30 -0
  178. package/chunk-KmRHZBOW.js +35 -0
  179. package/common-DeZaonK1.mjs +208 -0
  180. package/common-DeZaonK1.mjs.map +1 -0
  181. package/common-Od8edUXU.js +232 -0
  182. package/common-Od8edUXU.js.map +1 -0
  183. package/common.cjs +31 -0
  184. package/common.d.ts +108 -0
  185. package/common.mjs +8 -0
  186. package/dispatch_runner-9j6bXHL3.mjs +1609 -0
  187. package/dispatch_runner-9j6bXHL3.mjs.map +1 -0
  188. package/dispatch_runner-CsoH0nld.js +1627 -0
  189. package/dispatch_runner-CsoH0nld.js.map +1 -0
  190. package/dispatch_runner.cjs +3 -0
  191. package/dispatch_runner.d.ts +17 -0
  192. package/dispatch_runner.mjs +2 -0
  193. package/exceptions-D5YrO9Vm.js +280 -0
  194. package/exceptions-D5YrO9Vm.js.map +1 -0
  195. package/exceptions-NrzIHw_R.mjs +244 -0
  196. package/exceptions-NrzIHw_R.mjs.map +1 -0
  197. package/exceptions.cjs +33 -0
  198. package/exceptions.d.ts +52 -0
  199. package/exceptions.mjs +3 -0
  200. package/factories.cjs +4 -0
  201. package/factories.d.ts +39 -0
  202. package/factories.mjs +2 -0
  203. package/forge.cjs +9 -0
  204. package/forge.d.ts +49 -0
  205. package/forge.mjs +5 -0
  206. package/guards.cjs +96 -0
  207. package/guards.cjs.map +1 -0
  208. package/guards.d.ts +83 -0
  209. package/guards.mjs +72 -0
  210. package/guards.mjs.map +1 -0
  211. package/index.cjs +107 -0
  212. package/index.cjs.map +1 -0
  213. package/index.d.ts +18 -0
  214. package/index.mjs +31 -0
  215. package/index.mjs.map +1 -0
  216. package/lib/classes/artifact_tool.d.ts +129 -0
  217. package/lib/classes/base_exception.d.ts +83 -0
  218. package/lib/classes/identity.d.ts +71 -0
  219. package/lib/classes/media.d.ts +326 -0
  220. package/lib/classes/memory.d.ts +72 -0
  221. package/lib/classes/message.d.ts +137 -0
  222. package/lib/classes/registry.d.ts +79 -0
  223. package/lib/classes/retrievable.d.ts +100 -0
  224. package/lib/classes/spooled_artifact.d.ts +296 -0
  225. package/lib/classes/spooled_json_artifact.d.ts +158 -0
  226. package/lib/classes/spooled_markdown_artifact.d.ts +202 -0
  227. package/lib/classes/thought.d.ts +142 -0
  228. package/lib/classes/tokenizable.d.ts +124 -0
  229. package/lib/classes/tool.d.ts +228 -0
  230. package/lib/classes/tool_call.d.ts +190 -0
  231. package/lib/classes/tool_registry.d.ts +159 -0
  232. package/lib/classes/turn_gate.d.ts +109 -0
  233. package/lib/contracts/dispatch_context.d.ts +345 -0
  234. package/lib/contracts/media_reader.d.ts +60 -0
  235. package/lib/contracts/spool_reader.d.ts +80 -0
  236. package/lib/contracts/spooled_artifact_constructor.d.ts +38 -0
  237. package/lib/contracts/turn_runner_config.d.ts +101 -0
  238. package/lib/contracts/turn_runner_context.d.ts +267 -0
  239. package/lib/dispatch_runner.d.ts +98 -0
  240. package/lib/exceptions/runtime.d.ts +370 -0
  241. package/lib/helpers/media_readers.d.ts +39 -0
  242. package/lib/turn_runner.d.ts +144 -0
  243. package/lib/types/dispatch_context.d.ts +233 -0
  244. package/lib/types/dispatch_runner.d.ts +387 -0
  245. package/lib/types/turn_runner.d.ts +322 -0
  246. package/lib/utils/canonical_json.d.ts +18 -0
  247. package/lib/utils/exceptions.d.ts +78 -0
  248. package/lib/utils/guards.d.ts +32 -0
  249. package/lib/utils/validation.d.ts +77 -0
  250. package/package.json +334 -0
  251. package/runtime-BJVkrGQe.js +519 -0
  252. package/runtime-BJVkrGQe.js.map +1 -0
  253. package/runtime-CrEPIFgr.mjs +346 -0
  254. package/runtime-CrEPIFgr.mjs.map +1 -0
  255. package/skills/adk-assembly/SKILL.md +109 -0
  256. package/skills/adk-assembly/references/assembly-contract.md +66 -0
  257. package/skills/adk-assembly/references/executors-tools-pipelines-events.md +113 -0
  258. package/skills/adk-assembly/references/first-integration.md +93 -0
  259. package/skills/adk-assembly/references/storage-and-context.md +102 -0
  260. package/spooled_artifact-C5ZtGxuJ.mjs +544 -0
  261. package/spooled_artifact-C5ZtGxuJ.mjs.map +1 -0
  262. package/spooled_artifact-Cm9Te22K.js +568 -0
  263. package/spooled_artifact-Cm9Te22K.js.map +1 -0
  264. package/spooled_artifact.cjs +7 -0
  265. package/spooled_artifact.d.ts +40 -0
  266. package/spooled_artifact.mjs +3 -0
  267. package/spooled_markdown_artifact-BpUJol0W.mjs +771 -0
  268. package/spooled_markdown_artifact-BpUJol0W.mjs.map +1 -0
  269. package/spooled_markdown_artifact-RRB113sy.js +786 -0
  270. package/spooled_markdown_artifact-RRB113sy.js.map +1 -0
  271. package/thought-CDb457b4.mjs +470 -0
  272. package/thought-CDb457b4.mjs.map +1 -0
  273. package/thought-DuN2PgdO.js +494 -0
  274. package/thought-DuN2PgdO.js.map +1 -0
  275. package/tool-COSeH8I6.js +302 -0
  276. package/tool-COSeH8I6.js.map +1 -0
  277. package/tool-D2WB1EA1.mjs +296 -0
  278. package/tool-D2WB1EA1.mjs.map +1 -0
  279. package/tool_call-BKyyxGaZ.mjs +578 -0
  280. package/tool_call-BKyyxGaZ.mjs.map +1 -0
  281. package/tool_call-DFgzcVcU.js +608 -0
  282. package/tool_call-DFgzcVcU.js.map +1 -0
  283. package/tool_registry-Dkfprsck.js +641 -0
  284. package/tool_registry-Dkfprsck.js.map +1 -0
  285. package/tool_registry-DqLOyGyG.mjs +592 -0
  286. package/tool_registry-DqLOyGyG.mjs.map +1 -0
  287. package/turn_runner-CMm2BHdX.js +615 -0
  288. package/turn_runner-CMm2BHdX.js.map +1 -0
  289. package/turn_runner-y7eyEcJH.mjs +603 -0
  290. package/turn_runner-y7eyEcJH.mjs.map +1 -0
  291. package/turn_runner.cjs +3 -0
  292. package/turn_runner.d.ts +21 -0
  293. package/turn_runner.mjs +2 -0
  294. package/types.cjs +1 -0
  295. package/types.d.ts +56 -0
  296. package/types.mjs +0 -0
  297. package/vite-env.d.ts +23 -0
@@ -0,0 +1,142 @@
1
+ import { Identity } from "./identity";
2
+ import { Tokenizable } from "./tokenizable";
3
+ import type { DateTime } from 'luxon';
4
+ import type { RawIdentity } from "./identity";
5
+ /**
6
+ * Plain input object supplied to {@link Thought} at construction time.
7
+ *
8
+ * @remarks
9
+ * Validated against `rawThoughtSchema` before the `Thought` instance is created.
10
+ * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,
11
+ * `Date` objects, or existing `DateTime` instances.
12
+ */
13
+ export interface RawThought {
14
+ /** Stable unique identifier for this thought. */
15
+ id: string;
16
+ /** The reasoning content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. */
17
+ content: string | Tokenizable;
18
+ /**
19
+ * The identity of the agent who produced this thought.
20
+ *
21
+ * @remarks
22
+ * Required in multi-agent conversations to attribute reasoning traces to a specific agent.
23
+ * Three accepted forms when provided:
24
+ * - A plain `string` — used as both `identifier` and `representation`.
25
+ * - A {@link @nhtio/adk!RawIdentity} object — validated and wrapped into an {@link @nhtio/adk!Identity}.
26
+ * - An existing {@link @nhtio/adk!Identity} instance — passed through unchanged.
27
+ *
28
+ * When omitted, defaults to `'assistant'` (both `identifier` and `representation`).
29
+ */
30
+ identity?: string | RawIdentity | Identity;
31
+ /**
32
+ * Optional vendor-opaque payload that round-trips back to a matching model wire.
33
+ *
34
+ * @remarks
35
+ * Carries anything the ADK cannot interpret but a specific provider can — for example,
36
+ * an Anthropic Messages thinking-block `signature`, an OpenAI Responses
37
+ * `ResponseReasoningItem.encrypted_content` blob, a DeepSeek server-side reasoning handle,
38
+ * or an MCP-mediated reasoning item.
39
+ *
40
+ * When present, an LLM battery MUST treat the thought as **opaque-mode**: do NOT inline
41
+ * `content` through the plain `<thought>` envelope; serialise `payload` back to the wire in
42
+ * whichever shape the matching {@link RawThought.replayCompatibility} identifier specifies.
43
+ * The plain-text `content` is kept alongside for token-accounting and human/observer
44
+ * inspection — it is not the thing the model sees.
45
+ *
46
+ * Cross-field invariant: a present `payload` REQUIRES a present {@link RawThought.replayCompatibility}.
47
+ * A `payload` without `replayCompatibility` is malformed (the ADK has no way to know
48
+ * which adapter can consume it) and {@link Thought.schema} rejects with
49
+ * {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE}.
50
+ *
51
+ * @defaultValue `undefined`
52
+ */
53
+ payload?: unknown;
54
+ /**
55
+ * Optional free-form identifier describing which adapter wire-shape this thought can be
56
+ * safely replayed into.
57
+ *
58
+ * @remarks
59
+ * Examples (none of these are reserved by the ADK — they are consumer conventions):
60
+ * - `'plain-text'` — replayable into every LLM battery
61
+ * - `'anthropic-messages-thinking-v1'`
62
+ * - `'openai-responses-reasoning-item-v1'`
63
+ * - `'deepseek-reasoning-handle-v1'`
64
+ *
65
+ * LLM batteries declare via constructor option which tags they can safely replay; matching
66
+ * opaque thoughts are routed to the wire's typed reasoning channel where it exists, or to a
67
+ * documented side-channel key on the request body where the wire has none. Non-matching
68
+ * opaque thoughts are elided from the current dispatch but NOT removed from
69
+ * `ctx.turnThoughts` — they remain in context so a subsequent dispatch to a different
70
+ * adapter that DOES declare the matching tag can pick them up.
71
+ *
72
+ * Plain-text thoughts (`payload === undefined` AND `replayCompatibility === undefined`, or
73
+ * explicit `replayCompatibility: 'plain-text'`) are always replayable.
74
+ *
75
+ * A `replayCompatibility` without a `payload` is allowed — it documents intent ("this
76
+ * plain-text thought is only meaningful to a specific fine-tuned variant") without
77
+ * requiring an opaque blob.
78
+ *
79
+ * @defaultValue `undefined`
80
+ */
81
+ replayCompatibility?: string;
82
+ /** When this thought was recorded. */
83
+ createdAt: string | number | Date | DateTime;
84
+ /** When this thought was last modified. */
85
+ updatedAt: string | number | Date | DateTime;
86
+ }
87
+ /**
88
+ * An immutable, validated internal reasoning trace produced by an agent.
89
+ *
90
+ * @remarks
91
+ * Represents an agent's internal thinking — distinct from {@link @nhtio/adk!Message} (which is part of
92
+ * the visible conversation) and never shown to end users directly. Carries an `identity` so
93
+ * reasoning traces can be attributed to a specific agent in multi-agent conversations.
94
+ * Constructed from a {@link RawThought} via `rawThoughtSchema`. The `content` field is always
95
+ * a {@link @nhtio/adk!Tokenizable} so token cost can be estimated inline.
96
+ */
97
+ export declare class Thought {
98
+ #private;
99
+ /**
100
+ * Validator schema that accepts a {@link RawThought} object.
101
+ *
102
+ * @remarks
103
+ * Reusable fragment for any schema that needs to validate or nest a thought entry.
104
+ */
105
+ static schema: import("@nhtio/validation").ObjectSchema<RawThought>;
106
+ /**
107
+ * Returns `true` if `value` is a {@link Thought} instance.
108
+ *
109
+ * @remarks
110
+ * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
111
+ * created in a different module copy or VM context.
112
+ *
113
+ * @param value - The value to test.
114
+ * @returns `true` when `value` is a {@link Thought} instance.
115
+ */
116
+ static isThought(value: unknown): value is Thought;
117
+ /** Stable unique identifier for this thought. */
118
+ readonly id: string;
119
+ /** The reasoning content as a {@link @nhtio/adk!Tokenizable} for inline token estimation. */
120
+ readonly content: Tokenizable;
121
+ /** The identity of the agent who produced this thought. */
122
+ readonly identity: Identity;
123
+ /**
124
+ * Optional vendor-opaque payload that round-trips back to a matching model wire.
125
+ * See {@link RawThought.payload}.
126
+ */
127
+ readonly payload: unknown;
128
+ /**
129
+ * Optional wire-shape identifier describing which adapter can safely replay this thought.
130
+ * See {@link RawThought.replayCompatibility}.
131
+ */
132
+ readonly replayCompatibility: string | undefined;
133
+ /** When this thought was recorded. */
134
+ readonly createdAt: DateTime;
135
+ /** When this thought was last modified. */
136
+ readonly updatedAt: DateTime;
137
+ /**
138
+ * @param raw - The raw thought input validated against `rawThoughtSchema`.
139
+ * @throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} when `raw` does not satisfy the schema.
140
+ */
141
+ constructor(raw: RawThought);
142
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * The set of supported token encoding identifiers.
3
+ *
4
+ * @remarks
5
+ * Each value maps to a specific estimation backend:
6
+ * - `gpt2`, `r50k_base`, `p50k_base`, `p50k_edit`, `cl100k_base`, `o200k_base` — exact counts
7
+ * via `js-tiktoken` (OpenAI / tiktoken-compatible models).
8
+ * - `gemini` — exact counts via `@lenml/tokenizer-gemini`, which embeds Gemini's actual
9
+ * SentencePiece vocabulary locally with no API call required.
10
+ * - `llama2` — exact counts via `llama-tokenizer-js` (Llama 1 and 2). Llama 3+ uses a
11
+ * different vocabulary and should use the `llama3` identifier once a suitable sync backend
12
+ * is available.
13
+ * - `claude` — heuristic approximation using Anthropic's published ~3.5 chars/token ratio.
14
+ * No local tokenizer is available for Claude 3+ models; the Anthropic SDK's
15
+ * `messages.countTokens()` API is the only exact path but requires a network call.
16
+ *
17
+ * When adding a new encoding, add a case to {@link Tokenizable.estimateTokens}.
18
+ */
19
+ export declare const TokenEncoding: readonly [
20
+ "gpt2",
21
+ "r50k_base",
22
+ "p50k_base",
23
+ "p50k_edit",
24
+ "cl100k_base",
25
+ "o200k_base",
26
+ "gemini",
27
+ "llama2",
28
+ "claude"
29
+ ];
30
+ /**
31
+ * Union of all recognised token encoding identifier strings.
32
+ *
33
+ * @remarks
34
+ * Derived from {@link TokenEncoding} so the type and the runtime array stay in sync
35
+ * automatically when new encodings are added.
36
+ */
37
+ export type TokenEncoding = (typeof TokenEncoding)[number];
38
+ /**
39
+ * A mutable string with a built-in token counter.
40
+ *
41
+ * @remarks
42
+ * The wrapped string can be read via the standard coercion protocol and updated at any time via
43
+ * {@link Tokenizable.set}. Token counts are computed lazily on first access per encoding and
44
+ * cached until the value changes, avoiding redundant encoder invocations when the same content
45
+ * is measured multiple times across a pipeline.
46
+ *
47
+ * Estimation is dispatched by encoding identifier — see {@link TokenEncoding} for the full list
48
+ * of supported backends and their accuracy characteristics. Unrecognised encodings fall back to
49
+ * a `ceil(length / 4)` character heuristic.
50
+ *
51
+ * The class implements the standard JS value-coercion protocol (`toString`, `valueOf`,
52
+ * `toJSON`, `toLocaleString`, `Symbol.for('nodejs.util.inspect.custom')`) so instances behave
53
+ * transparently as strings in most contexts.
54
+ */
55
+ export declare class Tokenizable {
56
+ #private;
57
+ static TokenEncoding: readonly [
58
+ "gpt2",
59
+ "r50k_base",
60
+ "p50k_base",
61
+ "p50k_edit",
62
+ "cl100k_base",
63
+ "o200k_base",
64
+ "gemini",
65
+ "llama2",
66
+ "claude"
67
+ ];
68
+ /**
69
+ * Validator schema that accepts a plain `string` or a {@link Tokenizable} instance.
70
+ *
71
+ * @remarks
72
+ * Reusable fragment for any schema that wants to accept either form — for example,
73
+ * `systemPrompt` and each item in `standingInstructions` in `turnContextSchema`.
74
+ */
75
+ static schema: import("@nhtio/validation").AlternativesSchema<any>;
76
+ toJSON: () => string;
77
+ toString: () => string;
78
+ valueOf: () => string;
79
+ toLocaleString: () => string;
80
+ set: (value: string) => void;
81
+ estimateTokens: (encoding: TokenEncoding) => number;
82
+ /**
83
+ * @param value - The initial string value to wrap.
84
+ */
85
+ constructor(value: string);
86
+ /**
87
+ * Convenience overload for one-off token counting without managing a {@link Tokenizable} instance.
88
+ *
89
+ * @remarks
90
+ * Creates a temporary instance and immediately discards it — no caching benefit. Use the
91
+ * instance method when you need to count the same value under multiple encodings or when the
92
+ * value may change over time.
93
+ *
94
+ * @param value - The string to count tokens for.
95
+ * @param encoding - The encoding identifier to use for counting.
96
+ * @returns The estimated number of tokens.
97
+ */
98
+ static estimateTokens(value: string, encoding: TokenEncoding): number;
99
+ /**
100
+ * Returns `true` if `value` is a {@link Tokenizable} instance.
101
+ *
102
+ * @remarks
103
+ * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
104
+ * created in a different module copy or VM context.
105
+ *
106
+ * @param value - The value to test.
107
+ * @returns `true` when `value` is a {@link Tokenizable} instance.
108
+ */
109
+ static isTokenizable(value: unknown): value is Tokenizable;
110
+ }
111
+ /**
112
+ * Returns `true` if `value` is a {@link Tokenizable} instance.
113
+ *
114
+ * @remarks
115
+ * Module-level convenience alias for {@link Tokenizable.isTokenizable}. Prefer this form when
116
+ * you need a standalone type guard without importing the full class.
117
+ *
118
+ * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
119
+ * created in a different module copy or VM context.
120
+ *
121
+ * @param value - The value to test.
122
+ * @returns `true` when `value` is a {@link Tokenizable} instance.
123
+ */
124
+ export declare const isTokenizable: (value: unknown) => value is Tokenizable;
@@ -0,0 +1,228 @@
1
+ import { Registry } from "./registry";
2
+ import type { Media } from "./media";
3
+ import type { Schema, Description } from '@nhtio/validation';
4
+ import type { DispatchContext } from "../contracts/dispatch_context";
5
+ import type { SpooledArtifact, SpooledArtifactConstructor } from "./spooled_artifact";
6
+ /**
7
+ * A zero-arg function that returns the {@link @nhtio/adk!SpooledArtifactConstructor} the consumer should
8
+ * use when wrapping this tool's serialised output into a `ToolCall.results` field.
9
+ *
10
+ * @remarks
11
+ * Why a resolver (and not the constructor itself)? `tool.ts` participates in a module-load
12
+ * cycle with `spooled_artifact.ts` and `artifact_tool.ts` (`ArtifactTool extends Tool` closes
13
+ * the loop). Any eager value-level reference to `SpooledArtifact` in `tool.ts` would crash the
14
+ * cycle with a TDZ error. A resolver lets `tool.ts` validate "is a function" at module-load
15
+ * time and defer the actual constructor check to validate-time (which always runs after every
16
+ * module body has executed). Wrap-sites invoke `tool.artifactConstructor?.() ?? SpooledArtifact`
17
+ * to obtain the final constructor.
18
+ */
19
+ export type ArtifactConstructorResolver<A extends SpooledArtifact = SpooledArtifact> = () => SpooledArtifactConstructor<A>;
20
+ /**
21
+ * The execution function for a {@link Tool}.
22
+ *
23
+ * @remarks
24
+ * Receives the raw arguments passed to the executor, the active {@link @nhtio/adk!DispatchContext}, and the
25
+ * tool's metadata registry.
26
+ *
27
+ * Return shapes:
28
+ * - `string` / `Uint8Array` — opaque serialised output. The ADK does not persist the bytes
29
+ * itself; the consumer's executor middleware is responsible for storing them and wrapping
30
+ * them via `tool.artifactConstructor?.() ?? SpooledArtifact` when assembling the `ToolCall`
31
+ * record.
32
+ * - {@link @nhtio/adk!Media} / `Media[]` — explicit-modality silo. Bypasses
33
+ * {@link Tool.artifactConstructor} — the handler returns the final result shape directly.
34
+ * The LLM battery renders each `Media` as a provider-specific content block.
35
+ */
36
+ export type ToolHandler = (args: unknown, ctx: DispatchContext, meta: Registry) => string | Uint8Array | Media | Media[] | Promise<string | Uint8Array | Media | Media[]>;
37
+ /**
38
+ * Plain input object supplied to {@link Tool} at construction time.
39
+ *
40
+ * @typeParam A - The {@link @nhtio/adk!SpooledArtifact} subtype used to wrap this tool's results when
41
+ * the consumer assembles a `ToolCall.results` field. Defaults to {@link @nhtio/adk!SpooledArtifact}
42
+ * (plain text). Tools producing JSON output should set this to `SpooledJsonArtifact`; tools
43
+ * producing markdown should set it to `SpooledMarkdownArtifact`; consumers can also pass a
44
+ * custom subclass.
45
+ */
46
+ export interface RawTool<A extends SpooledArtifact = SpooledArtifact> {
47
+ /** Unique identifier used in LLM tool definitions. Recommend lowercase snake_case. */
48
+ name: string;
49
+ /** Human-readable description passed to the model to explain what the tool does. */
50
+ description: string;
51
+ /** @nhtio/validation schema for the tool's input arguments. Annotate with `.description()`, `.note()`, `.example()` etc. to produce rich LLM tool definitions via `.describe()`. */
52
+ inputSchema: Schema;
53
+ /** Execution function. Not exposed as a public property — invoke via `executor()`. */
54
+ handler: ToolHandler;
55
+ /**
56
+ * Zero-arg resolver returning the {@link @nhtio/adk!SpooledArtifactConstructor} the consumer should use
57
+ * when wrapping this tool's serialised output into a `ToolCall.results` field. Optional —
58
+ * when omitted, wrap-sites fall back to {@link @nhtio/adk!SpooledArtifact} (plain text).
59
+ *
60
+ * @remarks
61
+ * Recommended call shape: `artifactConstructor: () => SpooledJsonArtifact`. The closure is
62
+ * the indirection that lets `tool.ts` validate this field without eagerly importing
63
+ * `SpooledArtifact` (which would crash the `tool.ts ↔ spooled_artifact.ts ↔ artifact_tool.ts`
64
+ * module-load cycle). At validate time the schema invokes the resolver and verifies its
65
+ * return value is a `SpooledArtifact`-derived constructor — wrong-shape resolvers throw
66
+ * {@link @nhtio/adk!E_INVALID_INITIAL_TOOL_VALUE}.
67
+ *
68
+ * Wrap-sites (storage batteries, scripted executors) read the constructor via
69
+ * `tool.artifactConstructor?.() ?? SpooledArtifact`.
70
+ */
71
+ artifactConstructor?: ArtifactConstructorResolver<A>;
72
+ /** Optional arbitrary metadata for this tool (e.g. RBAC scopes, feature flags). Defaults to `{}`. Stored in a {@link @nhtio/adk!Registry} for dot-path access. */
73
+ meta?: Record<string, unknown>;
74
+ /**
75
+ * When `true`, marks this tool as owned by a specific {@link @nhtio/adk!DispatchContext} so that
76
+ * `ToolRegistry.pruneEphemeral()` will drop it at ctx-completion.
77
+ *
78
+ * @remarks
79
+ * The flag is advisory at the `Tool` level — registries decide what to do with it. The canonical
80
+ * producer of ephemeral tools is `SpooledArtifact.forgeTools(ctx)`, which sets this to `true`
81
+ * on every artifact-query tool it emits.
82
+ *
83
+ * @defaultValue `false`
84
+ */
85
+ ephemeral?: boolean;
86
+ /**
87
+ * When `true`, declares that this tool's output should be treated as **trusted developer/user
88
+ * intent** rather than as untrusted third-party text when surfaced to the model.
89
+ *
90
+ * @remarks
91
+ * LLM batteries read this flag per call when rendering tool-call results. The default
92
+ * untrusted envelope (e.g. `<untrusted_content>` in the OpenAI Chat Completions battery) is the
93
+ * secure-by-default treatment for arbitrary tool output. A tool whose output is authored by the
94
+ * user or operator (Q&A tools surfacing user-authored answers, human-in-the-loop approval
95
+ * gates, feedback-collection tools, configuration tools returning developer-authored
96
+ * constants) sets this to `true` so the LLM battery routes the result through its trusted
97
+ * envelope (`<trusted_content>` in the OpenAI Chat Completions battery).
98
+ *
99
+ * Trust is a property of the tool's output, not a property of how a particular battery is
100
+ * wired — putting the flag here means the trust signal travels with the tool wherever it is
101
+ * registered, no per-battery string lists, no name-matching to fail-open on typos.
102
+ *
103
+ * @defaultValue `false`
104
+ */
105
+ trusted?: boolean;
106
+ /**
107
+ * Self-declared merge collision policy. Honoured by `ToolRegistry.merge` (NOT by
108
+ * `ToolRegistry.register`) when this tool collides with another of the same name.
109
+ *
110
+ * @remarks
111
+ * - `'throw'` (default): defer to the merge-level `options.onCollision`. If that is also
112
+ * `'throw'`, the merge raises `E_TOOL_ALREADY_REGISTERED`. This matches the default behaviour
113
+ * of `ToolRegistry.register`.
114
+ * - `'replace'`: this tool always wins the collision, regardless of the merge-level option.
115
+ * - `'keep'`: this tool always loses to any previously-registered tool of the same name.
116
+ *
117
+ * Forged artifact-query tools set this to `'replace'` so that merging multiple
118
+ * `Subclass.forgeTools(ctx)` outputs (whose base-method tools overlap by name) resolves
119
+ * silently — the descriptors, snapshot, and handler behaviour are interchangeable across
120
+ * subclasses, so replacement is a behavioural no-op.
121
+ *
122
+ * @defaultValue `'throw'`
123
+ */
124
+ onCollision?: 'throw' | 'replace' | 'keep';
125
+ }
126
+ /**
127
+ * A tool definition that serves as the single source of truth for a callable tool: its name,
128
+ * description, input schema, execution handler, and the {@link @nhtio/adk!SpooledArtifact} subclass that
129
+ * wraps its serialised output.
130
+ *
131
+ * @typeParam A - The {@link @nhtio/adk!SpooledArtifact} subtype this tool's results should be wrapped in.
132
+ * Defaults to {@link @nhtio/adk!SpooledArtifact}.
133
+ *
134
+ * @remarks
135
+ * The `inputSchema` is a `@nhtio/validation` schema. It is used at runtime to validate incoming
136
+ * arguments before the handler is called, and its `.describe()` output provides all the metadata
137
+ * needed to build a provider-specific LLM tool definition — annotate the schema with
138
+ * `.description()`, `.note()`, `.example()` etc. once, and that information is available in both
139
+ * contexts without duplication.
140
+ *
141
+ * The handler is private — invoke it only through `executor(ctx)` which validates args, fires
142
+ * observability events (with a stable `callId` derived from the tool name and arguments), and
143
+ * wraps handler errors in {@link @nhtio/adk!E_TOOL_DOWNSTREAM_ERROR}. The handler returns serialised bytes
144
+ * (`string | Uint8Array`); persistence is the consumer's responsibility.
145
+ *
146
+ * `artifactConstructor` is the {@link @nhtio/adk!SpooledArtifact} subclass the consumer should use when
147
+ * wrapping the handler's output into a `ToolCall.results` field. The author declares it once
148
+ * on the tool instance; the consumer reads it when assembling persisted records.
149
+ */
150
+ export declare class Tool<A extends SpooledArtifact = SpooledArtifact> {
151
+ #private;
152
+ /**
153
+ * Validator schema that accepts a {@link RawTool} object.
154
+ *
155
+ * @remarks
156
+ * Reusable fragment for any schema that needs to validate or nest a tool entry
157
+ * (e.g. `TurnRunnerConfig.tools`).
158
+ */
159
+ static schema: import("@nhtio/validation").ObjectSchema<RawTool<SpooledArtifact>>;
160
+ /**
161
+ * Returns `true` if `value` is a {@link Tool} instance.
162
+ *
163
+ * @param value - The value to test.
164
+ * @returns `true` when `value` is a {@link Tool} instance.
165
+ */
166
+ static isTool(value: unknown): value is Tool;
167
+ readonly name: string;
168
+ readonly description: string;
169
+ readonly inputSchema: Schema;
170
+ readonly artifactConstructor: ArtifactConstructorResolver<A> | undefined;
171
+ readonly meta: Registry;
172
+ readonly ephemeral: boolean;
173
+ readonly trusted: boolean;
174
+ readonly onCollision: 'throw' | 'replace' | 'keep';
175
+ /**
176
+ * @param raw - The raw tool input validated against `rawToolSchema`.
177
+ * @throws {@link @nhtio/adk!E_INVALID_INITIAL_TOOL_VALUE} when `raw` does not satisfy the schema.
178
+ */
179
+ constructor(raw: RawTool<A>);
180
+ /**
181
+ * Validates `args` against the tool's input schema asynchronously.
182
+ *
183
+ * @remarks
184
+ * Async to support schemas with external validators (e.g. database lookups, API calls).
185
+ * A validation failure throws {@link @nhtio/adk!E_INVALID_TOOL_ARGS} — this indicates a programming error
186
+ * in the tool call loop, not a downstream failure.
187
+ *
188
+ * @param args - The arguments to validate.
189
+ * @returns The validated (and coerced) arguments.
190
+ * @throws {@link @nhtio/adk!E_INVALID_TOOL_ARGS} when `args` does not satisfy the input schema.
191
+ */
192
+ validate(args: unknown): Promise<unknown>;
193
+ /**
194
+ * Returns a bound executor function for this tool against the given turn context.
195
+ *
196
+ * @remarks
197
+ * The executor: (1) computes a stable `callId` as `sha256(canonicalStringify({tool, args}))`
198
+ * over the **raw, pre-validation args**, (2) validates `args` via {@link Tool.validate},
199
+ * (3) emits `toolExecutionStart` on the context (with the computed `callId`), (4) calls the
200
+ * handler, (5) emits `toolExecutionEnd` (with the same `callId`), (6) wraps any handler error
201
+ * in {@link @nhtio/adk!E_TOOL_DOWNSTREAM_ERROR} before re-throwing.
202
+ *
203
+ * The handler returns serialised bytes (`string | Uint8Array`) — persistence is the consumer's
204
+ * concern. Use {@link Tool.artifactConstructor} when wrapping the bytes into a
205
+ * `ToolCall.results` field.
206
+ *
207
+ * Pattern mirrors `Middleware.runner()` — call once per turn, reuse the returned function.
208
+ *
209
+ * @param ctx - The active turn context. Provides emit functions and turn ID.
210
+ * @returns An async function `(args) => Promise<string | Uint8Array>`.
211
+ */
212
+ executor(ctx: DispatchContext): (args: unknown) => Promise<string | Uint8Array | Media | Media[]>;
213
+ /**
214
+ * Returns a fully serialisable snapshot of this tool's definition.
215
+ *
216
+ * @remarks
217
+ * The `inputSchema` property is the result of calling `.describe()` on the raw schema — a plain
218
+ * object carrying all the annotation metadata (descriptions, notes, examples, types) without any
219
+ * validator functions. Use this to build provider-specific LLM tool definitions.
220
+ *
221
+ * @returns `{ name, description, inputSchema }` where `inputSchema` is the schema description.
222
+ */
223
+ describe(): {
224
+ name: string;
225
+ description: string;
226
+ inputSchema: Description;
227
+ };
228
+ }