@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 @@
|
|
|
1
|
+
{"version":3,"file":"thought-CDb457b4.mjs","names":["#identifier","#representation","#id","#content","#confidence","#importance","#createdAt","#updatedAt","#id","#role","#content","#attachments","#identity","#createdAt","#updatedAt","#id","#content","#identity","#payload","#replayCompatibility","#createdAt","#updatedAt"],"sources":["../src/lib/classes/identity.ts","../src/lib/classes/memory.ts","../src/lib/classes/message.ts","../src/lib/classes/thought.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_IDENTITY_VALUE } from '../exceptions/runtime'\n\n/**\n * Plain input object supplied to {@link Identity} at construction time.\n *\n * @remarks\n * Validated against `rawIdentitySchema` before the `Identity` instance is created.\n */\nexport interface RawIdentity {\n /**\n * The system-facing identifier for this participant.\n *\n * @remarks\n * Used internally to correlate messages to a specific participant — e.g. a database ID or\n * a username. Never sent to the model directly; use `representation` for that.\n */\n identifier: string | number\n /**\n * How this participant should be presented to the model.\n *\n * @remarks\n * Accepts a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. This is what the model\n * sees when it needs to distinguish between participants of the same role.\n */\n representation: string | Tokenizable\n}\n\n/**\n * A fully-resolved {@link RawIdentity} where `representation` has been normalised to a\n * {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Used internally by the {@link Identity} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedIdentity {\n identifier: string | number\n representation: Tokenizable\n}\n\n/**\n * Validator schema used to validate a {@link RawIdentity} before constructing an {@link Identity}.\n *\n * @remarks\n * Validates both fields of {@link RawIdentity}:\n * - `identifier` — required string or number.\n * - `representation` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} (via the {@link Identity} constructor) when\n * validation fails.\n */\nconst rawIdentitySchema = validator.object<RawIdentity>({\n identifier: validator.alternatives(validator.string(), validator.number()).required(),\n representation: Tokenizable.schema.required(),\n})\n\n/**\n * An immutable, validated participant identity attached to a {@link @nhtio/adk!Message}.\n *\n * @remarks\n * Carries two distinct representations of the same participant: `identifier` is the\n * system-facing key (e.g. a database ID) used to correlate messages programmatically;\n * `representation` is what the model sees when it needs to distinguish between participants\n * sharing the same role. The `representation` is always a {@link @nhtio/adk!Tokenizable} so token cost\n * can be estimated inline.\n */\nexport class Identity {\n /**\n * Validator schema that accepts a {@link RawIdentity} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest an identity — for example,\n * as a required field inside a message schema.\n */\n public static schema = rawIdentitySchema\n\n /**\n * Returns `true` if `value` is an {@link Identity} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is an {@link Identity} instance.\n */\n public static isIdentity(value: unknown): value is Identity {\n return isInstanceOf(value, 'Identity', Identity)\n }\n\n /**\n * The system-facing identifier for this participant — never sent to the model directly.\n */\n declare readonly identifier: string | number\n\n /**\n * How this participant is presented to the model, as a {@link @nhtio/adk!Tokenizable} for inline\n * token estimation.\n */\n declare readonly representation: Tokenizable\n\n #identifier: string | number\n #representation: Tokenizable\n\n /**\n * @param raw - The raw identity input validated against `rawIdentitySchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawIdentity) {\n let resolved: ResolvedIdentity\n try {\n resolved = validateOrThrow<ResolvedIdentity>(rawIdentitySchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_IDENTITY_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#identifier = resolved.identifier\n this.#representation = Tokenizable.isTokenizable(resolved.representation)\n ? resolved.representation\n : new Tokenizable(resolved.representation)\n\n Object.defineProperties(this, {\n identifier: {\n get: () => this.#identifier,\n enumerable: true,\n configurable: false,\n },\n representation: {\n get: () => this.#representation,\n enumerable: true,\n configurable: false,\n },\n })\n }\n}\n","import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_MEMORY_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\n\n/**\n * Plain input object supplied to {@link Memory} at construction time.\n *\n * @remarks\n * Validated against `rawMemorySchema` before the `Memory` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawMemory {\n /** Stable unique identifier for this memory entry. */\n id: string\n /** The memory content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. */\n content: string | Tokenizable\n /** Confidence score in the range `[0, 1]` — how certain the agent is that this memory is accurate. */\n confidence: number\n /** Importance score in the range `[0, 1]` — how much weight this memory should carry during retrieval. */\n importance: number\n /** When this memory was first recorded. */\n createdAt: string | number | Date | DateTime\n /** When this memory was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawMemory} where all fields have been validated and temporal values\n * normalised to Luxon `DateTime` instances.\n *\n * @remarks\n * This is the shape returned by `rawMemorySchema` after validation — used internally by the\n * {@link Memory} constructor to assign private fields with guaranteed types.\n */\ninterface ResolvedMemory {\n id: string\n content: Tokenizable\n confidence: number\n importance: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawMemory} before constructing a {@link Memory}.\n *\n * @remarks\n * Validates all six fields of {@link RawMemory}:\n * - `id` — required non-empty string.\n * - `content` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n * - `confidence` — required number in `[0, 1]`.\n * - `importance` — required number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} (via the {@link Memory} constructor) when\n * validation fails.\n */\nconst rawMemorySchema = validator.object<RawMemory>({\n id: validator.string().required(),\n content: Tokenizable.schema.required(),\n confidence: validator.number().min(0).max(1).required(),\n importance: validator.number().min(0).max(1).required(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated memory entry held by the agent.\n *\n * @remarks\n * Constructed from a {@link RawMemory} via `rawMemorySchema`. All temporal fields are\n * normalised to Luxon `DateTime` instances at construction time. The `content` field is\n * always a {@link @nhtio/adk!Tokenizable} so callers can estimate token cost without an additional\n * wrapping step.\n */\nexport class Memory {\n /**\n * Validator schema that accepts a {@link RawMemory} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a memory entry — for\n * example, a collection schema that holds an array of memories.\n */\n public static schema = rawMemorySchema\n\n /**\n * Returns `true` if `value` is a {@link Memory} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Memory} instance.\n */\n public static isMemory(value: unknown): value is Memory {\n return isInstanceOf(value, 'Memory', Memory)\n }\n /** Stable unique identifier for this memory entry. */\n declare readonly id: string\n /** The memory content as a {@link @nhtio/adk!Tokenizable} for inline token estimation. */\n declare readonly content: Tokenizable\n /** Confidence score in the range `[0, 1]`. */\n declare readonly confidence: number\n /** Importance score in the range `[0, 1]`. */\n declare readonly importance: number\n /** When this memory was first recorded. */\n declare readonly createdAt: DateTime\n /** When this memory was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable\n #confidence: number\n #importance: number\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw memory input validated against `rawMemorySchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawMemory) {\n let resolved: ResolvedMemory\n try {\n resolved = validateOrThrow<ResolvedMemory>(rawMemorySchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_MEMORY_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content = Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#confidence = resolved.confidence\n this.#importance = resolved.importance\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n confidence: {\n get: () => this.#confidence,\n enumerable: true,\n configurable: false,\n },\n importance: {\n get: () => this.#importance,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n}\n","import { Media } from './media'\nimport { Identity } from './identity'\nimport { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_MESSAGE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { RawIdentity } from './identity'\n\n/**\n * The roles a {@link Message} author can hold.\n *\n * @remarks\n * Restricted to `user` and `assistant` — system instructions, developer directives, and\n * tool results are handled separately and never appear in the persisted message history.\n */\nexport type MessageRole = 'user' | 'assistant'\n\n/**\n * Plain input object supplied to {@link Message} at construction time.\n *\n * @remarks\n * Validated against `rawMessageSchema` before the `Message` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n *\n * At least one of `content` or `attachments` (non-empty) must be present — a message with\n * neither throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE}.\n */\nexport interface RawMessage {\n /** Stable unique identifier for this message. */\n id: string\n /** Whether this message is from the human participant or the model. */\n role: MessageRole\n /**\n * The message content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance.\n *\n * @remarks\n * Optional — but required when `attachments` is absent or empty. The cross-field rule on\n * `rawMessageSchema` enforces that at least one of `content` or `attachments` is present.\n */\n content?: string | Tokenizable\n /**\n * Media attachments carried by this message — images, audio, video, documents.\n *\n * @remarks\n * Optional and symmetric across roles: both `user` and `assistant` messages may carry\n * attachments. Each attachment carries its own `trustTier` and `modalityHazard`, which the\n * renderer uses to wrap the asset in its own trust envelope independent of the message\n * envelope. How a renderer orders text vs attachments in the on-the-wire content array is\n * a renderer-policy concern, not a contract of {@link Message}.\n */\n attachments?: Media[]\n /**\n * The identity of the participant who authored this message.\n *\n * @remarks\n * Optional. When omitted, the `role` value is used as both the system-facing `identifier`\n * and the model-facing `representation`. Three accepted forms when provided:\n * - A plain `string` — used as both `identifier` and `representation`.\n * - A {@link @nhtio/adk!RawIdentity} object — validated and wrapped into an {@link @nhtio/adk!Identity}.\n * - An existing {@link @nhtio/adk!Identity} instance — passed through unchanged.\n */\n identity?: string | RawIdentity | Identity\n /** When this message was created. */\n createdAt: string | number | Date | DateTime\n /** When this message was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawMessage} where temporal fields have been normalised to Luxon\n * `DateTime` instances and `identity` is a validated {@link @nhtio/adk!Identity}.\n *\n * @remarks\n * Used internally by the {@link Message} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedMessage {\n id: string\n role: MessageRole\n content?: Tokenizable\n attachments: Media[]\n identity: string | RawIdentity | Identity\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawMessage} before constructing a {@link Message}.\n *\n * @remarks\n * Validates all fields of {@link RawMessage}:\n * - `id` — required non-empty string.\n * - `role` — required; must be `'user'` or `'assistant'`.\n * - `content` — optional string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n * - `attachments` — optional array of {@link @nhtio/adk!Media} instances. Defaults to `[]`.\n * - At least one of `content` or `attachments` must be present and non-empty; a message with\n * neither is invalid.\n * - `identity` — required string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; a plain string is\n * mapped to both `identifier` and `representation` automatically.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} (via the {@link Message} constructor) when\n * validation fails.\n */\nconst rawMessageSchema = validator\n .object<RawMessage>({\n id: validator.string().required(),\n role: validator.string().valid('user', 'assistant').required(),\n content: Tokenizable.schema.optional(),\n attachments: validator\n .array()\n .items(\n validator.any().custom((value, helpers) => {\n if (Media.isMedia(value)) return value\n return helpers.error('any.invalid')\n })\n )\n .default([]),\n identity: validator\n .alternatives(validator.string(), Identity.schema)\n .default(validator.ref('role')),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n })\n .custom((value, helpers) => {\n const resolved = value as ResolvedMessage\n const hasContent = resolved.content !== undefined && resolved.content !== null\n const hasAttachments = Array.isArray(resolved.attachments) && resolved.attachments.length > 0\n if (!hasContent && !hasAttachments) {\n return helpers.error('any.invalid')\n }\n return resolved\n })\n\n/**\n * An immutable, validated conversation message from a human participant or the model.\n *\n * @remarks\n * Covers only `user` and `assistant` roles — system instructions, developer directives, and\n * tool results are not represented here. Constructed from a {@link RawMessage} via\n * `rawMessageSchema`. Temporal fields are normalised to Luxon `DateTime` instances at\n * construction time. Both `content` and `identity.representation` are {@link @nhtio/adk!Tokenizable} so\n * token cost can be estimated inline.\n *\n * A message may carry `content` (text), `attachments` (media), or both. The cross-field rule\n * on `rawMessageSchema` enforces that at least one is present. Downstream code that reaches\n * for `message.content` must handle the attachments-only case where `content` is `undefined`.\n */\nexport class Message {\n /**\n * Validator schema that accepts a {@link RawMessage} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a message entry — for\n * example, a collection schema that holds an array of messages.\n */\n public static schema = rawMessageSchema\n\n /**\n * Returns `true` if `value` is a {@link Message} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Message} instance.\n */\n public static isMessage(value: unknown): value is Message {\n return isInstanceOf(value, 'Message', Message)\n }\n\n /** Stable unique identifier for this message. */\n declare readonly id: string\n /** Whether this message is from the human participant or the model. */\n declare readonly role: MessageRole\n /**\n * The message content as a {@link @nhtio/adk!Tokenizable} for inline token estimation, or `undefined`\n * for attachments-only messages.\n *\n * @remarks\n * `undefined` when the message was constructed with only `attachments`. Render code that\n * needs the text portion must guard for the missing case rather than blindly calling\n * `message.content.toString()`.\n */\n declare readonly content: Tokenizable | undefined\n /**\n * Media attachments carried by this message.\n *\n * @remarks\n * Always defined as a frozen array — empty when the message has no attachments. Both\n * `user` and `assistant` messages may carry attachments. Each entry carries its own\n * `trustTier` and `modalityHazard`; the renderer wraps each in its own trust envelope\n * independent of the message envelope.\n */\n declare readonly attachments: ReadonlyArray<Media>\n /** The identity of the participant who authored this message. */\n declare readonly identity: Identity\n /** When this message was created. */\n declare readonly createdAt: DateTime\n /** When this message was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #role: MessageRole\n #content: Tokenizable | undefined\n #attachments: ReadonlyArray<Media>\n #identity: Identity\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw message input validated against `rawMessageSchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} when `raw` does not satisfy the schema —\n * including the cross-field rule that at least one of `content` or `attachments` must be\n * present and non-empty.\n */\n constructor(raw: RawMessage) {\n let resolved: ResolvedMessage\n try {\n resolved = validateOrThrow<ResolvedMessage>(rawMessageSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_MESSAGE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#role = resolved.role\n this.#content =\n resolved.content === undefined || resolved.content === null\n ? undefined\n : Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#attachments = Object.freeze([...(resolved.attachments ?? [])])\n const rawIdentity = resolved.identity\n this.#identity = Identity.isIdentity(rawIdentity)\n ? rawIdentity\n : typeof rawIdentity === 'string'\n ? new Identity({ identifier: rawIdentity, representation: rawIdentity })\n : new Identity(rawIdentity)\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n role: {\n get: () => this.#role,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n attachments: {\n get: () => this.#attachments,\n enumerable: true,\n configurable: false,\n },\n identity: {\n get: () => this.#identity,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n}\n","import { Identity } from './identity'\nimport { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_THOUGHT_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { RawIdentity } from './identity'\n\n/**\n * Plain input object supplied to {@link Thought} at construction time.\n *\n * @remarks\n * Validated against `rawThoughtSchema` before the `Thought` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawThought {\n /** Stable unique identifier for this thought. */\n id: string\n /** The reasoning content as a plain string or an existing {@link @nhtio/adk!Tokenizable} instance. */\n content: string | Tokenizable\n /**\n * The identity of the agent who produced this thought.\n *\n * @remarks\n * Required in multi-agent conversations to attribute reasoning traces to a specific agent.\n * Three accepted forms when provided:\n * - A plain `string` — used as both `identifier` and `representation`.\n * - A {@link @nhtio/adk!RawIdentity} object — validated and wrapped into an {@link @nhtio/adk!Identity}.\n * - An existing {@link @nhtio/adk!Identity} instance — passed through unchanged.\n *\n * When omitted, defaults to `'assistant'` (both `identifier` and `representation`).\n */\n identity?: string | RawIdentity | Identity\n /**\n * Optional vendor-opaque payload that round-trips back to a matching model wire.\n *\n * @remarks\n * Carries anything the ADK cannot interpret but a specific provider can — for example,\n * an Anthropic Messages thinking-block `signature`, an OpenAI Responses\n * `ResponseReasoningItem.encrypted_content` blob, a DeepSeek server-side reasoning handle,\n * or an MCP-mediated reasoning item.\n *\n * When present, an LLM battery MUST treat the thought as **opaque-mode**: do NOT inline\n * `content` through the plain `<thought>` envelope; serialise `payload` back to the wire in\n * whichever shape the matching {@link RawThought.replayCompatibility} identifier specifies.\n * The plain-text `content` is kept alongside for token-accounting and human/observer\n * inspection — it is not the thing the model sees.\n *\n * Cross-field invariant: a present `payload` REQUIRES a present {@link RawThought.replayCompatibility}.\n * A `payload` without `replayCompatibility` is malformed (the ADK has no way to know\n * which adapter can consume it) and {@link Thought.schema} rejects with\n * {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE}.\n *\n * @defaultValue `undefined`\n */\n payload?: unknown\n /**\n * Optional free-form identifier describing which adapter wire-shape this thought can be\n * safely replayed into.\n *\n * @remarks\n * Examples (none of these are reserved by the ADK — they are consumer conventions):\n * - `'plain-text'` — replayable into every LLM battery\n * - `'anthropic-messages-thinking-v1'`\n * - `'openai-responses-reasoning-item-v1'`\n * - `'deepseek-reasoning-handle-v1'`\n *\n * LLM batteries declare via constructor option which tags they can safely replay; matching\n * opaque thoughts are routed to the wire's typed reasoning channel where it exists, or to a\n * documented side-channel key on the request body where the wire has none. Non-matching\n * opaque thoughts are elided from the current dispatch but NOT removed from\n * `ctx.turnThoughts` — they remain in context so a subsequent dispatch to a different\n * adapter that DOES declare the matching tag can pick them up.\n *\n * Plain-text thoughts (`payload === undefined` AND `replayCompatibility === undefined`, or\n * explicit `replayCompatibility: 'plain-text'`) are always replayable.\n *\n * A `replayCompatibility` without a `payload` is allowed — it documents intent (\"this\n * plain-text thought is only meaningful to a specific fine-tuned variant\") without\n * requiring an opaque blob.\n *\n * @defaultValue `undefined`\n */\n replayCompatibility?: string\n /** When this thought was recorded. */\n createdAt: string | number | Date | DateTime\n /** When this thought was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawThought} where temporal fields have been normalised to Luxon\n * `DateTime` instances.\n *\n * @remarks\n * Used internally by the {@link Thought} constructor to assign private fields with\n * guaranteed types.\n */\ninterface ResolvedThought {\n id: string\n content: Tokenizable\n identity: string | RawIdentity | Identity\n payload?: unknown\n replayCompatibility?: string\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawThought} before constructing a {@link Thought}.\n *\n * @remarks\n * Validates all fields of {@link RawThought}:\n * - `id` — required non-empty string.\n * - `content` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.\n * - `identity` — optional string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; defaults to\n * `'assistant'` when omitted.\n * - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.\n *\n * Throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} (via the {@link Thought} constructor) when\n * validation fails.\n */\nconst rawThoughtSchema = validator\n .object<RawThought>({\n id: validator.string().required(),\n content: Tokenizable.schema.required(),\n identity: validator.alternatives(validator.string(), Identity.schema).default('assistant'),\n payload: validator.any().optional(),\n replayCompatibility: validator.string().min(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n })\n .custom((value, helpers) => {\n const v = value as RawThought\n if (\n v.payload !== undefined &&\n (v.replayCompatibility === undefined || v.replayCompatibility === null)\n ) {\n return helpers.error('any.invalid')\n }\n return value\n })\n\n/**\n * An immutable, validated internal reasoning trace produced by an agent.\n *\n * @remarks\n * Represents an agent's internal thinking — distinct from {@link @nhtio/adk!Message} (which is part of\n * the visible conversation) and never shown to end users directly. Carries an `identity` so\n * reasoning traces can be attributed to a specific agent in multi-agent conversations.\n * Constructed from a {@link RawThought} via `rawThoughtSchema`. The `content` field is always\n * a {@link @nhtio/adk!Tokenizable} so token cost can be estimated inline.\n */\nexport class Thought {\n /**\n * Validator schema that accepts a {@link RawThought} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a thought entry.\n */\n public static schema = rawThoughtSchema\n\n /**\n * Returns `true` if `value` is a {@link Thought} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances\n * created in a different module copy or VM context.\n *\n * @param value - The value to test.\n * @returns `true` when `value` is a {@link Thought} instance.\n */\n public static isThought(value: unknown): value is Thought {\n return isInstanceOf(value, 'Thought', Thought)\n }\n\n /** Stable unique identifier for this thought. */\n declare readonly id: string\n /** The reasoning content as a {@link @nhtio/adk!Tokenizable} for inline token estimation. */\n declare readonly content: Tokenizable\n /** The identity of the agent who produced this thought. */\n declare readonly identity: Identity\n /**\n * Optional vendor-opaque payload that round-trips back to a matching model wire.\n * See {@link RawThought.payload}.\n */\n declare readonly payload: unknown\n /**\n * Optional wire-shape identifier describing which adapter can safely replay this thought.\n * See {@link RawThought.replayCompatibility}.\n */\n declare readonly replayCompatibility: string | undefined\n /** When this thought was recorded. */\n declare readonly createdAt: DateTime\n /** When this thought was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable\n #identity: Identity\n #payload: unknown\n #replayCompatibility: string | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw thought input validated against `rawThoughtSchema`.\n * @throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawThought) {\n let resolved: ResolvedThought\n try {\n resolved = validateOrThrow<ResolvedThought>(rawThoughtSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_THOUGHT_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content = Tokenizable.isTokenizable(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n const rawIdentity = resolved.identity\n this.#identity = Identity.isIdentity(rawIdentity)\n ? rawIdentity\n : typeof rawIdentity === 'string'\n ? new Identity({ identifier: rawIdentity, representation: rawIdentity })\n : new Identity(rawIdentity)\n this.#payload = resolved.payload\n this.#replayCompatibility = resolved.replayCompatibility\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n identity: {\n get: () => this.#identity,\n enumerable: true,\n configurable: false,\n },\n payload: {\n get: () => this.#payload,\n enumerable: true,\n configurable: false,\n },\n replayCompatibility: {\n get: () => this.#replayCompatibility,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuDA,IAAM,oBAAoB,UAAU,OAAoB;CACtD,YAAY,UAAU,aAAa,UAAU,OAAO,GAAG,UAAU,OAAO,CAAC,EAAE,SAAS;CACpF,gBAAgB,YAAY,OAAO,SAAS;AAC9C,CAAC;;;;;;;;;;;AAYD,IAAa,WAAb,MAAa,SAAS;;;;;;;;CAQpB,OAAc,SAAS;;;;;;;;;;;CAYvB,OAAc,WAAW,OAAmC;EAC1D,OAAO,aAAa,OAAO,YAAY,QAAQ;CACjD;CAaA;CACA;;;;;CAMA,YAAY,KAAkB;EAC5B,IAAI;EACJ,IAAI;GACF,WAAW,gBAAkC,mBAAmB,KAAK,IAAI;EAC3E,SAAS,KAAK;GACZ,MAAM,IAAI,iCAAiC,EAAE,OAAO,QAAQ,GAAG,IAAI,MAAM,KAAA,EAAU,CAAC;EACtF;EACA,KAAKA,cAAc,SAAS;EAC5B,KAAKC,kBAAkB,YAAY,cAAc,SAAS,cAAc,IACpE,SAAS,iBACT,IAAI,YAAY,SAAS,cAAc;EAE3C,OAAO,iBAAiB,MAAM;GAC5B,YAAY;IACV,WAAW,KAAKD;IAChB,YAAY;IACZ,cAAc;GAChB;GACA,gBAAgB;IACd,WAAW,KAAKC;IAChB,YAAY;IACZ,cAAc;GAChB;EACF,CAAC;CACH;AACF;;;;;;;;;;;;;;;;;AC5EA,IAAM,kBAAkB,UAAU,OAAkB;CAClD,IAAI,UAAU,OAAO,EAAE,SAAS;CAChC,SAAS,YAAY,OAAO,SAAS;CACrC,YAAY,UAAU,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;CACtD,YAAY,UAAU,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EA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GACA,WAAW;IACT,WAAW,KAAKC;IAChB,YAAY;IACZ,cAAc;GAChB;EACF,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
require("./chunk-KmRHZBOW.js");
|
|
2
|
+
const require_exceptions = require("./exceptions-D5YrO9Vm.js");
|
|
3
|
+
const require_tool_registry = require("./tool_registry-Dkfprsck.js");
|
|
4
|
+
const require_runtime = require("./runtime-BJVkrGQe.js");
|
|
5
|
+
const require_tool_call = require("./tool_call-DFgzcVcU.js");
|
|
6
|
+
let _nhtio_validation = require("@nhtio/validation");
|
|
7
|
+
//#region src/lib/classes/identity.ts
|
|
8
|
+
/**
|
|
9
|
+
* Validator schema used to validate a {@link RawIdentity} before constructing an {@link Identity}.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Validates both fields of {@link RawIdentity}:
|
|
13
|
+
* - `identifier` — required string or number.
|
|
14
|
+
* - `representation` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.
|
|
15
|
+
*
|
|
16
|
+
* Throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} (via the {@link Identity} constructor) when
|
|
17
|
+
* validation fails.
|
|
18
|
+
*/
|
|
19
|
+
var rawIdentitySchema = _nhtio_validation.validator.object({
|
|
20
|
+
identifier: _nhtio_validation.validator.alternatives(_nhtio_validation.validator.string(), _nhtio_validation.validator.number()).required(),
|
|
21
|
+
representation: require_tool_registry.Tokenizable.schema.required()
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* An immutable, validated participant identity attached to a {@link @nhtio/adk!Message}.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* Carries two distinct representations of the same participant: `identifier` is the
|
|
28
|
+
* system-facing key (e.g. a database ID) used to correlate messages programmatically;
|
|
29
|
+
* `representation` is what the model sees when it needs to distinguish between participants
|
|
30
|
+
* sharing the same role. The `representation` is always a {@link @nhtio/adk!Tokenizable} so token cost
|
|
31
|
+
* can be estimated inline.
|
|
32
|
+
*/
|
|
33
|
+
var Identity = class Identity {
|
|
34
|
+
/**
|
|
35
|
+
* Validator schema that accepts a {@link RawIdentity} object.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Reusable fragment for any schema that needs to validate or nest an identity — for example,
|
|
39
|
+
* as a required field inside a message schema.
|
|
40
|
+
*/
|
|
41
|
+
static schema = rawIdentitySchema;
|
|
42
|
+
/**
|
|
43
|
+
* Returns `true` if `value` is an {@link Identity} instance.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
|
|
47
|
+
* created in a different module copy or VM context.
|
|
48
|
+
*
|
|
49
|
+
* @param value - The value to test.
|
|
50
|
+
* @returns `true` when `value` is an {@link Identity} instance.
|
|
51
|
+
*/
|
|
52
|
+
static isIdentity(value) {
|
|
53
|
+
return require_tool_registry.isInstanceOf(value, "Identity", Identity);
|
|
54
|
+
}
|
|
55
|
+
#identifier;
|
|
56
|
+
#representation;
|
|
57
|
+
/**
|
|
58
|
+
* @param raw - The raw identity input validated against `rawIdentitySchema`.
|
|
59
|
+
* @throws {@link @nhtio/adk!E_INVALID_INITIAL_IDENTITY_VALUE} when `raw` does not satisfy the schema.
|
|
60
|
+
*/
|
|
61
|
+
constructor(raw) {
|
|
62
|
+
let resolved;
|
|
63
|
+
try {
|
|
64
|
+
resolved = require_exceptions.validateOrThrow(rawIdentitySchema, raw, true);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
throw new require_runtime.E_INVALID_INITIAL_IDENTITY_VALUE({ cause: require_tool_registry.isError(err) ? err : void 0 });
|
|
67
|
+
}
|
|
68
|
+
this.#identifier = resolved.identifier;
|
|
69
|
+
this.#representation = require_tool_registry.Tokenizable.isTokenizable(resolved.representation) ? resolved.representation : new require_tool_registry.Tokenizable(resolved.representation);
|
|
70
|
+
Object.defineProperties(this, {
|
|
71
|
+
identifier: {
|
|
72
|
+
get: () => this.#identifier,
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: false
|
|
75
|
+
},
|
|
76
|
+
representation: {
|
|
77
|
+
get: () => this.#representation,
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: false
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/lib/classes/memory.ts
|
|
86
|
+
/**
|
|
87
|
+
* Validator schema used to validate a {@link RawMemory} before constructing a {@link Memory}.
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* Validates all six fields of {@link RawMemory}:
|
|
91
|
+
* - `id` — required non-empty string.
|
|
92
|
+
* - `content` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.
|
|
93
|
+
* - `confidence` — required number in `[0, 1]`.
|
|
94
|
+
* - `importance` — required number in `[0, 1]`.
|
|
95
|
+
* - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.
|
|
96
|
+
*
|
|
97
|
+
* Throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} (via the {@link Memory} constructor) when
|
|
98
|
+
* validation fails.
|
|
99
|
+
*/
|
|
100
|
+
var rawMemorySchema = _nhtio_validation.validator.object({
|
|
101
|
+
id: _nhtio_validation.validator.string().required(),
|
|
102
|
+
content: require_tool_registry.Tokenizable.schema.required(),
|
|
103
|
+
confidence: _nhtio_validation.validator.number().min(0).max(1).required(),
|
|
104
|
+
importance: _nhtio_validation.validator.number().min(0).max(1).required(),
|
|
105
|
+
createdAt: _nhtio_validation.validator.datetime().required(),
|
|
106
|
+
updatedAt: _nhtio_validation.validator.datetime().required()
|
|
107
|
+
});
|
|
108
|
+
/**
|
|
109
|
+
* An immutable, validated memory entry held by the agent.
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* Constructed from a {@link RawMemory} via `rawMemorySchema`. All temporal fields are
|
|
113
|
+
* normalised to Luxon `DateTime` instances at construction time. The `content` field is
|
|
114
|
+
* always a {@link @nhtio/adk!Tokenizable} so callers can estimate token cost without an additional
|
|
115
|
+
* wrapping step.
|
|
116
|
+
*/
|
|
117
|
+
var Memory = class Memory {
|
|
118
|
+
/**
|
|
119
|
+
* Validator schema that accepts a {@link RawMemory} object.
|
|
120
|
+
*
|
|
121
|
+
* @remarks
|
|
122
|
+
* Reusable fragment for any schema that needs to validate or nest a memory entry — for
|
|
123
|
+
* example, a collection schema that holds an array of memories.
|
|
124
|
+
*/
|
|
125
|
+
static schema = rawMemorySchema;
|
|
126
|
+
/**
|
|
127
|
+
* Returns `true` if `value` is a {@link Memory} instance.
|
|
128
|
+
*
|
|
129
|
+
* @remarks
|
|
130
|
+
* Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
|
|
131
|
+
* created in a different module copy or VM context.
|
|
132
|
+
*
|
|
133
|
+
* @param value - The value to test.
|
|
134
|
+
* @returns `true` when `value` is a {@link Memory} instance.
|
|
135
|
+
*/
|
|
136
|
+
static isMemory(value) {
|
|
137
|
+
return require_tool_registry.isInstanceOf(value, "Memory", Memory);
|
|
138
|
+
}
|
|
139
|
+
#id;
|
|
140
|
+
#content;
|
|
141
|
+
#confidence;
|
|
142
|
+
#importance;
|
|
143
|
+
#createdAt;
|
|
144
|
+
#updatedAt;
|
|
145
|
+
/**
|
|
146
|
+
* @param raw - The raw memory input validated against `rawMemorySchema`.
|
|
147
|
+
* @throws {@link @nhtio/adk!E_INVALID_INITIAL_MEMORY_VALUE} when `raw` does not satisfy the schema.
|
|
148
|
+
*/
|
|
149
|
+
constructor(raw) {
|
|
150
|
+
let resolved;
|
|
151
|
+
try {
|
|
152
|
+
resolved = require_exceptions.validateOrThrow(rawMemorySchema, raw, true);
|
|
153
|
+
} catch (err) {
|
|
154
|
+
throw new require_runtime.E_INVALID_INITIAL_MEMORY_VALUE({ cause: require_tool_registry.isError(err) ? err : void 0 });
|
|
155
|
+
}
|
|
156
|
+
this.#id = resolved.id;
|
|
157
|
+
this.#content = require_tool_registry.Tokenizable.isTokenizable(resolved.content) ? resolved.content : new require_tool_registry.Tokenizable(resolved.content);
|
|
158
|
+
this.#confidence = resolved.confidence;
|
|
159
|
+
this.#importance = resolved.importance;
|
|
160
|
+
this.#createdAt = resolved.createdAt;
|
|
161
|
+
this.#updatedAt = resolved.updatedAt;
|
|
162
|
+
Object.defineProperties(this, {
|
|
163
|
+
id: {
|
|
164
|
+
get: () => this.#id,
|
|
165
|
+
enumerable: true,
|
|
166
|
+
configurable: false
|
|
167
|
+
},
|
|
168
|
+
content: {
|
|
169
|
+
get: () => this.#content,
|
|
170
|
+
enumerable: true,
|
|
171
|
+
configurable: false
|
|
172
|
+
},
|
|
173
|
+
confidence: {
|
|
174
|
+
get: () => this.#confidence,
|
|
175
|
+
enumerable: true,
|
|
176
|
+
configurable: false
|
|
177
|
+
},
|
|
178
|
+
importance: {
|
|
179
|
+
get: () => this.#importance,
|
|
180
|
+
enumerable: true,
|
|
181
|
+
configurable: false
|
|
182
|
+
},
|
|
183
|
+
createdAt: {
|
|
184
|
+
get: () => this.#createdAt,
|
|
185
|
+
enumerable: true,
|
|
186
|
+
configurable: false
|
|
187
|
+
},
|
|
188
|
+
updatedAt: {
|
|
189
|
+
get: () => this.#updatedAt,
|
|
190
|
+
enumerable: true,
|
|
191
|
+
configurable: false
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/lib/classes/message.ts
|
|
198
|
+
/**
|
|
199
|
+
* Validator schema used to validate a {@link RawMessage} before constructing a {@link Message}.
|
|
200
|
+
*
|
|
201
|
+
* @remarks
|
|
202
|
+
* Validates all fields of {@link RawMessage}:
|
|
203
|
+
* - `id` — required non-empty string.
|
|
204
|
+
* - `role` — required; must be `'user'` or `'assistant'`.
|
|
205
|
+
* - `content` — optional string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.
|
|
206
|
+
* - `attachments` — optional array of {@link @nhtio/adk!Media} instances. Defaults to `[]`.
|
|
207
|
+
* - At least one of `content` or `attachments` must be present and non-empty; a message with
|
|
208
|
+
* neither is invalid.
|
|
209
|
+
* - `identity` — required string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; a plain string is
|
|
210
|
+
* mapped to both `identifier` and `representation` automatically.
|
|
211
|
+
* - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.
|
|
212
|
+
*
|
|
213
|
+
* Throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} (via the {@link Message} constructor) when
|
|
214
|
+
* validation fails.
|
|
215
|
+
*/
|
|
216
|
+
var rawMessageSchema = _nhtio_validation.validator.object({
|
|
217
|
+
id: _nhtio_validation.validator.string().required(),
|
|
218
|
+
role: _nhtio_validation.validator.string().valid("user", "assistant").required(),
|
|
219
|
+
content: require_tool_registry.Tokenizable.schema.optional(),
|
|
220
|
+
attachments: _nhtio_validation.validator.array().items(_nhtio_validation.validator.any().custom((value, helpers) => {
|
|
221
|
+
if (require_tool_call.Media.isMedia(value)) return value;
|
|
222
|
+
return helpers.error("any.invalid");
|
|
223
|
+
})).default([]),
|
|
224
|
+
identity: _nhtio_validation.validator.alternatives(_nhtio_validation.validator.string(), Identity.schema).default(_nhtio_validation.validator.ref("role")),
|
|
225
|
+
createdAt: _nhtio_validation.validator.datetime().required(),
|
|
226
|
+
updatedAt: _nhtio_validation.validator.datetime().required()
|
|
227
|
+
}).custom((value, helpers) => {
|
|
228
|
+
const resolved = value;
|
|
229
|
+
const hasContent = resolved.content !== void 0 && resolved.content !== null;
|
|
230
|
+
const hasAttachments = Array.isArray(resolved.attachments) && resolved.attachments.length > 0;
|
|
231
|
+
if (!hasContent && !hasAttachments) return helpers.error("any.invalid");
|
|
232
|
+
return resolved;
|
|
233
|
+
});
|
|
234
|
+
/**
|
|
235
|
+
* An immutable, validated conversation message from a human participant or the model.
|
|
236
|
+
*
|
|
237
|
+
* @remarks
|
|
238
|
+
* Covers only `user` and `assistant` roles — system instructions, developer directives, and
|
|
239
|
+
* tool results are not represented here. Constructed from a {@link RawMessage} via
|
|
240
|
+
* `rawMessageSchema`. Temporal fields are normalised to Luxon `DateTime` instances at
|
|
241
|
+
* construction time. Both `content` and `identity.representation` are {@link @nhtio/adk!Tokenizable} so
|
|
242
|
+
* token cost can be estimated inline.
|
|
243
|
+
*
|
|
244
|
+
* A message may carry `content` (text), `attachments` (media), or both. The cross-field rule
|
|
245
|
+
* on `rawMessageSchema` enforces that at least one is present. Downstream code that reaches
|
|
246
|
+
* for `message.content` must handle the attachments-only case where `content` is `undefined`.
|
|
247
|
+
*/
|
|
248
|
+
var Message = class Message {
|
|
249
|
+
/**
|
|
250
|
+
* Validator schema that accepts a {@link RawMessage} object.
|
|
251
|
+
*
|
|
252
|
+
* @remarks
|
|
253
|
+
* Reusable fragment for any schema that needs to validate or nest a message entry — for
|
|
254
|
+
* example, a collection schema that holds an array of messages.
|
|
255
|
+
*/
|
|
256
|
+
static schema = rawMessageSchema;
|
|
257
|
+
/**
|
|
258
|
+
* Returns `true` if `value` is a {@link Message} instance.
|
|
259
|
+
*
|
|
260
|
+
* @remarks
|
|
261
|
+
* Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
|
|
262
|
+
* created in a different module copy or VM context.
|
|
263
|
+
*
|
|
264
|
+
* @param value - The value to test.
|
|
265
|
+
* @returns `true` when `value` is a {@link Message} instance.
|
|
266
|
+
*/
|
|
267
|
+
static isMessage(value) {
|
|
268
|
+
return require_tool_registry.isInstanceOf(value, "Message", Message);
|
|
269
|
+
}
|
|
270
|
+
#id;
|
|
271
|
+
#role;
|
|
272
|
+
#content;
|
|
273
|
+
#attachments;
|
|
274
|
+
#identity;
|
|
275
|
+
#createdAt;
|
|
276
|
+
#updatedAt;
|
|
277
|
+
/**
|
|
278
|
+
* @param raw - The raw message input validated against `rawMessageSchema`.
|
|
279
|
+
* @throws {@link @nhtio/adk!E_INVALID_INITIAL_MESSAGE_VALUE} when `raw` does not satisfy the schema —
|
|
280
|
+
* including the cross-field rule that at least one of `content` or `attachments` must be
|
|
281
|
+
* present and non-empty.
|
|
282
|
+
*/
|
|
283
|
+
constructor(raw) {
|
|
284
|
+
let resolved;
|
|
285
|
+
try {
|
|
286
|
+
resolved = require_exceptions.validateOrThrow(rawMessageSchema, raw, true);
|
|
287
|
+
} catch (err) {
|
|
288
|
+
throw new require_runtime.E_INVALID_INITIAL_MESSAGE_VALUE({ cause: require_tool_registry.isError(err) ? err : void 0 });
|
|
289
|
+
}
|
|
290
|
+
this.#id = resolved.id;
|
|
291
|
+
this.#role = resolved.role;
|
|
292
|
+
this.#content = resolved.content === void 0 || resolved.content === null ? void 0 : require_tool_registry.Tokenizable.isTokenizable(resolved.content) ? resolved.content : new require_tool_registry.Tokenizable(resolved.content);
|
|
293
|
+
this.#attachments = Object.freeze([...resolved.attachments ?? []]);
|
|
294
|
+
const rawIdentity = resolved.identity;
|
|
295
|
+
this.#identity = Identity.isIdentity(rawIdentity) ? rawIdentity : typeof rawIdentity === "string" ? new Identity({
|
|
296
|
+
identifier: rawIdentity,
|
|
297
|
+
representation: rawIdentity
|
|
298
|
+
}) : new Identity(rawIdentity);
|
|
299
|
+
this.#createdAt = resolved.createdAt;
|
|
300
|
+
this.#updatedAt = resolved.updatedAt;
|
|
301
|
+
Object.defineProperties(this, {
|
|
302
|
+
id: {
|
|
303
|
+
get: () => this.#id,
|
|
304
|
+
enumerable: true,
|
|
305
|
+
configurable: false
|
|
306
|
+
},
|
|
307
|
+
role: {
|
|
308
|
+
get: () => this.#role,
|
|
309
|
+
enumerable: true,
|
|
310
|
+
configurable: false
|
|
311
|
+
},
|
|
312
|
+
content: {
|
|
313
|
+
get: () => this.#content,
|
|
314
|
+
enumerable: true,
|
|
315
|
+
configurable: false
|
|
316
|
+
},
|
|
317
|
+
attachments: {
|
|
318
|
+
get: () => this.#attachments,
|
|
319
|
+
enumerable: true,
|
|
320
|
+
configurable: false
|
|
321
|
+
},
|
|
322
|
+
identity: {
|
|
323
|
+
get: () => this.#identity,
|
|
324
|
+
enumerable: true,
|
|
325
|
+
configurable: false
|
|
326
|
+
},
|
|
327
|
+
createdAt: {
|
|
328
|
+
get: () => this.#createdAt,
|
|
329
|
+
enumerable: true,
|
|
330
|
+
configurable: false
|
|
331
|
+
},
|
|
332
|
+
updatedAt: {
|
|
333
|
+
get: () => this.#updatedAt,
|
|
334
|
+
enumerable: true,
|
|
335
|
+
configurable: false
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/lib/classes/thought.ts
|
|
342
|
+
/**
|
|
343
|
+
* Validator schema used to validate a {@link RawThought} before constructing a {@link Thought}.
|
|
344
|
+
*
|
|
345
|
+
* @remarks
|
|
346
|
+
* Validates all fields of {@link RawThought}:
|
|
347
|
+
* - `id` — required non-empty string.
|
|
348
|
+
* - `content` — required string or {@link @nhtio/adk!Tokenizable}, via {@link @nhtio/adk!Tokenizable.schema}.
|
|
349
|
+
* - `identity` — optional string, {@link @nhtio/adk!RawIdentity}, or {@link @nhtio/adk!Identity}; defaults to
|
|
350
|
+
* `'assistant'` when omitted.
|
|
351
|
+
* - `createdAt` / `updatedAt` — required datetime-parseable values, normalised to `DateTime`.
|
|
352
|
+
*
|
|
353
|
+
* Throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} (via the {@link Thought} constructor) when
|
|
354
|
+
* validation fails.
|
|
355
|
+
*/
|
|
356
|
+
var rawThoughtSchema = _nhtio_validation.validator.object({
|
|
357
|
+
id: _nhtio_validation.validator.string().required(),
|
|
358
|
+
content: require_tool_registry.Tokenizable.schema.required(),
|
|
359
|
+
identity: _nhtio_validation.validator.alternatives(_nhtio_validation.validator.string(), Identity.schema).default("assistant"),
|
|
360
|
+
payload: _nhtio_validation.validator.any().optional(),
|
|
361
|
+
replayCompatibility: _nhtio_validation.validator.string().min(1).optional(),
|
|
362
|
+
createdAt: _nhtio_validation.validator.datetime().required(),
|
|
363
|
+
updatedAt: _nhtio_validation.validator.datetime().required()
|
|
364
|
+
}).custom((value, helpers) => {
|
|
365
|
+
const v = value;
|
|
366
|
+
if (v.payload !== void 0 && (v.replayCompatibility === void 0 || v.replayCompatibility === null)) return helpers.error("any.invalid");
|
|
367
|
+
return value;
|
|
368
|
+
});
|
|
369
|
+
/**
|
|
370
|
+
* An immutable, validated internal reasoning trace produced by an agent.
|
|
371
|
+
*
|
|
372
|
+
* @remarks
|
|
373
|
+
* Represents an agent's internal thinking — distinct from {@link @nhtio/adk!Message} (which is part of
|
|
374
|
+
* the visible conversation) and never shown to end users directly. Carries an `identity` so
|
|
375
|
+
* reasoning traces can be attributed to a specific agent in multi-agent conversations.
|
|
376
|
+
* Constructed from a {@link RawThought} via `rawThoughtSchema`. The `content` field is always
|
|
377
|
+
* a {@link @nhtio/adk!Tokenizable} so token cost can be estimated inline.
|
|
378
|
+
*/
|
|
379
|
+
var Thought = class Thought {
|
|
380
|
+
/**
|
|
381
|
+
* Validator schema that accepts a {@link RawThought} object.
|
|
382
|
+
*
|
|
383
|
+
* @remarks
|
|
384
|
+
* Reusable fragment for any schema that needs to validate or nest a thought entry.
|
|
385
|
+
*/
|
|
386
|
+
static schema = rawThoughtSchema;
|
|
387
|
+
/**
|
|
388
|
+
* Returns `true` if `value` is a {@link Thought} instance.
|
|
389
|
+
*
|
|
390
|
+
* @remarks
|
|
391
|
+
* Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
|
|
392
|
+
* created in a different module copy or VM context.
|
|
393
|
+
*
|
|
394
|
+
* @param value - The value to test.
|
|
395
|
+
* @returns `true` when `value` is a {@link Thought} instance.
|
|
396
|
+
*/
|
|
397
|
+
static isThought(value) {
|
|
398
|
+
return require_tool_registry.isInstanceOf(value, "Thought", Thought);
|
|
399
|
+
}
|
|
400
|
+
#id;
|
|
401
|
+
#content;
|
|
402
|
+
#identity;
|
|
403
|
+
#payload;
|
|
404
|
+
#replayCompatibility;
|
|
405
|
+
#createdAt;
|
|
406
|
+
#updatedAt;
|
|
407
|
+
/**
|
|
408
|
+
* @param raw - The raw thought input validated against `rawThoughtSchema`.
|
|
409
|
+
* @throws {@link @nhtio/adk!E_INVALID_INITIAL_THOUGHT_VALUE} when `raw` does not satisfy the schema.
|
|
410
|
+
*/
|
|
411
|
+
constructor(raw) {
|
|
412
|
+
let resolved;
|
|
413
|
+
try {
|
|
414
|
+
resolved = require_exceptions.validateOrThrow(rawThoughtSchema, raw, true);
|
|
415
|
+
} catch (err) {
|
|
416
|
+
throw new require_runtime.E_INVALID_INITIAL_THOUGHT_VALUE({ cause: require_tool_registry.isError(err) ? err : void 0 });
|
|
417
|
+
}
|
|
418
|
+
this.#id = resolved.id;
|
|
419
|
+
this.#content = require_tool_registry.Tokenizable.isTokenizable(resolved.content) ? resolved.content : new require_tool_registry.Tokenizable(resolved.content);
|
|
420
|
+
const rawIdentity = resolved.identity;
|
|
421
|
+
this.#identity = Identity.isIdentity(rawIdentity) ? rawIdentity : typeof rawIdentity === "string" ? new Identity({
|
|
422
|
+
identifier: rawIdentity,
|
|
423
|
+
representation: rawIdentity
|
|
424
|
+
}) : new Identity(rawIdentity);
|
|
425
|
+
this.#payload = resolved.payload;
|
|
426
|
+
this.#replayCompatibility = resolved.replayCompatibility;
|
|
427
|
+
this.#createdAt = resolved.createdAt;
|
|
428
|
+
this.#updatedAt = resolved.updatedAt;
|
|
429
|
+
Object.defineProperties(this, {
|
|
430
|
+
id: {
|
|
431
|
+
get: () => this.#id,
|
|
432
|
+
enumerable: true,
|
|
433
|
+
configurable: false
|
|
434
|
+
},
|
|
435
|
+
content: {
|
|
436
|
+
get: () => this.#content,
|
|
437
|
+
enumerable: true,
|
|
438
|
+
configurable: false
|
|
439
|
+
},
|
|
440
|
+
identity: {
|
|
441
|
+
get: () => this.#identity,
|
|
442
|
+
enumerable: true,
|
|
443
|
+
configurable: false
|
|
444
|
+
},
|
|
445
|
+
payload: {
|
|
446
|
+
get: () => this.#payload,
|
|
447
|
+
enumerable: true,
|
|
448
|
+
configurable: false
|
|
449
|
+
},
|
|
450
|
+
replayCompatibility: {
|
|
451
|
+
get: () => this.#replayCompatibility,
|
|
452
|
+
enumerable: true,
|
|
453
|
+
configurable: false
|
|
454
|
+
},
|
|
455
|
+
createdAt: {
|
|
456
|
+
get: () => this.#createdAt,
|
|
457
|
+
enumerable: true,
|
|
458
|
+
configurable: false
|
|
459
|
+
},
|
|
460
|
+
updatedAt: {
|
|
461
|
+
get: () => this.#updatedAt,
|
|
462
|
+
enumerable: true,
|
|
463
|
+
configurable: false
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
//#endregion
|
|
469
|
+
Object.defineProperty(exports, "Identity", {
|
|
470
|
+
enumerable: true,
|
|
471
|
+
get: function() {
|
|
472
|
+
return Identity;
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
Object.defineProperty(exports, "Memory", {
|
|
476
|
+
enumerable: true,
|
|
477
|
+
get: function() {
|
|
478
|
+
return Memory;
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
Object.defineProperty(exports, "Message", {
|
|
482
|
+
enumerable: true,
|
|
483
|
+
get: function() {
|
|
484
|
+
return Message;
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
Object.defineProperty(exports, "Thought", {
|
|
488
|
+
enumerable: true,
|
|
489
|
+
get: function() {
|
|
490
|
+
return Thought;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
//# sourceMappingURL=thought-DuN2PgdO.js.map
|