@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,190 @@
|
|
|
1
|
+
import { Media } from "./media";
|
|
2
|
+
import { Tokenizable } from "./tokenizable";
|
|
3
|
+
import { SpooledArtifact } from "./spooled_artifact";
|
|
4
|
+
import type { DateTime } from 'luxon';
|
|
5
|
+
/**
|
|
6
|
+
* Union of every shape a {@link ToolCall.results} field may carry.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Three silos with distinct render-time semantics:
|
|
10
|
+
*
|
|
11
|
+
* - {@link @nhtio/adk!Tokenizable} — always singular. The {@link @nhtio/adk!ArtifactTool}
|
|
12
|
+
* carve-out: a model-visible text answer that explicitly opts out of artifact wrapping to
|
|
13
|
+
* break the recursive grep-on-the-grep-result loop.
|
|
14
|
+
* - {@link @nhtio/adk!SpooledArtifact} or `SpooledArtifact[]` — bounded text output spooled to durable
|
|
15
|
+
* storage. A single tool call may legitimately produce multiple artifacts (e.g. one tool
|
|
16
|
+
* that returns N PR bodies). LLM adapters render either inline (full body in trust envelope)
|
|
17
|
+
* or as a handle reference (forged artifact-query tools).
|
|
18
|
+
* - {@link @nhtio/adk!Media} or `Media[]` — binary modality output (image, audio, video, document).
|
|
19
|
+
* Adapters render as provider-specific content blocks (`image_url`, `input_audio`, `file`,
|
|
20
|
+
* etc.). Bytes are lazy — reached only through {@link @nhtio/adk!Media.stream}.
|
|
21
|
+
*/
|
|
22
|
+
export type ToolCallResults = Tokenizable | SpooledArtifact | SpooledArtifact[] | Media | Media[];
|
|
23
|
+
/**
|
|
24
|
+
* Plain input object supplied to {@link ToolCall} at construction time.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* Validated against `rawToolCallSchema` before the `ToolCall` instance is created.
|
|
28
|
+
* Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,
|
|
29
|
+
* `Date` objects, or existing `DateTime` instances.
|
|
30
|
+
*/
|
|
31
|
+
export interface RawToolCall {
|
|
32
|
+
/** Stable unique identifier for this tool call; correlates the request with its result. */
|
|
33
|
+
id: string;
|
|
34
|
+
/** Name of the tool the model has requested. */
|
|
35
|
+
tool: string;
|
|
36
|
+
/**
|
|
37
|
+
* Arguments the model supplied for this tool call.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* Accepts either a plain object or a JSON-encoded string that deserialises to an object.
|
|
41
|
+
* Always exposed as a plain object on the constructed {@link ToolCall} instance.
|
|
42
|
+
*/
|
|
43
|
+
args: string | Record<string, unknown>;
|
|
44
|
+
/** Integrity checksum over `tool` and `args`; can be used to detect tampering before execution. */
|
|
45
|
+
checksum: string;
|
|
46
|
+
/** `true` once the tool call has finished (successfully or not). */
|
|
47
|
+
isComplete: boolean;
|
|
48
|
+
/** `true` when the tool execution produced an error; inspect `results` for detail. */
|
|
49
|
+
isError: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Result returned by the tool, or error detail when `isError` is `true`.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Three silos with distinct render-time semantics — see {@link ToolCallResults}:
|
|
55
|
+
*
|
|
56
|
+
* - For a normal {@link @nhtio/adk!Tool} call whose handler returned `string` or
|
|
57
|
+
* `Uint8Array`, this is a {@link @nhtio/adk!SpooledArtifact} (or one of its subclasses) wrapping the
|
|
58
|
+
* spooled bytes. Tools that legitimately produce multiple bounded artifacts may return
|
|
59
|
+
* a `SpooledArtifact[]`.
|
|
60
|
+
* - For a `Tool` call whose handler returned a {@link @nhtio/adk!Media} or `Media[]`, this is the same
|
|
61
|
+
* media handle(s) — the explicit-modality silo bypasses `SpooledArtifact` wrapping because
|
|
62
|
+
* the bytes are binary and rendered as provider-specific content blocks, not text.
|
|
63
|
+
* - For an {@link @nhtio/adk!ArtifactTool} call (a forged artifact-query tool),
|
|
64
|
+
* this is a {@link @nhtio/adk!Tokenizable} holding the raw model-visible answer — `ArtifactTool`
|
|
65
|
+
* explicitly opts out of wrapping to break the recursive grep-on-the-grep-result loop.
|
|
66
|
+
*
|
|
67
|
+
* The ADK sets {@link RawToolCall.fromArtifactTool} on calls produced by an
|
|
68
|
+
* `ArtifactTool` so subsequent `forgeTools(ctx)` invocations can filter them out of the
|
|
69
|
+
* `callId` enum.
|
|
70
|
+
*/
|
|
71
|
+
results: ToolCallResults;
|
|
72
|
+
/**
|
|
73
|
+
* `true` when this tool call originated from an {@link @nhtio/adk!ArtifactTool}
|
|
74
|
+
* invocation. Defaults to `false`.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* Set by the ADK's result-wrapping touch sites when `ArtifactTool.isArtifactTool(tool)`
|
|
78
|
+
* holds. Read by `SpooledArtifact.forgeTools(ctx)` when building each descriptor's `callId`
|
|
79
|
+
* enum — calls with this flag set are excluded so the model can't `artifact_grep` on a
|
|
80
|
+
* previous `artifact_grep` result. Optional in the raw shape (defaults to `false`); always
|
|
81
|
+
* defined on the constructed {@link ToolCall}.
|
|
82
|
+
*
|
|
83
|
+
* @defaultValue `false`
|
|
84
|
+
*/
|
|
85
|
+
fromArtifactTool?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* When `true` (default), LLM adapters render this tool call's result inline — the full
|
|
88
|
+
* stringified body is wrapped in the adapter's trust envelope and sent to the model as the
|
|
89
|
+
* `tool` role content. When `false`, the adapter surfaces the result as a "handle" — a
|
|
90
|
+
* directions-bearing envelope that tells the model which forged artifact-query tools to call
|
|
91
|
+
* against this `tc.id` to read the content incrementally.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* Policy is the producer's or middleware's call:
|
|
95
|
+
* - A normal tool returns its result with `inline: true` by default so its output is shown
|
|
96
|
+
* verbatim.
|
|
97
|
+
* - Middleware that wants to keep large results out of the model's prompt sets `inline: false`
|
|
98
|
+
* (typically via `ctx.mutateToolCall(tc.id, { inline: false })`) before yielding.
|
|
99
|
+
* - LLM adapters do not override the flag, do not size-check the result, and do not silently
|
|
100
|
+
* switch to the handle pattern.
|
|
101
|
+
*
|
|
102
|
+
* For {@link @nhtio/adk!Tokenizable} results, the flag is effectively informational — handles only make
|
|
103
|
+
* sense for {@link @nhtio/adk!SpooledArtifact} (which is the only result kind the forged artifact-query
|
|
104
|
+
* tools can read). When `inline: false` is set on a call whose `results` is a `Tokenizable`,
|
|
105
|
+
* the adapter renders inline anyway and may log a warning.
|
|
106
|
+
*
|
|
107
|
+
* @defaultValue `true`
|
|
108
|
+
*/
|
|
109
|
+
inline?: boolean;
|
|
110
|
+
/** When this tool call was first created. */
|
|
111
|
+
createdAt: string | number | Date | DateTime;
|
|
112
|
+
/** When this tool call was last modified. */
|
|
113
|
+
updatedAt: string | number | Date | DateTime;
|
|
114
|
+
/** When the tool call completed. */
|
|
115
|
+
completedAt: string | number | Date | DateTime;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* An immutable, validated tool call record associated with a turn.
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* Represents a completed tool invocation from the conversation history — `results`,
|
|
122
|
+
* `completedAt`, `isComplete`, and `isError` are all present and required.
|
|
123
|
+
* Temporal fields are normalised to Luxon `DateTime` instances at construction time.
|
|
124
|
+
*/
|
|
125
|
+
export declare class ToolCall {
|
|
126
|
+
#private;
|
|
127
|
+
/**
|
|
128
|
+
* Validator schema that accepts a {@link RawToolCall} object.
|
|
129
|
+
*
|
|
130
|
+
* @remarks
|
|
131
|
+
* Reusable fragment for any schema that needs to validate or nest a tool call entry.
|
|
132
|
+
*/
|
|
133
|
+
static schema: import("@nhtio/validation").ObjectSchema<RawToolCall>;
|
|
134
|
+
/**
|
|
135
|
+
* Returns `true` if `value` is a {@link ToolCall} instance.
|
|
136
|
+
*
|
|
137
|
+
* @remarks
|
|
138
|
+
* Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety — `instanceof` would fail for instances
|
|
139
|
+
* created in a different module copy or VM context.
|
|
140
|
+
*
|
|
141
|
+
* @param value - The value to test.
|
|
142
|
+
* @returns `true` when `value` is a {@link ToolCall} instance.
|
|
143
|
+
*/
|
|
144
|
+
static isToolCall(value: unknown): value is ToolCall;
|
|
145
|
+
/** Stable unique identifier for this tool call; correlates the request with its result. */
|
|
146
|
+
readonly id: string;
|
|
147
|
+
/** Name of the tool the model has requested. */
|
|
148
|
+
readonly tool: string;
|
|
149
|
+
/** Arguments the model supplied for this tool call, always as a plain object. */
|
|
150
|
+
readonly args: Record<string, unknown>;
|
|
151
|
+
/** Integrity checksum over `tool` and `args`. */
|
|
152
|
+
readonly checksum: string;
|
|
153
|
+
/** `true` once the tool call has finished (successfully or not). */
|
|
154
|
+
readonly isComplete: boolean;
|
|
155
|
+
/** `true` when the tool execution produced an error; inspect `results` for detail. */
|
|
156
|
+
readonly isError: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Result returned by the tool, or error detail when `isError` is `true`.
|
|
159
|
+
*
|
|
160
|
+
* @remarks
|
|
161
|
+
* One of three silos — see {@link ToolCallResults}. {@link @nhtio/adk!SpooledArtifact} or
|
|
162
|
+
* `SpooledArtifact[]` for normal text-output {@link @nhtio/adk!Tool} calls;
|
|
163
|
+
* {@link @nhtio/adk!Media} or `Media[]` for tool calls whose handler returned binary modality output;
|
|
164
|
+
* {@link @nhtio/adk!Tokenizable} for {@link @nhtio/adk!ArtifactTool} calls
|
|
165
|
+
* (see {@link ToolCall.fromArtifactTool}).
|
|
166
|
+
*/
|
|
167
|
+
readonly results: ToolCallResults;
|
|
168
|
+
/**
|
|
169
|
+
* `true` when this tool call originated from an {@link @nhtio/adk!ArtifactTool}
|
|
170
|
+
* invocation. Used by `SpooledArtifact.forgeTools(ctx)` to filter out forged-tool results from
|
|
171
|
+
* the `callId` enum it builds.
|
|
172
|
+
*/
|
|
173
|
+
readonly fromArtifactTool: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* `true` (default) renders this tool call's result inline in the prompt; `false` instructs LLM
|
|
176
|
+
* adapters to surface the result as a handle reference. See {@link RawToolCall.inline}.
|
|
177
|
+
*/
|
|
178
|
+
readonly inline: boolean;
|
|
179
|
+
/** When this tool call was first created. */
|
|
180
|
+
readonly createdAt: DateTime;
|
|
181
|
+
/** When this tool call was last modified. */
|
|
182
|
+
readonly updatedAt: DateTime;
|
|
183
|
+
/** When the tool call completed. */
|
|
184
|
+
readonly completedAt: DateTime;
|
|
185
|
+
/**
|
|
186
|
+
* @param raw - The raw tool call input validated against `rawToolCallSchema`.
|
|
187
|
+
* @throws {@link @nhtio/adk!E_INVALID_INITIAL_TOOL_CALL_VALUE} when `raw` does not satisfy the schema.
|
|
188
|
+
*/
|
|
189
|
+
constructor(raw: RawToolCall);
|
|
190
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { Tool } from "./tool";
|
|
2
|
+
import type { DispatchContext } from "../contracts/dispatch_context";
|
|
3
|
+
/**
|
|
4
|
+
* Options accepted by {@link ToolRegistry.merge}.
|
|
5
|
+
*/
|
|
6
|
+
export interface MergeOptions {
|
|
7
|
+
/**
|
|
8
|
+
* What to do when two registries contain a tool with the same name AND neither tool's own
|
|
9
|
+
* `onCollision` resolves the collision.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* - `'throw'` (default): raise {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} on the first unresolved
|
|
13
|
+
* collision. Mirrors the default behaviour of {@link ToolRegistry.register} and surfaces
|
|
14
|
+
* accidental name shadowing immediately.
|
|
15
|
+
* - `'replace'`: the later registry's tool wins.
|
|
16
|
+
* - `'keep'`: the earlier registry's tool wins; later occurrences are dropped.
|
|
17
|
+
*
|
|
18
|
+
* Per-tool {@link @nhtio/adk!Tool.onCollision} takes precedence: if the incoming tool declares
|
|
19
|
+
* `'replace'` or `'keep'`, that policy wins regardless of this option. Only when the incoming
|
|
20
|
+
* tool's policy is `'throw'` (the default) does this fallback apply.
|
|
21
|
+
*
|
|
22
|
+
* @defaultValue `'throw'`
|
|
23
|
+
*/
|
|
24
|
+
onCollision?: 'throw' | 'replace' | 'keep';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A mutable, turn-scoped collection of {@link @nhtio/adk!Tool} instances.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* Each `TurnRunner.run()` call constructs a fresh `ToolRegistry` from the runner's configured
|
|
31
|
+
* baseline tools, so middleware edits are isolated to the current turn and cannot bleed across
|
|
32
|
+
* concurrent or subsequent turns.
|
|
33
|
+
*
|
|
34
|
+
* `Tool` instances are immutable, so `all()` returns a fresh array without deep-cloning.
|
|
35
|
+
*
|
|
36
|
+
* `register()` throws {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} if a tool with the same name is already
|
|
37
|
+
* present — pass `overwrite: true` to replace it explicitly.
|
|
38
|
+
*/
|
|
39
|
+
export declare class ToolRegistry {
|
|
40
|
+
#private;
|
|
41
|
+
/**
|
|
42
|
+
* Returns `true` if `value` is a {@link ToolRegistry} instance.
|
|
43
|
+
*
|
|
44
|
+
* @param value - The value to test.
|
|
45
|
+
* @returns `true` when `value` is a {@link ToolRegistry} instance.
|
|
46
|
+
*/
|
|
47
|
+
static isToolRegistry(value: unknown): value is ToolRegistry;
|
|
48
|
+
/**
|
|
49
|
+
* @param tools - Optional initial tools. Insertion order is preserved. Duplicate names throw
|
|
50
|
+
* {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} — ensure each tool has a unique name.
|
|
51
|
+
* @throws {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} when two tools in `tools` share a name.
|
|
52
|
+
*/
|
|
53
|
+
constructor(tools?: Tool[]);
|
|
54
|
+
/**
|
|
55
|
+
* Adds a tool to the registry.
|
|
56
|
+
*
|
|
57
|
+
* @param tool - The tool to register.
|
|
58
|
+
* @param overwrite - When `true`, silently replaces an existing tool with the same name.
|
|
59
|
+
* Defaults to `false`.
|
|
60
|
+
* @throws {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} when a tool with the same name is already registered
|
|
61
|
+
* and `overwrite` is not `true`.
|
|
62
|
+
*/
|
|
63
|
+
register(tool: Tool, overwrite?: boolean): void;
|
|
64
|
+
/**
|
|
65
|
+
* Removes the tool with the given name from the registry.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* No-ops if no tool with that name is registered.
|
|
69
|
+
*
|
|
70
|
+
* @param name - The name of the tool to remove.
|
|
71
|
+
*/
|
|
72
|
+
unregister(name: string): void;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the tool registered under `name`, or `undefined` if not present.
|
|
75
|
+
*
|
|
76
|
+
* @param name - The tool name to look up.
|
|
77
|
+
*/
|
|
78
|
+
get(name: string): Tool | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Returns `true` if a tool with the given name is registered.
|
|
81
|
+
*
|
|
82
|
+
* @param name - The tool name to test.
|
|
83
|
+
*/
|
|
84
|
+
has(name: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Returns a fresh array of all registered tools in insertion order.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* Since {@link @nhtio/adk!Tool} instances are immutable, no deep-cloning is needed.
|
|
90
|
+
*/
|
|
91
|
+
all(): Tool[];
|
|
92
|
+
/**
|
|
93
|
+
* Removes every tool whose {@link @nhtio/adk!Tool.ephemeral} flag is `true`.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* Synchronous and idempotent — calling it twice in a row is a no-op the second time. The
|
|
97
|
+
* canonical caller is {@link ToolRegistry.bindContext}, which schedules this method to run
|
|
98
|
+
* at {@link @nhtio/adk!DispatchContext.ack}. Non-ephemeral tools are left untouched.
|
|
99
|
+
*/
|
|
100
|
+
pruneEphemeral(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Binds this registry to a {@link @nhtio/adk!DispatchContext} so that {@link pruneEphemeral} runs
|
|
103
|
+
* automatically when the context is acked.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* The handler does NOT fire on {@link @nhtio/adk!DispatchContext.nack} — failed executor runs leave
|
|
107
|
+
* any forged tools in place so the consumer can inspect what was registered when debugging the
|
|
108
|
+
* failure. Subscriptions are short-lived and die with the context regardless.
|
|
109
|
+
*
|
|
110
|
+
* Forgetting this call after merging in `Subclass.forgeTools(ctx)` output means ephemeral tools
|
|
111
|
+
* accumulate across executor invocations, and subsequent `forgeTools(ctx)` calls in later
|
|
112
|
+
* iterations will see a stale `callId` enum that excludes new tool calls. The plan-documented
|
|
113
|
+
* pattern is:
|
|
114
|
+
*
|
|
115
|
+
* ```ts
|
|
116
|
+
* const executor: DispatchExecutorFn = async (ctx) => {
|
|
117
|
+
* const forged = SpooledArtifact.forgeTools(ctx)
|
|
118
|
+
* const merged = ToolRegistry.merge([main, forged])
|
|
119
|
+
* main.bindContext(ctx)
|
|
120
|
+
* const result = await llm.invoke({ tools: merged.all(), ... })
|
|
121
|
+
* ctx.ack()
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @param ctx - The execution context whose `ack` event should trigger pruning.
|
|
126
|
+
* @returns An unsubscribe function — calling it before `ctx.ack()` prevents pruning. Rarely
|
|
127
|
+
* useful outside of tests.
|
|
128
|
+
*
|
|
129
|
+
* @see {@link @nhtio/adk!SpooledArtifact.forgeTools}
|
|
130
|
+
* @see {@link @nhtio/adk!DispatchContext.onAck}
|
|
131
|
+
*/
|
|
132
|
+
bindContext(ctx: DispatchContext): () => void;
|
|
133
|
+
/**
|
|
134
|
+
* Combines multiple {@link ToolRegistry} instances into a fresh registry without mutating any
|
|
135
|
+
* input.
|
|
136
|
+
*
|
|
137
|
+
* @remarks
|
|
138
|
+
* Iteration is left-to-right across `registries` and then in each registry's insertion order.
|
|
139
|
+
* Collisions are resolved by consulting the **incoming** tool's {@link @nhtio/adk!Tool.onCollision} first:
|
|
140
|
+
*
|
|
141
|
+
* - `'replace'` (per-tool): the incoming tool wins, replacing the existing entry.
|
|
142
|
+
* - `'keep'` (per-tool): the existing entry wins; the incoming tool is dropped.
|
|
143
|
+
* - `'throw'` (per-tool, the default): fall back to the merge-level `options.onCollision`.
|
|
144
|
+
*
|
|
145
|
+
* The merge-level `options.onCollision` defaults to `'throw'`, which mirrors {@link register}.
|
|
146
|
+
*
|
|
147
|
+
* The result is a brand-new registry; no input is mutated and no event subscription is
|
|
148
|
+
* propagated. Each `Tool`'s `ephemeral` flag carries through unchanged — the flag lives on the
|
|
149
|
+
* tool, not the registry, so `bindContext(ctx)` on the merged registry will prune the forged
|
|
150
|
+
* tools as expected.
|
|
151
|
+
*
|
|
152
|
+
* @param registries - Registries to merge, in priority order (left-to-right insertion).
|
|
153
|
+
* @param options - Merge-level collision policy. Defaults to `{ onCollision: 'throw' }`.
|
|
154
|
+
* @returns A fresh {@link ToolRegistry} containing the resolved union of all inputs.
|
|
155
|
+
* @throws {@link @nhtio/adk!E_TOOL_ALREADY_REGISTERED} when the resolved collision policy is `'throw'`
|
|
156
|
+
* and a collision occurs.
|
|
157
|
+
*/
|
|
158
|
+
static merge(registries: ToolRegistry[], options?: MergeOptions): ToolRegistry;
|
|
159
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { DateTime } from 'luxon';
|
|
2
|
+
import type { Schema } from '@nhtio/validation';
|
|
3
|
+
/**
|
|
4
|
+
* Plain input object supplied to {@link TurnGate} at construction time.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* `turnId` and `abortSignal` are injected by the runner — callers constructing a gate via
|
|
8
|
+
* `ctx.waitFor()` never supply them directly.
|
|
9
|
+
*
|
|
10
|
+
* `abortSignal` is `AbortSignal` (not `AbortController`) because the gate reacts to turn-level
|
|
11
|
+
* cancellation but cannot trigger it. The gate owns its own internal `AbortController` for
|
|
12
|
+
* `gate.abort()`.
|
|
13
|
+
*/
|
|
14
|
+
export interface RawTurnGate {
|
|
15
|
+
/** Stable unique identifier for this gate. */
|
|
16
|
+
id: string;
|
|
17
|
+
/** The ID of the turn that opened this gate. */
|
|
18
|
+
turnId: string;
|
|
19
|
+
/** Human-readable label describing why this gate was opened (e.g. `'tool_approval'`). */
|
|
20
|
+
reason: string;
|
|
21
|
+
/** Arbitrary data supplied to the gate opener; passed through to `turnGateOpen` listeners. */
|
|
22
|
+
payload: unknown;
|
|
23
|
+
/** Optional validator schema for the resolution value. When present, `resolve()` validates before settling. */
|
|
24
|
+
schema?: Schema;
|
|
25
|
+
/** Optional timeout in milliseconds. When elapsed the gate self-rejects with {@link @nhtio/adk!E_TURN_GATE_TIMEOUT}. */
|
|
26
|
+
timeout?: number;
|
|
27
|
+
/** The turn's abort signal. When fired the gate self-rejects with {@link @nhtio/adk!E_TURN_GATE_ABORTED}. */
|
|
28
|
+
abortSignal?: AbortSignal;
|
|
29
|
+
/** When this gate was created. */
|
|
30
|
+
createdAt: string | number | Date | DateTime;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A cooperative suspension gate that blocks a turn's middleware pipeline until resolved, rejected,
|
|
34
|
+
* aborted, or timed out.
|
|
35
|
+
*
|
|
36
|
+
* @typeParam T - The expected type of the resolution value.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* Created exclusively via `ctx.waitFor()` — middleware never constructs a gate directly.
|
|
40
|
+
* The gate emits `turnGateOpen` on the runner's observability bus at creation time and
|
|
41
|
+
* `turnGateClosed` when it settles.
|
|
42
|
+
*
|
|
43
|
+
* Resolution is validated against an optional schema before the internal promise is settled.
|
|
44
|
+
* A validation failure throws {@link @nhtio/adk!E_INVALID_TURN_GATE_RESOLUTION} **synchronously in the
|
|
45
|
+
* caller's context** — the promise is NOT settled and the gate remains open.
|
|
46
|
+
*/
|
|
47
|
+
export declare class TurnGate<T = unknown> {
|
|
48
|
+
#private;
|
|
49
|
+
/**
|
|
50
|
+
* Validator schema that accepts a {@link RawTurnGate} object.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Reusable fragment for any schema that needs to validate or nest a gate entry.
|
|
54
|
+
*/
|
|
55
|
+
static schema: import("@nhtio/validation").ObjectSchema<RawTurnGate>;
|
|
56
|
+
/**
|
|
57
|
+
* Returns `true` if `value` is a {@link TurnGate} instance.
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.
|
|
61
|
+
*
|
|
62
|
+
* @param value - The value to test.
|
|
63
|
+
* @returns `true` when `value` is a {@link TurnGate} instance.
|
|
64
|
+
*/
|
|
65
|
+
static isTurnGate(value: unknown): value is TurnGate;
|
|
66
|
+
readonly id: string;
|
|
67
|
+
readonly turnId: string;
|
|
68
|
+
readonly reason: string;
|
|
69
|
+
readonly payload: unknown;
|
|
70
|
+
readonly createdAt: DateTime;
|
|
71
|
+
readonly isSettled: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* @param raw - The raw gate input validated against `rawTurnGateSchema`.
|
|
74
|
+
* @throws {@link @nhtio/adk!E_INVALID_INITIAL_TURN_GATE_VALUE} when `raw` does not satisfy the schema.
|
|
75
|
+
*/
|
|
76
|
+
constructor(raw: RawTurnGate);
|
|
77
|
+
/**
|
|
78
|
+
* Resolves the gate with `value`, unblocking the awaiting middleware.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* If a schema was provided at construction, `value` is validated synchronously before the
|
|
82
|
+
* promise is settled. A validation failure throws {@link @nhtio/adk!E_INVALID_TURN_GATE_RESOLUTION}
|
|
83
|
+
* in the caller's context — the promise is NOT settled and the gate remains open.
|
|
84
|
+
*
|
|
85
|
+
* No-ops if the gate is already settled.
|
|
86
|
+
*
|
|
87
|
+
* @param value - The resolution value. Must satisfy the gate's schema when one was provided.
|
|
88
|
+
* @throws {@link @nhtio/adk!E_INVALID_TURN_GATE_RESOLUTION} when `value` fails schema validation.
|
|
89
|
+
*/
|
|
90
|
+
resolve(value: unknown): void;
|
|
91
|
+
/**
|
|
92
|
+
* Rejects the gate with `error`, unblocking the awaiting middleware with a rejection.
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* No-ops if the gate is already settled.
|
|
96
|
+
*
|
|
97
|
+
* @param error - The rejection reason.
|
|
98
|
+
*/
|
|
99
|
+
reject(error: Error): void;
|
|
100
|
+
/**
|
|
101
|
+
* Aborts the gate by firing the internal `AbortController`, which rejects the promise with
|
|
102
|
+
* {@link @nhtio/adk!E_TURN_GATE_ABORTED}.
|
|
103
|
+
*
|
|
104
|
+
* @remarks
|
|
105
|
+
* No-ops if the gate is already settled. Distinct from the turn-level abort signal — this
|
|
106
|
+
* allows callers to cancel a specific gate without aborting the whole turn.
|
|
107
|
+
*/
|
|
108
|
+
abort(): void;
|
|
109
|
+
}
|