@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.
- package/LICENSE.md +9 -0
- package/README.md +3 -0
- package/batteries/index.d.ts +28 -0
- package/batteries/llm/index.d.ts +11 -0
- package/batteries/llm/openai_chat_completions/adapter.cjs +916 -0
- package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/adapter.d.ts +101 -0
- package/batteries/llm/openai_chat_completions/adapter.mjs +914 -0
- package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions/exceptions.cjs +89 -0
- package/batteries/llm/openai_chat_completions/exceptions.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/exceptions.d.ts +97 -0
- package/batteries/llm/openai_chat_completions/exceptions.mjs +81 -0
- package/batteries/llm/openai_chat_completions/exceptions.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions/helpers.cjs +819 -0
- package/batteries/llm/openai_chat_completions/helpers.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/helpers.d.ts +233 -0
- package/batteries/llm/openai_chat_completions/helpers.mjs +783 -0
- package/batteries/llm/openai_chat_completions/helpers.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions/index.d.ts +27 -0
- package/batteries/llm/openai_chat_completions/types.cjs +1 -0
- package/batteries/llm/openai_chat_completions/types.d.ts +524 -0
- package/batteries/llm/openai_chat_completions/types.mjs +0 -0
- package/batteries/llm/openai_chat_completions/validation.cjs +190 -0
- package/batteries/llm/openai_chat_completions/validation.cjs.map +1 -0
- package/batteries/llm/openai_chat_completions/validation.d.ts +31 -0
- package/batteries/llm/openai_chat_completions/validation.mjs +187 -0
- package/batteries/llm/openai_chat_completions/validation.mjs.map +1 -0
- package/batteries/llm/openai_chat_completions.cjs +51 -0
- package/batteries/llm/openai_chat_completions.mjs +5 -0
- package/batteries/llm/webllm_chat_completions/adapter.cjs +658 -0
- package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/adapter.d.ts +103 -0
- package/batteries/llm/webllm_chat_completions/adapter.mjs +656 -0
- package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/exceptions.cjs +70 -0
- package/batteries/llm/webllm_chat_completions/exceptions.cjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/exceptions.d.ts +74 -0
- package/batteries/llm/webllm_chat_completions/exceptions.mjs +65 -0
- package/batteries/llm/webllm_chat_completions/exceptions.mjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/helpers.cjs +38 -0
- package/batteries/llm/webllm_chat_completions/helpers.d.ts +6 -0
- package/batteries/llm/webllm_chat_completions/helpers.mjs +2 -0
- package/batteries/llm/webllm_chat_completions/index.d.ts +25 -0
- package/batteries/llm/webllm_chat_completions/types.d.ts +31 -0
- package/batteries/llm/webllm_chat_completions/validation.cjs +115 -0
- package/batteries/llm/webllm_chat_completions/validation.cjs.map +1 -0
- package/batteries/llm/webllm_chat_completions/validation.d.ts +8 -0
- package/batteries/llm/webllm_chat_completions/validation.mjs +112 -0
- package/batteries/llm/webllm_chat_completions/validation.mjs.map +1 -0
- package/batteries/llm/webllm_chat_completions.cjs +50 -0
- package/batteries/llm/webllm_chat_completions.mjs +6 -0
- package/batteries/llm.cjs +63 -0
- package/batteries/llm.mjs +10 -0
- package/batteries/storage/flydrive/index.d.ts +167 -0
- package/batteries/storage/flydrive.cjs +249 -0
- package/batteries/storage/flydrive.cjs.map +1 -0
- package/batteries/storage/flydrive.mjs +249 -0
- package/batteries/storage/flydrive.mjs.map +1 -0
- package/batteries/storage/in_memory/index.d.ts +106 -0
- package/batteries/storage/in_memory.cjs +121 -0
- package/batteries/storage/in_memory.cjs.map +1 -0
- package/batteries/storage/in_memory.mjs +119 -0
- package/batteries/storage/in_memory.mjs.map +1 -0
- package/batteries/storage/index.d.ts +18 -0
- package/batteries/storage/opfs/index.d.ts +299 -0
- package/batteries/storage/opfs.cjs +368 -0
- package/batteries/storage/opfs.cjs.map +1 -0
- package/batteries/storage/opfs.mjs +366 -0
- package/batteries/storage/opfs.mjs.map +1 -0
- package/batteries/storage.cjs +4 -0
- package/batteries/storage.mjs +2 -0
- package/batteries/tools/color/index.d.ts +37 -0
- package/batteries/tools/color.cjs +659 -0
- package/batteries/tools/color.cjs.map +1 -0
- package/batteries/tools/color.mjs +655 -0
- package/batteries/tools/color.mjs.map +1 -0
- package/batteries/tools/comparison/index.d.ts +29 -0
- package/batteries/tools/comparison.cjs +171 -0
- package/batteries/tools/comparison.cjs.map +1 -0
- package/batteries/tools/comparison.mjs +168 -0
- package/batteries/tools/comparison.mjs.map +1 -0
- package/batteries/tools/data_structure/index.d.ts +30 -0
- package/batteries/tools/data_structure.cjs +270 -0
- package/batteries/tools/data_structure.cjs.map +1 -0
- package/batteries/tools/data_structure.mjs +267 -0
- package/batteries/tools/data_structure.mjs.map +1 -0
- package/batteries/tools/datetime_extended/index.d.ts +51 -0
- package/batteries/tools/datetime_extended.cjs +309 -0
- package/batteries/tools/datetime_extended.cjs.map +1 -0
- package/batteries/tools/datetime_extended.mjs +302 -0
- package/batteries/tools/datetime_extended.mjs.map +1 -0
- package/batteries/tools/datetime_math/index.d.ts +36 -0
- package/batteries/tools/datetime_math.cjs +175 -0
- package/batteries/tools/datetime_math.cjs.map +1 -0
- package/batteries/tools/datetime_math.mjs +171 -0
- package/batteries/tools/datetime_math.mjs.map +1 -0
- package/batteries/tools/encoding/index.d.ts +36 -0
- package/batteries/tools/encoding.cjs +156 -0
- package/batteries/tools/encoding.cjs.map +1 -0
- package/batteries/tools/encoding.mjs +152 -0
- package/batteries/tools/encoding.mjs.map +1 -0
- package/batteries/tools/formatting/index.d.ts +28 -0
- package/batteries/tools/formatting.cjs +120 -0
- package/batteries/tools/formatting.cjs.map +1 -0
- package/batteries/tools/formatting.mjs +117 -0
- package/batteries/tools/formatting.mjs.map +1 -0
- package/batteries/tools/geo_basics/index.d.ts +33 -0
- package/batteries/tools/geo_basics.cjs +136 -0
- package/batteries/tools/geo_basics.cjs.map +1 -0
- package/batteries/tools/geo_basics.mjs +132 -0
- package/batteries/tools/geo_basics.mjs.map +1 -0
- package/batteries/tools/index.d.ts +32 -0
- package/batteries/tools/math/index.d.ts +37 -0
- package/batteries/tools/math.cjs +136 -0
- package/batteries/tools/math.cjs.map +1 -0
- package/batteries/tools/math.mjs +133 -0
- package/batteries/tools/math.mjs.map +1 -0
- package/batteries/tools/memory/index.d.ts +73 -0
- package/batteries/tools/memory.cjs +193 -0
- package/batteries/tools/memory.cjs.map +1 -0
- package/batteries/tools/memory.mjs +187 -0
- package/batteries/tools/memory.mjs.map +1 -0
- package/batteries/tools/parsing/index.d.ts +47 -0
- package/batteries/tools/parsing.cjs +191 -0
- package/batteries/tools/parsing.cjs.map +1 -0
- package/batteries/tools/parsing.mjs +185 -0
- package/batteries/tools/parsing.mjs.map +1 -0
- package/batteries/tools/retrievables/index.d.ts +81 -0
- package/batteries/tools/retrievables.cjs +215 -0
- package/batteries/tools/retrievables.cjs.map +1 -0
- package/batteries/tools/retrievables.mjs +209 -0
- package/batteries/tools/retrievables.mjs.map +1 -0
- package/batteries/tools/standing_instructions/index.d.ts +64 -0
- package/batteries/tools/standing_instructions.cjs +126 -0
- package/batteries/tools/standing_instructions.cjs.map +1 -0
- package/batteries/tools/standing_instructions.mjs +121 -0
- package/batteries/tools/standing_instructions.mjs.map +1 -0
- package/batteries/tools/statistics/index.d.ts +46 -0
- package/batteries/tools/statistics.cjs +253 -0
- package/batteries/tools/statistics.cjs.map +1 -0
- package/batteries/tools/statistics.mjs +248 -0
- package/batteries/tools/statistics.mjs.map +1 -0
- package/batteries/tools/string_processing/index.d.ts +29 -0
- package/batteries/tools/string_processing.cjs +154 -0
- package/batteries/tools/string_processing.cjs.map +1 -0
- package/batteries/tools/string_processing.mjs +151 -0
- package/batteries/tools/string_processing.mjs.map +1 -0
- package/batteries/tools/structured_data/index.d.ts +34 -0
- package/batteries/tools/structured_data.cjs +189 -0
- package/batteries/tools/structured_data.cjs.map +1 -0
- package/batteries/tools/structured_data.mjs +185 -0
- package/batteries/tools/structured_data.mjs.map +1 -0
- package/batteries/tools/text_analysis/index.d.ts +31 -0
- package/batteries/tools/text_analysis.cjs +120 -0
- package/batteries/tools/text_analysis.cjs.map +1 -0
- package/batteries/tools/text_analysis.mjs +117 -0
- package/batteries/tools/text_analysis.mjs.map +1 -0
- package/batteries/tools/text_comparison/index.d.ts +28 -0
- package/batteries/tools/text_comparison.cjs +96 -0
- package/batteries/tools/text_comparison.cjs.map +1 -0
- package/batteries/tools/text_comparison.mjs +93 -0
- package/batteries/tools/text_comparison.mjs.map +1 -0
- package/batteries/tools/time/index.d.ts +27 -0
- package/batteries/tools/time.cjs +63 -0
- package/batteries/tools/time.cjs.map +1 -0
- package/batteries/tools/time.mjs +60 -0
- package/batteries/tools/time.mjs.map +1 -0
- package/batteries/tools/unit_conversion/index.d.ts +19 -0
- package/batteries/tools/unit_conversion.cjs +452 -0
- package/batteries/tools/unit_conversion.cjs.map +1 -0
- package/batteries/tools/unit_conversion.mjs +450 -0
- package/batteries/tools/unit_conversion.mjs.map +1 -0
- package/batteries/tools.cjs +80 -0
- package/batteries/tools.mjs +21 -0
- package/batteries.cjs +142 -0
- package/batteries.mjs +30 -0
- package/chunk-KmRHZBOW.js +35 -0
- package/common-DeZaonK1.mjs +208 -0
- package/common-DeZaonK1.mjs.map +1 -0
- package/common-Od8edUXU.js +232 -0
- package/common-Od8edUXU.js.map +1 -0
- package/common.cjs +31 -0
- package/common.d.ts +108 -0
- package/common.mjs +8 -0
- package/dispatch_runner-9j6bXHL3.mjs +1609 -0
- package/dispatch_runner-9j6bXHL3.mjs.map +1 -0
- package/dispatch_runner-CsoH0nld.js +1627 -0
- package/dispatch_runner-CsoH0nld.js.map +1 -0
- package/dispatch_runner.cjs +3 -0
- package/dispatch_runner.d.ts +17 -0
- package/dispatch_runner.mjs +2 -0
- package/exceptions-D5YrO9Vm.js +280 -0
- package/exceptions-D5YrO9Vm.js.map +1 -0
- package/exceptions-NrzIHw_R.mjs +244 -0
- package/exceptions-NrzIHw_R.mjs.map +1 -0
- package/exceptions.cjs +33 -0
- package/exceptions.d.ts +52 -0
- package/exceptions.mjs +3 -0
- package/factories.cjs +4 -0
- package/factories.d.ts +39 -0
- package/factories.mjs +2 -0
- package/forge.cjs +9 -0
- package/forge.d.ts +49 -0
- package/forge.mjs +5 -0
- package/guards.cjs +96 -0
- package/guards.cjs.map +1 -0
- package/guards.d.ts +83 -0
- package/guards.mjs +72 -0
- package/guards.mjs.map +1 -0
- package/index.cjs +107 -0
- package/index.cjs.map +1 -0
- package/index.d.ts +18 -0
- package/index.mjs +31 -0
- package/index.mjs.map +1 -0
- package/lib/classes/artifact_tool.d.ts +129 -0
- package/lib/classes/base_exception.d.ts +83 -0
- package/lib/classes/identity.d.ts +71 -0
- package/lib/classes/media.d.ts +326 -0
- package/lib/classes/memory.d.ts +72 -0
- package/lib/classes/message.d.ts +137 -0
- package/lib/classes/registry.d.ts +79 -0
- package/lib/classes/retrievable.d.ts +100 -0
- package/lib/classes/spooled_artifact.d.ts +296 -0
- package/lib/classes/spooled_json_artifact.d.ts +158 -0
- package/lib/classes/spooled_markdown_artifact.d.ts +202 -0
- package/lib/classes/thought.d.ts +142 -0
- package/lib/classes/tokenizable.d.ts +124 -0
- package/lib/classes/tool.d.ts +228 -0
- package/lib/classes/tool_call.d.ts +190 -0
- package/lib/classes/tool_registry.d.ts +159 -0
- package/lib/classes/turn_gate.d.ts +109 -0
- package/lib/contracts/dispatch_context.d.ts +345 -0
- package/lib/contracts/media_reader.d.ts +60 -0
- package/lib/contracts/spool_reader.d.ts +80 -0
- package/lib/contracts/spooled_artifact_constructor.d.ts +38 -0
- package/lib/contracts/turn_runner_config.d.ts +101 -0
- package/lib/contracts/turn_runner_context.d.ts +267 -0
- package/lib/dispatch_runner.d.ts +98 -0
- package/lib/exceptions/runtime.d.ts +370 -0
- package/lib/helpers/media_readers.d.ts +39 -0
- package/lib/turn_runner.d.ts +144 -0
- package/lib/types/dispatch_context.d.ts +233 -0
- package/lib/types/dispatch_runner.d.ts +387 -0
- package/lib/types/turn_runner.d.ts +322 -0
- package/lib/utils/canonical_json.d.ts +18 -0
- package/lib/utils/exceptions.d.ts +78 -0
- package/lib/utils/guards.d.ts +32 -0
- package/lib/utils/validation.d.ts +77 -0
- package/package.json +334 -0
- package/runtime-BJVkrGQe.js +519 -0
- package/runtime-BJVkrGQe.js.map +1 -0
- package/runtime-CrEPIFgr.mjs +346 -0
- package/runtime-CrEPIFgr.mjs.map +1 -0
- package/skills/adk-assembly/SKILL.md +109 -0
- package/skills/adk-assembly/references/assembly-contract.md +66 -0
- package/skills/adk-assembly/references/executors-tools-pipelines-events.md +113 -0
- package/skills/adk-assembly/references/first-integration.md +93 -0
- package/skills/adk-assembly/references/storage-and-context.md +102 -0
- package/spooled_artifact-C5ZtGxuJ.mjs +544 -0
- package/spooled_artifact-C5ZtGxuJ.mjs.map +1 -0
- package/spooled_artifact-Cm9Te22K.js +568 -0
- package/spooled_artifact-Cm9Te22K.js.map +1 -0
- package/spooled_artifact.cjs +7 -0
- package/spooled_artifact.d.ts +40 -0
- package/spooled_artifact.mjs +3 -0
- package/spooled_markdown_artifact-BpUJol0W.mjs +771 -0
- package/spooled_markdown_artifact-BpUJol0W.mjs.map +1 -0
- package/spooled_markdown_artifact-RRB113sy.js +786 -0
- package/spooled_markdown_artifact-RRB113sy.js.map +1 -0
- package/thought-CDb457b4.mjs +470 -0
- package/thought-CDb457b4.mjs.map +1 -0
- package/thought-DuN2PgdO.js +494 -0
- package/thought-DuN2PgdO.js.map +1 -0
- package/tool-COSeH8I6.js +302 -0
- package/tool-COSeH8I6.js.map +1 -0
- package/tool-D2WB1EA1.mjs +296 -0
- package/tool-D2WB1EA1.mjs.map +1 -0
- package/tool_call-BKyyxGaZ.mjs +578 -0
- package/tool_call-BKyyxGaZ.mjs.map +1 -0
- package/tool_call-DFgzcVcU.js +608 -0
- package/tool_call-DFgzcVcU.js.map +1 -0
- package/tool_registry-Dkfprsck.js +641 -0
- package/tool_registry-Dkfprsck.js.map +1 -0
- package/tool_registry-DqLOyGyG.mjs +592 -0
- package/tool_registry-DqLOyGyG.mjs.map +1 -0
- package/turn_runner-CMm2BHdX.js +615 -0
- package/turn_runner-CMm2BHdX.js.map +1 -0
- package/turn_runner-y7eyEcJH.mjs +603 -0
- package/turn_runner-y7eyEcJH.mjs.map +1 -0
- package/turn_runner.cjs +3 -0
- package/turn_runner.d.ts +21 -0
- package/turn_runner.mjs +2 -0
- package/types.cjs +1 -0
- package/types.d.ts +56 -0
- package/types.mjs +0 -0
- package/vite-env.d.ts +23 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory spool readers and stores for tests, scripts, and non-durable prototypes.
|
|
3
|
+
*
|
|
4
|
+
* @module @nhtio/adk/batteries/storage/in_memory
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Opt-in in-memory persistence battery. Provides {@link InMemorySpoolReader} (a sync
|
|
8
|
+
* {@link @nhtio/adk!SpoolReader} over a string) plus {@link InMemorySpoolStore} (a `Map<callId, bytes>`
|
|
9
|
+
* with a `write()` method that returns a fresh reader bound to the stored bytes).
|
|
10
|
+
*
|
|
11
|
+
* Use this when:
|
|
12
|
+
*
|
|
13
|
+
* - Writing unit or functional tests that need a real `SpoolReader` over known bytes.
|
|
14
|
+
* - Running a REPL or one-shot script where persistence beyond the process lifetime is not
|
|
15
|
+
* needed.
|
|
16
|
+
* - Prototyping an agent before deciding on a real disk/object-store-backed persistence layer.
|
|
17
|
+
*
|
|
18
|
+
* Do **not** use this for production agents that need durability across process restarts —
|
|
19
|
+
* everything lives in process memory and is lost on exit.
|
|
20
|
+
*/
|
|
21
|
+
import type { SpoolReader } from "../../../common";
|
|
22
|
+
/**
|
|
23
|
+
* Sync in-memory {@link @nhtio/adk!SpoolReader} over a `string` body.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Splits the supplied content on `\n` at construction time and caches the resulting line array
|
|
27
|
+
* plus the UTF-8 byte length. All three `SpoolReader` methods resolve synchronously from the
|
|
28
|
+
* cache — no I/O happens after construction.
|
|
29
|
+
*
|
|
30
|
+
* Empty input yields a reader with `lineCount() === 0` and `byteLength() === 0`. A trailing
|
|
31
|
+
* newline produces a final empty line: `"a\nb\n".split('\n') === ['a', 'b', '']`. This matches
|
|
32
|
+
* the JavaScript `String.prototype.split` contract and lets a `lineCount()` consumer
|
|
33
|
+
* distinguish "two lines, no trailing newline" from "two lines, trailing newline".
|
|
34
|
+
*/
|
|
35
|
+
export declare class InMemorySpoolReader implements SpoolReader {
|
|
36
|
+
#private;
|
|
37
|
+
constructor(content: string);
|
|
38
|
+
line(index: number): string | undefined;
|
|
39
|
+
byteLength(): number;
|
|
40
|
+
lineCount(): number;
|
|
41
|
+
readAll(): string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* In-memory "give bytes, get a reader" persistence layer keyed by `callId`.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* Stores the canonical UTF-8 string form of each value. `Uint8Array` inputs are decoded via
|
|
48
|
+
* `TextDecoder` once at write time — subsequent `read()` calls return a reader over the cached
|
|
49
|
+
* string with no further decoding.
|
|
50
|
+
*
|
|
51
|
+
* Each `write()` and each `read()` returns a *fresh* {@link InMemorySpoolReader} — the store
|
|
52
|
+
* owns the bytes, the reader is a view. Mutating the store after handing out a reader does not
|
|
53
|
+
* invalidate the reader.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const store = new InMemorySpoolStore()
|
|
58
|
+
* const bytes = await tool.executor(ctx)(args)
|
|
59
|
+
* const reader = store.write(callId, bytes)
|
|
60
|
+
* const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact
|
|
61
|
+
* const artifact = new Ctor(reader)
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare class InMemorySpoolStore {
|
|
65
|
+
#private;
|
|
66
|
+
/**
|
|
67
|
+
* Persists `bytes` under `callId` and returns a reader over them.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* `Uint8Array` inputs are decoded as UTF-8. Re-writing the same `callId` replaces the prior
|
|
71
|
+
* entry; readers handed out before the rewrite continue to view the old bytes (they hold their
|
|
72
|
+
* own snapshot via the `InMemorySpoolReader` constructor).
|
|
73
|
+
*
|
|
74
|
+
* @param callId - Identifier used to retrieve the bytes via {@link InMemorySpoolStore.read}.
|
|
75
|
+
* @param bytes - The bytes to store, as a `string` or `Uint8Array`.
|
|
76
|
+
* @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes.
|
|
77
|
+
*/
|
|
78
|
+
write(callId: string, bytes: string | Uint8Array): InMemorySpoolReader;
|
|
79
|
+
/**
|
|
80
|
+
* Returns a reader over the bytes previously written under `callId`, or `undefined` if the
|
|
81
|
+
* entry has not been written or has been deleted.
|
|
82
|
+
*
|
|
83
|
+
* @param callId - Identifier supplied to a prior {@link InMemorySpoolStore.write} call.
|
|
84
|
+
* @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes, or `undefined`.
|
|
85
|
+
*/
|
|
86
|
+
read(callId: string): InMemorySpoolReader | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Removes the entry under `callId`.
|
|
89
|
+
*
|
|
90
|
+
* @param callId - Identifier whose entry should be removed.
|
|
91
|
+
* @returns `true` if an entry existed and was removed; `false` otherwise.
|
|
92
|
+
*/
|
|
93
|
+
delete(callId: string): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Removes every entry from the store.
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* Existing readers handed out by prior `write()` / `read()` calls remain valid — they hold
|
|
99
|
+
* their own snapshot.
|
|
100
|
+
*/
|
|
101
|
+
clear(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Returns the number of entries currently in the store.
|
|
104
|
+
*/
|
|
105
|
+
get size(): number;
|
|
106
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/batteries/storage/in_memory/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Sync in-memory {@link @nhtio/adk!SpoolReader} over a `string` body.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Splits the supplied content on `\n` at construction time and caches the resulting line array
|
|
8
|
+
* plus the UTF-8 byte length. All three `SpoolReader` methods resolve synchronously from the
|
|
9
|
+
* cache — no I/O happens after construction.
|
|
10
|
+
*
|
|
11
|
+
* Empty input yields a reader with `lineCount() === 0` and `byteLength() === 0`. A trailing
|
|
12
|
+
* newline produces a final empty line: `"a\nb\n".split('\n') === ['a', 'b', '']`. This matches
|
|
13
|
+
* the JavaScript `String.prototype.split` contract and lets a `lineCount()` consumer
|
|
14
|
+
* distinguish "two lines, no trailing newline" from "two lines, trailing newline".
|
|
15
|
+
*/
|
|
16
|
+
var InMemorySpoolReader = class {
|
|
17
|
+
#content;
|
|
18
|
+
#lines;
|
|
19
|
+
#bytes;
|
|
20
|
+
constructor(content) {
|
|
21
|
+
this.#content = content;
|
|
22
|
+
this.#lines = content === "" ? [] : content.split("\n");
|
|
23
|
+
this.#bytes = new TextEncoder().encode(content).length;
|
|
24
|
+
}
|
|
25
|
+
line(index) {
|
|
26
|
+
return this.#lines[index];
|
|
27
|
+
}
|
|
28
|
+
byteLength() {
|
|
29
|
+
return this.#bytes;
|
|
30
|
+
}
|
|
31
|
+
lineCount() {
|
|
32
|
+
return this.#lines.length;
|
|
33
|
+
}
|
|
34
|
+
readAll() {
|
|
35
|
+
return this.#content;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* In-memory "give bytes, get a reader" persistence layer keyed by `callId`.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Stores the canonical UTF-8 string form of each value. `Uint8Array` inputs are decoded via
|
|
43
|
+
* `TextDecoder` once at write time — subsequent `read()` calls return a reader over the cached
|
|
44
|
+
* string with no further decoding.
|
|
45
|
+
*
|
|
46
|
+
* Each `write()` and each `read()` returns a *fresh* {@link InMemorySpoolReader} — the store
|
|
47
|
+
* owns the bytes, the reader is a view. Mutating the store after handing out a reader does not
|
|
48
|
+
* invalidate the reader.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const store = new InMemorySpoolStore()
|
|
53
|
+
* const bytes = await tool.executor(ctx)(args)
|
|
54
|
+
* const reader = store.write(callId, bytes)
|
|
55
|
+
* const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact
|
|
56
|
+
* const artifact = new Ctor(reader)
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
var InMemorySpoolStore = class {
|
|
60
|
+
#entries = /* @__PURE__ */ new Map();
|
|
61
|
+
#decoder = new TextDecoder();
|
|
62
|
+
/**
|
|
63
|
+
* Persists `bytes` under `callId` and returns a reader over them.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* `Uint8Array` inputs are decoded as UTF-8. Re-writing the same `callId` replaces the prior
|
|
67
|
+
* entry; readers handed out before the rewrite continue to view the old bytes (they hold their
|
|
68
|
+
* own snapshot via the `InMemorySpoolReader` constructor).
|
|
69
|
+
*
|
|
70
|
+
* @param callId - Identifier used to retrieve the bytes via {@link InMemorySpoolStore.read}.
|
|
71
|
+
* @param bytes - The bytes to store, as a `string` or `Uint8Array`.
|
|
72
|
+
* @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes.
|
|
73
|
+
*/
|
|
74
|
+
write(callId, bytes) {
|
|
75
|
+
const text = typeof bytes === "string" ? bytes : this.#decoder.decode(bytes);
|
|
76
|
+
this.#entries.set(callId, text);
|
|
77
|
+
return new InMemorySpoolReader(text);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns a reader over the bytes previously written under `callId`, or `undefined` if the
|
|
81
|
+
* entry has not been written or has been deleted.
|
|
82
|
+
*
|
|
83
|
+
* @param callId - Identifier supplied to a prior {@link InMemorySpoolStore.write} call.
|
|
84
|
+
* @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes, or `undefined`.
|
|
85
|
+
*/
|
|
86
|
+
read(callId) {
|
|
87
|
+
const text = this.#entries.get(callId);
|
|
88
|
+
if (text === void 0) return void 0;
|
|
89
|
+
return new InMemorySpoolReader(text);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Removes the entry under `callId`.
|
|
93
|
+
*
|
|
94
|
+
* @param callId - Identifier whose entry should be removed.
|
|
95
|
+
* @returns `true` if an entry existed and was removed; `false` otherwise.
|
|
96
|
+
*/
|
|
97
|
+
delete(callId) {
|
|
98
|
+
return this.#entries.delete(callId);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Removes every entry from the store.
|
|
102
|
+
*
|
|
103
|
+
* @remarks
|
|
104
|
+
* Existing readers handed out by prior `write()` / `read()` calls remain valid — they hold
|
|
105
|
+
* their own snapshot.
|
|
106
|
+
*/
|
|
107
|
+
clear() {
|
|
108
|
+
this.#entries.clear();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Returns the number of entries currently in the store.
|
|
112
|
+
*/
|
|
113
|
+
get size() {
|
|
114
|
+
return this.#entries.size;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
//#endregion
|
|
118
|
+
exports.InMemorySpoolReader = InMemorySpoolReader;
|
|
119
|
+
exports.InMemorySpoolStore = InMemorySpoolStore;
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=in_memory.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in_memory.cjs","names":["#content","#lines","#bytes","#entries","#decoder"],"sources":["../../../src/batteries/storage/in_memory/index.ts"],"sourcesContent":["/**\n * In-memory spool readers and stores for tests, scripts, and non-durable prototypes.\n *\n * @module @nhtio/adk/batteries/storage/in_memory\n *\n * @remarks\n * Opt-in in-memory persistence battery. Provides {@link InMemorySpoolReader} (a sync\n * {@link @nhtio/adk!SpoolReader} over a string) plus {@link InMemorySpoolStore} (a `Map<callId, bytes>`\n * with a `write()` method that returns a fresh reader bound to the stored bytes).\n *\n * Use this when:\n *\n * - Writing unit or functional tests that need a real `SpoolReader` over known bytes.\n * - Running a REPL or one-shot script where persistence beyond the process lifetime is not\n * needed.\n * - Prototyping an agent before deciding on a real disk/object-store-backed persistence layer.\n *\n * Do **not** use this for production agents that need durability across process restarts —\n * everything lives in process memory and is lost on exit.\n */\n\nimport type { SpoolReader } from '@nhtio/adk/common'\n\n/**\n * Sync in-memory {@link @nhtio/adk!SpoolReader} over a `string` body.\n *\n * @remarks\n * Splits the supplied content on `\\n` at construction time and caches the resulting line array\n * plus the UTF-8 byte length. All three `SpoolReader` methods resolve synchronously from the\n * cache — no I/O happens after construction.\n *\n * Empty input yields a reader with `lineCount() === 0` and `byteLength() === 0`. A trailing\n * newline produces a final empty line: `\"a\\nb\\n\".split('\\n') === ['a', 'b', '']`. This matches\n * the JavaScript `String.prototype.split` contract and lets a `lineCount()` consumer\n * distinguish \"two lines, no trailing newline\" from \"two lines, trailing newline\".\n */\nexport class InMemorySpoolReader implements SpoolReader {\n readonly #content: string\n readonly #lines: string[]\n readonly #bytes: number\n\n constructor(content: string) {\n this.#content = content\n this.#lines = content === '' ? [] : content.split('\\n')\n this.#bytes = new TextEncoder().encode(content).length\n }\n\n line(index: number): string | undefined {\n return this.#lines[index]\n }\n\n byteLength(): number {\n return this.#bytes\n }\n\n lineCount(): number {\n return this.#lines.length\n }\n\n readAll(): string {\n return this.#content\n }\n}\n\n/**\n * In-memory \"give bytes, get a reader\" persistence layer keyed by `callId`.\n *\n * @remarks\n * Stores the canonical UTF-8 string form of each value. `Uint8Array` inputs are decoded via\n * `TextDecoder` once at write time — subsequent `read()` calls return a reader over the cached\n * string with no further decoding.\n *\n * Each `write()` and each `read()` returns a *fresh* {@link InMemorySpoolReader} — the store\n * owns the bytes, the reader is a view. Mutating the store after handing out a reader does not\n * invalidate the reader.\n *\n * @example\n * ```ts\n * const store = new InMemorySpoolStore()\n * const bytes = await tool.executor(ctx)(args)\n * const reader = store.write(callId, bytes)\n * const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact\n * const artifact = new Ctor(reader)\n * ```\n */\nexport class InMemorySpoolStore {\n readonly #entries = new Map<string, string>()\n readonly #decoder = new TextDecoder()\n\n /**\n * Persists `bytes` under `callId` and returns a reader over them.\n *\n * @remarks\n * `Uint8Array` inputs are decoded as UTF-8. Re-writing the same `callId` replaces the prior\n * entry; readers handed out before the rewrite continue to view the old bytes (they hold their\n * own snapshot via the `InMemorySpoolReader` constructor).\n *\n * @param callId - Identifier used to retrieve the bytes via {@link InMemorySpoolStore.read}.\n * @param bytes - The bytes to store, as a `string` or `Uint8Array`.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes.\n */\n write(callId: string, bytes: string | Uint8Array): InMemorySpoolReader {\n const text = typeof bytes === 'string' ? bytes : this.#decoder.decode(bytes)\n this.#entries.set(callId, text)\n return new InMemorySpoolReader(text)\n }\n\n /**\n * Returns a reader over the bytes previously written under `callId`, or `undefined` if the\n * entry has not been written or has been deleted.\n *\n * @param callId - Identifier supplied to a prior {@link InMemorySpoolStore.write} call.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes, or `undefined`.\n */\n read(callId: string): InMemorySpoolReader | undefined {\n const text = this.#entries.get(callId)\n if (text === undefined) return undefined\n return new InMemorySpoolReader(text)\n }\n\n /**\n * Removes the entry under `callId`.\n *\n * @param callId - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise.\n */\n delete(callId: string): boolean {\n return this.#entries.delete(callId)\n }\n\n /**\n * Removes every entry from the store.\n *\n * @remarks\n * Existing readers handed out by prior `write()` / `read()` calls remain valid — they hold\n * their own snapshot.\n */\n clear(): void {\n this.#entries.clear()\n }\n\n /**\n * Returns the number of entries currently in the store.\n */\n get size(): number {\n return this.#entries.size\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoCA,IAAa,sBAAb,MAAwD;CACtD;CACA;CACA;CAEA,YAAY,SAAiB;EAC3B,KAAKA,WAAW;EAChB,KAAKC,SAAS,YAAY,KAAK,CAAC,IAAI,QAAQ,MAAM,IAAI;EACtD,KAAKC,SAAS,IAAI,YAAY,EAAE,OAAO,OAAO,EAAE;CAClD;CAEA,KAAK,OAAmC;EACtC,OAAO,KAAKD,OAAO;CACrB;CAEA,aAAqB;EACnB,OAAO,KAAKC;CACd;CAEA,YAAoB;EAClB,OAAO,KAAKD,OAAO;CACrB;CAEA,UAAkB;EAChB,OAAO,KAAKD;CACd;AACF;;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAa,qBAAb,MAAgC;CAC9B,2BAAoB,IAAI,IAAoB;CAC5C,WAAoB,IAAI,YAAY;;;;;;;;;;;;;CAcpC,MAAM,QAAgB,OAAiD;EACrE,MAAM,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAKI,SAAS,OAAO,KAAK;EAC3E,KAAKD,SAAS,IAAI,QAAQ,IAAI;EAC9B,OAAO,IAAI,oBAAoB,IAAI;CACrC;;;;;;;;CASA,KAAK,QAAiD;EACpD,MAAM,OAAO,KAAKA,SAAS,IAAI,MAAM;EACrC,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;EAC/B,OAAO,IAAI,oBAAoB,IAAI;CACrC;;;;;;;CAQA,OAAO,QAAyB;EAC9B,OAAO,KAAKA,SAAS,OAAO,MAAM;CACpC;;;;;;;;CASA,QAAc;EACZ,KAAKA,SAAS,MAAM;CACtB;;;;CAKA,IAAI,OAAe;EACjB,OAAO,KAAKA,SAAS;CACvB;AACF"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
//#region src/batteries/storage/in_memory/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Sync in-memory {@link @nhtio/adk!SpoolReader} over a `string` body.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Splits the supplied content on `\n` at construction time and caches the resulting line array
|
|
7
|
+
* plus the UTF-8 byte length. All three `SpoolReader` methods resolve synchronously from the
|
|
8
|
+
* cache — no I/O happens after construction.
|
|
9
|
+
*
|
|
10
|
+
* Empty input yields a reader with `lineCount() === 0` and `byteLength() === 0`. A trailing
|
|
11
|
+
* newline produces a final empty line: `"a\nb\n".split('\n') === ['a', 'b', '']`. This matches
|
|
12
|
+
* the JavaScript `String.prototype.split` contract and lets a `lineCount()` consumer
|
|
13
|
+
* distinguish "two lines, no trailing newline" from "two lines, trailing newline".
|
|
14
|
+
*/
|
|
15
|
+
var InMemorySpoolReader = class {
|
|
16
|
+
#content;
|
|
17
|
+
#lines;
|
|
18
|
+
#bytes;
|
|
19
|
+
constructor(content) {
|
|
20
|
+
this.#content = content;
|
|
21
|
+
this.#lines = content === "" ? [] : content.split("\n");
|
|
22
|
+
this.#bytes = new TextEncoder().encode(content).length;
|
|
23
|
+
}
|
|
24
|
+
line(index) {
|
|
25
|
+
return this.#lines[index];
|
|
26
|
+
}
|
|
27
|
+
byteLength() {
|
|
28
|
+
return this.#bytes;
|
|
29
|
+
}
|
|
30
|
+
lineCount() {
|
|
31
|
+
return this.#lines.length;
|
|
32
|
+
}
|
|
33
|
+
readAll() {
|
|
34
|
+
return this.#content;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* In-memory "give bytes, get a reader" persistence layer keyed by `callId`.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* Stores the canonical UTF-8 string form of each value. `Uint8Array` inputs are decoded via
|
|
42
|
+
* `TextDecoder` once at write time — subsequent `read()` calls return a reader over the cached
|
|
43
|
+
* string with no further decoding.
|
|
44
|
+
*
|
|
45
|
+
* Each `write()` and each `read()` returns a *fresh* {@link InMemorySpoolReader} — the store
|
|
46
|
+
* owns the bytes, the reader is a view. Mutating the store after handing out a reader does not
|
|
47
|
+
* invalidate the reader.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const store = new InMemorySpoolStore()
|
|
52
|
+
* const bytes = await tool.executor(ctx)(args)
|
|
53
|
+
* const reader = store.write(callId, bytes)
|
|
54
|
+
* const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact
|
|
55
|
+
* const artifact = new Ctor(reader)
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
var InMemorySpoolStore = class {
|
|
59
|
+
#entries = /* @__PURE__ */ new Map();
|
|
60
|
+
#decoder = new TextDecoder();
|
|
61
|
+
/**
|
|
62
|
+
* Persists `bytes` under `callId` and returns a reader over them.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* `Uint8Array` inputs are decoded as UTF-8. Re-writing the same `callId` replaces the prior
|
|
66
|
+
* entry; readers handed out before the rewrite continue to view the old bytes (they hold their
|
|
67
|
+
* own snapshot via the `InMemorySpoolReader` constructor).
|
|
68
|
+
*
|
|
69
|
+
* @param callId - Identifier used to retrieve the bytes via {@link InMemorySpoolStore.read}.
|
|
70
|
+
* @param bytes - The bytes to store, as a `string` or `Uint8Array`.
|
|
71
|
+
* @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes.
|
|
72
|
+
*/
|
|
73
|
+
write(callId, bytes) {
|
|
74
|
+
const text = typeof bytes === "string" ? bytes : this.#decoder.decode(bytes);
|
|
75
|
+
this.#entries.set(callId, text);
|
|
76
|
+
return new InMemorySpoolReader(text);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns a reader over the bytes previously written under `callId`, or `undefined` if the
|
|
80
|
+
* entry has not been written or has been deleted.
|
|
81
|
+
*
|
|
82
|
+
* @param callId - Identifier supplied to a prior {@link InMemorySpoolStore.write} call.
|
|
83
|
+
* @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes, or `undefined`.
|
|
84
|
+
*/
|
|
85
|
+
read(callId) {
|
|
86
|
+
const text = this.#entries.get(callId);
|
|
87
|
+
if (text === void 0) return void 0;
|
|
88
|
+
return new InMemorySpoolReader(text);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Removes the entry under `callId`.
|
|
92
|
+
*
|
|
93
|
+
* @param callId - Identifier whose entry should be removed.
|
|
94
|
+
* @returns `true` if an entry existed and was removed; `false` otherwise.
|
|
95
|
+
*/
|
|
96
|
+
delete(callId) {
|
|
97
|
+
return this.#entries.delete(callId);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Removes every entry from the store.
|
|
101
|
+
*
|
|
102
|
+
* @remarks
|
|
103
|
+
* Existing readers handed out by prior `write()` / `read()` calls remain valid — they hold
|
|
104
|
+
* their own snapshot.
|
|
105
|
+
*/
|
|
106
|
+
clear() {
|
|
107
|
+
this.#entries.clear();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns the number of entries currently in the store.
|
|
111
|
+
*/
|
|
112
|
+
get size() {
|
|
113
|
+
return this.#entries.size;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
//#endregion
|
|
117
|
+
export { InMemorySpoolReader, InMemorySpoolStore };
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=in_memory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in_memory.mjs","names":["#content","#lines","#bytes","#entries","#decoder"],"sources":["../../../src/batteries/storage/in_memory/index.ts"],"sourcesContent":["/**\n * In-memory spool readers and stores for tests, scripts, and non-durable prototypes.\n *\n * @module @nhtio/adk/batteries/storage/in_memory\n *\n * @remarks\n * Opt-in in-memory persistence battery. Provides {@link InMemorySpoolReader} (a sync\n * {@link @nhtio/adk!SpoolReader} over a string) plus {@link InMemorySpoolStore} (a `Map<callId, bytes>`\n * with a `write()` method that returns a fresh reader bound to the stored bytes).\n *\n * Use this when:\n *\n * - Writing unit or functional tests that need a real `SpoolReader` over known bytes.\n * - Running a REPL or one-shot script where persistence beyond the process lifetime is not\n * needed.\n * - Prototyping an agent before deciding on a real disk/object-store-backed persistence layer.\n *\n * Do **not** use this for production agents that need durability across process restarts —\n * everything lives in process memory and is lost on exit.\n */\n\nimport type { SpoolReader } from '@nhtio/adk/common'\n\n/**\n * Sync in-memory {@link @nhtio/adk!SpoolReader} over a `string` body.\n *\n * @remarks\n * Splits the supplied content on `\\n` at construction time and caches the resulting line array\n * plus the UTF-8 byte length. All three `SpoolReader` methods resolve synchronously from the\n * cache — no I/O happens after construction.\n *\n * Empty input yields a reader with `lineCount() === 0` and `byteLength() === 0`. A trailing\n * newline produces a final empty line: `\"a\\nb\\n\".split('\\n') === ['a', 'b', '']`. This matches\n * the JavaScript `String.prototype.split` contract and lets a `lineCount()` consumer\n * distinguish \"two lines, no trailing newline\" from \"two lines, trailing newline\".\n */\nexport class InMemorySpoolReader implements SpoolReader {\n readonly #content: string\n readonly #lines: string[]\n readonly #bytes: number\n\n constructor(content: string) {\n this.#content = content\n this.#lines = content === '' ? [] : content.split('\\n')\n this.#bytes = new TextEncoder().encode(content).length\n }\n\n line(index: number): string | undefined {\n return this.#lines[index]\n }\n\n byteLength(): number {\n return this.#bytes\n }\n\n lineCount(): number {\n return this.#lines.length\n }\n\n readAll(): string {\n return this.#content\n }\n}\n\n/**\n * In-memory \"give bytes, get a reader\" persistence layer keyed by `callId`.\n *\n * @remarks\n * Stores the canonical UTF-8 string form of each value. `Uint8Array` inputs are decoded via\n * `TextDecoder` once at write time — subsequent `read()` calls return a reader over the cached\n * string with no further decoding.\n *\n * Each `write()` and each `read()` returns a *fresh* {@link InMemorySpoolReader} — the store\n * owns the bytes, the reader is a view. Mutating the store after handing out a reader does not\n * invalidate the reader.\n *\n * @example\n * ```ts\n * const store = new InMemorySpoolStore()\n * const bytes = await tool.executor(ctx)(args)\n * const reader = store.write(callId, bytes)\n * const Ctor = tool.artifactConstructor?.() ?? SpooledArtifact\n * const artifact = new Ctor(reader)\n * ```\n */\nexport class InMemorySpoolStore {\n readonly #entries = new Map<string, string>()\n readonly #decoder = new TextDecoder()\n\n /**\n * Persists `bytes` under `callId` and returns a reader over them.\n *\n * @remarks\n * `Uint8Array` inputs are decoded as UTF-8. Re-writing the same `callId` replaces the prior\n * entry; readers handed out before the rewrite continue to view the old bytes (they hold their\n * own snapshot via the `InMemorySpoolReader` constructor).\n *\n * @param callId - Identifier used to retrieve the bytes via {@link InMemorySpoolStore.read}.\n * @param bytes - The bytes to store, as a `string` or `Uint8Array`.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes.\n */\n write(callId: string, bytes: string | Uint8Array): InMemorySpoolReader {\n const text = typeof bytes === 'string' ? bytes : this.#decoder.decode(bytes)\n this.#entries.set(callId, text)\n return new InMemorySpoolReader(text)\n }\n\n /**\n * Returns a reader over the bytes previously written under `callId`, or `undefined` if the\n * entry has not been written or has been deleted.\n *\n * @param callId - Identifier supplied to a prior {@link InMemorySpoolStore.write} call.\n * @returns A fresh {@link InMemorySpoolReader} bound to the stored bytes, or `undefined`.\n */\n read(callId: string): InMemorySpoolReader | undefined {\n const text = this.#entries.get(callId)\n if (text === undefined) return undefined\n return new InMemorySpoolReader(text)\n }\n\n /**\n * Removes the entry under `callId`.\n *\n * @param callId - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise.\n */\n delete(callId: string): boolean {\n return this.#entries.delete(callId)\n }\n\n /**\n * Removes every entry from the store.\n *\n * @remarks\n * Existing readers handed out by prior `write()` / `read()` calls remain valid — they hold\n * their own snapshot.\n */\n clear(): void {\n this.#entries.clear()\n }\n\n /**\n * Returns the number of entries currently in the store.\n */\n get size(): number {\n return this.#entries.size\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,IAAa,sBAAb,MAAwD;CACtD;CACA;CACA;CAEA,YAAY,SAAiB;EAC3B,KAAKA,WAAW;EAChB,KAAKC,SAAS,YAAY,KAAK,CAAC,IAAI,QAAQ,MAAM,IAAI;EACtD,KAAKC,SAAS,IAAI,YAAY,EAAE,OAAO,OAAO,EAAE;CAClD;CAEA,KAAK,OAAmC;EACtC,OAAO,KAAKD,OAAO;CACrB;CAEA,aAAqB;EACnB,OAAO,KAAKC;CACd;CAEA,YAAoB;EAClB,OAAO,KAAKD,OAAO;CACrB;CAEA,UAAkB;EAChB,OAAO,KAAKD;CACd;AACF;;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAa,qBAAb,MAAgC;CAC9B,2BAAoB,IAAI,IAAoB;CAC5C,WAAoB,IAAI,YAAY;;;;;;;;;;;;;CAcpC,MAAM,QAAgB,OAAiD;EACrE,MAAM,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAKI,SAAS,OAAO,KAAK;EAC3E,KAAKD,SAAS,IAAI,QAAQ,IAAI;EAC9B,OAAO,IAAI,oBAAoB,IAAI;CACrC;;;;;;;;CASA,KAAK,QAAiD;EACpD,MAAM,OAAO,KAAKA,SAAS,IAAI,MAAM;EACrC,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;EAC/B,OAAO,IAAI,oBAAoB,IAAI;CACrC;;;;;;;CAQA,OAAO,QAAyB;EAC9B,OAAO,KAAKA,SAAS,OAAO,MAAM;CACpC;;;;;;;;CASA,QAAc;EACZ,KAAKA,SAAS,MAAM;CACtB;;;;CAKA,IAAI,OAAe;EACjB,OAAO,KAAKA,SAAS;CACvB;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment-neutral aggregate barrel for bundled storage batteries.
|
|
3
|
+
*
|
|
4
|
+
* @module @nhtio/adk/batteries/storage
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Aggregate barrel for the storage batteries. Re-exports only **environment-neutral** storage
|
|
8
|
+
* helpers — currently just the in-memory battery — so that consumers can import this barrel from
|
|
9
|
+
* either Node or the browser without dragging in environment-specific runtime requirements.
|
|
10
|
+
*
|
|
11
|
+
* Environment-specific batteries are reachable only through their own subpath:
|
|
12
|
+
*
|
|
13
|
+
* - `@nhtio/adk/batteries/storage/flydrive` — Node-only (uses `node:stream`).
|
|
14
|
+
* - `@nhtio/adk/batteries/storage/opfs` — browser-only (uses the OPFS API).
|
|
15
|
+
*
|
|
16
|
+
* Deep-import the subpath you need; don't expect either to be re-exported from this barrel.
|
|
17
|
+
*/
|
|
18
|
+
export * from "./in_memory/index";
|