@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,322 @@
|
|
|
1
|
+
import type { DateTime } from 'luxon';
|
|
2
|
+
import type { NextFn } from '@nhtio/middleware';
|
|
3
|
+
import type { BaseException } from "../classes/base_exception";
|
|
4
|
+
import type { TurnGate, RawTurnGate } from "../classes/turn_gate";
|
|
5
|
+
import type { TurnContext } from "../contracts/turn_runner_context";
|
|
6
|
+
import type { EventMap, Key, Listener } from '@nhtio/tiny-typed-emitter';
|
|
7
|
+
import type { DispatchStartEvent, DispatchEndEvent, IterationStartEvent, IterationEndEvent, LogEvent } from "./dispatch_runner";
|
|
8
|
+
/**
|
|
9
|
+
* Middleware function signature for the input and output pipelines in a {@link @nhtio/adk!TurnRunner}.
|
|
10
|
+
*
|
|
11
|
+
* @param ctx - The mutable {@link @nhtio/adk!TurnContext} for the current turn.
|
|
12
|
+
* @param next - Callback to advance to the next middleware in the chain.
|
|
13
|
+
*/
|
|
14
|
+
export type TurnPipelineMiddlewareFn = (ctx: TurnContext, next: NextFn) => void | Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* A unit of streamable content emitted during a turn.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Each emission represents either a visible assistant message or an internal reasoning trace.
|
|
20
|
+
* `aDelta` carries the incremental text since the last emission; `full` is the accumulated text
|
|
21
|
+
* so far. `isComplete` is `true` on the final emission for a given `id`.
|
|
22
|
+
*/
|
|
23
|
+
export interface TurnStreamableContent {
|
|
24
|
+
/** Stable identifier for this content stream; groups deltas from the same generation. */
|
|
25
|
+
id: string;
|
|
26
|
+
/** Timestamp when this content stream was first created. */
|
|
27
|
+
createdAt: DateTime;
|
|
28
|
+
/** Timestamp of the most recent delta received for this stream. */
|
|
29
|
+
updatedAt: DateTime;
|
|
30
|
+
/** Full accumulated text received so far for this stream. */
|
|
31
|
+
full: string;
|
|
32
|
+
/** Incremental text added since the previous emission. */
|
|
33
|
+
aDelta: string;
|
|
34
|
+
/** `true` on the final chunk for this `id`; subsequent emissions will use a new `id`. */
|
|
35
|
+
isComplete: boolean;
|
|
36
|
+
/** Timestamp when the stream completed. Absent until `isComplete` is `true`. */
|
|
37
|
+
completedAt?: DateTime;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A tool call invocation emitted during a turn, including its result once available.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* Emitted at least once when the model requests a tool call. The same `id` is re-emitted with
|
|
44
|
+
* `results` populated and `isComplete` set to `true` after the tool has been executed. If
|
|
45
|
+
* execution fails, `isError` is `true` and `results` contains the error detail.
|
|
46
|
+
*/
|
|
47
|
+
export interface TurnToolCallContent {
|
|
48
|
+
/** Stable identifier for this tool call; correlates the initial request with its result. */
|
|
49
|
+
id: string;
|
|
50
|
+
/** Name of the tool the model has requested. */
|
|
51
|
+
tool: string;
|
|
52
|
+
/** Arguments the model supplied for the tool call. */
|
|
53
|
+
args: unknown;
|
|
54
|
+
/** Integrity checksum over `tool` and `args`; can be used to detect tampering before execution. */
|
|
55
|
+
checksum: string;
|
|
56
|
+
/** Timestamp when this tool call was first emitted. */
|
|
57
|
+
createdAt: DateTime;
|
|
58
|
+
/** Timestamp of the most recent update to this tool call (e.g. when results arrived). */
|
|
59
|
+
updatedAt: DateTime;
|
|
60
|
+
/**
|
|
61
|
+
* Result returned by the tool, or error detail when `isError` is `true`. Absent until execution
|
|
62
|
+
* completes.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* Shape depends on the underlying tool kind. For a normal {@link @nhtio/adk!Tool}
|
|
66
|
+
* call, this carries one or more {@link @nhtio/adk!SpooledArtifact}
|
|
67
|
+
* instances (single artifact or `SpooledArtifact[]`) wrapping the bytes returned by the handler,
|
|
68
|
+
* or one or more {@link @nhtio/adk!Media} instances (single `Media` or
|
|
69
|
+
* `Media[]`) when the handler took the explicit-modality return path. For an
|
|
70
|
+
* {@link @nhtio/adk!ArtifactTool} call, this is the raw string the
|
|
71
|
+
* handler emitted (`Tokenizable.toString()`-equivalent) — already the model-visible answer.
|
|
72
|
+
* Type stays `unknown` to keep this event payload narrow; the underlying
|
|
73
|
+
* `ToolCall.results` is `Tokenizable | SpooledArtifact | SpooledArtifact[] | Media | Media[]`.
|
|
74
|
+
*
|
|
75
|
+
* @see {@link @nhtio/adk!ToolCall.results}
|
|
76
|
+
*/
|
|
77
|
+
results?: unknown;
|
|
78
|
+
/** `true` once the tool call has finished (successfully or not). */
|
|
79
|
+
isComplete: boolean;
|
|
80
|
+
/** `true` when the tool execution produced an error; inspect `results` for detail. */
|
|
81
|
+
isError: boolean;
|
|
82
|
+
/** Timestamp when the tool call completed (successfully or not). */
|
|
83
|
+
completedAt?: DateTime;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Payload emitted when a turn begins.
|
|
87
|
+
*/
|
|
88
|
+
export interface TurnStartEvent {
|
|
89
|
+
/** The unique ID of the turn that started. */
|
|
90
|
+
turnId: string;
|
|
91
|
+
/** When the turn started. */
|
|
92
|
+
startedAt: DateTime;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Payload emitted when a turn ends.
|
|
96
|
+
*/
|
|
97
|
+
export interface TurnEndEvent {
|
|
98
|
+
/** The unique ID of the turn that ended. */
|
|
99
|
+
turnId: string;
|
|
100
|
+
/** When the turn started. */
|
|
101
|
+
startedAt: DateTime;
|
|
102
|
+
/** When the turn ended. */
|
|
103
|
+
endedAt: DateTime;
|
|
104
|
+
/** Duration of the turn in milliseconds. */
|
|
105
|
+
durationMs: number;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Payload emitted on the observability bus when a tool's executor begins executing the handler.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* Fired after arg validation passes and immediately before the handler is called.
|
|
112
|
+
* `callId` correlates the event with the {@link @nhtio/adk!ToolCall} record if one is being tracked. Fires
|
|
113
|
+
* for both {@link @nhtio/adk!Tool} and
|
|
114
|
+
* {@link @nhtio/adk!ArtifactTool} invocations — the payload is identical.
|
|
115
|
+
*/
|
|
116
|
+
export interface ToolExecutionStartEvent {
|
|
117
|
+
/** Name of the tool being executed. */
|
|
118
|
+
toolName: string;
|
|
119
|
+
/** ID of the turn in which the tool is being executed. */
|
|
120
|
+
turnId: string;
|
|
121
|
+
/** Correlates with the associated ToolCall id, if known. Empty string when not provided. */
|
|
122
|
+
callId: string;
|
|
123
|
+
/** The validated arguments that will be passed to the handler. */
|
|
124
|
+
args: unknown;
|
|
125
|
+
/** When execution started. */
|
|
126
|
+
startedAt: DateTime;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Payload emitted on the observability bus when a tool's executor finishes (successfully or not).
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* Fired after the handler returns or throws. When `isError` is `true`, the handler threw and the
|
|
133
|
+
* error has been wrapped in {@link @nhtio/adk!E_TOOL_DOWNSTREAM_ERROR}. Fires for both
|
|
134
|
+
* {@link @nhtio/adk!Tool} and
|
|
135
|
+
* {@link @nhtio/adk!ArtifactTool} invocations — the payload is identical.
|
|
136
|
+
*/
|
|
137
|
+
export interface ToolExecutionEndEvent {
|
|
138
|
+
/** Name of the tool that was executed. */
|
|
139
|
+
toolName: string;
|
|
140
|
+
/** ID of the turn in which the tool was executed. */
|
|
141
|
+
turnId: string;
|
|
142
|
+
/** Correlates with the associated ToolCall id, if known. Empty string when not provided. */
|
|
143
|
+
callId: string;
|
|
144
|
+
/** When execution started. */
|
|
145
|
+
startedAt: DateTime;
|
|
146
|
+
/** When execution ended. */
|
|
147
|
+
endedAt: DateTime;
|
|
148
|
+
/** Duration of the execution in milliseconds. */
|
|
149
|
+
durationMs: number;
|
|
150
|
+
/** `true` when the handler threw an error; the rejection reason is {@link @nhtio/adk!E_TOOL_DOWNSTREAM_ERROR}. */
|
|
151
|
+
isError: boolean;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Payload emitted when a {@link @nhtio/adk!TurnGate} settles (resolved, rejected, aborted, or timed out).
|
|
155
|
+
*/
|
|
156
|
+
export interface TurnGateClosedEvent {
|
|
157
|
+
/** ID of the gate that settled. */
|
|
158
|
+
gateId: string;
|
|
159
|
+
/** ID of the turn that owned the gate. */
|
|
160
|
+
turnId: string;
|
|
161
|
+
/** How the gate settled. */
|
|
162
|
+
result: 'resolved' | 'rejected' | 'aborted' | 'timeout';
|
|
163
|
+
/** When the gate settled. */
|
|
164
|
+
settledAt: DateTime;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* A function that emits a `message` event on the {@link @nhtio/adk!TurnRunner}.
|
|
168
|
+
*
|
|
169
|
+
* @remarks
|
|
170
|
+
* Injected into {@link @nhtio/adk!TurnContext} so middleware can surface streaming message chunks without
|
|
171
|
+
* holding a reference to the runner or its emitter.
|
|
172
|
+
*/
|
|
173
|
+
export type EmitMessageFn = (content: TurnStreamableContent) => void;
|
|
174
|
+
/**
|
|
175
|
+
* A function that emits a `thought` event on the {@link @nhtio/adk!TurnRunner}.
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* Injected into {@link @nhtio/adk!TurnContext} so middleware can surface reasoning trace chunks without
|
|
179
|
+
* holding a reference to the runner or its emitter.
|
|
180
|
+
*/
|
|
181
|
+
export type EmitThoughtFn = (content: TurnStreamableContent) => void;
|
|
182
|
+
/**
|
|
183
|
+
* A function that emits a `toolCall` event on the {@link @nhtio/adk!TurnRunner}.
|
|
184
|
+
*
|
|
185
|
+
* @remarks
|
|
186
|
+
* Injected into {@link @nhtio/adk!TurnContext} so middleware can surface tool call lifecycle events —
|
|
187
|
+
* both the initial request and the settled result — without holding a reference to the runner.
|
|
188
|
+
*/
|
|
189
|
+
export type EmitToolCallFn = (content: TurnToolCallContent) => void;
|
|
190
|
+
/**
|
|
191
|
+
* A function that emits a `toolExecutionStart` event on the {@link @nhtio/adk!TurnRunner} observability bus.
|
|
192
|
+
*
|
|
193
|
+
* @remarks
|
|
194
|
+
* Injected into both {@link @nhtio/adk!TurnContext} and `DispatchContext` so `Tool.executor()` can emit
|
|
195
|
+
* lifecycle events without holding a reference to the runner or its emitter. Tool execution
|
|
196
|
+
* happens inside an LLM dispatch loop; `DispatchContext` is the canonical context the tool
|
|
197
|
+
* handler receives.
|
|
198
|
+
*/
|
|
199
|
+
export type EmitToolExecutionStartFn = (event: ToolExecutionStartEvent) => void;
|
|
200
|
+
/**
|
|
201
|
+
* A function that emits a `toolExecutionEnd` event on the {@link @nhtio/adk!TurnRunner} observability bus.
|
|
202
|
+
*
|
|
203
|
+
* @remarks
|
|
204
|
+
* Injected into both {@link @nhtio/adk!TurnContext} and `DispatchContext` so `Tool.executor()` can emit
|
|
205
|
+
* lifecycle events without holding a reference to the runner or its emitter. Tool execution
|
|
206
|
+
* happens inside an LLM dispatch loop; `DispatchContext` is the canonical context the tool
|
|
207
|
+
* handler receives.
|
|
208
|
+
*/
|
|
209
|
+
export type EmitToolExecutionEndFn = (event: ToolExecutionEndEvent) => void;
|
|
210
|
+
/**
|
|
211
|
+
* A function that opens a {@link @nhtio/adk!TurnGate} for the current turn.
|
|
212
|
+
*
|
|
213
|
+
* @remarks
|
|
214
|
+
* Injected into {@link @nhtio/adk!TurnContext} as `waitFor`. The runner closure supplies `turnId` and
|
|
215
|
+
* `abortSignal` automatically — callers only provide the gate-specific fields.
|
|
216
|
+
*
|
|
217
|
+
* @typeParam T - The expected type of the resolution value.
|
|
218
|
+
*/
|
|
219
|
+
export type OpenGateFn = <T>(raw: Omit<RawTurnGate, 'turnId' | 'abortSignal'>) => Promise<T>;
|
|
220
|
+
/**
|
|
221
|
+
* Functional events emitted by {@link @nhtio/adk!TurnRunner} during a turn.
|
|
222
|
+
*
|
|
223
|
+
* @remarks
|
|
224
|
+
* These events are pipeline-affecting and are registered via `on` / `off` / `once`.
|
|
225
|
+
*
|
|
226
|
+
* - `message` — a visible assistant message chunk; may be emitted at any point during the turn.
|
|
227
|
+
* - `thought` — an internal reasoning/thinking trace chunk; may be emitted at any point during
|
|
228
|
+
* the turn. Not shown to end users by default.
|
|
229
|
+
* - `toolCall` — emitted when the model requests a tool call and again when the result is
|
|
230
|
+
* available. Check {@link TurnToolCallContent.isComplete} to distinguish the two emissions.
|
|
231
|
+
*/
|
|
232
|
+
export type TurnEvents = EventMap<{
|
|
233
|
+
message: [
|
|
234
|
+
TurnStreamableContent
|
|
235
|
+
];
|
|
236
|
+
thought: [
|
|
237
|
+
TurnStreamableContent
|
|
238
|
+
];
|
|
239
|
+
toolCall: [
|
|
240
|
+
TurnToolCallContent
|
|
241
|
+
];
|
|
242
|
+
}>;
|
|
243
|
+
/**
|
|
244
|
+
* Observability events emitted by {@link @nhtio/adk!TurnRunner} for instrumentation.
|
|
245
|
+
*
|
|
246
|
+
* @remarks
|
|
247
|
+
* These events are for monitoring and instrumentation only and are registered via
|
|
248
|
+
* `observe` / `unobserve` / `observeOnce`. They do not affect pipeline execution.
|
|
249
|
+
*
|
|
250
|
+
* - `turnStart` — emitted immediately before the input pipeline runs.
|
|
251
|
+
* - `turnEnd` — emitted after the pipeline completes (or is aborted/errored).
|
|
252
|
+
* - `turnGateOpen` — emitted when middleware calls `ctx.waitFor()`, opening a gate.
|
|
253
|
+
* - `turnGateClosed` — emitted when a gate settles (resolved, rejected, aborted, or timed out).
|
|
254
|
+
* - `toolExecutionStart` — emitted before a tool handler is called (after arg validation).
|
|
255
|
+
* - `toolExecutionEnd` — emitted after a tool handler returns or throws.
|
|
256
|
+
* - `error` — emitted when a non-fatal error occurs inside the input or output pipeline.
|
|
257
|
+
* - `log` — emitted when the LLM executor (or anything wired through `helpers.log`) writes a
|
|
258
|
+
* structured observability record. Carries `dispatchId`, `iteration`, `emittedAt`, `level`,
|
|
259
|
+
* `kind`, `message`, and an optional `payload`.
|
|
260
|
+
*/
|
|
261
|
+
export type TurnObservabilityEvents = EventMap<{
|
|
262
|
+
turnStart: [
|
|
263
|
+
TurnStartEvent
|
|
264
|
+
];
|
|
265
|
+
turnEnd: [
|
|
266
|
+
TurnEndEvent
|
|
267
|
+
];
|
|
268
|
+
turnGateOpen: [
|
|
269
|
+
TurnGate
|
|
270
|
+
];
|
|
271
|
+
turnGateClosed: [
|
|
272
|
+
TurnGateClosedEvent
|
|
273
|
+
];
|
|
274
|
+
toolExecutionStart: [
|
|
275
|
+
ToolExecutionStartEvent
|
|
276
|
+
];
|
|
277
|
+
toolExecutionEnd: [
|
|
278
|
+
ToolExecutionEndEvent
|
|
279
|
+
];
|
|
280
|
+
dispatchStart: [
|
|
281
|
+
DispatchStartEvent
|
|
282
|
+
];
|
|
283
|
+
dispatchEnd: [
|
|
284
|
+
DispatchEndEvent
|
|
285
|
+
];
|
|
286
|
+
iterationStart: [
|
|
287
|
+
IterationStartEvent
|
|
288
|
+
];
|
|
289
|
+
iterationEnd: [
|
|
290
|
+
IterationEndEvent
|
|
291
|
+
];
|
|
292
|
+
log: [
|
|
293
|
+
LogEvent
|
|
294
|
+
];
|
|
295
|
+
error: [
|
|
296
|
+
BaseException
|
|
297
|
+
];
|
|
298
|
+
}>;
|
|
299
|
+
/**
|
|
300
|
+
* Valid event name keys for the {@link @nhtio/adk!TurnRunner} functional bus.
|
|
301
|
+
*
|
|
302
|
+
* @typeParam K - Inferred from the key of {@link TurnEvents}.
|
|
303
|
+
*/
|
|
304
|
+
export type TurnEvent<K> = Key<K, TurnEvents>;
|
|
305
|
+
/**
|
|
306
|
+
* Listener signature for a given {@link @nhtio/adk!TurnRunner} functional event.
|
|
307
|
+
*
|
|
308
|
+
* @typeParam K - The event key; inferred from the key of {@link TurnEvents}.
|
|
309
|
+
*/
|
|
310
|
+
export type TurnEventListener<K> = Listener<K, TurnEvents>;
|
|
311
|
+
/**
|
|
312
|
+
* Valid event name keys for the {@link @nhtio/adk!TurnRunner} observability bus.
|
|
313
|
+
*
|
|
314
|
+
* @typeParam K - Inferred from the key of {@link TurnObservabilityEvents}.
|
|
315
|
+
*/
|
|
316
|
+
export type TurnObservabilityEvent<K> = Key<K, TurnObservabilityEvents>;
|
|
317
|
+
/**
|
|
318
|
+
* Listener signature for a given {@link @nhtio/adk!TurnRunner} observability event.
|
|
319
|
+
*
|
|
320
|
+
* @typeParam K - The event key; inferred from the key of {@link TurnObservabilityEvents}.
|
|
321
|
+
*/
|
|
322
|
+
export type TurnObservabilityEventListener<K> = Listener<K, TurnObservabilityEvents>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical `JSON.stringify` that sorts object keys recursively so that semantically-equal
|
|
3
|
+
* objects produce identical strings.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Used wherever the ADK derives a stable identity from a structured value — for example,
|
|
7
|
+
* `Tool.executor` computing the `callId` for `ToolExecutionStart`/`End` events, and the
|
|
8
|
+
* `reportToolCall` executor helper computing the `checksum` field on `TurnToolCallContent`.
|
|
9
|
+
* Both code paths hash `canonicalStringify({ tool, args })` so that argument key order does not
|
|
10
|
+
* affect the resulting identifier.
|
|
11
|
+
*
|
|
12
|
+
* Arrays are serialised in their declared order (order is meaningful for an array). Object keys
|
|
13
|
+
* are sorted with `Array.prototype.sort()`'s default lexicographic comparator.
|
|
14
|
+
*
|
|
15
|
+
* @param value - The value to serialise.
|
|
16
|
+
* @returns A canonical JSON string representation of `value`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function canonicalStringify(value: unknown): string;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BaseException } from "../classes/base_exception";
|
|
2
|
+
/**
|
|
3
|
+
* Options accepted by {@link @nhtio/adk!BaseException} (and factory-created exceptions) beyond the
|
|
4
|
+
* standard `ErrorOptions`.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* These mirror the static defaults on {@link @nhtio/adk!BaseException} but allow per-throw overrides so a
|
|
8
|
+
* single exception class can carry different metadata at different throw sites.
|
|
9
|
+
*/
|
|
10
|
+
export type ExceptionOptions = ErrorOptions & {
|
|
11
|
+
code?: string;
|
|
12
|
+
status?: number;
|
|
13
|
+
fatal?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Constructor signature of an exception class produced by {@link createException}.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam T - Tuple of printf-style format argument types. When `T` is an empty tuple the
|
|
19
|
+
* constructor takes no positional message arguments; when non-empty the first argument must be
|
|
20
|
+
* an array of values matching `T`.
|
|
21
|
+
*/
|
|
22
|
+
export type CreatedException<T extends any[] = [
|
|
23
|
+
]> = typeof BaseException & (T extends [
|
|
24
|
+
] ? {
|
|
25
|
+
new (options?: ExceptionOptions): BaseException;
|
|
26
|
+
} : {
|
|
27
|
+
new (args: T, options?: ExceptionOptions): BaseException;
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Factory that produces a named {@link @nhtio/adk!BaseException} subclass with a fixed printf-style message
|
|
31
|
+
* template, error code, HTTP status, and fatality flag.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Prefer this over hand-writing subclasses for simple, static exception definitions.
|
|
35
|
+
*
|
|
36
|
+
* @typeParam T - Tuple of printf format argument types. Pass a non-empty tuple to require
|
|
37
|
+
* callers to supply interpolation values at the throw site.
|
|
38
|
+
*
|
|
39
|
+
* @param name - The `name` property set on thrown instances (used by {@link isNamedException}).
|
|
40
|
+
* @param message - Printf-style template string for the error message.
|
|
41
|
+
* @param code - Machine-readable error code stored on the static and instance `code` property.
|
|
42
|
+
* @param status - HTTP status code associated with this exception class.
|
|
43
|
+
* @param fatal - When `true`, signals that the error is unrecoverable.
|
|
44
|
+
* @returns A constructor for a {@link @nhtio/adk!BaseException} subclass with the given metadata baked in.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* export const E_NOT_FOUND = createException<[string]>(
|
|
49
|
+
* 'E_NOT_FOUND', 'Resource %s not found', 'E_NOT_FOUND', 404, false
|
|
50
|
+
* )
|
|
51
|
+
* throw new E_NOT_FOUND(['my-id'])
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const createException: <T extends any[] = [
|
|
55
|
+
]>(name: string, message: string, code: string, status?: number, fatal?: boolean) => CreatedException<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Returns `true` if `value` is a {@link @nhtio/adk!BaseException} or satisfies its minimum duck-type shape.
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* The duck-typing path handles exceptions that cross module or realm boundaries where
|
|
61
|
+
* `instanceof` would return `false` for structurally identical objects.
|
|
62
|
+
*
|
|
63
|
+
* @param value - The value to test.
|
|
64
|
+
* @returns `true` when `value` conforms to the {@link @nhtio/adk!BaseException} shape.
|
|
65
|
+
*/
|
|
66
|
+
export declare const isException: (value: unknown) => value is BaseException;
|
|
67
|
+
/**
|
|
68
|
+
* Narrows `value` to a {@link @nhtio/adk!BaseException} whose `name` property matches `name` exactly.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* Useful for catching a specific factory-created exception by its string identifier when
|
|
72
|
+
* `instanceof` checks are not available (e.g. across module boundaries).
|
|
73
|
+
*
|
|
74
|
+
* @param value - The value to test.
|
|
75
|
+
* @param name - The exact string to compare against `value.name`.
|
|
76
|
+
* @returns `true` when `value` is a {@link @nhtio/adk!BaseException} with the given `name`.
|
|
77
|
+
*/
|
|
78
|
+
export declare const isNamedException: (value: unknown, name: string) => value is BaseException;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns `true` if `value` is an instance of the class identified by `type` (and optionally `ctor`).
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Performs three checks in order: `instanceof ctor`, `Symbol.hasInstance`, then constructor-name
|
|
6
|
+
* comparison. The constructor-name fallback handles cross-realm cases where `instanceof` fails.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam T - The expected instance type.
|
|
9
|
+
* @param value - The value to test.
|
|
10
|
+
* @param type - The constructor name to compare against when `instanceof` is unavailable.
|
|
11
|
+
* @param ctor - Optional constructor to use for `instanceof` and `Symbol.hasInstance` checks.
|
|
12
|
+
* @returns `true` when `value` is an instance of the class described by `type`/`ctor`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const isInstanceOf: <T>(value: unknown, type: string, ctor?: new (...args: any[]) => T) => value is T;
|
|
15
|
+
/**
|
|
16
|
+
* Returns `true` if `value` is an `Error` instance or satisfies the `Error` duck-type shape.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Returns `false` for `undefined` and `null` — the `Error` contract requires an actual instance.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The value to test.
|
|
22
|
+
* @returns `true` when `value` conforms to the `Error` shape.
|
|
23
|
+
*/
|
|
24
|
+
export declare const isError: (value: unknown) => value is Error;
|
|
25
|
+
/**
|
|
26
|
+
* Type guard to check if a value is a plain object (not null, not array)
|
|
27
|
+
* @param value - The value to check
|
|
28
|
+
* @returns True if the value is a plain object, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
export declare const isObject: (value: unknown) => value is {
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { BaseException } from "../classes/base_exception";
|
|
2
|
+
import { ValidationError } from '@nhtio/validation';
|
|
3
|
+
import type { Schema } from '@nhtio/validation';
|
|
4
|
+
/**
|
|
5
|
+
* Returns `true` if `value` satisfies `schema` without throwing.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Aborts on the first validation error. Use {@link validateOrThrow} or
|
|
9
|
+
* {@link asyncValidateOrThrow} when you need the full set of field errors.
|
|
10
|
+
*
|
|
11
|
+
* @param schema - The schema to validate against.
|
|
12
|
+
* @param value - The value to test.
|
|
13
|
+
* @returns `true` when `value` passes the schema; `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export declare const passesSchema: (schema: Schema, value: unknown) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Returns `true` if `value` is a `ValidationError` or satisfies its minimum duck-type shape.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* The duck-typing path handles `ValidationError` objects that cross module or realm boundaries
|
|
21
|
+
* where `instanceof` would return `false`.
|
|
22
|
+
*
|
|
23
|
+
* @param value - The value to test.
|
|
24
|
+
* @returns `true` when `value` conforms to the `ValidationError` shape.
|
|
25
|
+
*/
|
|
26
|
+
export declare const isValidationError: (value: unknown) => value is ValidationError;
|
|
27
|
+
/**
|
|
28
|
+
* Thrown when input fails schema validation.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* Carries the full `details` array from the underlying `ValidationError` so callers can surface
|
|
32
|
+
* field-level messages without unwrapping the `cause` manually.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ValidationException extends BaseException {
|
|
35
|
+
static status: number;
|
|
36
|
+
static code: string;
|
|
37
|
+
static fatal: boolean;
|
|
38
|
+
/** The raw field-level error details from the underlying `ValidationError`. */
|
|
39
|
+
readonly details?: ValidationError['details'];
|
|
40
|
+
/**
|
|
41
|
+
* @param reason - The `ValidationError` thrown by the schema; its `details` are surfaced
|
|
42
|
+
* directly on this exception and its messages are joined to form the human-readable message.
|
|
43
|
+
*/
|
|
44
|
+
constructor(reason: ValidationError);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validates `value` against `schema` synchronously and returns the coerced result typed as `T`.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* Collects all field errors before throwing. Use {@link asyncValidateOrThrow} for schemas that
|
|
51
|
+
* include async custom validators.
|
|
52
|
+
*
|
|
53
|
+
* @typeParam T - The expected type of `value` after successful validation.
|
|
54
|
+
* @param schema - The schema to validate against.
|
|
55
|
+
* @param value - The value to validate.
|
|
56
|
+
* @param convert - When `true`, the validator coerces values to their target types (e.g. string
|
|
57
|
+
* `"1"` → number `1`). Defaults to `false` to prevent silent type coercion.
|
|
58
|
+
* @returns The validated (and optionally coerced) value typed as `T`.
|
|
59
|
+
* @throws {@link ValidationException} when `value` does not satisfy `schema`.
|
|
60
|
+
*/
|
|
61
|
+
export declare const validateOrThrow: <T>(schema: Schema, value: unknown, convert?: boolean) => T;
|
|
62
|
+
/**
|
|
63
|
+
* Validates `value` against `schema` asynchronously and returns the coerced result typed as `T`.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* Collects all field errors before throwing. Prefer this over {@link validateOrThrow} when the
|
|
67
|
+
* schema includes async custom validators.
|
|
68
|
+
*
|
|
69
|
+
* @typeParam T - The expected type of the validated and coerced return value.
|
|
70
|
+
* @param schema - The schema to validate against.
|
|
71
|
+
* @param value - The value to validate.
|
|
72
|
+
* @param convert - When `true`, the validator coerces values to their target types (e.g. string
|
|
73
|
+
* `"1"` → number `1`). Defaults to `false` to prevent silent type coercion.
|
|
74
|
+
* @returns The validated (and optionally coerced) value typed as `T`.
|
|
75
|
+
* @throws {@link ValidationException} when `value` does not satisfy `schema`.
|
|
76
|
+
*/
|
|
77
|
+
export declare const asyncValidateOrThrow: <T>(schema: Schema, value: unknown, convert?: boolean) => Promise<T>;
|