@nhtio/adk 0.1.0-master-d3feb810 → 0.1.0-master-445a9ed0

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 (170) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/batteries/llm/openai_chat_completions/adapter.cjs +9 -10
  3. package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -1
  4. package/batteries/llm/openai_chat_completions/adapter.mjs +8 -8
  5. package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -1
  6. package/batteries/llm/openai_chat_completions/exceptions.cjs +1 -1
  7. package/batteries/llm/openai_chat_completions/helpers.cjs +16 -16
  8. package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -1
  9. package/batteries/llm/openai_chat_completions/helpers.d.ts +10 -10
  10. package/batteries/llm/openai_chat_completions/helpers.mjs +16 -16
  11. package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -1
  12. package/batteries/llm/openai_chat_completions/types.d.ts +26 -6
  13. package/batteries/llm/openai_chat_completions/validation.cjs +3 -1
  14. package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -1
  15. package/batteries/llm/openai_chat_completions/validation.mjs +2 -0
  16. package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -1
  17. package/batteries/llm/webllm_chat_completions/adapter.cjs +9 -10
  18. package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -1
  19. package/batteries/llm/webllm_chat_completions/adapter.mjs +8 -8
  20. package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -1
  21. package/batteries/llm/webllm_chat_completions/exceptions.cjs +1 -1
  22. package/batteries/llm/webllm_chat_completions/validation.cjs +3 -1
  23. package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -1
  24. package/batteries/llm/webllm_chat_completions/validation.mjs +2 -0
  25. package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -1
  26. package/batteries/storage/flydrive/index.d.ts +10 -4
  27. package/batteries/storage/flydrive.cjs +12 -3
  28. package/batteries/storage/flydrive.cjs.map +1 -1
  29. package/batteries/storage/flydrive.mjs +11 -2
  30. package/batteries/storage/flydrive.mjs.map +1 -1
  31. package/batteries/storage/in_memory/index.d.ts +31 -17
  32. package/batteries/storage/in_memory.cjs +89 -30
  33. package/batteries/storage/in_memory.cjs.map +1 -1
  34. package/batteries/storage/in_memory.mjs +89 -30
  35. package/batteries/storage/in_memory.mjs.map +1 -1
  36. package/batteries/storage/opfs/index.d.ts +10 -4
  37. package/batteries/storage/opfs.cjs +55 -5
  38. package/batteries/storage/opfs.cjs.map +1 -1
  39. package/batteries/storage/opfs.mjs +54 -4
  40. package/batteries/storage/opfs.mjs.map +1 -1
  41. package/batteries/tools/color.cjs +3 -3
  42. package/batteries/tools/color.mjs +2 -2
  43. package/batteries/tools/comparison.cjs +3 -4
  44. package/batteries/tools/comparison.cjs.map +1 -1
  45. package/batteries/tools/comparison.mjs +2 -2
  46. package/batteries/tools/data_structure.cjs +3 -4
  47. package/batteries/tools/data_structure.cjs.map +1 -1
  48. package/batteries/tools/data_structure.mjs +2 -2
  49. package/batteries/tools/datetime_extended.cjs +4 -4
  50. package/batteries/tools/datetime_extended.mjs +2 -2
  51. package/batteries/tools/datetime_math.cjs +3 -3
  52. package/batteries/tools/datetime_math.mjs +2 -2
  53. package/batteries/tools/encoding.cjs +3 -4
  54. package/batteries/tools/encoding.cjs.map +1 -1
  55. package/batteries/tools/encoding.mjs +2 -2
  56. package/batteries/tools/formatting.cjs +3 -4
  57. package/batteries/tools/formatting.cjs.map +1 -1
  58. package/batteries/tools/formatting.mjs +2 -2
  59. package/batteries/tools/geo_basics.cjs +3 -3
  60. package/batteries/tools/geo_basics.mjs +2 -2
  61. package/batteries/tools/math.cjs +3 -4
  62. package/batteries/tools/math.cjs.map +1 -1
  63. package/batteries/tools/math.mjs +2 -2
  64. package/batteries/tools/memory.cjs +6 -7
  65. package/batteries/tools/memory.cjs.map +1 -1
  66. package/batteries/tools/memory.mjs +5 -5
  67. package/batteries/tools/parsing.cjs +5 -6
  68. package/batteries/tools/parsing.cjs.map +1 -1
  69. package/batteries/tools/parsing.mjs +3 -3
  70. package/batteries/tools/retrievables.cjs +11 -11
  71. package/batteries/tools/retrievables.cjs.map +1 -1
  72. package/batteries/tools/retrievables.mjs +10 -9
  73. package/batteries/tools/retrievables.mjs.map +1 -1
  74. package/batteries/tools/standing_instructions.cjs +4 -5
  75. package/batteries/tools/standing_instructions.cjs.map +1 -1
  76. package/batteries/tools/standing_instructions.mjs +3 -3
  77. package/batteries/tools/statistics.cjs +4 -5
  78. package/batteries/tools/statistics.cjs.map +1 -1
  79. package/batteries/tools/statistics.mjs +3 -3
  80. package/batteries/tools/string_processing.cjs +3 -4
  81. package/batteries/tools/string_processing.cjs.map +1 -1
  82. package/batteries/tools/string_processing.mjs +2 -2
  83. package/batteries/tools/structured_data.cjs +3 -4
  84. package/batteries/tools/structured_data.cjs.map +1 -1
  85. package/batteries/tools/structured_data.mjs +2 -2
  86. package/batteries/tools/text_analysis.cjs +4 -4
  87. package/batteries/tools/text_analysis.mjs +3 -3
  88. package/batteries/tools/text_comparison.cjs +3 -3
  89. package/batteries/tools/text_comparison.mjs +2 -2
  90. package/batteries/tools/time.cjs +3 -3
  91. package/batteries/tools/time.mjs +2 -2
  92. package/batteries/tools/unit_conversion.cjs +3 -3
  93. package/batteries/tools/unit_conversion.mjs +2 -2
  94. package/batteries/tools.cjs +3 -3
  95. package/batteries/tools.mjs +3 -3
  96. package/batteries.cjs +3 -3
  97. package/batteries.mjs +3 -3
  98. package/{common-Od8edUXU.js → common-BJ6V6dsH.js} +89 -12
  99. package/common-BJ6V6dsH.js.map +1 -0
  100. package/{common-DeZaonK1.mjs → common-aFmr9Oqs.mjs} +76 -10
  101. package/common-aFmr9Oqs.mjs.map +1 -0
  102. package/common.cjs +9 -7
  103. package/common.d.ts +8 -0
  104. package/common.mjs +7 -7
  105. package/{dispatch_runner-CsoH0nld.js → dispatch_runner-BWYNxmnp.js} +37 -6
  106. package/dispatch_runner-BWYNxmnp.js.map +1 -0
  107. package/{dispatch_runner-9j6bXHL3.mjs → dispatch_runner-OimGCkk7.mjs} +34 -2
  108. package/dispatch_runner-OimGCkk7.mjs.map +1 -0
  109. package/dispatch_runner.cjs +1 -1
  110. package/dispatch_runner.mjs +1 -1
  111. package/{exceptions-D5YrO9Vm.js → exceptions-CSqzbL1N.js} +2 -2
  112. package/{exceptions-D5YrO9Vm.js.map → exceptions-CSqzbL1N.js.map} +1 -1
  113. package/exceptions.cjs +2 -2
  114. package/factories.cjs +1 -1
  115. package/forge.cjs +4 -4
  116. package/forge.mjs +3 -3
  117. package/guards.cjs +9 -9
  118. package/guards.mjs +7 -7
  119. package/index.cjs +12 -12
  120. package/index.cjs.map +1 -1
  121. package/index.d.ts +1 -1
  122. package/index.mjs +9 -9
  123. package/index.mjs.map +1 -1
  124. package/lib/classes/retrievable.d.ts +47 -4
  125. package/lib/contracts/byte_store.d.ts +93 -0
  126. package/lib/contracts/dispatch_context.d.ts +44 -0
  127. package/lib/contracts/turn_runner_config.d.ts +5 -1
  128. package/lib/contracts/turn_runner_context.d.ts +25 -0
  129. package/package.json +67 -67
  130. package/{runtime-BJVkrGQe.js → runtime-BUDWyd-R.js} +2 -2
  131. package/{runtime-BJVkrGQe.js.map → runtime-BUDWyd-R.js.map} +1 -1
  132. package/skills/adk-assembly/SKILL.md +2 -2
  133. package/{spooled_artifact-C5ZtGxuJ.mjs → spooled_artifact-B_tVDDdB.mjs} +2 -2
  134. package/{spooled_artifact-C5ZtGxuJ.mjs.map → spooled_artifact-B_tVDDdB.mjs.map} +1 -1
  135. package/{spooled_artifact-Cm9Te22K.js → spooled_artifact-CFstzlqX.js} +5 -6
  136. package/{spooled_artifact-Cm9Te22K.js.map → spooled_artifact-CFstzlqX.js.map} +1 -1
  137. package/spooled_artifact.cjs +2 -2
  138. package/spooled_artifact.mjs +2 -2
  139. package/{spooled_markdown_artifact-RRB113sy.js → spooled_markdown_artifact-DK-T8Hy6.js} +6 -7
  140. package/{spooled_markdown_artifact-RRB113sy.js.map → spooled_markdown_artifact-DK-T8Hy6.js.map} +1 -1
  141. package/{spooled_markdown_artifact-BpUJol0W.mjs → spooled_markdown_artifact-DWWak35I.mjs} +2 -2
  142. package/{spooled_markdown_artifact-BpUJol0W.mjs.map → spooled_markdown_artifact-DWWak35I.mjs.map} +1 -1
  143. package/{thought-CDb457b4.mjs → thought-DDqjQu3m.mjs} +2 -2
  144. package/{thought-CDb457b4.mjs.map → thought-DDqjQu3m.mjs.map} +1 -1
  145. package/{thought-DuN2PgdO.js → thought-DTsFRGdE.js} +5 -6
  146. package/{thought-DuN2PgdO.js.map → thought-DTsFRGdE.js.map} +1 -1
  147. package/{tool-COSeH8I6.js → tool-cwJyEHI9.js} +4 -5
  148. package/{tool-COSeH8I6.js.map → tool-cwJyEHI9.js.map} +1 -1
  149. package/{tool-D2WB1EA1.mjs → tool-q4LskG7K.mjs} +1 -1
  150. package/{tool-D2WB1EA1.mjs.map → tool-q4LskG7K.mjs.map} +1 -1
  151. package/{tool_call-DFgzcVcU.js → tool_call-3T0xTXlD.js} +5 -6
  152. package/{tool_call-DFgzcVcU.js.map → tool_call-3T0xTXlD.js.map} +1 -1
  153. package/{tool_call-BKyyxGaZ.mjs → tool_call-BKIdAAoY.mjs} +2 -2
  154. package/{tool_call-BKyyxGaZ.mjs.map → tool_call-BKIdAAoY.mjs.map} +1 -1
  155. package/{tool_registry-Dkfprsck.js → tool_registry-snPjF0zJ.js} +39 -5
  156. package/{tool_registry-Dkfprsck.js.map → tool_registry-snPjF0zJ.js.map} +1 -1
  157. package/{turn_runner-CMm2BHdX.js → turn_runner-BScT8OgA.js} +10 -7
  158. package/turn_runner-BScT8OgA.js.map +1 -0
  159. package/{turn_runner-y7eyEcJH.mjs → turn_runner-DRBLN2Y_.mjs} +7 -3
  160. package/turn_runner-DRBLN2Y_.mjs.map +1 -0
  161. package/turn_runner.cjs +1 -1
  162. package/turn_runner.mjs +1 -1
  163. package/types.d.ts +2 -2
  164. package/chunk-KmRHZBOW.js +0 -35
  165. package/common-DeZaonK1.mjs.map +0 -1
  166. package/common-Od8edUXU.js.map +0 -1
  167. package/dispatch_runner-9j6bXHL3.mjs.map +0 -1
  168. package/dispatch_runner-CsoH0nld.js.map +0 -1
  169. package/turn_runner-CMm2BHdX.js.map +0 -1
  170. package/turn_runner-y7eyEcJH.mjs.map +0 -1
@@ -1,12 +1,11 @@
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
- require("./thought-DuN2PgdO.js");
6
- require("./tool_call-DFgzcVcU.js");
7
- require("./tool-COSeH8I6.js");
8
- require("./spooled_artifact-Cm9Te22K.js");
9
- require("./spooled_markdown_artifact-RRB113sy.js");
1
+ const require_tool_registry = require("./tool_registry-snPjF0zJ.js");
2
+ const require_exceptions = require("./exceptions-CSqzbL1N.js");
3
+ const require_runtime = require("./runtime-BUDWyd-R.js");
4
+ require("./thought-DTsFRGdE.js");
5
+ require("./tool-cwJyEHI9.js");
6
+ const require_spooled_artifact = require("./spooled_artifact-CFstzlqX.js");
7
+ require("./tool_call-3T0xTXlD.js");
8
+ require("./spooled_markdown_artifact-DK-T8Hy6.js");
10
9
  let _nhtio_validation = require("@nhtio/validation");
11
10
  //#region src/lib/classes/retrievable.ts
12
11
  /**
@@ -25,9 +24,13 @@ let _nhtio_validation = require("@nhtio/validation");
25
24
  * Throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} (via the {@link Retrievable} constructor)
26
25
  * when validation fails.
27
26
  */
27
+ var contentSchema = _nhtio_validation.validator.alternatives(_nhtio_validation.validator.string(), _nhtio_validation.validator.custom((value, helpers) => {
28
+ if (require_tool_registry.Tokenizable.isTokenizable(value) || require_spooled_artifact.SpooledArtifact.isSpooledArtifact(value)) return value;
29
+ return helpers.error("any.invalid");
30
+ }));
28
31
  var rawRetrievableSchema = _nhtio_validation.validator.object({
29
32
  id: _nhtio_validation.validator.string().required(),
30
- content: require_tool_registry.Tokenizable.schema.required(),
33
+ content: contentSchema.required(),
31
34
  trustTier: _nhtio_validation.validator.string().valid("first-party", "third-party-public", "third-party-private").required(),
32
35
  source: _nhtio_validation.validator.string().optional(),
33
36
  kind: _nhtio_validation.validator.string().optional(),
@@ -81,7 +84,7 @@ var Retrievable = class Retrievable {
81
84
  throw new require_runtime.E_INVALID_INITIAL_RETRIEVABLE_VALUE({ cause: require_tool_registry.isError(err) ? err : void 0 });
82
85
  }
83
86
  this.#id = resolved.id;
84
- this.#content = require_tool_registry.Tokenizable.isTokenizable(resolved.content) ? resolved.content : new require_tool_registry.Tokenizable(resolved.content);
87
+ this.#content = require_tool_registry.Tokenizable.isTokenizable(resolved.content) || require_spooled_artifact.SpooledArtifact.isSpooledArtifact(resolved.content) ? resolved.content : new require_tool_registry.Tokenizable(resolved.content);
85
88
  this.#trustTier = resolved.trustTier;
86
89
  this.#source = resolved.source;
87
90
  this.#kind = resolved.kind;
@@ -131,6 +134,68 @@ var Retrievable = class Retrievable {
131
134
  }
132
135
  });
133
136
  }
137
+ /**
138
+ * Estimates the token count of the content under `encoding`.
139
+ *
140
+ * @remarks
141
+ * Delegates to the content's own `estimateTokens`: synchronous for a {@link @nhtio/adk!Tokenizable}
142
+ * (returns `number`), asynchronous for a {@link @nhtio/adk!SpooledArtifact} (returns
143
+ * `Promise<number>`, reading the bytes from the backing store on demand). Both shapes satisfy the
144
+ * adapter's token-budget path, which already awaits estimates.
145
+ *
146
+ * Note: the `SpooledArtifact` branch materialises the full decoded string transiently to count
147
+ * tokens — reader-backing keeps the body off the *permanent* heap, but does not eliminate the
148
+ * transient allocation at budgeting time.
149
+ *
150
+ * @param encoding - The encoding identifier to use for counting.
151
+ * @returns The estimated token count.
152
+ */
153
+ estimateTokens(encoding) {
154
+ return this.#content.estimateTokens(encoding);
155
+ }
156
+ /**
157
+ * Returns the content body as a single string.
158
+ *
159
+ * @remarks
160
+ * For a {@link @nhtio/adk!Tokenizable} this is synchronous in effect (resolved immediately); for a
161
+ * {@link @nhtio/adk!SpooledArtifact} it reads the full body from the backing store via
162
+ * {@link @nhtio/adk!SpooledArtifact.asString}. Always returns a `Promise` so callers have one
163
+ * code path; render helpers `await` it at the point the trust-tier envelope is built.
164
+ *
165
+ * @returns The full content body as a string.
166
+ */
167
+ async contentString() {
168
+ return require_spooled_artifact.SpooledArtifact.isSpooledArtifact(this.#content) ? this.#content.asString() : this.#content.toString();
169
+ }
170
+ };
171
+ //#endregion
172
+ //#region src/lib/contracts/byte_store.ts
173
+ /**
174
+ * Validator schema used to validate a {@link ByteStore} value.
175
+ *
176
+ * @remarks
177
+ * Because `ByteStore` is a structural interface with no associated constructor, validation is
178
+ * duck-typed: the value must be non-null with `write`, `read`, and `delete` present as callable
179
+ * properties. Arity is not enforced — implementations may add optional parameters beyond the
180
+ * contract. The reader type `R` cannot be checked structurally here; conformance of the reader is
181
+ * the caller's concern at the point of use.
182
+ */
183
+ var byteStoreSchema = _nhtio_validation.validator.any().custom((value, helpers) => {
184
+ if (value !== null && value !== void 0 && typeof value.write === "function" && typeof value.read === "function" && typeof value.delete === "function") return value;
185
+ return helpers.error("any.invalid");
186
+ });
187
+ /**
188
+ * Returns `true` if `value` implements the {@link ByteStore} interface.
189
+ *
190
+ * @remarks
191
+ * Duck-typed: checks that `value` is non-null with `write`, `read`, and `delete` as callable
192
+ * functions. Does not use `instanceof` — there is no `ByteStore` constructor.
193
+ *
194
+ * @param value - The value to test.
195
+ * @returns `true` when `value` conforms to the {@link ByteStore} interface.
196
+ */
197
+ var implementsByteStore = (value) => {
198
+ return require_exceptions.passesSchema(byteStoreSchema, value);
134
199
  };
135
200
  //#endregion
136
201
  //#region src/lib/helpers/media_readers.ts
@@ -210,6 +275,12 @@ Object.defineProperty(exports, "Retrievable", {
210
275
  return Retrievable;
211
276
  }
212
277
  });
278
+ Object.defineProperty(exports, "byteStoreSchema", {
279
+ enumerable: true,
280
+ get: function() {
281
+ return byteStoreSchema;
282
+ }
283
+ });
213
284
  Object.defineProperty(exports, "fromFetch", {
214
285
  enumerable: true,
215
286
  get: function() {
@@ -222,6 +293,12 @@ Object.defineProperty(exports, "fromWebFile", {
222
293
  return fromWebFile;
223
294
  }
224
295
  });
296
+ Object.defineProperty(exports, "implementsByteStore", {
297
+ enumerable: true,
298
+ get: function() {
299
+ return implementsByteStore;
300
+ }
301
+ });
225
302
  Object.defineProperty(exports, "inMemoryMediaReader", {
226
303
  enumerable: true,
227
304
  get: function() {
@@ -229,4 +306,4 @@ Object.defineProperty(exports, "inMemoryMediaReader", {
229
306
  }
230
307
  });
231
308
 
232
- //# sourceMappingURL=common-Od8edUXU.js.map
309
+ //# sourceMappingURL=common-BJ6V6dsH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-BJ6V6dsH.js","names":["#id","#content","#trustTier","#source","#kind","#score","#createdAt","#updatedAt"],"sources":["../src/lib/classes/retrievable.ts","../src/lib/contracts/byte_store.ts","../src/lib/helpers/media_readers.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { SpooledArtifact } from './spooled_artifact'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_RETRIEVABLE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { TokenEncoding } from './tokenizable'\n\n/**\n * Trust-tier discriminator declared by the retrieval middleware at construction time. Drives\n * which envelope the LLM battery wraps the record in.\n *\n * @remarks\n * Vocabulary deliberately mirrors the published security-research taxonomy (\"first-party /\n * third-party\" per *Hidden-in-Plain-Text* WWW '26 and *When AI Meets the Web* IEEE S&P 2026)\n * and explicitly avoids the words \"user\" or \"system\" so the names cannot leak into the model's\n * OpenAI-Model-Spec role-tier authority resolution.\n *\n * - `'first-party'` — deployer-vetted corpora (signed internal docs, policy KBs, curated\n * reference material). Rendered as a `<retrieved_corpus>` parent with per-record nonce-keyed\n * `<retrieved>` children. The label \"first-party\" never appears in the envelope itself.\n * - `'third-party-public'` — open-web scrapes, search results, public APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-public'`.\n * - `'third-party-private'` — user uploads, pasted attachments, partner APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-private'`.\n */\nexport type RetrievableTrustTier = 'first-party' | 'third-party-public' | 'third-party-private'\n\n/**\n * Plain input object supplied to {@link Retrievable} at construction time.\n *\n * @remarks\n * Validated against `rawRetrievableSchema` before the `Retrievable` 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 RawRetrievable {\n /**\n * Stable unique identifier for this retrieved record. Used as the closing-tag nonce in the\n * rendered envelope, so it must be unguessable from the payload.\n */\n id: string\n /**\n * The retrieved content. A plain `string` or {@link @nhtio/adk!Tokenizable} for small inline text, or a\n * {@link @nhtio/adk!SpooledArtifact} when the extracted text is large and lives in a consumer\n * {@link @nhtio/adk!ByteStore} (persist it via {@link @nhtio/adk!DispatchContext.storeRetrievableBytes}, wrap\n * the returned reader in a `SpooledArtifact`, and pass it here). Reader-backed content keeps the\n * body out of the permanent heap, but token estimation and render still materialise it\n * transiently (see {@link Retrievable.estimateTokens}).\n */\n content: string | Tokenizable | SpooledArtifact\n /**\n * Trust tier declared by the retrieval middleware at construction time. Required — there is\n * NO default. The decision must be conscious. See {@link RetrievableTrustTier}.\n */\n trustTier: RetrievableTrustTier\n /** Optional provenance string: URL, document path, knowledge-base id, etc. */\n source?: string\n /** Optional semantic label: 'policy' | 'reference' | 'web-page' | 'pdf' | etc. */\n kind?: string\n /** Optional relevance / similarity score in `[0, 1]` from the retrieval middleware. */\n score?: number\n /** When the source record was created (publication date, upload date, etc.). */\n createdAt: string | number | Date | DateTime\n /** When the source record was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawRetrievable} where all fields have been validated and temporal\n * values normalised to Luxon `DateTime` instances.\n */\ninterface ResolvedRetrievable {\n id: string\n content: Tokenizable | SpooledArtifact\n trustTier: RetrievableTrustTier\n source?: string\n kind?: string\n score?: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawRetrievable} before constructing a\n * {@link Retrievable}.\n *\n * @remarks\n * - `id` — required non-empty string.\n * - `content` — required {@link @nhtio/adk!Tokenizable.schema}.\n * - `trustTier` — required, one of `'first-party'`, `'third-party-public'`,\n * `'third-party-private'`. Unknown / missing values reject.\n * - `source` / `kind` — optional strings.\n * - `score` — optional number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values.\n *\n * Throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} (via the {@link Retrievable} constructor)\n * when validation fails.\n */\nconst contentSchema = validator.alternatives(\n validator.string(),\n validator.custom((value, helpers) => {\n if (Tokenizable.isTokenizable(value) || SpooledArtifact.isSpooledArtifact(value)) {\n return value\n }\n return helpers.error('any.invalid')\n })\n)\n\nconst rawRetrievableSchema = validator.object<RawRetrievable>({\n id: validator.string().required(),\n content: contentSchema.required(),\n trustTier: validator\n .string()\n .valid('first-party', 'third-party-public', 'third-party-private')\n .required(),\n source: validator.string().optional(),\n kind: validator.string().optional(),\n score: validator.number().min(0).max(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated retrieved record (RAG content) held by the agent.\n *\n * @remarks\n * Peer of {@link @nhtio/adk!Memory} / `Message` / `Thought` / `ToolCall`. Carries an explicit `trustTier`\n * that LLM batteries branch on to choose the rendering envelope. The retrieval middleware that\n * produced the record is the only party that knows its provenance — batteries MUST NOT\n * auto-classify or infer the tier from `source`.\n */\nexport class Retrievable {\n /**\n * Validator schema that accepts a {@link RawRetrievable} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a retrievable record.\n */\n public static schema = rawRetrievableSchema\n\n /**\n * Returns `true` if `value` is a {@link Retrievable} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.\n */\n public static isRetrievable(value: unknown): value is Retrievable {\n return isInstanceOf(value, 'Retrievable', Retrievable)\n }\n\n /** Stable unique identifier for this retrieved record. */\n declare readonly id: string\n /**\n * The retrieved content: a {@link @nhtio/adk!Tokenizable} (inline text) or a\n * {@link @nhtio/adk!SpooledArtifact} (reader-backed, large text living in a consumer store). Use\n * {@link Retrievable.estimateTokens} for budgeting and {@link Retrievable.contentString} to\n * materialise the body at render time.\n */\n declare readonly content: Tokenizable | SpooledArtifact\n /** Trust tier declared by the retrieval middleware. */\n declare readonly trustTier: RetrievableTrustTier\n /** Optional provenance string. */\n declare readonly source: string | undefined\n /** Optional semantic label. */\n declare readonly kind: string | undefined\n /** Optional relevance / similarity score in `[0, 1]`. */\n declare readonly score: number | undefined\n /** When the source record was created. */\n declare readonly createdAt: DateTime\n /** When the source record was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable | SpooledArtifact\n #trustTier: RetrievableTrustTier\n #source: string | undefined\n #kind: string | undefined\n #score: number | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw retrievable input validated against `rawRetrievableSchema`.\n * @throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawRetrievable) {\n let resolved: ResolvedRetrievable\n try {\n resolved = validateOrThrow<ResolvedRetrievable>(rawRetrievableSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_RETRIEVABLE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content =\n Tokenizable.isTokenizable(resolved.content) ||\n SpooledArtifact.isSpooledArtifact(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#trustTier = resolved.trustTier\n this.#source = resolved.source\n this.#kind = resolved.kind\n this.#score = resolved.score\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 trustTier: {\n get: () => this.#trustTier,\n enumerable: true,\n configurable: false,\n },\n source: {\n get: () => this.#source,\n enumerable: true,\n configurable: false,\n },\n kind: {\n get: () => this.#kind,\n enumerable: true,\n configurable: false,\n },\n score: {\n get: () => this.#score,\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 * Estimates the token count of the content under `encoding`.\n *\n * @remarks\n * Delegates to the content's own `estimateTokens`: synchronous for a {@link @nhtio/adk!Tokenizable}\n * (returns `number`), asynchronous for a {@link @nhtio/adk!SpooledArtifact} (returns\n * `Promise<number>`, reading the bytes from the backing store on demand). Both shapes satisfy the\n * adapter's token-budget path, which already awaits estimates.\n *\n * Note: the `SpooledArtifact` branch materialises the full decoded string transiently to count\n * tokens — reader-backing keeps the body off the *permanent* heap, but does not eliminate the\n * transient allocation at budgeting time.\n *\n * @param encoding - The encoding identifier to use for counting.\n * @returns The estimated token count.\n */\n estimateTokens(encoding: TokenEncoding): number | Promise<number> {\n return this.#content.estimateTokens(encoding)\n }\n\n /**\n * Returns the content body as a single string.\n *\n * @remarks\n * For a {@link @nhtio/adk!Tokenizable} this is synchronous in effect (resolved immediately); for a\n * {@link @nhtio/adk!SpooledArtifact} it reads the full body from the backing store via\n * {@link @nhtio/adk!SpooledArtifact.asString}. Always returns a `Promise` so callers have one\n * code path; render helpers `await` it at the point the trust-tier envelope is built.\n *\n * @returns The full content body as a string.\n */\n async contentString(): Promise<string> {\n return SpooledArtifact.isSpooledArtifact(this.#content)\n ? this.#content.asString()\n : this.#content.toString()\n }\n}\n","import { validator } from '@nhtio/validation'\nimport { passesSchema } from '../utils/validation'\nimport type { SpoolReader } from './spool_reader'\nimport type { MediaReader } from './media_reader'\n\n/**\n * Unified \"give bytes, get a reader\" persistence contract.\n *\n * @remarks\n * For the purposes of storage there is no meaningful distinction between text and binary — bytes\n * are bytes. `ByteStore` is the single low-level shape every ADK storage layer implements: hand it\n * bytes under an `id`, get back a replayable reader `R`; read or delete by the same `id` later. The\n * generic `R` is the reader the store hands out — different reader contracts (line-indexed\n * {@link @nhtio/adk!SpoolReader} vs binary-streamed {@link @nhtio/adk!MediaReader}) are\n * distinguished by the `R` instantiation, not by separate store interfaces. See the {@link SpoolStore}\n * and {@link MediaStore} aliases for the two concrete semantics.\n *\n * `write` accepts a `string`, a `Uint8Array`, or a `ReadableStream<Uint8Array>`. The stream form is\n * the point of the contract: a durable store can persist an arbitrarily large payload straight to\n * disk/object storage without first materializing it in memory. **String input is encoded as\n * UTF-8.** The returned reader is only guaranteed readable once the `write` result has resolved.\n *\n * All three methods may be synchronous or asynchronous so that in-memory implementations are not\n * forced to pay promise overhead while I/O-backed implementations stay async. Note that any\n * implementation accepting a `ReadableStream` must return a `Promise` for that input — draining a\n * stream cannot be synchronous.\n */\nexport interface ByteStore<R> {\n /**\n * Persists `bytes` under `id` and returns a reader over them.\n *\n * @remarks\n * Re-writing the same `id` replaces the prior entry. `string` input is encoded as UTF-8;\n * `Uint8Array` and `ReadableStream<Uint8Array>` are stored byte-faithfully. Stream input\n * necessarily resolves asynchronously.\n *\n * @param id - Identifier used to retrieve or delete the bytes later.\n * @param bytes - The payload, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A reader over the stored bytes (or a `Promise` of one).\n */\n write(id: string, bytes: string | Uint8Array | ReadableStream<Uint8Array>): R | Promise<R>\n\n /**\n * Returns a reader over the bytes previously written under `id`, or `undefined` if no entry\n * exists.\n *\n * @param id - Identifier supplied to a prior {@link ByteStore.write} call.\n * @returns A reader over the stored bytes, `undefined`, or a `Promise` of either.\n */\n read(id: string): R | undefined | Promise<R | undefined>\n\n /**\n * Removes the entry under `id`.\n *\n * @param id - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise (or a `Promise` of one).\n */\n delete(id: string): boolean | Promise<boolean>\n}\n\n/**\n * A {@link ByteStore} that hands out line-indexed text readers ({@link @nhtio/adk!SpoolReader}).\n *\n * @remarks\n * The store backing tool-output artifacts. Stored bytes are decoded as UTF-8 text for line-oriented\n * reads; binary input is stored byte-faithfully but `SpoolReader.readAll()` interprets it as text,\n * so opaque binary belongs in a {@link MediaStore} / `Media`, not here.\n */\nexport type SpoolStore = ByteStore<SpoolReader>\n\n/**\n * A {@link ByteStore} that hands out binary-streamed readers ({@link @nhtio/adk!MediaReader}).\n *\n * @remarks\n * The store backing persisted media bytes. Stored bytes are opaque and replayable via\n * `MediaReader.stream()`; no text decoding is implied.\n */\nexport type MediaStore = ByteStore<MediaReader>\n\n/**\n * Validator schema used to validate a {@link ByteStore} value.\n *\n * @remarks\n * Because `ByteStore` is a structural interface with no associated constructor, validation is\n * duck-typed: the value must be non-null with `write`, `read`, and `delete` present as callable\n * properties. Arity is not enforced — implementations may add optional parameters beyond the\n * contract. The reader type `R` cannot be checked structurally here; conformance of the reader is\n * the caller's concern at the point of use.\n */\nexport const byteStoreSchema = validator.any().custom((value, helpers) => {\n if (\n value !== null &&\n value !== undefined &&\n typeof (value as any).write === 'function' &&\n typeof (value as any).read === 'function' &&\n typeof (value as any).delete === 'function'\n ) {\n return value\n }\n return helpers.error('any.invalid')\n})\n\n/**\n * Returns `true` if `value` implements the {@link ByteStore} interface.\n *\n * @remarks\n * Duck-typed: checks that `value` is non-null with `write`, `read`, and `delete` as callable\n * functions. Does not use `instanceof` — there is no `ByteStore` constructor.\n *\n * @param value - The value to test.\n * @returns `true` when `value` conforms to the {@link ByteStore} interface.\n */\nexport const implementsByteStore = <R = unknown>(value: unknown): value is ByteStore<R> => {\n return passesSchema(byteStoreSchema, value)\n}\n","import type { MediaReader } from '../contracts/media_reader'\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by an in-memory `Uint8Array`.\n *\n * @remarks\n * Each `stream()` call returns a fresh single-chunk `ReadableStream` over the same buffer. The\n * reader is re-openable by construction — call `stream()` as many times as needed.\n *\n * @param bytes - The buffer to serve.\n * @returns A {@link @nhtio/adk!MediaReader} that re-reads `bytes` on every call.\n */\nexport const inMemoryMediaReader = (bytes: Uint8Array): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.enqueue(bytes)\n controller.close()\n },\n })\n },\n byteLength(): number {\n return bytes.byteLength\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a fetch call.\n *\n * @remarks\n * Each `stream()` call re-issues the fetch. Tool authors whose underlying source is rate-limited\n * or expensive must cache locally before constructing the reader — the framework cannot make\n * that decision for them.\n *\n * `byteLength()` returns `undefined` because most remote sources do not promise it without an\n * extra HEAD request; consumers that need a byte size should resolve it out-of-band.\n *\n * @param url - The URL to fetch on each call.\n * @param init - Optional `fetch` init forwarded verbatim.\n * @returns A {@link @nhtio/adk!MediaReader} that re-issues `fetch(url, init)` on every call.\n */\nexport const fromFetch = (url: string | URL, init?: RequestInit): MediaReader => {\n return {\n async stream(): Promise<ReadableStream<Uint8Array>> {\n const response = await fetch(url, init)\n if (!response.ok) {\n throw new Error(`fromFetch: fetch failed with status ${response.status}`)\n }\n if (!response.body) {\n throw new Error('fromFetch: response has no body')\n }\n return response.body as ReadableStream<Uint8Array>\n },\n byteLength(): undefined {\n return undefined\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a browser `File` or `Blob`.\n *\n * @remarks\n * Each `stream()` call re-streams the underlying File via `File.stream()`. `byteLength()`\n * resolves from `file.size`.\n *\n * @param file - The browser `File` or `Blob` to stream.\n * @returns A {@link @nhtio/adk!MediaReader} that re-streams `file` on every call.\n */\nexport const fromWebFile = (file: Blob): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return file.stream() as ReadableStream<Uint8Array>\n },\n byteLength(): number {\n return file.size\n },\n }\n}\n"],"mappings":"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"}
@@ -1,11 +1,11 @@
1
- import { a as validateOrThrow } from "./exceptions-NrzIHw_R.mjs";
1
+ import { a as validateOrThrow, i as passesSchema } from "./exceptions-NrzIHw_R.mjs";
2
2
  import { a as Tokenizable, o as isError, s as isInstanceOf } from "./tool_registry-DqLOyGyG.mjs";
3
3
  import { c as E_INVALID_INITIAL_RETRIEVABLE_VALUE } from "./runtime-CrEPIFgr.mjs";
4
- import "./thought-CDb457b4.mjs";
5
- import "./tool_call-BKyyxGaZ.mjs";
6
- import "./tool-D2WB1EA1.mjs";
7
- import "./spooled_artifact-C5ZtGxuJ.mjs";
8
- import "./spooled_markdown_artifact-BpUJol0W.mjs";
4
+ import "./thought-DDqjQu3m.mjs";
5
+ import "./tool-q4LskG7K.mjs";
6
+ import { t as SpooledArtifact } from "./spooled_artifact-B_tVDDdB.mjs";
7
+ import "./tool_call-BKIdAAoY.mjs";
8
+ import "./spooled_markdown_artifact-DWWak35I.mjs";
9
9
  import { validator } from "@nhtio/validation";
10
10
  //#region src/lib/classes/retrievable.ts
11
11
  /**
@@ -24,9 +24,13 @@ import { validator } from "@nhtio/validation";
24
24
  * Throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} (via the {@link Retrievable} constructor)
25
25
  * when validation fails.
26
26
  */
27
+ var contentSchema = validator.alternatives(validator.string(), validator.custom((value, helpers) => {
28
+ if (Tokenizable.isTokenizable(value) || SpooledArtifact.isSpooledArtifact(value)) return value;
29
+ return helpers.error("any.invalid");
30
+ }));
27
31
  var rawRetrievableSchema = validator.object({
28
32
  id: validator.string().required(),
29
- content: Tokenizable.schema.required(),
33
+ content: contentSchema.required(),
30
34
  trustTier: validator.string().valid("first-party", "third-party-public", "third-party-private").required(),
31
35
  source: validator.string().optional(),
32
36
  kind: validator.string().optional(),
@@ -80,7 +84,7 @@ var Retrievable = class Retrievable {
80
84
  throw new E_INVALID_INITIAL_RETRIEVABLE_VALUE({ cause: isError(err) ? err : void 0 });
81
85
  }
82
86
  this.#id = resolved.id;
83
- this.#content = Tokenizable.isTokenizable(resolved.content) ? resolved.content : new Tokenizable(resolved.content);
87
+ this.#content = Tokenizable.isTokenizable(resolved.content) || SpooledArtifact.isSpooledArtifact(resolved.content) ? resolved.content : new Tokenizable(resolved.content);
84
88
  this.#trustTier = resolved.trustTier;
85
89
  this.#source = resolved.source;
86
90
  this.#kind = resolved.kind;
@@ -130,6 +134,68 @@ var Retrievable = class Retrievable {
130
134
  }
131
135
  });
132
136
  }
137
+ /**
138
+ * Estimates the token count of the content under `encoding`.
139
+ *
140
+ * @remarks
141
+ * Delegates to the content's own `estimateTokens`: synchronous for a {@link @nhtio/adk!Tokenizable}
142
+ * (returns `number`), asynchronous for a {@link @nhtio/adk!SpooledArtifact} (returns
143
+ * `Promise<number>`, reading the bytes from the backing store on demand). Both shapes satisfy the
144
+ * adapter's token-budget path, which already awaits estimates.
145
+ *
146
+ * Note: the `SpooledArtifact` branch materialises the full decoded string transiently to count
147
+ * tokens — reader-backing keeps the body off the *permanent* heap, but does not eliminate the
148
+ * transient allocation at budgeting time.
149
+ *
150
+ * @param encoding - The encoding identifier to use for counting.
151
+ * @returns The estimated token count.
152
+ */
153
+ estimateTokens(encoding) {
154
+ return this.#content.estimateTokens(encoding);
155
+ }
156
+ /**
157
+ * Returns the content body as a single string.
158
+ *
159
+ * @remarks
160
+ * For a {@link @nhtio/adk!Tokenizable} this is synchronous in effect (resolved immediately); for a
161
+ * {@link @nhtio/adk!SpooledArtifact} it reads the full body from the backing store via
162
+ * {@link @nhtio/adk!SpooledArtifact.asString}. Always returns a `Promise` so callers have one
163
+ * code path; render helpers `await` it at the point the trust-tier envelope is built.
164
+ *
165
+ * @returns The full content body as a string.
166
+ */
167
+ async contentString() {
168
+ return SpooledArtifact.isSpooledArtifact(this.#content) ? this.#content.asString() : this.#content.toString();
169
+ }
170
+ };
171
+ //#endregion
172
+ //#region src/lib/contracts/byte_store.ts
173
+ /**
174
+ * Validator schema used to validate a {@link ByteStore} value.
175
+ *
176
+ * @remarks
177
+ * Because `ByteStore` is a structural interface with no associated constructor, validation is
178
+ * duck-typed: the value must be non-null with `write`, `read`, and `delete` present as callable
179
+ * properties. Arity is not enforced — implementations may add optional parameters beyond the
180
+ * contract. The reader type `R` cannot be checked structurally here; conformance of the reader is
181
+ * the caller's concern at the point of use.
182
+ */
183
+ var byteStoreSchema = validator.any().custom((value, helpers) => {
184
+ if (value !== null && value !== void 0 && typeof value.write === "function" && typeof value.read === "function" && typeof value.delete === "function") return value;
185
+ return helpers.error("any.invalid");
186
+ });
187
+ /**
188
+ * Returns `true` if `value` implements the {@link ByteStore} interface.
189
+ *
190
+ * @remarks
191
+ * Duck-typed: checks that `value` is non-null with `write`, `read`, and `delete` as callable
192
+ * functions. Does not use `instanceof` — there is no `ByteStore` constructor.
193
+ *
194
+ * @param value - The value to test.
195
+ * @returns `true` when `value` conforms to the {@link ByteStore} interface.
196
+ */
197
+ var implementsByteStore = (value) => {
198
+ return passesSchema(byteStoreSchema, value);
133
199
  };
134
200
  //#endregion
135
201
  //#region src/lib/helpers/media_readers.ts
@@ -203,6 +269,6 @@ var fromWebFile = (file) => {
203
269
  };
204
270
  };
205
271
  //#endregion
206
- export { Retrievable as i, fromWebFile as n, inMemoryMediaReader as r, fromFetch as t };
272
+ export { implementsByteStore as a, byteStoreSchema as i, fromWebFile as n, Retrievable as o, inMemoryMediaReader as r, fromFetch as t };
207
273
 
208
- //# sourceMappingURL=common-DeZaonK1.mjs.map
274
+ //# sourceMappingURL=common-aFmr9Oqs.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-aFmr9Oqs.mjs","names":["#id","#content","#trustTier","#source","#kind","#score","#createdAt","#updatedAt"],"sources":["../src/lib/classes/retrievable.ts","../src/lib/contracts/byte_store.ts","../src/lib/helpers/media_readers.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { SpooledArtifact } from './spooled_artifact'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_RETRIEVABLE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { TokenEncoding } from './tokenizable'\n\n/**\n * Trust-tier discriminator declared by the retrieval middleware at construction time. Drives\n * which envelope the LLM battery wraps the record in.\n *\n * @remarks\n * Vocabulary deliberately mirrors the published security-research taxonomy (\"first-party /\n * third-party\" per *Hidden-in-Plain-Text* WWW '26 and *When AI Meets the Web* IEEE S&P 2026)\n * and explicitly avoids the words \"user\" or \"system\" so the names cannot leak into the model's\n * OpenAI-Model-Spec role-tier authority resolution.\n *\n * - `'first-party'` — deployer-vetted corpora (signed internal docs, policy KBs, curated\n * reference material). Rendered as a `<retrieved_corpus>` parent with per-record nonce-keyed\n * `<retrieved>` children. The label \"first-party\" never appears in the envelope itself.\n * - `'third-party-public'` — open-web scrapes, search results, public APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-public'`.\n * - `'third-party-private'` — user uploads, pasted attachments, partner APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-private'`.\n */\nexport type RetrievableTrustTier = 'first-party' | 'third-party-public' | 'third-party-private'\n\n/**\n * Plain input object supplied to {@link Retrievable} at construction time.\n *\n * @remarks\n * Validated against `rawRetrievableSchema` before the `Retrievable` 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 RawRetrievable {\n /**\n * Stable unique identifier for this retrieved record. Used as the closing-tag nonce in the\n * rendered envelope, so it must be unguessable from the payload.\n */\n id: string\n /**\n * The retrieved content. A plain `string` or {@link @nhtio/adk!Tokenizable} for small inline text, or a\n * {@link @nhtio/adk!SpooledArtifact} when the extracted text is large and lives in a consumer\n * {@link @nhtio/adk!ByteStore} (persist it via {@link @nhtio/adk!DispatchContext.storeRetrievableBytes}, wrap\n * the returned reader in a `SpooledArtifact`, and pass it here). Reader-backed content keeps the\n * body out of the permanent heap, but token estimation and render still materialise it\n * transiently (see {@link Retrievable.estimateTokens}).\n */\n content: string | Tokenizable | SpooledArtifact\n /**\n * Trust tier declared by the retrieval middleware at construction time. Required — there is\n * NO default. The decision must be conscious. See {@link RetrievableTrustTier}.\n */\n trustTier: RetrievableTrustTier\n /** Optional provenance string: URL, document path, knowledge-base id, etc. */\n source?: string\n /** Optional semantic label: 'policy' | 'reference' | 'web-page' | 'pdf' | etc. */\n kind?: string\n /** Optional relevance / similarity score in `[0, 1]` from the retrieval middleware. */\n score?: number\n /** When the source record was created (publication date, upload date, etc.). */\n createdAt: string | number | Date | DateTime\n /** When the source record was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawRetrievable} where all fields have been validated and temporal\n * values normalised to Luxon `DateTime` instances.\n */\ninterface ResolvedRetrievable {\n id: string\n content: Tokenizable | SpooledArtifact\n trustTier: RetrievableTrustTier\n source?: string\n kind?: string\n score?: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawRetrievable} before constructing a\n * {@link Retrievable}.\n *\n * @remarks\n * - `id` — required non-empty string.\n * - `content` — required {@link @nhtio/adk!Tokenizable.schema}.\n * - `trustTier` — required, one of `'first-party'`, `'third-party-public'`,\n * `'third-party-private'`. Unknown / missing values reject.\n * - `source` / `kind` — optional strings.\n * - `score` — optional number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values.\n *\n * Throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} (via the {@link Retrievable} constructor)\n * when validation fails.\n */\nconst contentSchema = validator.alternatives(\n validator.string(),\n validator.custom((value, helpers) => {\n if (Tokenizable.isTokenizable(value) || SpooledArtifact.isSpooledArtifact(value)) {\n return value\n }\n return helpers.error('any.invalid')\n })\n)\n\nconst rawRetrievableSchema = validator.object<RawRetrievable>({\n id: validator.string().required(),\n content: contentSchema.required(),\n trustTier: validator\n .string()\n .valid('first-party', 'third-party-public', 'third-party-private')\n .required(),\n source: validator.string().optional(),\n kind: validator.string().optional(),\n score: validator.number().min(0).max(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated retrieved record (RAG content) held by the agent.\n *\n * @remarks\n * Peer of {@link @nhtio/adk!Memory} / `Message` / `Thought` / `ToolCall`. Carries an explicit `trustTier`\n * that LLM batteries branch on to choose the rendering envelope. The retrieval middleware that\n * produced the record is the only party that knows its provenance — batteries MUST NOT\n * auto-classify or infer the tier from `source`.\n */\nexport class Retrievable {\n /**\n * Validator schema that accepts a {@link RawRetrievable} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a retrievable record.\n */\n public static schema = rawRetrievableSchema\n\n /**\n * Returns `true` if `value` is a {@link Retrievable} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.\n */\n public static isRetrievable(value: unknown): value is Retrievable {\n return isInstanceOf(value, 'Retrievable', Retrievable)\n }\n\n /** Stable unique identifier for this retrieved record. */\n declare readonly id: string\n /**\n * The retrieved content: a {@link @nhtio/adk!Tokenizable} (inline text) or a\n * {@link @nhtio/adk!SpooledArtifact} (reader-backed, large text living in a consumer store). Use\n * {@link Retrievable.estimateTokens} for budgeting and {@link Retrievable.contentString} to\n * materialise the body at render time.\n */\n declare readonly content: Tokenizable | SpooledArtifact\n /** Trust tier declared by the retrieval middleware. */\n declare readonly trustTier: RetrievableTrustTier\n /** Optional provenance string. */\n declare readonly source: string | undefined\n /** Optional semantic label. */\n declare readonly kind: string | undefined\n /** Optional relevance / similarity score in `[0, 1]`. */\n declare readonly score: number | undefined\n /** When the source record was created. */\n declare readonly createdAt: DateTime\n /** When the source record was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable | SpooledArtifact\n #trustTier: RetrievableTrustTier\n #source: string | undefined\n #kind: string | undefined\n #score: number | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw retrievable input validated against `rawRetrievableSchema`.\n * @throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawRetrievable) {\n let resolved: ResolvedRetrievable\n try {\n resolved = validateOrThrow<ResolvedRetrievable>(rawRetrievableSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_RETRIEVABLE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content =\n Tokenizable.isTokenizable(resolved.content) ||\n SpooledArtifact.isSpooledArtifact(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#trustTier = resolved.trustTier\n this.#source = resolved.source\n this.#kind = resolved.kind\n this.#score = resolved.score\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 trustTier: {\n get: () => this.#trustTier,\n enumerable: true,\n configurable: false,\n },\n source: {\n get: () => this.#source,\n enumerable: true,\n configurable: false,\n },\n kind: {\n get: () => this.#kind,\n enumerable: true,\n configurable: false,\n },\n score: {\n get: () => this.#score,\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 * Estimates the token count of the content under `encoding`.\n *\n * @remarks\n * Delegates to the content's own `estimateTokens`: synchronous for a {@link @nhtio/adk!Tokenizable}\n * (returns `number`), asynchronous for a {@link @nhtio/adk!SpooledArtifact} (returns\n * `Promise<number>`, reading the bytes from the backing store on demand). Both shapes satisfy the\n * adapter's token-budget path, which already awaits estimates.\n *\n * Note: the `SpooledArtifact` branch materialises the full decoded string transiently to count\n * tokens — reader-backing keeps the body off the *permanent* heap, but does not eliminate the\n * transient allocation at budgeting time.\n *\n * @param encoding - The encoding identifier to use for counting.\n * @returns The estimated token count.\n */\n estimateTokens(encoding: TokenEncoding): number | Promise<number> {\n return this.#content.estimateTokens(encoding)\n }\n\n /**\n * Returns the content body as a single string.\n *\n * @remarks\n * For a {@link @nhtio/adk!Tokenizable} this is synchronous in effect (resolved immediately); for a\n * {@link @nhtio/adk!SpooledArtifact} it reads the full body from the backing store via\n * {@link @nhtio/adk!SpooledArtifact.asString}. Always returns a `Promise` so callers have one\n * code path; render helpers `await` it at the point the trust-tier envelope is built.\n *\n * @returns The full content body as a string.\n */\n async contentString(): Promise<string> {\n return SpooledArtifact.isSpooledArtifact(this.#content)\n ? this.#content.asString()\n : this.#content.toString()\n }\n}\n","import { validator } from '@nhtio/validation'\nimport { passesSchema } from '../utils/validation'\nimport type { SpoolReader } from './spool_reader'\nimport type { MediaReader } from './media_reader'\n\n/**\n * Unified \"give bytes, get a reader\" persistence contract.\n *\n * @remarks\n * For the purposes of storage there is no meaningful distinction between text and binary — bytes\n * are bytes. `ByteStore` is the single low-level shape every ADK storage layer implements: hand it\n * bytes under an `id`, get back a replayable reader `R`; read or delete by the same `id` later. The\n * generic `R` is the reader the store hands out — different reader contracts (line-indexed\n * {@link @nhtio/adk!SpoolReader} vs binary-streamed {@link @nhtio/adk!MediaReader}) are\n * distinguished by the `R` instantiation, not by separate store interfaces. See the {@link SpoolStore}\n * and {@link MediaStore} aliases for the two concrete semantics.\n *\n * `write` accepts a `string`, a `Uint8Array`, or a `ReadableStream<Uint8Array>`. The stream form is\n * the point of the contract: a durable store can persist an arbitrarily large payload straight to\n * disk/object storage without first materializing it in memory. **String input is encoded as\n * UTF-8.** The returned reader is only guaranteed readable once the `write` result has resolved.\n *\n * All three methods may be synchronous or asynchronous so that in-memory implementations are not\n * forced to pay promise overhead while I/O-backed implementations stay async. Note that any\n * implementation accepting a `ReadableStream` must return a `Promise` for that input — draining a\n * stream cannot be synchronous.\n */\nexport interface ByteStore<R> {\n /**\n * Persists `bytes` under `id` and returns a reader over them.\n *\n * @remarks\n * Re-writing the same `id` replaces the prior entry. `string` input is encoded as UTF-8;\n * `Uint8Array` and `ReadableStream<Uint8Array>` are stored byte-faithfully. Stream input\n * necessarily resolves asynchronously.\n *\n * @param id - Identifier used to retrieve or delete the bytes later.\n * @param bytes - The payload, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A reader over the stored bytes (or a `Promise` of one).\n */\n write(id: string, bytes: string | Uint8Array | ReadableStream<Uint8Array>): R | Promise<R>\n\n /**\n * Returns a reader over the bytes previously written under `id`, or `undefined` if no entry\n * exists.\n *\n * @param id - Identifier supplied to a prior {@link ByteStore.write} call.\n * @returns A reader over the stored bytes, `undefined`, or a `Promise` of either.\n */\n read(id: string): R | undefined | Promise<R | undefined>\n\n /**\n * Removes the entry under `id`.\n *\n * @param id - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise (or a `Promise` of one).\n */\n delete(id: string): boolean | Promise<boolean>\n}\n\n/**\n * A {@link ByteStore} that hands out line-indexed text readers ({@link @nhtio/adk!SpoolReader}).\n *\n * @remarks\n * The store backing tool-output artifacts. Stored bytes are decoded as UTF-8 text for line-oriented\n * reads; binary input is stored byte-faithfully but `SpoolReader.readAll()` interprets it as text,\n * so opaque binary belongs in a {@link MediaStore} / `Media`, not here.\n */\nexport type SpoolStore = ByteStore<SpoolReader>\n\n/**\n * A {@link ByteStore} that hands out binary-streamed readers ({@link @nhtio/adk!MediaReader}).\n *\n * @remarks\n * The store backing persisted media bytes. Stored bytes are opaque and replayable via\n * `MediaReader.stream()`; no text decoding is implied.\n */\nexport type MediaStore = ByteStore<MediaReader>\n\n/**\n * Validator schema used to validate a {@link ByteStore} value.\n *\n * @remarks\n * Because `ByteStore` is a structural interface with no associated constructor, validation is\n * duck-typed: the value must be non-null with `write`, `read`, and `delete` present as callable\n * properties. Arity is not enforced — implementations may add optional parameters beyond the\n * contract. The reader type `R` cannot be checked structurally here; conformance of the reader is\n * the caller's concern at the point of use.\n */\nexport const byteStoreSchema = validator.any().custom((value, helpers) => {\n if (\n value !== null &&\n value !== undefined &&\n typeof (value as any).write === 'function' &&\n typeof (value as any).read === 'function' &&\n typeof (value as any).delete === 'function'\n ) {\n return value\n }\n return helpers.error('any.invalid')\n})\n\n/**\n * Returns `true` if `value` implements the {@link ByteStore} interface.\n *\n * @remarks\n * Duck-typed: checks that `value` is non-null with `write`, `read`, and `delete` as callable\n * functions. Does not use `instanceof` — there is no `ByteStore` constructor.\n *\n * @param value - The value to test.\n * @returns `true` when `value` conforms to the {@link ByteStore} interface.\n */\nexport const implementsByteStore = <R = unknown>(value: unknown): value is ByteStore<R> => {\n return passesSchema(byteStoreSchema, value)\n}\n","import type { MediaReader } from '../contracts/media_reader'\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by an in-memory `Uint8Array`.\n *\n * @remarks\n * Each `stream()` call returns a fresh single-chunk `ReadableStream` over the same buffer. The\n * reader is re-openable by construction — call `stream()` as many times as needed.\n *\n * @param bytes - The buffer to serve.\n * @returns A {@link @nhtio/adk!MediaReader} that re-reads `bytes` on every call.\n */\nexport const inMemoryMediaReader = (bytes: Uint8Array): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.enqueue(bytes)\n controller.close()\n },\n })\n },\n byteLength(): number {\n return bytes.byteLength\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a fetch call.\n *\n * @remarks\n * Each `stream()` call re-issues the fetch. Tool authors whose underlying source is rate-limited\n * or expensive must cache locally before constructing the reader — the framework cannot make\n * that decision for them.\n *\n * `byteLength()` returns `undefined` because most remote sources do not promise it without an\n * extra HEAD request; consumers that need a byte size should resolve it out-of-band.\n *\n * @param url - The URL to fetch on each call.\n * @param init - Optional `fetch` init forwarded verbatim.\n * @returns A {@link @nhtio/adk!MediaReader} that re-issues `fetch(url, init)` on every call.\n */\nexport const fromFetch = (url: string | URL, init?: RequestInit): MediaReader => {\n return {\n async stream(): Promise<ReadableStream<Uint8Array>> {\n const response = await fetch(url, init)\n if (!response.ok) {\n throw new Error(`fromFetch: fetch failed with status ${response.status}`)\n }\n if (!response.body) {\n throw new Error('fromFetch: response has no body')\n }\n return response.body as ReadableStream<Uint8Array>\n },\n byteLength(): undefined {\n return undefined\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a browser `File` or `Blob`.\n *\n * @remarks\n * Each `stream()` call re-streams the underlying File via `File.stream()`. `byteLength()`\n * resolves from `file.size`.\n *\n * @param file - The browser `File` or `Blob` to stream.\n * @returns A {@link @nhtio/adk!MediaReader} that re-streams `file` on every call.\n */\nexport const fromWebFile = (file: Blob): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return file.stream() as ReadableStream<Uint8Array>\n },\n byteLength(): number {\n return file.size\n },\n }\n}\n"],"mappings":"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"}
package/common.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_tool_registry = require("./tool_registry-Dkfprsck.js");
3
- const require_thought = require("./thought-DuN2PgdO.js");
4
- const require_common = require("./common-Od8edUXU.js");
5
- const require_tool_call = require("./tool_call-DFgzcVcU.js");
6
- const require_tool = require("./tool-COSeH8I6.js");
7
- const require_spooled_artifact = require("./spooled_artifact-Cm9Te22K.js");
8
- const require_spooled_markdown_artifact = require("./spooled_markdown_artifact-RRB113sy.js");
2
+ const require_tool_registry = require("./tool_registry-snPjF0zJ.js");
3
+ const require_thought = require("./thought-DTsFRGdE.js");
4
+ const require_tool = require("./tool-cwJyEHI9.js");
5
+ const require_spooled_artifact = require("./spooled_artifact-CFstzlqX.js");
6
+ const require_common = require("./common-BJ6V6dsH.js");
7
+ const require_tool_call = require("./tool_call-3T0xTXlD.js");
8
+ const require_spooled_markdown_artifact = require("./spooled_markdown_artifact-DK-T8Hy6.js");
9
9
  exports.ArtifactTool = require_spooled_artifact.ArtifactTool;
10
10
  exports.Identity = require_thought.Identity;
11
11
  exports.Media = require_tool_call.Media;
@@ -22,8 +22,10 @@ exports.Tokenizable = require_tool_registry.Tokenizable;
22
22
  exports.Tool = require_tool.Tool;
23
23
  exports.ToolCall = require_tool_call.ToolCall;
24
24
  exports.ToolRegistry = require_tool_registry.ToolRegistry;
25
+ exports.byteStoreSchema = require_common.byteStoreSchema;
25
26
  exports.fromFetch = require_common.fromFetch;
26
27
  exports.fromWebFile = require_common.fromWebFile;
28
+ exports.implementsByteStore = require_common.implementsByteStore;
27
29
  exports.implementsMediaReader = require_tool_call.implementsMediaReader;
28
30
  exports.implementsSpoolReader = require_spooled_artifact.implementsSpoolReader;
29
31
  exports.inMemoryMediaReader = require_common.inMemoryMediaReader;
package/common.d.ts CHANGED
@@ -82,6 +82,14 @@ export type { RawTurnGate } from "./lib/classes/turn_gate";
82
82
  export { SpooledArtifact } from "./lib/classes/spooled_artifact";
83
83
  export { implementsSpoolReader } from "./lib/contracts/spool_reader";
84
84
  export type { SpoolReader } from "./lib/contracts/spool_reader";
85
+ /**
86
+ * @primaryExport
87
+ */
88
+ export { implementsByteStore, byteStoreSchema } from "./lib/contracts/byte_store";
89
+ /**
90
+ * @primaryExport
91
+ */
92
+ export type { ByteStore, SpoolStore, MediaStore } from "./lib/contracts/byte_store";
85
93
  /**
86
94
  * @primaryExport
87
95
  */
package/common.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { a as Tokenizable, i as TokenEncoding, r as Registry, t as ToolRegistry } from "./tool_registry-DqLOyGyG.mjs";
2
- import { i as Identity, n as Message, r as Memory, t as Thought } from "./thought-CDb457b4.mjs";
3
- import { i as Retrievable, n as fromWebFile, r as inMemoryMediaReader, t as fromFetch } from "./common-DeZaonK1.mjs";
4
- import { a as mediaReaderSchema, i as implementsMediaReader, n as Media, r as isMedia, t as ToolCall } from "./tool_call-BKyyxGaZ.mjs";
5
- import { t as Tool } from "./tool-D2WB1EA1.mjs";
6
- import { i as ArtifactTool, r as implementsSpoolReader, t as SpooledArtifact } from "./spooled_artifact-C5ZtGxuJ.mjs";
7
- import { n as SpooledJsonArtifact, t as SpooledMarkdownArtifact } from "./spooled_markdown_artifact-BpUJol0W.mjs";
8
- export { ArtifactTool, Identity, Media, Memory, Message, Registry, Retrievable, SpooledArtifact, SpooledJsonArtifact, SpooledMarkdownArtifact, Thought, TokenEncoding, Tokenizable, Tool, ToolCall, ToolRegistry, fromFetch, fromWebFile, implementsMediaReader, implementsSpoolReader, inMemoryMediaReader, isMedia, mediaReaderSchema };
2
+ import { i as Identity, n as Message, r as Memory, t as Thought } from "./thought-DDqjQu3m.mjs";
3
+ import { t as Tool } from "./tool-q4LskG7K.mjs";
4
+ import { i as ArtifactTool, r as implementsSpoolReader, t as SpooledArtifact } from "./spooled_artifact-B_tVDDdB.mjs";
5
+ import { a as implementsByteStore, i as byteStoreSchema, n as fromWebFile, o as Retrievable, r as inMemoryMediaReader, t as fromFetch } from "./common-aFmr9Oqs.mjs";
6
+ import { a as mediaReaderSchema, i as implementsMediaReader, n as Media, r as isMedia, t as ToolCall } from "./tool_call-BKIdAAoY.mjs";
7
+ import { n as SpooledJsonArtifact, t as SpooledMarkdownArtifact } from "./spooled_markdown_artifact-DWWak35I.mjs";
8
+ export { ArtifactTool, Identity, Media, Memory, Message, Registry, Retrievable, SpooledArtifact, SpooledJsonArtifact, SpooledMarkdownArtifact, Thought, TokenEncoding, Tokenizable, Tool, ToolCall, ToolRegistry, byteStoreSchema, fromFetch, fromWebFile, implementsByteStore, implementsMediaReader, implementsSpoolReader, inMemoryMediaReader, isMedia, mediaReaderSchema };
@@ -1,11 +1,10 @@
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");
1
+ const require_tool_registry = require("./tool_registry-snPjF0zJ.js");
2
+ const require_exceptions = require("./exceptions-CSqzbL1N.js");
3
+ const require_runtime = require("./runtime-BUDWyd-R.js");
5
4
  let _nhtio_validation = require("@nhtio/validation");
6
- let uuid = require("uuid");
7
5
  let luxon = require("luxon");
8
6
  let js_sha256 = require("js-sha256");
7
+ let uuid = require("uuid");
9
8
  let _nhtio_hooks = require("@nhtio/hooks");
10
9
  let _nhtio_middleware = require("@nhtio/middleware");
11
10
  //#region src/lib/contracts/turn_runner_context.ts
@@ -299,6 +298,18 @@ var TurnContext = class TurnContext {
299
298
  configurable: false,
300
299
  writable: false
301
300
  },
301
+ storeMediaBytes: {
302
+ value: (id, bytes) => injected.storeMediaBytes(this, id, bytes),
303
+ enumerable: true,
304
+ configurable: false,
305
+ writable: false
306
+ },
307
+ storeRetrievableBytes: {
308
+ value: (id, bytes) => injected.storeRetrievableBytes(this, id, bytes),
309
+ enumerable: true,
310
+ configurable: false,
311
+ writable: false
312
+ },
302
313
  emitMessage: {
303
314
  value: injected.emitMessage,
304
315
  enumerable: true,
@@ -381,6 +392,8 @@ var rawDispatchContextSchema = _nhtio_validation.validator.object({
381
392
  storeToolCall: _nhtio_validation.validator.function().required(),
382
393
  mutateToolCall: _nhtio_validation.validator.function().required(),
383
394
  deleteToolCall: _nhtio_validation.validator.function().required(),
395
+ storeMediaBytes: _nhtio_validation.validator.function().required(),
396
+ storeRetrievableBytes: _nhtio_validation.validator.function().required(),
384
397
  hooks: _nhtio_validation.validator.object().optional(),
385
398
  waitFor: _nhtio_validation.validator.function().optional()
386
399
  });
@@ -445,6 +458,8 @@ var DispatchContext = class DispatchContext {
445
458
  #storeToolCall;
446
459
  #mutateToolCall;
447
460
  #deleteToolCall;
461
+ #storeMediaBytes;
462
+ #storeRetrievableBytes;
448
463
  #waitFor;
449
464
  #toolCallChecksums;
450
465
  #signalled;
@@ -503,6 +518,8 @@ var DispatchContext = class DispatchContext {
503
518
  this.#storeToolCall = resolved.storeToolCall;
504
519
  this.#mutateToolCall = resolved.mutateToolCall;
505
520
  this.#deleteToolCall = resolved.deleteToolCall;
521
+ this.#storeMediaBytes = resolved.storeMediaBytes;
522
+ this.#storeRetrievableBytes = resolved.storeRetrievableBytes;
506
523
  this.#waitFor = resolved.waitFor;
507
524
  this.#signalled = void 0;
508
525
  this.#nackError = void 0;
@@ -759,6 +776,18 @@ var DispatchContext = class DispatchContext {
759
776
  configurable: false,
760
777
  writable: false
761
778
  },
779
+ storeMediaBytes: {
780
+ value: (id, bytes) => this.#storeMediaBytes(this, id, bytes),
781
+ enumerable: true,
782
+ configurable: false,
783
+ writable: false
784
+ },
785
+ storeRetrievableBytes: {
786
+ value: (id, bytes) => this.#storeRetrievableBytes(this, id, bytes),
787
+ enumerable: true,
788
+ configurable: false,
789
+ writable: false
790
+ },
762
791
  emitMessage: {
763
792
  value: (content) => {
764
793
  this.#hooks.runner("message").run(content);
@@ -1187,6 +1216,8 @@ var DispatchRunner = class DispatchRunner {
1187
1216
  storeToolCall: (_c, v) => source.storeToolCall(v),
1188
1217
  mutateToolCall: (_c, v) => source.mutateToolCall(v),
1189
1218
  deleteToolCall: (_c, id) => source.deleteToolCall(id),
1219
+ storeMediaBytes: (_c, id, bytes) => source.storeMediaBytes(id, bytes),
1220
+ storeRetrievableBytes: (_c, id, bytes) => source.storeRetrievableBytes(id, bytes),
1190
1221
  waitFor: source.waitFor
1191
1222
  });
1192
1223
  }
@@ -1624,4 +1655,4 @@ Object.defineProperty(exports, "TurnContext", {
1624
1655
  }
1625
1656
  });
1626
1657
 
1627
- //# sourceMappingURL=dispatch_runner-CsoH0nld.js.map
1658
+ //# sourceMappingURL=dispatch_runner-BWYNxmnp.js.map