@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,608 @@
1
+ require("./chunk-KmRHZBOW.js");
2
+ const require_exceptions = require("./exceptions-D5YrO9Vm.js");
3
+ const require_tool_registry = require("./tool_registry-Dkfprsck.js");
4
+ const require_runtime = require("./runtime-BJVkrGQe.js");
5
+ const require_spooled_artifact = require("./spooled_artifact-Cm9Te22K.js");
6
+ let _nhtio_validation = require("@nhtio/validation");
7
+ let uuid = require("uuid");
8
+ //#region src/lib/contracts/media_reader.ts
9
+ /**
10
+ * Validator schema used to validate a MediaReader value.
11
+ *
12
+ * @remarks
13
+ * Because MediaReader is a structural interface with no associated constructor, validation is
14
+ * duck-typed: the value must be an object, class instance, or function with `stream` and
15
+ * `byteLength` present as callable properties. Arity is not enforced.
16
+ */
17
+ var mediaReaderSchema = _nhtio_validation.validator.any().required().custom((value, helpers) => {
18
+ if (value !== null && value !== void 0 && typeof value.stream === "function" && typeof value.byteLength === "function") return value;
19
+ return helpers.error("any.invalid");
20
+ });
21
+ /**
22
+ * Returns `true` if `value` implements the MediaReader interface.
23
+ *
24
+ * @remarks
25
+ * Duck-typed: checks that `value` is non-null with `stream` and `byteLength` as callable
26
+ * functions. Does not use `instanceof` — there is no MediaReader constructor.
27
+ *
28
+ * @param value - The value to test.
29
+ * @returns `true` when `value` conforms to the MediaReader interface.
30
+ */
31
+ var implementsMediaReader = (value) => {
32
+ return require_exceptions.passesSchema(mediaReaderSchema, value);
33
+ };
34
+ //#endregion
35
+ //#region src/lib/classes/media.ts
36
+ /**
37
+ * The set of supported media kinds.
38
+ *
39
+ * @remarks
40
+ * Modality coverage is asymmetric across providers. The framework defines no
41
+ * `supportedModalities` field — how a battery handles a modality it cannot natively render is
42
+ * the battery author's call (see `unsupportedMediaPolicy` on the OpenAI Chat Completions
43
+ * battery).
44
+ */
45
+ var MediaKind = [
46
+ "image",
47
+ "audio",
48
+ "video",
49
+ "document"
50
+ ];
51
+ /**
52
+ * Provenance axis. *Who is the framework willing to vouch for as the source of these bytes?*
53
+ *
54
+ * @remarks
55
+ * Mirrors `RetrievableTrustTier` deliberately — same vocabulary, same question:
56
+ * *did this content come from a place the agent should treat as authoritative?*
57
+ *
58
+ * - `'first-party'` — deployer-vetted bytes (tool output the operator authored, signed
59
+ * internal assets).
60
+ * - `'third-party-public'` — open-web fetches, public APIs, public corpora.
61
+ * - `'third-party-private'` — user uploads, partner APIs, private corpora.
62
+ */
63
+ var MediaTrustTier = [
64
+ "first-party",
65
+ "third-party-public",
66
+ "third-party-private"
67
+ ];
68
+ /**
69
+ * Modality-hazard axis. *How dangerous is it to let the model decode these bytes?*
70
+ *
71
+ * @remarks
72
+ * Orthogonal to provenance — a first-party trusted PDF can still carry hidden text layers; a
73
+ * third-party-public raw image can still be encoded as opaque pixels with adversarial
74
+ * perturbations.
75
+ *
76
+ * - `'inert'` — bytes the model never decodes as instructions (e.g. a handle that is never
77
+ * inlined into the prompt).
78
+ * - `'extractable-instructions'` — text-bearing media: PDFs, screenshots with UI text, documents.
79
+ * Hazard is OCR / embedded-text-layer reads.
80
+ * - `'opaque-perceptual'` — raw vision/audio/video the model encodes directly. Hazard is
81
+ * steganographic LSB prompts, adversarial perturbations, ultrasonic audio — invisible to any
82
+ * pre-screen.
83
+ *
84
+ * See `/the-loop/trust-tiers/media` and its research sub-page `/the-loop/trust-tiers/media/research`.
85
+ */
86
+ var MediaModalityHazard = [
87
+ "inert",
88
+ "extractable-instructions",
89
+ "opaque-perceptual"
90
+ ];
91
+ var stashEntrySchema = _nhtio_validation.validator.object({
92
+ value: _nhtio_validation.validator.any().required(),
93
+ trustTier: _nhtio_validation.validator.string().valid(...MediaTrustTier).required(),
94
+ derivedFromMedia: _nhtio_validation.validator.string().optional()
95
+ }).unknown(false);
96
+ /**
97
+ * Validator schema used to validate a {@link RawMedia} before constructing a {@link Media}.
98
+ */
99
+ var rawMediaSchema = _nhtio_validation.validator.object({
100
+ id: _nhtio_validation.validator.string().optional(),
101
+ kind: _nhtio_validation.validator.string().valid(...MediaKind).required(),
102
+ mimeType: _nhtio_validation.validator.string().required(),
103
+ filename: _nhtio_validation.validator.string().required(),
104
+ reader: mediaReaderSchema.required(),
105
+ trustTier: _nhtio_validation.validator.string().valid(...MediaTrustTier).required(),
106
+ modalityHazard: _nhtio_validation.validator.string().valid(...MediaModalityHazard).required(),
107
+ source: _nhtio_validation.validator.string().optional(),
108
+ stash: _nhtio_validation.validator.object().pattern(_nhtio_validation.validator.string(), stashEntrySchema).optional()
109
+ });
110
+ var conservativeHazardForKind = (kind) => {
111
+ return kind === "document" ? "extractable-instructions" : "opaque-perceptual";
112
+ };
113
+ /**
114
+ * Cross-environment base64 encoder for a `Uint8Array`.
115
+ *
116
+ * @remarks
117
+ * Prefers Node's `Buffer.from(buf).toString('base64')` when `globalThis.Buffer` exists; otherwise
118
+ * chunk-encodes through `btoa` with a 0x8000-byte window to avoid `Maximum call stack size
119
+ * exceeded` on large buffers.
120
+ */
121
+ var encodeBase64 = (bytes) => {
122
+ const maybeBuffer = globalThis.Buffer;
123
+ if (maybeBuffer && typeof maybeBuffer.from === "function") return maybeBuffer.from(bytes).toString("base64");
124
+ const chunkSize = 32768;
125
+ let binary = "";
126
+ for (let i = 0; i < bytes.length; i += chunkSize) {
127
+ const chunk = bytes.subarray(i, i + chunkSize);
128
+ binary += String.fromCharCode.apply(null, Array.from(chunk));
129
+ }
130
+ return btoa(binary);
131
+ };
132
+ /**
133
+ * Lazy, re-openable view over a binary asset (image, audio, video, document).
134
+ *
135
+ * @remarks
136
+ * Dual-peer to {@link @nhtio/adk!Tokenizable} (silo) and {@link @nhtio/adk!SpooledArtifact}
137
+ * (handle). Wraps a {@link @nhtio/adk!MediaReader} contract — the framework owns the contract, the
138
+ * implementor owns the storage backend. Bytes are reached only through the reader; the primitive
139
+ * itself never inlines bytes.
140
+ *
141
+ * Construction requires `trustTier` and `modalityHazard` — the framework refuses to guess
142
+ * provenance or decoding hazard. Ergonomic factories ({@link Media.userAttachment},
143
+ * {@link Media.toolGenerated}, {@link Media.retrievedPublic}, {@link Media.retrievedPrivate})
144
+ * force the labelling decision at the call site without becoming defaults on the bare
145
+ * constructor.
146
+ */
147
+ var Media = class Media {
148
+ /**
149
+ * Validator schema that accepts a {@link RawMedia} object.
150
+ */
151
+ static schema = rawMediaSchema;
152
+ /**
153
+ * The set of recognised media kinds. Exposed for downstream schemas that need to discriminate
154
+ * on `kind`.
155
+ */
156
+ static MediaKind = MediaKind;
157
+ /**
158
+ * The set of recognised trust tiers.
159
+ */
160
+ static MediaTrustTier = MediaTrustTier;
161
+ /**
162
+ * The set of recognised modality hazards.
163
+ */
164
+ static MediaModalityHazard = MediaModalityHazard;
165
+ /**
166
+ * Returns `true` if `value` is a {@link Media} instance.
167
+ *
168
+ * @remarks
169
+ * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.
170
+ *
171
+ * @param value - The value to test.
172
+ * @returns `true` when `value` is a {@link Media} instance.
173
+ */
174
+ static isMedia(value) {
175
+ return require_tool_registry.isInstanceOf(value, "Media", Media);
176
+ }
177
+ #id;
178
+ #kind;
179
+ #mimeType;
180
+ #filename;
181
+ #source;
182
+ #trustTier;
183
+ #modalityHazard;
184
+ #reader;
185
+ #stash;
186
+ /**
187
+ * @param raw - The raw media input validated against `rawMediaSchema`.
188
+ * @throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_MEDIA_VALUE} when `raw` does not satisfy the schema.
189
+ * @throws {@link @nhtio/adk/exceptions!E_NOT_A_MEDIA_READER} when `raw.reader` does not implement {@link @nhtio/adk!MediaReader}.
190
+ */
191
+ constructor(raw) {
192
+ let resolved;
193
+ try {
194
+ resolved = require_exceptions.validateOrThrow(rawMediaSchema, raw, true);
195
+ } catch (err) {
196
+ throw new require_runtime.E_INVALID_INITIAL_MEDIA_VALUE({ cause: require_tool_registry.isError(err) ? err : void 0 });
197
+ }
198
+ if (!implementsMediaReader(resolved.reader)) throw new require_runtime.E_NOT_A_MEDIA_READER();
199
+ this.#id = resolved.id ?? (0, uuid.v6)();
200
+ this.#kind = resolved.kind;
201
+ this.#mimeType = resolved.mimeType;
202
+ this.#filename = resolved.filename;
203
+ this.#source = resolved.source;
204
+ this.#trustTier = resolved.trustTier;
205
+ this.#modalityHazard = resolved.modalityHazard;
206
+ this.#reader = resolved.reader;
207
+ this.#stash = new require_tool_registry.Registry(resolved.stash);
208
+ Object.defineProperties(this, {
209
+ id: {
210
+ get: () => this.#id,
211
+ enumerable: true,
212
+ configurable: false
213
+ },
214
+ kind: {
215
+ get: () => this.#kind,
216
+ enumerable: true,
217
+ configurable: false
218
+ },
219
+ mimeType: {
220
+ get: () => this.#mimeType,
221
+ enumerable: true,
222
+ configurable: false
223
+ },
224
+ filename: {
225
+ get: () => this.#filename,
226
+ enumerable: true,
227
+ configurable: false
228
+ },
229
+ source: {
230
+ get: () => this.#source,
231
+ enumerable: true,
232
+ configurable: false
233
+ },
234
+ trustTier: {
235
+ get: () => this.#trustTier,
236
+ enumerable: true,
237
+ configurable: false
238
+ },
239
+ modalityHazard: {
240
+ get: () => this.#modalityHazard,
241
+ enumerable: true,
242
+ configurable: false
243
+ },
244
+ stash: {
245
+ get: () => this.#stash,
246
+ enumerable: true,
247
+ configurable: false
248
+ }
249
+ });
250
+ }
251
+ /**
252
+ * Re-opens the underlying byte source and returns a fresh ReadableStream.
253
+ *
254
+ * @returns A drainable `ReadableStream` over the underlying bytes.
255
+ */
256
+ async stream() {
257
+ return this.#reader.stream();
258
+ }
259
+ /**
260
+ * Returns the total number of bytes in the underlying data, or `undefined` if unknown.
261
+ *
262
+ * @returns The byte length, or `undefined` when the underlying source cannot report it.
263
+ */
264
+ async byteLength() {
265
+ return this.#reader.byteLength();
266
+ }
267
+ /**
268
+ * Drains the reader's stream and returns the underlying bytes as a single `Uint8Array`.
269
+ *
270
+ * @remarks
271
+ * Convenience for callers that need the full buffer (e.g. inline base64 encoding). Forces
272
+ * full materialisation — large assets should be piped through {@link Media.stream} instead.
273
+ */
274
+ async asBytes() {
275
+ const reader = (await this.stream()).getReader();
276
+ const chunks = [];
277
+ let total = 0;
278
+ while (true) {
279
+ const { value, done } = await reader.read();
280
+ if (done) break;
281
+ if (value) {
282
+ chunks.push(value);
283
+ total += value.byteLength;
284
+ }
285
+ }
286
+ const out = new Uint8Array(total);
287
+ let offset = 0;
288
+ for (const chunk of chunks) {
289
+ out.set(chunk, offset);
290
+ offset += chunk.byteLength;
291
+ }
292
+ return out;
293
+ }
294
+ /**
295
+ * Drains the reader's stream and returns the underlying bytes as a base64 string.
296
+ *
297
+ * @remarks
298
+ * Cross-environment: prefers Node's `Buffer.from(buf).toString('base64')` when available;
299
+ * otherwise chunk-encodes through `btoa` with a 0x8000-byte window to avoid stack overflow
300
+ * on large buffers.
301
+ */
302
+ async asBase64() {
303
+ return encodeBase64(await this.asBytes());
304
+ }
305
+ /**
306
+ * Returns the metadata-only serialisation of this Media. Bytes and the reader are stripped
307
+ * so naive event/log serialisation never materialises bytes.
308
+ *
309
+ * @remarks
310
+ * Implementations that have cheap, already-cached `byteLength` may opt to include it; this
311
+ * default implementation omits it to preserve the "lazy by default" invariant. Consumers that
312
+ * need byteLength on the serialised payload should call `await media.byteLength()` and merge
313
+ * the result.
314
+ */
315
+ toJSON() {
316
+ return {
317
+ id: this.#id,
318
+ kind: this.#kind,
319
+ mimeType: this.#mimeType,
320
+ filename: this.#filename,
321
+ source: this.#source,
322
+ trustTier: this.#trustTier,
323
+ modalityHazard: this.#modalityHazard,
324
+ stash: this.#stash.all()
325
+ };
326
+ }
327
+ /**
328
+ * Factory: constructs a {@link Media} representing a user-supplied attachment.
329
+ *
330
+ * @remarks
331
+ * Pre-fills `trustTier: 'third-party-private'` and derives `modalityHazard` from `kind`
332
+ * (`document` → `'extractable-instructions'`; everything else → `'opaque-perceptual'`).
333
+ * Use the bare constructor when the conservative kind→hazard mapping is wrong for your case.
334
+ */
335
+ static userAttachment(args) {
336
+ return new Media({
337
+ ...args,
338
+ trustTier: "third-party-private",
339
+ modalityHazard: conservativeHazardForKind(args.kind)
340
+ });
341
+ }
342
+ /**
343
+ * Factory: constructs a {@link Media} produced by a first-party tool.
344
+ *
345
+ * @remarks
346
+ * Pre-fills `trustTier: 'first-party'` and derives `modalityHazard` from `kind`.
347
+ */
348
+ static toolGenerated(args) {
349
+ return new Media({
350
+ ...args,
351
+ trustTier: "first-party",
352
+ modalityHazard: conservativeHazardForKind(args.kind)
353
+ });
354
+ }
355
+ /**
356
+ * Factory: constructs a {@link Media} retrieved from a public third-party source.
357
+ *
358
+ * @remarks
359
+ * Pre-fills `trustTier: 'third-party-public'` and derives `modalityHazard` from `kind`.
360
+ */
361
+ static retrievedPublic(args) {
362
+ return new Media({
363
+ ...args,
364
+ trustTier: "third-party-public",
365
+ modalityHazard: conservativeHazardForKind(args.kind)
366
+ });
367
+ }
368
+ /**
369
+ * Factory: constructs a {@link Media} retrieved from a private third-party source.
370
+ *
371
+ * @remarks
372
+ * Pre-fills `trustTier: 'third-party-private'` and derives `modalityHazard` from `kind`.
373
+ */
374
+ static retrievedPrivate(args) {
375
+ return new Media({
376
+ ...args,
377
+ trustTier: "third-party-private",
378
+ modalityHazard: conservativeHazardForKind(args.kind)
379
+ });
380
+ }
381
+ };
382
+ /**
383
+ * Returns `true` if `value` is a {@link Media} instance.
384
+ *
385
+ * @remarks
386
+ * Module-level convenience alias for {@link Media.isMedia}. Uses {@link @nhtio/adk!isInstanceOf} for
387
+ * cross-realm safety.
388
+ */
389
+ var isMedia = (value) => {
390
+ return require_tool_registry.isInstanceOf(value, "Media", Media);
391
+ };
392
+ //#endregion
393
+ //#region src/lib/classes/tool_call.ts
394
+ var isToolCallResults = (value) => {
395
+ if (require_tool_registry.Tokenizable.isTokenizable(value)) return true;
396
+ if (require_spooled_artifact.SpooledArtifact.isSpooledArtifact(value)) return true;
397
+ if (Media.isMedia(value)) return true;
398
+ if (Array.isArray(value) && value.length > 0) {
399
+ if (value.every((entry) => Media.isMedia(entry))) return true;
400
+ if (value.every((entry) => require_spooled_artifact.SpooledArtifact.isSpooledArtifact(entry))) return true;
401
+ }
402
+ return false;
403
+ };
404
+ /**
405
+ * Validator schema used to validate a {@link RawToolCall} before constructing a {@link ToolCall}.
406
+ *
407
+ * @remarks
408
+ * Validates all fields of {@link RawToolCall}:
409
+ * - `id` — required non-empty string.
410
+ * - `tool` — required non-empty string.
411
+ * - `args` — required; either a plain object or a JSON string that deserialises to an object.
412
+ * Strings are parsed and the resulting object is stored.
413
+ * - `checksum` — required string.
414
+ * - `isComplete` — required boolean.
415
+ * - `isError` — required boolean.
416
+ * - `results` — required; one of {@link @nhtio/adk!Tokenizable}, {@link @nhtio/adk!SpooledArtifact}, a non-empty
417
+ * `SpooledArtifact[]`, {@link @nhtio/adk!Media}, or a non-empty `Media[]`. Arrays must be homogeneous.
418
+ * - `createdAt` / `updatedAt` / `completedAt` — required datetime-parseable values, normalised to `DateTime`.
419
+ *
420
+ * Throws {@link @nhtio/adk!E_INVALID_INITIAL_TOOL_CALL_VALUE} (via the {@link ToolCall} constructor) when
421
+ * validation fails.
422
+ */
423
+ var rawToolCallSchema = _nhtio_validation.validator.object({
424
+ id: _nhtio_validation.validator.string().required(),
425
+ tool: _nhtio_validation.validator.string().required(),
426
+ args: _nhtio_validation.validator.alternatives(_nhtio_validation.validator.object().unknown(true), _nhtio_validation.validator.string().custom((value, helpers) => {
427
+ try {
428
+ const parsed = JSON.parse(value);
429
+ if (!require_tool_registry.isObject(parsed)) return helpers.error("any.invalid");
430
+ return parsed;
431
+ } catch {
432
+ return helpers.error("any.invalid");
433
+ }
434
+ })).required(),
435
+ checksum: _nhtio_validation.validator.string().required(),
436
+ isComplete: _nhtio_validation.validator.boolean().required(),
437
+ isError: _nhtio_validation.validator.boolean().required(),
438
+ results: _nhtio_validation.validator.any().custom((value, helpers) => {
439
+ if (isToolCallResults(value)) return value;
440
+ return helpers.error("any.invalid");
441
+ }).required(),
442
+ fromArtifactTool: _nhtio_validation.validator.boolean().default(false),
443
+ inline: _nhtio_validation.validator.boolean().default(true),
444
+ createdAt: _nhtio_validation.validator.datetime().required(),
445
+ updatedAt: _nhtio_validation.validator.datetime().required(),
446
+ completedAt: _nhtio_validation.validator.datetime().required()
447
+ });
448
+ /**
449
+ * An immutable, validated tool call record associated with a turn.
450
+ *
451
+ * @remarks
452
+ * Represents a completed tool invocation from the conversation history — `results`,
453
+ * `completedAt`, `isComplete`, and `isError` are all present and required.
454
+ * Temporal fields are normalised to Luxon `DateTime` instances at construction time.
455
+ */
456
+ var ToolCall = class ToolCall {
457
+ /**
458
+ * Validator schema that accepts a {@link RawToolCall} object.
459
+ *
460
+ * @remarks
461
+ * Reusable fragment for any schema that needs to validate or nest a tool call entry.
462
+ */
463
+ static schema = rawToolCallSchema;
464
+ /**
465
+ * Returns `true` if `value` is a {@link ToolCall} instance.
466
+ *
467
+ * @remarks
468
+ * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
469
+ * created in a different module copy or VM context.
470
+ *
471
+ * @param value - The value to test.
472
+ * @returns `true` when `value` is a {@link ToolCall} instance.
473
+ */
474
+ static isToolCall(value) {
475
+ return require_tool_registry.isInstanceOf(value, "ToolCall", ToolCall);
476
+ }
477
+ #id;
478
+ #tool;
479
+ #args;
480
+ #checksum;
481
+ #isComplete;
482
+ #isError;
483
+ #results;
484
+ #fromArtifactTool;
485
+ #inline;
486
+ #createdAt;
487
+ #updatedAt;
488
+ #completedAt;
489
+ /**
490
+ * @param raw - The raw tool call input validated against `rawToolCallSchema`.
491
+ * @throws {@link @nhtio/adk!E_INVALID_INITIAL_TOOL_CALL_VALUE} when `raw` does not satisfy the schema.
492
+ */
493
+ constructor(raw) {
494
+ let resolved;
495
+ try {
496
+ resolved = require_exceptions.validateOrThrow(rawToolCallSchema, raw, true);
497
+ } catch (err) {
498
+ throw new require_runtime.E_INVALID_INITIAL_TOOL_CALL_VALUE({ cause: require_tool_registry.isError(err) ? err : void 0 });
499
+ }
500
+ this.#id = resolved.id;
501
+ this.#tool = resolved.tool;
502
+ this.#args = resolved.args;
503
+ this.#checksum = resolved.checksum;
504
+ this.#isComplete = resolved.isComplete;
505
+ this.#isError = resolved.isError;
506
+ this.#results = resolved.results;
507
+ this.#fromArtifactTool = resolved.fromArtifactTool;
508
+ this.#inline = resolved.inline;
509
+ this.#createdAt = resolved.createdAt;
510
+ this.#updatedAt = resolved.updatedAt;
511
+ this.#completedAt = resolved.completedAt;
512
+ Object.defineProperties(this, {
513
+ id: {
514
+ get: () => this.#id,
515
+ enumerable: true,
516
+ configurable: false
517
+ },
518
+ tool: {
519
+ get: () => this.#tool,
520
+ enumerable: true,
521
+ configurable: false
522
+ },
523
+ args: {
524
+ get: () => this.#args,
525
+ enumerable: true,
526
+ configurable: false
527
+ },
528
+ checksum: {
529
+ get: () => this.#checksum,
530
+ enumerable: true,
531
+ configurable: false
532
+ },
533
+ isComplete: {
534
+ get: () => this.#isComplete,
535
+ enumerable: true,
536
+ configurable: false
537
+ },
538
+ isError: {
539
+ get: () => this.#isError,
540
+ enumerable: true,
541
+ configurable: false
542
+ },
543
+ results: {
544
+ get: () => this.#results,
545
+ enumerable: true,
546
+ configurable: false
547
+ },
548
+ fromArtifactTool: {
549
+ get: () => this.#fromArtifactTool,
550
+ enumerable: true,
551
+ configurable: false
552
+ },
553
+ inline: {
554
+ get: () => this.#inline,
555
+ enumerable: true,
556
+ configurable: false
557
+ },
558
+ createdAt: {
559
+ get: () => this.#createdAt,
560
+ enumerable: true,
561
+ configurable: false
562
+ },
563
+ updatedAt: {
564
+ get: () => this.#updatedAt,
565
+ enumerable: true,
566
+ configurable: false
567
+ },
568
+ completedAt: {
569
+ get: () => this.#completedAt,
570
+ enumerable: true,
571
+ configurable: false
572
+ }
573
+ });
574
+ }
575
+ };
576
+ //#endregion
577
+ Object.defineProperty(exports, "Media", {
578
+ enumerable: true,
579
+ get: function() {
580
+ return Media;
581
+ }
582
+ });
583
+ Object.defineProperty(exports, "ToolCall", {
584
+ enumerable: true,
585
+ get: function() {
586
+ return ToolCall;
587
+ }
588
+ });
589
+ Object.defineProperty(exports, "implementsMediaReader", {
590
+ enumerable: true,
591
+ get: function() {
592
+ return implementsMediaReader;
593
+ }
594
+ });
595
+ Object.defineProperty(exports, "isMedia", {
596
+ enumerable: true,
597
+ get: function() {
598
+ return isMedia;
599
+ }
600
+ });
601
+ Object.defineProperty(exports, "mediaReaderSchema", {
602
+ enumerable: true,
603
+ get: function() {
604
+ return mediaReaderSchema;
605
+ }
606
+ });
607
+
608
+ //# sourceMappingURL=tool_call-DFgzcVcU.js.map