@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,345 @@
|
|
|
1
|
+
import { Registry } from "../classes/registry";
|
|
2
|
+
import { Tokenizable } from "../classes/tokenizable";
|
|
3
|
+
import { ToolRegistry } from "../classes/tool_registry";
|
|
4
|
+
import type { Tool } from "../classes/tool";
|
|
5
|
+
import type { Memory } from "../classes/memory";
|
|
6
|
+
import type { Message } from "../classes/message";
|
|
7
|
+
import type { Thought } from "../classes/thought";
|
|
8
|
+
import type { ToolCall } from "../classes/tool_call";
|
|
9
|
+
import type { Retrievable } from "../classes/retrievable";
|
|
10
|
+
import type { DispatchContextHookRegistrations } from "../types/dispatch_context";
|
|
11
|
+
import type { EmitMessageFn, EmitThoughtFn, EmitToolCallFn, EmitToolExecutionStartFn, EmitToolExecutionEndFn, OpenGateFn } from "../types/turn_runner";
|
|
12
|
+
/** Retrieves memories for an LLM execution context. */
|
|
13
|
+
export type DispatchMemoryRetrievalFn = (ctx: DispatchContext) => Memory[] | Promise<Memory[]>;
|
|
14
|
+
/** Retrieves messages for an LLM execution context. */
|
|
15
|
+
export type DispatchMessageRetrievalFn = (ctx: DispatchContext) => Message[] | Promise<Message[]>;
|
|
16
|
+
/** Retrieves thoughts for an LLM execution context. */
|
|
17
|
+
export type DispatchThoughtRetrievalFn = (ctx: DispatchContext) => Thought[] | Promise<Thought[]>;
|
|
18
|
+
/** Retrieves tool calls for an LLM execution context. */
|
|
19
|
+
export type DispatchToolCallRetrievalFn = (ctx: DispatchContext) => ToolCall[] | Promise<ToolCall[]>;
|
|
20
|
+
/** Retrieves tools for an LLM execution context. */
|
|
21
|
+
export type DispatchToolsRetrievalFn = (ctx: DispatchContext) => Tool[] | Promise<Tool[]>;
|
|
22
|
+
/** Refreshes and returns standing instructions for an LLM execution context. */
|
|
23
|
+
export type DispatchStandingInstructionsRefreshFn = (ctx: DispatchContext) => (string | Tokenizable)[] | Promise<(string | Tokenizable)[]>;
|
|
24
|
+
/** Stores a new standing instruction (LLM execution context variant). */
|
|
25
|
+
export type DispatchStandingInstructionStoreFn = (ctx: DispatchContext, v: string | Tokenizable) => void | Promise<void>;
|
|
26
|
+
/** Updates an existing standing instruction (LLM execution context variant). */
|
|
27
|
+
export type DispatchStandingInstructionMutateFn = (ctx: DispatchContext, v: string | Tokenizable) => void | Promise<void>;
|
|
28
|
+
/** Removes a standing instruction (LLM execution context variant). */
|
|
29
|
+
export type DispatchStandingInstructionDeleteFn = (ctx: DispatchContext, v: string | Tokenizable) => void | Promise<void>;
|
|
30
|
+
/** Stores a new memory (LLM execution context variant). */
|
|
31
|
+
export type DispatchMemoryStoreFn = (ctx: DispatchContext, v: Memory) => void | Promise<void>;
|
|
32
|
+
/** Updates an existing memory (LLM execution context variant). */
|
|
33
|
+
export type DispatchMemoryMutateFn = (ctx: DispatchContext, v: Memory) => void | Promise<void>;
|
|
34
|
+
/** Removes a memory by ID (LLM execution context variant). */
|
|
35
|
+
export type DispatchMemoryDeleteFn = (ctx: DispatchContext, id: string) => void | Promise<void>;
|
|
36
|
+
/** Retrieves retrievable records for an LLM execution context. */
|
|
37
|
+
export type DispatchRetrievableRetrievalFn = (ctx: DispatchContext) => Retrievable[] | Promise<Retrievable[]>;
|
|
38
|
+
/** Stores a new retrievable record (LLM execution context variant). */
|
|
39
|
+
export type DispatchRetrievableStoreFn = (ctx: DispatchContext, v: Retrievable) => void | Promise<void>;
|
|
40
|
+
/** Updates an existing retrievable record (LLM execution context variant). */
|
|
41
|
+
export type DispatchRetrievableMutateFn = (ctx: DispatchContext, v: Retrievable) => void | Promise<void>;
|
|
42
|
+
/** Removes a retrievable record by ID (LLM execution context variant). */
|
|
43
|
+
export type DispatchRetrievableDeleteFn = (ctx: DispatchContext, id: string) => void | Promise<void>;
|
|
44
|
+
/** Stores a new message (LLM execution context variant). */
|
|
45
|
+
export type DispatchMessageStoreFn = (ctx: DispatchContext, v: Message) => void | Promise<void>;
|
|
46
|
+
/** Updates an existing message (LLM execution context variant). */
|
|
47
|
+
export type DispatchMessageMutateFn = (ctx: DispatchContext, v: Message) => void | Promise<void>;
|
|
48
|
+
/** Removes a message by ID (LLM execution context variant). */
|
|
49
|
+
export type DispatchMessageDeleteFn = (ctx: DispatchContext, id: string) => void | Promise<void>;
|
|
50
|
+
/** Stores a new thought (LLM execution context variant). */
|
|
51
|
+
export type DispatchThoughtStoreFn = (ctx: DispatchContext, v: Thought) => void | Promise<void>;
|
|
52
|
+
/** Updates an existing thought (LLM execution context variant). */
|
|
53
|
+
export type DispatchThoughtMutateFn = (ctx: DispatchContext, v: Thought) => void | Promise<void>;
|
|
54
|
+
/** Removes a thought by ID (LLM execution context variant). */
|
|
55
|
+
export type DispatchThoughtDeleteFn = (ctx: DispatchContext, id: string) => void | Promise<void>;
|
|
56
|
+
/** Stores a new tool call (LLM execution context variant). */
|
|
57
|
+
export type DispatchToolCallStoreFn = (ctx: DispatchContext, v: ToolCall) => void | Promise<void>;
|
|
58
|
+
/** Updates an existing tool call (LLM execution context variant). */
|
|
59
|
+
export type DispatchToolCallMutateFn = (ctx: DispatchContext, v: ToolCall) => void | Promise<void>;
|
|
60
|
+
/** Removes a tool call by ID (LLM execution context variant). */
|
|
61
|
+
export type DispatchToolCallDeleteFn = (ctx: DispatchContext, id: string) => void | Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Plain input object supplied to {@link DispatchContext} at construction time.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* All fetch and mutation callbacks are required — every execution context must have a persistence
|
|
67
|
+
* layer wired up, even in standalone mode. Optional pre-fetched arrays populate the context's Sets
|
|
68
|
+
* at construction time without replacing the callbacks (the callbacks are still invoked on
|
|
69
|
+
* subsequent fetch calls).
|
|
70
|
+
*/
|
|
71
|
+
export interface RawDispatchContext {
|
|
72
|
+
/** `AbortController` whose signal can cancel execution mid-flight. */
|
|
73
|
+
turnAbortController?: AbortController;
|
|
74
|
+
/** Arbitrary key-value store for cross-step state. */
|
|
75
|
+
stash?: Record<string, unknown>;
|
|
76
|
+
/** The system prompt for this execution. */
|
|
77
|
+
systemPrompt: string | Tokenizable;
|
|
78
|
+
/** Standing instructions for this execution. */
|
|
79
|
+
standingInstructions?: (string | Tokenizable)[];
|
|
80
|
+
/** Pre-fetched memories to populate the context at construction. */
|
|
81
|
+
memories?: Memory[];
|
|
82
|
+
/** Pre-fetched retrievable records to populate the context at construction. */
|
|
83
|
+
retrievables?: Retrievable[];
|
|
84
|
+
/** Pre-fetched messages to populate the context at construction. */
|
|
85
|
+
messages?: Message[];
|
|
86
|
+
/** Pre-fetched thoughts to populate the context at construction. */
|
|
87
|
+
thoughts?: Thought[];
|
|
88
|
+
/** Pre-fetched tool calls to populate the context at construction. */
|
|
89
|
+
toolCalls?: ToolCall[];
|
|
90
|
+
/** Pre-fetched tools to populate the tool registry at construction. */
|
|
91
|
+
tools?: Tool[];
|
|
92
|
+
/** Retrieves memories for this execution. */
|
|
93
|
+
fetchMemories: DispatchMemoryRetrievalFn;
|
|
94
|
+
/** Retrieves retrievable records for this execution. */
|
|
95
|
+
fetchRetrievables: DispatchRetrievableRetrievalFn;
|
|
96
|
+
/** Retrieves messages for this execution. */
|
|
97
|
+
fetchMessages: DispatchMessageRetrievalFn;
|
|
98
|
+
/** Retrieves thoughts for this execution. */
|
|
99
|
+
fetchThoughts: DispatchThoughtRetrievalFn;
|
|
100
|
+
/** Retrieves tool calls for this execution. */
|
|
101
|
+
fetchToolCalls: DispatchToolCallRetrievalFn;
|
|
102
|
+
/** Retrieves tools for this execution. */
|
|
103
|
+
fetchTools: DispatchToolsRetrievalFn;
|
|
104
|
+
/** Refreshes and returns standing instructions for this execution. */
|
|
105
|
+
refreshStandingInstructions: DispatchStandingInstructionsRefreshFn;
|
|
106
|
+
/** Stores a new standing instruction. */
|
|
107
|
+
storeStandingInstruction: DispatchStandingInstructionStoreFn;
|
|
108
|
+
/** Updates an existing standing instruction. */
|
|
109
|
+
mutateStandingInstruction: DispatchStandingInstructionMutateFn;
|
|
110
|
+
/** Removes a standing instruction. */
|
|
111
|
+
deleteStandingInstruction: DispatchStandingInstructionDeleteFn;
|
|
112
|
+
/** Stores a new memory. */
|
|
113
|
+
storeMemory: DispatchMemoryStoreFn;
|
|
114
|
+
/** Updates an existing memory. */
|
|
115
|
+
mutateMemory: DispatchMemoryMutateFn;
|
|
116
|
+
/** Removes a memory by ID. */
|
|
117
|
+
deleteMemory: DispatchMemoryDeleteFn;
|
|
118
|
+
/** Stores a new retrievable record. */
|
|
119
|
+
storeRetrievable: DispatchRetrievableStoreFn;
|
|
120
|
+
/** Updates an existing retrievable record. */
|
|
121
|
+
mutateRetrievable: DispatchRetrievableMutateFn;
|
|
122
|
+
/** Removes a retrievable record by ID. */
|
|
123
|
+
deleteRetrievable: DispatchRetrievableDeleteFn;
|
|
124
|
+
/** Stores a new message. */
|
|
125
|
+
storeMessage: DispatchMessageStoreFn;
|
|
126
|
+
/** Updates an existing message. */
|
|
127
|
+
mutateMessage: DispatchMessageMutateFn;
|
|
128
|
+
/** Removes a message by ID. */
|
|
129
|
+
deleteMessage: DispatchMessageDeleteFn;
|
|
130
|
+
/** Stores a new thought. */
|
|
131
|
+
storeThought: DispatchThoughtStoreFn;
|
|
132
|
+
/** Updates an existing thought. */
|
|
133
|
+
mutateThought: DispatchThoughtMutateFn;
|
|
134
|
+
/** Removes a thought by ID. */
|
|
135
|
+
deleteThought: DispatchThoughtDeleteFn;
|
|
136
|
+
/** Stores a new tool call. */
|
|
137
|
+
storeToolCall: DispatchToolCallStoreFn;
|
|
138
|
+
/** Updates an existing tool call. */
|
|
139
|
+
mutateToolCall: DispatchToolCallMutateFn;
|
|
140
|
+
/** Removes a tool call by ID. */
|
|
141
|
+
deleteToolCall: DispatchToolCallDeleteFn;
|
|
142
|
+
/** Optional hook registrations for emit events. */
|
|
143
|
+
hooks?: DispatchContextHookRegistrations;
|
|
144
|
+
/** Optional gate suspension function. When absent, `waitFor` rejects with {@link @nhtio/adk!E_LLM_EXECUTION_GATE_NOT_SUPPORTED}. */
|
|
145
|
+
waitFor?: OpenGateFn;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Context object for a single LLM execution call.
|
|
149
|
+
*
|
|
150
|
+
* @remarks
|
|
151
|
+
* Mirrors the surface of {@link @nhtio/adk!TurnContext} but is path-agnostic — it knows nothing about a
|
|
152
|
+
* parent context. Mutations apply to local Sets immediately, call persistence callbacks
|
|
153
|
+
* immediately, and fire the corresponding mutation hook (`storedMemory`, `mutatedMemory`,
|
|
154
|
+
* `deletedMemory`, etc.) in both standalone and derived dispatches.
|
|
155
|
+
*
|
|
156
|
+
* The {@link @nhtio/adk!DispatchRunner} is the only thing that creates a context with a parent
|
|
157
|
+
* relationship: when dispatched with a `source: TurnContext`, the runner subscribes to the
|
|
158
|
+
* mutation hooks, queues deltas internally, and flushes them to the parent's Sets at the end of
|
|
159
|
+
* each iteration. The context itself remains unaware of the parent.
|
|
160
|
+
*
|
|
161
|
+
* Middleware/executor signals termination via {@link DispatchContext.ack} (clean completion)
|
|
162
|
+
* or {@link DispatchContext.nack} (failure). Both set an internal flag the runner reads at
|
|
163
|
+
* end-of-iteration to decide whether to loop or exit. {@link DispatchContext.isSignalled},
|
|
164
|
+
* {@link DispatchContext.isAcked}, and {@link DispatchContext.nackError} are publicly
|
|
165
|
+
* readable getters so middleware can inspect signal state and bail early.
|
|
166
|
+
*/
|
|
167
|
+
export declare class DispatchContext {
|
|
168
|
+
#private;
|
|
169
|
+
/**
|
|
170
|
+
* @param raw - Raw input validated against the schema.
|
|
171
|
+
* @throws {@link @nhtio/adk!E_INVALID_LLM_EXECUTION_CONTEXT} when `raw` does not satisfy the schema.
|
|
172
|
+
*/
|
|
173
|
+
constructor(raw: RawDispatchContext);
|
|
174
|
+
/**
|
|
175
|
+
* Returns how many times a tool call with the given checksum has been stored in this execution.
|
|
176
|
+
*
|
|
177
|
+
* @remarks
|
|
178
|
+
* Checksums are computed over `tool + args` (see {@link @nhtio/adk!ToolCall.checksum}). This count lets
|
|
179
|
+
* the executor detect repeat invocations of the same call without scanning the full Set.
|
|
180
|
+
* Returns `0` when the checksum has not been seen.
|
|
181
|
+
*
|
|
182
|
+
* @param checksum - The `ToolCall.checksum` value to look up.
|
|
183
|
+
*/
|
|
184
|
+
toolCallCount(checksum: string): number;
|
|
185
|
+
/**
|
|
186
|
+
* Signals successful completion of this execution.
|
|
187
|
+
*
|
|
188
|
+
* @remarks
|
|
189
|
+
* Sets the context's internal signal flag. The {@link @nhtio/adk!DispatchRunner} reads the flag at the
|
|
190
|
+
* end of each iteration to decide whether to loop or exit. Calling `ack()` does NOT abort the
|
|
191
|
+
* current iteration — the current pipeline and flush complete first.
|
|
192
|
+
*
|
|
193
|
+
* @throws {@link @nhtio/adk!E_LLM_EXECUTION_ALREADY_SIGNALLED} when the context has already been signalled
|
|
194
|
+
* (whether via `ack()` or `nack()`).
|
|
195
|
+
*/
|
|
196
|
+
ack(): void;
|
|
197
|
+
/**
|
|
198
|
+
* Registers a handler to run when this context completes successfully via {@link ack}.
|
|
199
|
+
*
|
|
200
|
+
* @remarks
|
|
201
|
+
* The handler does NOT fire on {@link nack} — failed executor runs should leave any
|
|
202
|
+
* ack-tied subscriptions alone so the consumer can inspect what was registered when
|
|
203
|
+
* debugging the failure. Returns an unsubscribe function; subscriptions are short-lived
|
|
204
|
+
* and die with the context regardless.
|
|
205
|
+
*
|
|
206
|
+
* The canonical consumer is `ToolRegistry.bindContext(ctx)`, which uses this hook to drop
|
|
207
|
+
* ephemeral tools (notably forged artifact-query tools from `SpooledArtifact.forgeTools(ctx)`)
|
|
208
|
+
* at ctx-completion. Consumers may also register custom handlers here for any per-executor
|
|
209
|
+
* cleanup.
|
|
210
|
+
*
|
|
211
|
+
* @param handler - Callback invoked when `ack()` is called.
|
|
212
|
+
* @returns An unsubscribe function that removes the handler.
|
|
213
|
+
*
|
|
214
|
+
* @see {@link @nhtio/adk!ToolRegistry.bindContext}
|
|
215
|
+
* @see {@link @nhtio/adk!SpooledArtifact.forgeTools}
|
|
216
|
+
*/
|
|
217
|
+
onAck(handler: () => void): () => void;
|
|
218
|
+
/**
|
|
219
|
+
* Signals failed completion of this execution, optionally with an error.
|
|
220
|
+
*
|
|
221
|
+
* @remarks
|
|
222
|
+
* Sets the context's internal signal flag and stores the error. The {@link @nhtio/adk!DispatchRunner}
|
|
223
|
+
* reads the flag at the end of each iteration and surfaces the error via the `dispatchEnd`
|
|
224
|
+
* observability payload and as the rejection reason of `dispatch()`. Calling `nack()` does NOT
|
|
225
|
+
* abort the current iteration — the current pipeline and flush complete first.
|
|
226
|
+
*
|
|
227
|
+
* @param error - Optional error describing the failure. If omitted, a generic Error is used.
|
|
228
|
+
* @throws {@link @nhtio/adk!E_LLM_EXECUTION_ALREADY_SIGNALLED} when the context has already been signalled.
|
|
229
|
+
*/
|
|
230
|
+
nack(error?: Error): void;
|
|
231
|
+
/**
|
|
232
|
+
* Returns `true` if `value` is a {@link DispatchContext} instance.
|
|
233
|
+
*
|
|
234
|
+
* @remarks
|
|
235
|
+
* Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety. The ADK does not export the
|
|
236
|
+
* `DispatchContext` class itself as a constructable value — use this guard plus the
|
|
237
|
+
* {@link DispatchContext} type for runtime detection and TypeScript narrowing.
|
|
238
|
+
*
|
|
239
|
+
* @param value - The value to test.
|
|
240
|
+
* @returns `true` when `value` is a {@link DispatchContext} instance.
|
|
241
|
+
*/
|
|
242
|
+
static isDispatchContext(value: unknown): value is DispatchContext;
|
|
243
|
+
/** Unique identifier for this execution context, generated as UUIDv6 at construction time. */
|
|
244
|
+
readonly id: string;
|
|
245
|
+
/** Stable identifier for the dispatch this context belongs to; set by `DispatchRunner`. */
|
|
246
|
+
readonly dispatchId: string;
|
|
247
|
+
/** 0-based iteration count within the current dispatch; updated by `DispatchRunner`. */
|
|
248
|
+
readonly iteration: number;
|
|
249
|
+
/** `true` when the abort controller signal has fired. */
|
|
250
|
+
readonly aborted: boolean;
|
|
251
|
+
/** The `AbortSignal` from the execution's `AbortController`. */
|
|
252
|
+
readonly abortSignal: AbortSignal;
|
|
253
|
+
/**
|
|
254
|
+
* Aborts the dispatch's `AbortController` with the supplied reason. Middleware should call this
|
|
255
|
+
* when refusing to proceed — the runner short-circuits cleanly, `dispatchEnd.status` resolves
|
|
256
|
+
* to `'aborted'`, and no `error` event is emitted.
|
|
257
|
+
*/
|
|
258
|
+
readonly abort: (reason?: unknown) => void;
|
|
259
|
+
/** `true` once {@link DispatchContext.ack} or {@link DispatchContext.nack} has been called. */
|
|
260
|
+
readonly isSignalled: boolean;
|
|
261
|
+
/** `true` when the context was signalled via {@link DispatchContext.ack}. */
|
|
262
|
+
readonly isAcked: boolean;
|
|
263
|
+
/** The error stored by {@link DispatchContext.nack}, or `undefined` if not nacked. */
|
|
264
|
+
readonly nackError: Error | undefined;
|
|
265
|
+
/** Arbitrary key-value store for cross-step state. */
|
|
266
|
+
readonly stash: Registry;
|
|
267
|
+
/** The system prompt for this execution. */
|
|
268
|
+
readonly systemPrompt: Tokenizable;
|
|
269
|
+
/** Standing instructions for this execution, in insertion order. */
|
|
270
|
+
readonly standingInstructions: Set<Tokenizable>;
|
|
271
|
+
/** Memories loaded for this execution. */
|
|
272
|
+
readonly turnMemories: Set<Memory>;
|
|
273
|
+
/** Retrievable records loaded for this execution. */
|
|
274
|
+
readonly turnRetrievables: Set<Retrievable>;
|
|
275
|
+
/** Messages loaded for this execution. */
|
|
276
|
+
readonly turnMessages: Set<Message>;
|
|
277
|
+
/** Thoughts loaded for this execution. */
|
|
278
|
+
readonly turnThoughts: Set<Thought>;
|
|
279
|
+
/** Tool calls loaded for this execution. */
|
|
280
|
+
readonly turnToolCalls: Set<ToolCall>;
|
|
281
|
+
/** Tool registry for this execution. */
|
|
282
|
+
readonly tools: ToolRegistry;
|
|
283
|
+
/** Fetches memories; delegates to the callback supplied at construction. */
|
|
284
|
+
readonly fetchMemories: () => Memory[] | Promise<Memory[]>;
|
|
285
|
+
/** Fetches retrievable records; delegates to the callback supplied at construction. */
|
|
286
|
+
readonly fetchRetrievables: () => Retrievable[] | Promise<Retrievable[]>;
|
|
287
|
+
/** Fetches messages; delegates to the callback supplied at construction. */
|
|
288
|
+
readonly fetchMessages: () => Message[] | Promise<Message[]>;
|
|
289
|
+
/** Fetches thoughts; delegates to the callback supplied at construction. */
|
|
290
|
+
readonly fetchThoughts: () => Thought[] | Promise<Thought[]>;
|
|
291
|
+
/** Fetches tool calls; delegates to the callback supplied at construction. */
|
|
292
|
+
readonly fetchToolCalls: () => ToolCall[] | Promise<ToolCall[]>;
|
|
293
|
+
/** Fetches tools; delegates to the callback supplied at construction. */
|
|
294
|
+
readonly fetchTools: () => Tool[] | Promise<Tool[]>;
|
|
295
|
+
/** Refreshes and returns standing instructions. */
|
|
296
|
+
readonly refreshStandingInstructions: () => (string | Tokenizable)[] | Promise<(string | Tokenizable)[]>;
|
|
297
|
+
/** Stores a new standing instruction in the local Set and persistence layer. */
|
|
298
|
+
readonly storeStandingInstruction: (v: string | Tokenizable) => Promise<void>;
|
|
299
|
+
/** Updates an existing standing instruction in the local Set and persistence layer. */
|
|
300
|
+
readonly mutateStandingInstruction: (v: string | Tokenizable) => Promise<void>;
|
|
301
|
+
/** Removes a standing instruction from the local Set and persistence layer. */
|
|
302
|
+
readonly deleteStandingInstruction: (v: string | Tokenizable) => Promise<void>;
|
|
303
|
+
/** Stores a new memory in the local Set and persistence layer. */
|
|
304
|
+
readonly storeMemory: (v: Memory) => Promise<void>;
|
|
305
|
+
/** Updates an existing memory in the local Set and persistence layer. */
|
|
306
|
+
readonly mutateMemory: (v: Memory) => Promise<void>;
|
|
307
|
+
/** Removes a memory from the local Set and persistence layer by ID. */
|
|
308
|
+
readonly deleteMemory: (id: string) => Promise<void>;
|
|
309
|
+
/** Stores a new retrievable record in the local Set and persistence layer. */
|
|
310
|
+
readonly storeRetrievable: (v: Retrievable) => Promise<void>;
|
|
311
|
+
/** Updates an existing retrievable record in the local Set and persistence layer. */
|
|
312
|
+
readonly mutateRetrievable: (v: Retrievable) => Promise<void>;
|
|
313
|
+
/** Removes a retrievable record from the local Set and persistence layer by ID. */
|
|
314
|
+
readonly deleteRetrievable: (id: string) => Promise<void>;
|
|
315
|
+
/** Stores a new message in the local Set and persistence layer. */
|
|
316
|
+
readonly storeMessage: (v: Message) => Promise<void>;
|
|
317
|
+
/** Updates an existing message in the local Set and persistence layer. */
|
|
318
|
+
readonly mutateMessage: (v: Message) => Promise<void>;
|
|
319
|
+
/** Removes a message from the local Set and persistence layer by ID. */
|
|
320
|
+
readonly deleteMessage: (id: string) => Promise<void>;
|
|
321
|
+
/** Stores a new thought in the local Set and persistence layer. */
|
|
322
|
+
readonly storeThought: (v: Thought) => Promise<void>;
|
|
323
|
+
/** Updates an existing thought in the local Set and persistence layer. */
|
|
324
|
+
readonly mutateThought: (v: Thought) => Promise<void>;
|
|
325
|
+
/** Removes a thought from the local Set and persistence layer by ID. */
|
|
326
|
+
readonly deleteThought: (id: string) => Promise<void>;
|
|
327
|
+
/** Stores a new tool call in the local Set and persistence layer. */
|
|
328
|
+
readonly storeToolCall: (v: ToolCall) => Promise<void>;
|
|
329
|
+
/** Updates an existing tool call in the local Set and persistence layer. */
|
|
330
|
+
readonly mutateToolCall: (v: ToolCall) => Promise<void>;
|
|
331
|
+
/** Removes a tool call from the local Set and persistence layer by ID. */
|
|
332
|
+
readonly deleteToolCall: (id: string) => Promise<void>;
|
|
333
|
+
/** Emits a `message` hook; fires registered handlers synchronously. */
|
|
334
|
+
readonly emitMessage: EmitMessageFn;
|
|
335
|
+
/** Emits a `thought` hook; fires registered handlers synchronously. */
|
|
336
|
+
readonly emitThought: EmitThoughtFn;
|
|
337
|
+
/** Emits a `toolCall` hook; fires registered handlers synchronously. */
|
|
338
|
+
readonly emitToolCall: EmitToolCallFn;
|
|
339
|
+
/** Emits a `toolExecutionStart` hook; fires registered handlers synchronously. */
|
|
340
|
+
readonly emitToolExecutionStart: EmitToolExecutionStartFn;
|
|
341
|
+
/** Emits a `toolExecutionEnd` hook; fires registered handlers synchronously. */
|
|
342
|
+
readonly emitToolExecutionEnd: EmitToolExecutionEndFn;
|
|
343
|
+
/** Opens a gate and suspends until it resolves, rejects, times out, or is aborted. */
|
|
344
|
+
readonly waitFor: OpenGateFn;
|
|
345
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-openable byte source contract for a Media instance.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Peer to {@link @nhtio/adk!SpoolReader} but tuned for binary streaming rather than line-indexed text.
|
|
6
|
+
* Each `stream()` call must return a fresh, drainable `ReadableStream` over the same underlying
|
|
7
|
+
* bytes — implementations model replay: in-memory readers reconstitute the stream from the
|
|
8
|
+
* buffer, file-backed readers reopen the file handle, HTTP-backed readers re-issue the fetch,
|
|
9
|
+
* cloud blob readers re-issue the GET. The implementor owns the storage and the cost of keeping
|
|
10
|
+
* the underlying source addressable. Implementors whose underlying source is genuinely
|
|
11
|
+
* non-replayable (a raw HTTP body they were handed once) are responsible for caching locally
|
|
12
|
+
* before constructing the Media.
|
|
13
|
+
*
|
|
14
|
+
* Both methods may be synchronous or asynchronous to accommodate both in-memory and I/O-backed
|
|
15
|
+
* implementations without forcing unnecessary promise overhead on simple cases.
|
|
16
|
+
*/
|
|
17
|
+
export interface MediaReader {
|
|
18
|
+
/**
|
|
19
|
+
* Re-opens the underlying byte source and returns a fresh ReadableStream.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Each call yields a new, drainable stream over the same bytes. Render code that needs the
|
|
23
|
+
* full buffer (e.g. base64-encoding an inline image_url) drains the stream; render code that
|
|
24
|
+
* can forward the stream (e.g. multipart upload) passes the stream through without buffering.
|
|
25
|
+
*
|
|
26
|
+
* @returns A drainable ReadableStream of Uint8Array chunks over the underlying bytes.
|
|
27
|
+
*/
|
|
28
|
+
stream(): ReadableStream<Uint8Array> | Promise<ReadableStream<Uint8Array>>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the total number of bytes in the underlying data, or `undefined` if unknown.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Used for telemetry, budget checks, and pre-flight provider size validation without forcing
|
|
34
|
+
* a stream drain. Sources of unknown length may return `undefined` — absence is treated as
|
|
35
|
+
* "unknown", not "zero".
|
|
36
|
+
*
|
|
37
|
+
* @returns The byte length of the underlying data, or `undefined` when unknown.
|
|
38
|
+
*/
|
|
39
|
+
byteLength(): number | undefined | Promise<number | undefined>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Validator schema used to validate a MediaReader value.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Because MediaReader is a structural interface with no associated constructor, validation is
|
|
46
|
+
* duck-typed: the value must be an object, class instance, or function with `stream` and
|
|
47
|
+
* `byteLength` present as callable properties. Arity is not enforced.
|
|
48
|
+
*/
|
|
49
|
+
export declare const mediaReaderSchema: import("@nhtio/validation").AnySchema<any>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns `true` if `value` implements the MediaReader interface.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Duck-typed: checks that `value` is non-null with `stream` and `byteLength` as callable
|
|
55
|
+
* functions. Does not use `instanceof` — there is no MediaReader constructor.
|
|
56
|
+
*
|
|
57
|
+
* @param value - The value to test.
|
|
58
|
+
* @returns `true` when `value` conforms to the MediaReader interface.
|
|
59
|
+
*/
|
|
60
|
+
export declare const implementsMediaReader: (value: unknown) => value is MediaReader;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backing store contract for a {@link @nhtio/adk!SpooledArtifact}.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Implementations may read from memory, a file handle, a network stream, or any other byte
|
|
6
|
+
* source. The interface is intentionally minimal — the artifact layer handles all higher-level
|
|
7
|
+
* operations (`head`, `tail`, `grep`, etc.) by composing calls to these three primitives.
|
|
8
|
+
*
|
|
9
|
+
* Line indexing is 0-based. Implementations must return `undefined` from {@link SpoolReader.line}
|
|
10
|
+
* when the index is out of range rather than throwing.
|
|
11
|
+
*
|
|
12
|
+
* All three methods may be synchronous or asynchronous to accommodate both in-memory and I/O-
|
|
13
|
+
* backed implementations without forcing unnecessary promise overhead on simple cases.
|
|
14
|
+
*/
|
|
15
|
+
export interface SpoolReader {
|
|
16
|
+
/**
|
|
17
|
+
* Returns the line at the given 0-based index, or `undefined` when out of range.
|
|
18
|
+
*
|
|
19
|
+
* @param index - 0-based line index.
|
|
20
|
+
* @returns The raw line string (without trailing newline), or `undefined`.
|
|
21
|
+
*/
|
|
22
|
+
line(index: number): string | undefined | Promise<string | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the total number of bytes in the underlying data.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* Used for reporting and token-estimation purposes. Byte length is distinct from character
|
|
28
|
+
* length for multi-byte encodings.
|
|
29
|
+
*
|
|
30
|
+
* @returns The byte length of the underlying data.
|
|
31
|
+
*/
|
|
32
|
+
byteLength(): number | Promise<number>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the total number of lines in the underlying data.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* Required so consumers know when to stop iterating; the line count must remain stable for the
|
|
38
|
+
* lifetime of the reader.
|
|
39
|
+
*
|
|
40
|
+
* @returns The total line count.
|
|
41
|
+
*/
|
|
42
|
+
lineCount(): number | Promise<number>;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the full underlying content as a single decoded string, byte-faithful to the source.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* Unlike {@link SpoolReader.line}, this method preserves trailing newlines and any non-`\n`
|
|
48
|
+
* line terminators (e.g. `\r\n`) present in the original bytes. It is the primitive that
|
|
49
|
+
* powers `SpooledArtifact.asString()` — the round-trip-faithful alternative to assembling
|
|
50
|
+
* the artifact body from per-line reads.
|
|
51
|
+
*
|
|
52
|
+
* Implementations should make this O(n) in the size of the underlying data and may cache the
|
|
53
|
+
* result if the read source is durable. Streaming implementations may choose not to cache.
|
|
54
|
+
*
|
|
55
|
+
* @returns The full underlying content as a single string.
|
|
56
|
+
*/
|
|
57
|
+
readAll(): string | Promise<string>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Validator schema used to validate a {@link SpoolReader} value.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* Because `SpoolReader` is a structural interface with no associated constructor, validation is
|
|
64
|
+
* duck-typed: the value must be an object, class instance, or function with `line`, `byteLength`,
|
|
65
|
+
* and `lineCount` present as callable properties. Arity is not enforced — implementations may add
|
|
66
|
+
* optional parameters beyond the contract.
|
|
67
|
+
*/
|
|
68
|
+
export declare const spoolReaderSchema: import("@nhtio/validation").AnySchema<any>;
|
|
69
|
+
/**
|
|
70
|
+
* Returns `true` if `value` implements the {@link SpoolReader} interface.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* Duck-typed: checks that `value` is non-null with `line`, `byteLength`, `lineCount`, and
|
|
74
|
+
* `readAll` as callable functions. Does not use `instanceof` — there is no `SpoolReader`
|
|
75
|
+
* constructor.
|
|
76
|
+
*
|
|
77
|
+
* @param value - The value to test.
|
|
78
|
+
* @returns `true` when `value` conforms to the {@link SpoolReader} interface.
|
|
79
|
+
*/
|
|
80
|
+
export declare const implementsSpoolReader: (value: unknown) => value is SpoolReader;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { SpooledArtifact } from "../classes/spooled_artifact";
|
|
2
|
+
/**
|
|
3
|
+
* Constructor signature for any {@link @nhtio/adk!SpooledArtifact} (the class itself or a subclass).
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Re-declared here at the contract level so consumers — and the `Tool.artifactConstructor`
|
|
7
|
+
* resolver validator in particular — can talk about the constructor shape without value-importing
|
|
8
|
+
* the {@link @nhtio/adk!SpooledArtifact} class (which would close the `tool.ts` ↔ `spooled_artifact.ts` ↔
|
|
9
|
+
* `artifact_tool.ts` module cycle at load time and TDZ-crash `ArtifactTool extends Tool`).
|
|
10
|
+
*
|
|
11
|
+
* @typeParam A - The {@link @nhtio/adk!SpooledArtifact} subtype the constructor produces.
|
|
12
|
+
*/
|
|
13
|
+
export type SpooledArtifactConstructorLike<A extends SpooledArtifact = SpooledArtifact> = new (...args: any[]) => A;
|
|
14
|
+
/**
|
|
15
|
+
* Validator schema used to validate a {@link SpooledArtifactConstructorLike} value.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Because the validator is invoked at validate-time (not at module-load), it is safe to inspect
|
|
19
|
+
* the constructor's prototype here. The check is duck-typed: the value must be a function whose
|
|
20
|
+
* `prototype` carries every canonical artifact instance method (`head`, `tail`, `grep`, `cat`,
|
|
21
|
+
* `byteLength`, `lineCount`, `estimateTokens`). This mirrors {@link spoolReaderSchema}'s
|
|
22
|
+
* cross-realm-safe duck-type pattern — `instanceof SpooledArtifact` would be tighter but would
|
|
23
|
+
* force a value-import of the class and reopen the module cycle.
|
|
24
|
+
*/
|
|
25
|
+
export declare const spooledArtifactConstructorSchema: import("@nhtio/validation").AnySchema<any>;
|
|
26
|
+
/**
|
|
27
|
+
* Returns `true` if `value` is a constructor whose prototype carries every canonical
|
|
28
|
+
* {@link @nhtio/adk!SpooledArtifact} instance method.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* Duck-typed; does not use `instanceof SpooledArtifact`. Used by the `Tool.artifactConstructor`
|
|
32
|
+
* resolver validator and any other site that needs to recognise a `SpooledArtifact`-like
|
|
33
|
+
* constructor without pulling the class into its module-load graph.
|
|
34
|
+
*
|
|
35
|
+
* @param value - The value to test.
|
|
36
|
+
* @returns `true` when `value` is a `SpooledArtifact`-shaped constructor.
|
|
37
|
+
*/
|
|
38
|
+
export declare const implementsSpooledArtifactConstructor: (value: unknown) => value is SpooledArtifactConstructorLike;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Tool } from "../classes/tool";
|
|
2
|
+
import type { TurnPipelineMiddlewareFn } from "../types/turn_runner";
|
|
3
|
+
import type { DispatchPipelineMiddlewareFn, DispatchExecutorFn } from "../types/dispatch_runner";
|
|
4
|
+
import type { MemoryRetrievalFn, MessageRetrievalFn, ThoughtRetrievalFn, ToolCallRetrievalFn, ToolsRetrievalFn, StandingInstructionsRefreshFn, StandingInstructionStoreFn, StandingInstructionMutateFn, StandingInstructionDeleteFn, MemoryStoreFn, MemoryMutateFn, MemoryDeleteFn, RetrievableRetrievalFn, RetrievableStoreFn, RetrievableMutateFn, RetrievableDeleteFn, MessageStoreFn, MessageMutateFn, MessageDeleteFn, ThoughtStoreFn, ThoughtMutateFn, ThoughtDeleteFn, ToolCallStoreFn, ToolCallMutateFn, ToolCallDeleteFn } from "./turn_runner_context";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration supplied to {@link @nhtio/adk!TurnRunner} at construction time.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Validated against `turnRunnerConfigSchema` at construction — a misconfigured runner throws
|
|
10
|
+
* immediately rather than failing on the first turn.
|
|
11
|
+
*
|
|
12
|
+
* All fetch and mutation callbacks are required: they are injected into each {@link @nhtio/adk!TurnContext}
|
|
13
|
+
* so middleware can call fetch, refresh, and persistence methods directly on the context without
|
|
14
|
+
* coupling to the runner.
|
|
15
|
+
*
|
|
16
|
+
* `tools` is optional at the caller level and defaults to `[]` after schema resolution — a runner
|
|
17
|
+
* with no baseline tools is valid.
|
|
18
|
+
*/
|
|
19
|
+
export interface TurnRunnerConfig {
|
|
20
|
+
/** Performs the LLM API/SDK call for each iteration of the dispatch loop; receives the active {@link @nhtio/adk!DispatchContext} and an {@link @nhtio/adk!DispatchExecutorHelpers} object for managing per-id stream state. */
|
|
21
|
+
executorCallback: DispatchExecutorFn;
|
|
22
|
+
/** Called once per turn to supply memories; receives the active {@link @nhtio/adk!TurnContext}. */
|
|
23
|
+
fetchMemoriesCallback: MemoryRetrievalFn;
|
|
24
|
+
/** Called once per turn to supply conversation history; receives the active {@link @nhtio/adk!TurnContext}. */
|
|
25
|
+
fetchMessagesCallback: MessageRetrievalFn;
|
|
26
|
+
/** Called once per turn to supply thought traces; receives the active {@link @nhtio/adk!TurnContext}. */
|
|
27
|
+
fetchThoughtsCallback: ThoughtRetrievalFn;
|
|
28
|
+
/** Called once per turn to supply tool call records; receives the active {@link @nhtio/adk!TurnContext}. */
|
|
29
|
+
fetchToolCallsCallback: ToolCallRetrievalFn;
|
|
30
|
+
/** Called to supply available tools; receives the active {@link @nhtio/adk!TurnContext}. */
|
|
31
|
+
fetchToolsCallback: ToolsRetrievalFn;
|
|
32
|
+
/** Called to refresh and return standing instructions; receives the active {@link @nhtio/adk!TurnContext}. */
|
|
33
|
+
refreshStandingInstructionsCallback: StandingInstructionsRefreshFn;
|
|
34
|
+
/** Persists a new standing instruction. */
|
|
35
|
+
storeStandingInstructionCallback: StandingInstructionStoreFn;
|
|
36
|
+
/** Updates an existing standing instruction in the persistence layer. */
|
|
37
|
+
mutateStandingInstructionCallback: StandingInstructionMutateFn;
|
|
38
|
+
/** Removes a standing instruction from the persistence layer. */
|
|
39
|
+
deleteStandingInstructionCallback: StandingInstructionDeleteFn;
|
|
40
|
+
/** Persists a new memory. */
|
|
41
|
+
storeMemoryCallback: MemoryStoreFn;
|
|
42
|
+
/** Updates an existing memory in the persistence layer. */
|
|
43
|
+
mutateMemoryCallback: MemoryMutateFn;
|
|
44
|
+
/** Removes a memory from the persistence layer by ID. */
|
|
45
|
+
deleteMemoryCallback: MemoryDeleteFn;
|
|
46
|
+
/** Called once per turn to supply retrievable (RAG) records; receives the active {@link @nhtio/adk!TurnContext}. */
|
|
47
|
+
fetchRetrievablesCallback: RetrievableRetrievalFn;
|
|
48
|
+
/** Persists a new retrievable record. */
|
|
49
|
+
storeRetrievableCallback: RetrievableStoreFn;
|
|
50
|
+
/** Updates an existing retrievable record in the persistence layer. */
|
|
51
|
+
mutateRetrievableCallback: RetrievableMutateFn;
|
|
52
|
+
/** Removes a retrievable record from the persistence layer by ID. */
|
|
53
|
+
deleteRetrievableCallback: RetrievableDeleteFn;
|
|
54
|
+
/** Persists a new message. */
|
|
55
|
+
storeMessageCallback: MessageStoreFn;
|
|
56
|
+
/** Updates an existing message in the persistence layer. */
|
|
57
|
+
mutateMessageCallback: MessageMutateFn;
|
|
58
|
+
/** Removes a message from the persistence layer by ID. */
|
|
59
|
+
deleteMessageCallback: MessageDeleteFn;
|
|
60
|
+
/** Persists a new thought. */
|
|
61
|
+
storeThoughtCallback: ThoughtStoreFn;
|
|
62
|
+
/** Updates an existing thought in the persistence layer. */
|
|
63
|
+
mutateThoughtCallback: ThoughtMutateFn;
|
|
64
|
+
/** Removes a thought from the persistence layer by ID. */
|
|
65
|
+
deleteThoughtCallback: ThoughtDeleteFn;
|
|
66
|
+
/** Persists a new tool call. */
|
|
67
|
+
storeToolCallCallback: ToolCallStoreFn;
|
|
68
|
+
/** Updates an existing tool call in the persistence layer. */
|
|
69
|
+
mutateToolCallCallback: ToolCallMutateFn;
|
|
70
|
+
/** Removes a tool call from the persistence layer by ID. */
|
|
71
|
+
deleteToolCallCallback: ToolCallDeleteFn;
|
|
72
|
+
/** Baseline tools available on every turn. Middleware may trim or extend this per-turn via `ctx.tools`. Defaults to `[]`. */
|
|
73
|
+
tools?: Tool[];
|
|
74
|
+
/** Turn-level input middleware, executed in order against the {@link @nhtio/adk!TurnContext} before the LLM dispatch. Defaults to `[]`. */
|
|
75
|
+
turnInputPipeline?: TurnPipelineMiddlewareFn[];
|
|
76
|
+
/** Turn-level output middleware, executed in order against the {@link @nhtio/adk!TurnContext} after the LLM dispatch resolves successfully. Defaults to `[]`. */
|
|
77
|
+
turnOutputPipeline?: TurnPipelineMiddlewareFn[];
|
|
78
|
+
/** LLM-iteration input middleware, executed in order against the {@link @nhtio/adk!DispatchContext} before the executor on each iteration. Defaults to `[]`. */
|
|
79
|
+
dispatchInputPipeline?: DispatchPipelineMiddlewareFn[];
|
|
80
|
+
/** LLM-iteration output middleware, executed in order against the {@link @nhtio/adk!DispatchContext} after the executor on each iteration. Defaults to `[]`. */
|
|
81
|
+
dispatchOutputPipeline?: DispatchPipelineMiddlewareFn[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Fully-resolved {@link TurnRunnerConfig} after schema validation.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* All optional fields are guaranteed present (e.g. `tools` defaults to `[]`). The runner stores
|
|
88
|
+
* this type internally so field access never needs to guard for undefined.
|
|
89
|
+
*/
|
|
90
|
+
export type ResolvedTurnRunnerConfig = Required<TurnRunnerConfig>;
|
|
91
|
+
/**
|
|
92
|
+
* Validator schema used to validate a {@link TurnRunnerConfig} at {@link @nhtio/adk!TurnRunner} construction time.
|
|
93
|
+
*
|
|
94
|
+
* @remarks
|
|
95
|
+
* Validates that all callbacks are functions of the correct arity, and that `tools` — when
|
|
96
|
+
* provided — is an array of valid {@link @nhtio/adk!Tool} instances. Defaults `tools` to `[]`.
|
|
97
|
+
*
|
|
98
|
+
* Throws {@link @nhtio/adk!E_INVALID_TURN_RUNNER_CONFIG} (via the {@link @nhtio/adk!TurnRunner} constructor) when
|
|
99
|
+
* validation fails.
|
|
100
|
+
*/
|
|
101
|
+
export declare const turnRunnerConfigSchema: import("@nhtio/validation").ObjectSchema<TurnRunnerConfig>;
|