@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,209 @@
|
|
|
1
|
+
import { o as isError } from "../../tool_registry-DqLOyGyG.mjs";
|
|
2
|
+
import { i as Retrievable } from "../../common-DeZaonK1.mjs";
|
|
3
|
+
import { t as Tool } from "../../tool-D2WB1EA1.mjs";
|
|
4
|
+
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-BpUJol0W.mjs";
|
|
5
|
+
import "../../guards.mjs";
|
|
6
|
+
import { validator } from "@nhtio/validation";
|
|
7
|
+
import { v6 } from "uuid";
|
|
8
|
+
import { DateTime } from "luxon";
|
|
9
|
+
//#region src/batteries/tools/retrievables/index.ts
|
|
10
|
+
/**
|
|
11
|
+
* Pre-constructed CRUD tools for model-visible retrievable and RAG-record management.
|
|
12
|
+
*
|
|
13
|
+
* @module @nhtio/adk/batteries/tools/retrievables
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Pre-constructed CRUD tools that expose the ADK's {@link @nhtio/adk!Retrievable} surface to the
|
|
17
|
+
* model. Each tool delegates to the corresponding callback on the active
|
|
18
|
+
* {@link @nhtio/adk!DispatchContext} (`fetchRetrievables`, `storeRetrievable`, `mutateRetrievable`,
|
|
19
|
+
* `deleteRetrievable`) — the persistence layer is whatever the consumer wired into the
|
|
20
|
+
* runner.
|
|
21
|
+
*
|
|
22
|
+
* Retrievables are RAG records and carry an explicit `trustTier` that drives the LLM
|
|
23
|
+
* battery's rendering envelope. Exposing these CRUD tools to the model is a deliberate
|
|
24
|
+
* deployer decision; the trust tier the model declares when creating or updating a record
|
|
25
|
+
* is honoured verbatim by the persistence layer. The deployer is responsible for choosing
|
|
26
|
+
* whether to register all four tools, only the read-only `list_retrievables`, or any subset
|
|
27
|
+
* thereof — that registration choice is exactly the trust boundary documented in the
|
|
28
|
+
* Retrievable battery contract.
|
|
29
|
+
*
|
|
30
|
+
* Output is JSON for every tool so consumers can parse the result without re-tokenising —
|
|
31
|
+
* the artifact constructor is set to {@link @nhtio/adk!SpooledJsonArtifact}.
|
|
32
|
+
*
|
|
33
|
+
* Tools:
|
|
34
|
+
* - {@link listRetrievablesTool} — read-only list of every retrievable currently held by
|
|
35
|
+
* the context.
|
|
36
|
+
* - {@link storeRetrievableTool} — create a new retrievable record (auto-generates `id` /
|
|
37
|
+
* `createdAt` / `updatedAt` unless explicit values are supplied).
|
|
38
|
+
* - {@link updateRetrievableTool} — replace an existing retrievable by `id`. Bumps
|
|
39
|
+
* `updatedAt`.
|
|
40
|
+
* - {@link deleteRetrievableTool} — remove a retrievable by `id`.
|
|
41
|
+
*/
|
|
42
|
+
var TRUST_TIERS = [
|
|
43
|
+
"first-party",
|
|
44
|
+
"third-party-public",
|
|
45
|
+
"third-party-private"
|
|
46
|
+
];
|
|
47
|
+
var serialiseRetrievable = (r) => ({
|
|
48
|
+
id: r.id,
|
|
49
|
+
content: r.content.toString(),
|
|
50
|
+
trustTier: r.trustTier,
|
|
51
|
+
source: r.source,
|
|
52
|
+
kind: r.kind,
|
|
53
|
+
score: r.score,
|
|
54
|
+
createdAt: r.createdAt.toISO(),
|
|
55
|
+
updatedAt: r.updatedAt.toISO()
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* List every retrievable record currently held by the active execution context.
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* Delegates to `ctx.fetchRetrievables()`. Returns a JSON-encoded array of retrievable records
|
|
62
|
+
* (id, content, trustTier, source, kind, score, createdAt, updatedAt).
|
|
63
|
+
*/
|
|
64
|
+
var listRetrievablesTool = new Tool({
|
|
65
|
+
name: "list_retrievables",
|
|
66
|
+
description: "List every retrievable record currently available to the agent. Returns a JSON array of records with id, content, trustTier, source, kind, score, createdAt, and updatedAt.",
|
|
67
|
+
inputSchema: validator.object({}),
|
|
68
|
+
artifactConstructor: () => SpooledJsonArtifact,
|
|
69
|
+
handler: async (_args, ctx) => {
|
|
70
|
+
try {
|
|
71
|
+
const retrievables = await ctx.fetchRetrievables();
|
|
72
|
+
return JSON.stringify(retrievables.map(serialiseRetrievable), null, 2);
|
|
73
|
+
} catch (err) {
|
|
74
|
+
return `Error: ${isError(err) ? err.message : String(err)}`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
/**
|
|
79
|
+
* Create a new {@link @nhtio/adk!Retrievable} record and persist it via the context's `storeRetrievable`
|
|
80
|
+
* callback.
|
|
81
|
+
*
|
|
82
|
+
* @remarks
|
|
83
|
+
* When `id` is omitted, a UUID v6 is generated. When `createdAt` / `updatedAt` are omitted,
|
|
84
|
+
* the current time is used. The model must declare `trustTier` explicitly — there is no
|
|
85
|
+
* default; the choice is consciously the model's, exposed by the deployer's decision to
|
|
86
|
+
* register this tool.
|
|
87
|
+
*/
|
|
88
|
+
var storeRetrievableTool = new Tool({
|
|
89
|
+
name: "store_retrievable",
|
|
90
|
+
description: "Store a new retrievable (RAG) record. The trustTier MUST be one of 'first-party' (deployer-vetted), 'third-party-public' (open-web), or 'third-party-private' (user uploads). id and timestamps are auto-generated if omitted.",
|
|
91
|
+
inputSchema: validator.object({
|
|
92
|
+
content: validator.string().required().description("The retrievable content as a plain string."),
|
|
93
|
+
trustTier: validator.string().valid(...TRUST_TIERS).required().description("Trust tier: 'first-party' for deployer-vetted material, 'third-party-public' for open-web or public APIs, 'third-party-private' for user uploads or partner APIs."),
|
|
94
|
+
source: validator.string().optional().description("Optional provenance string: URL, document path, KB id, etc."),
|
|
95
|
+
kind: validator.string().optional().description("Optional semantic label: 'policy', 'reference', 'web-page', 'pdf', etc."),
|
|
96
|
+
score: validator.number().min(0).max(1).optional().description("Optional relevance / similarity score in [0, 1]."),
|
|
97
|
+
id: validator.string().optional().description("Optional stable id. Auto-generated when absent.")
|
|
98
|
+
}),
|
|
99
|
+
artifactConstructor: () => SpooledJsonArtifact,
|
|
100
|
+
handler: async (args, ctx) => {
|
|
101
|
+
const { content, trustTier, source, kind, score, id } = args;
|
|
102
|
+
try {
|
|
103
|
+
const now = DateTime.now();
|
|
104
|
+
const retrievable = new Retrievable({
|
|
105
|
+
id: id ?? v6(),
|
|
106
|
+
content,
|
|
107
|
+
trustTier,
|
|
108
|
+
source,
|
|
109
|
+
kind,
|
|
110
|
+
score,
|
|
111
|
+
createdAt: now,
|
|
112
|
+
updatedAt: now
|
|
113
|
+
});
|
|
114
|
+
await ctx.storeRetrievable(retrievable);
|
|
115
|
+
return JSON.stringify({
|
|
116
|
+
ok: true,
|
|
117
|
+
retrievable: serialiseRetrievable(retrievable)
|
|
118
|
+
}, null, 2);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
return `Error: ${isError(err) ? err.message : String(err)}`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* Replace an existing {@link @nhtio/adk!Retrievable} by `id`.
|
|
126
|
+
*
|
|
127
|
+
* @remarks
|
|
128
|
+
* The model supplies `id` plus any subset of `content` / `trustTier` / `source` / `kind` /
|
|
129
|
+
* `score`; omitted fields retain their prior values. `updatedAt` is always bumped;
|
|
130
|
+
* `createdAt` is preserved. Returns an error when no retrievable with the supplied `id` is
|
|
131
|
+
* found.
|
|
132
|
+
*/
|
|
133
|
+
var updateRetrievableTool = new Tool({
|
|
134
|
+
name: "update_retrievable",
|
|
135
|
+
description: "Update an existing retrievable by id. Supply any subset of content / trustTier / source / kind / score — omitted fields retain their prior values. updatedAt is always refreshed.",
|
|
136
|
+
inputSchema: validator.object({
|
|
137
|
+
id: validator.string().required().description("Id of the retrievable to update."),
|
|
138
|
+
content: validator.string().optional().description("Replacement content."),
|
|
139
|
+
trustTier: validator.string().valid(...TRUST_TIERS).optional().description("Replacement trust tier."),
|
|
140
|
+
source: validator.string().optional().description("Replacement provenance string."),
|
|
141
|
+
kind: validator.string().optional().description("Replacement semantic label."),
|
|
142
|
+
score: validator.number().min(0).max(1).optional().description("Replacement score in [0, 1].")
|
|
143
|
+
}),
|
|
144
|
+
artifactConstructor: () => SpooledJsonArtifact,
|
|
145
|
+
handler: async (args, ctx) => {
|
|
146
|
+
const { id, content, trustTier, source, kind, score } = args;
|
|
147
|
+
try {
|
|
148
|
+
const existing = (await ctx.fetchRetrievables()).find((r) => r.id === id);
|
|
149
|
+
if (!existing) return `Error: No retrievable found with id "${id}".`;
|
|
150
|
+
const updated = new Retrievable({
|
|
151
|
+
id: existing.id,
|
|
152
|
+
content: content ?? existing.content,
|
|
153
|
+
trustTier: trustTier ?? existing.trustTier,
|
|
154
|
+
source: source ?? existing.source,
|
|
155
|
+
kind: kind ?? existing.kind,
|
|
156
|
+
score: score ?? existing.score,
|
|
157
|
+
createdAt: existing.createdAt,
|
|
158
|
+
updatedAt: DateTime.now()
|
|
159
|
+
});
|
|
160
|
+
await ctx.mutateRetrievable(updated);
|
|
161
|
+
return JSON.stringify({
|
|
162
|
+
ok: true,
|
|
163
|
+
retrievable: serialiseRetrievable(updated)
|
|
164
|
+
}, null, 2);
|
|
165
|
+
} catch (err) {
|
|
166
|
+
return `Error: ${isError(err) ? err.message : String(err)}`;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
/**
|
|
171
|
+
* Remove an existing {@link @nhtio/adk!Retrievable} by `id`.
|
|
172
|
+
*
|
|
173
|
+
* @remarks
|
|
174
|
+
* Delegates to `ctx.deleteRetrievable(id)`. Returns `{ ok: true, id }` on success regardless
|
|
175
|
+
* of whether a retrievable was actually present — `deleteRetrievable` is idempotent at the
|
|
176
|
+
* ADK level.
|
|
177
|
+
*/
|
|
178
|
+
var deleteRetrievableTool = new Tool({
|
|
179
|
+
name: "delete_retrievable",
|
|
180
|
+
description: "Delete a retrievable by id.",
|
|
181
|
+
inputSchema: validator.object({ id: validator.string().required().description("Id of the retrievable to delete.") }),
|
|
182
|
+
artifactConstructor: () => SpooledJsonArtifact,
|
|
183
|
+
handler: async (args, ctx) => {
|
|
184
|
+
const { id } = args;
|
|
185
|
+
try {
|
|
186
|
+
await ctx.deleteRetrievable(id);
|
|
187
|
+
return JSON.stringify({
|
|
188
|
+
ok: true,
|
|
189
|
+
id
|
|
190
|
+
}, null, 2);
|
|
191
|
+
} catch (err) {
|
|
192
|
+
return `Error: ${isError(err) ? err.message : String(err)}`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
/**
|
|
197
|
+
* Convenience tuple of every retrievable CRUD tool. Spread into a {@link @nhtio/adk!ToolRegistry} to
|
|
198
|
+
* register the entire category at once.
|
|
199
|
+
*/
|
|
200
|
+
var retrievableTools = [
|
|
201
|
+
listRetrievablesTool,
|
|
202
|
+
storeRetrievableTool,
|
|
203
|
+
updateRetrievableTool,
|
|
204
|
+
deleteRetrievableTool
|
|
205
|
+
];
|
|
206
|
+
//#endregion
|
|
207
|
+
export { deleteRetrievableTool, listRetrievablesTool, retrievableTools, storeRetrievableTool, updateRetrievableTool };
|
|
208
|
+
|
|
209
|
+
//# sourceMappingURL=retrievables.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrievables.mjs","names":[],"sources":["../../../src/batteries/tools/retrievables/index.ts"],"sourcesContent":["/**\n * Pre-constructed CRUD tools for model-visible retrievable and RAG-record management.\n *\n * @module @nhtio/adk/batteries/tools/retrievables\n *\n * @remarks\n * Pre-constructed CRUD tools that expose the ADK's {@link @nhtio/adk!Retrievable} surface to the\n * model. Each tool delegates to the corresponding callback on the active\n * {@link @nhtio/adk!DispatchContext} (`fetchRetrievables`, `storeRetrievable`, `mutateRetrievable`,\n * `deleteRetrievable`) — the persistence layer is whatever the consumer wired into the\n * runner.\n *\n * Retrievables are RAG records and carry an explicit `trustTier` that drives the LLM\n * battery's rendering envelope. Exposing these CRUD tools to the model is a deliberate\n * deployer decision; the trust tier the model declares when creating or updating a record\n * is honoured verbatim by the persistence layer. The deployer is responsible for choosing\n * whether to register all four tools, only the read-only `list_retrievables`, or any subset\n * thereof — that registration choice is exactly the trust boundary documented in the\n * Retrievable battery contract.\n *\n * Output is JSON for every tool so consumers can parse the result without re-tokenising —\n * the artifact constructor is set to {@link @nhtio/adk!SpooledJsonArtifact}.\n *\n * Tools:\n * - {@link listRetrievablesTool} — read-only list of every retrievable currently held by\n * the context.\n * - {@link storeRetrievableTool} — create a new retrievable record (auto-generates `id` /\n * `createdAt` / `updatedAt` unless explicit values are supplied).\n * - {@link updateRetrievableTool} — replace an existing retrievable by `id`. Bumps\n * `updatedAt`.\n * - {@link deleteRetrievableTool} — remove a retrievable by `id`.\n */\n\nimport { DateTime } from 'luxon'\nimport { v6 as uuidv6 } from 'uuid'\nimport { isError } from '@nhtio/adk/guards'\nimport { validator } from '@nhtio/validation'\nimport { Retrievable, SpooledJsonArtifact, Tool } from '@nhtio/adk/common'\n\nconst TRUST_TIERS = ['first-party', 'third-party-public', 'third-party-private'] as const\ntype TrustTier = (typeof TRUST_TIERS)[number]\n\nconst serialiseRetrievable = (r: Retrievable): Record<string, unknown> => ({\n id: r.id,\n content: r.content.toString(),\n trustTier: r.trustTier,\n source: r.source,\n kind: r.kind,\n score: r.score,\n createdAt: r.createdAt.toISO(),\n updatedAt: r.updatedAt.toISO(),\n})\n\n/**\n * List every retrievable record currently held by the active execution context.\n *\n * @remarks\n * Delegates to `ctx.fetchRetrievables()`. Returns a JSON-encoded array of retrievable records\n * (id, content, trustTier, source, kind, score, createdAt, updatedAt).\n */\nexport const listRetrievablesTool = new Tool({\n name: 'list_retrievables',\n description:\n 'List every retrievable record currently available to the agent. Returns a JSON array of records with id, content, trustTier, source, kind, score, createdAt, and updatedAt.',\n inputSchema: validator.object({}),\n artifactConstructor: () => SpooledJsonArtifact,\n handler: async (_args, ctx) => {\n try {\n const retrievables = await ctx.fetchRetrievables()\n return JSON.stringify(retrievables.map(serialiseRetrievable), null, 2)\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Create a new {@link @nhtio/adk!Retrievable} record and persist it via the context's `storeRetrievable`\n * callback.\n *\n * @remarks\n * When `id` is omitted, a UUID v6 is generated. When `createdAt` / `updatedAt` are omitted,\n * the current time is used. The model must declare `trustTier` explicitly — there is no\n * default; the choice is consciously the model's, exposed by the deployer's decision to\n * register this tool.\n */\nexport const storeRetrievableTool = new Tool({\n name: 'store_retrievable',\n description:\n \"Store a new retrievable (RAG) record. The trustTier MUST be one of 'first-party' (deployer-vetted), 'third-party-public' (open-web), or 'third-party-private' (user uploads). id and timestamps are auto-generated if omitted.\",\n inputSchema: validator.object({\n content: validator\n .string()\n .required()\n .description('The retrievable content as a plain string.'),\n trustTier: validator\n .string()\n .valid(...TRUST_TIERS)\n .required()\n .description(\n \"Trust tier: 'first-party' for deployer-vetted material, 'third-party-public' for open-web or public APIs, 'third-party-private' for user uploads or partner APIs.\"\n ),\n source: validator\n .string()\n .optional()\n .description('Optional provenance string: URL, document path, KB id, etc.'),\n kind: validator\n .string()\n .optional()\n .description(\"Optional semantic label: 'policy', 'reference', 'web-page', 'pdf', etc.\"),\n score: validator\n .number()\n .min(0)\n .max(1)\n .optional()\n .description('Optional relevance / similarity score in [0, 1].'),\n id: validator\n .string()\n .optional()\n .description('Optional stable id. Auto-generated when absent.'),\n }),\n artifactConstructor: () => SpooledJsonArtifact,\n handler: async (args, ctx) => {\n const { content, trustTier, source, kind, score, id } = args as {\n content: string\n trustTier: TrustTier\n source?: string\n kind?: string\n score?: number\n id?: string\n }\n try {\n const now = DateTime.now()\n const retrievable = new Retrievable({\n id: id ?? uuidv6(),\n content,\n trustTier,\n source,\n kind,\n score,\n createdAt: now,\n updatedAt: now,\n })\n await ctx.storeRetrievable(retrievable)\n return JSON.stringify({ ok: true, retrievable: serialiseRetrievable(retrievable) }, null, 2)\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Replace an existing {@link @nhtio/adk!Retrievable} by `id`.\n *\n * @remarks\n * The model supplies `id` plus any subset of `content` / `trustTier` / `source` / `kind` /\n * `score`; omitted fields retain their prior values. `updatedAt` is always bumped;\n * `createdAt` is preserved. Returns an error when no retrievable with the supplied `id` is\n * found.\n */\nexport const updateRetrievableTool = new Tool({\n name: 'update_retrievable',\n description:\n 'Update an existing retrievable by id. Supply any subset of content / trustTier / source / kind / score — omitted fields retain their prior values. updatedAt is always refreshed.',\n inputSchema: validator.object({\n id: validator.string().required().description('Id of the retrievable to update.'),\n content: validator.string().optional().description('Replacement content.'),\n trustTier: validator\n .string()\n .valid(...TRUST_TIERS)\n .optional()\n .description('Replacement trust tier.'),\n source: validator.string().optional().description('Replacement provenance string.'),\n kind: validator.string().optional().description('Replacement semantic label.'),\n score: validator.number().min(0).max(1).optional().description('Replacement score in [0, 1].'),\n }),\n artifactConstructor: () => SpooledJsonArtifact,\n handler: async (args, ctx) => {\n const { id, content, trustTier, source, kind, score } = args as {\n id: string\n content?: string\n trustTier?: TrustTier\n source?: string\n kind?: string\n score?: number\n }\n try {\n const retrievables = await ctx.fetchRetrievables()\n const existing = retrievables.find((r) => r.id === id)\n if (!existing) {\n return `Error: No retrievable found with id \"${id}\".`\n }\n const updated = new Retrievable({\n id: existing.id,\n content: content ?? existing.content,\n trustTier: trustTier ?? existing.trustTier,\n source: source ?? existing.source,\n kind: kind ?? existing.kind,\n score: score ?? existing.score,\n createdAt: existing.createdAt,\n updatedAt: DateTime.now(),\n })\n await ctx.mutateRetrievable(updated)\n return JSON.stringify({ ok: true, retrievable: serialiseRetrievable(updated) }, null, 2)\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Remove an existing {@link @nhtio/adk!Retrievable} by `id`.\n *\n * @remarks\n * Delegates to `ctx.deleteRetrievable(id)`. Returns `{ ok: true, id }` on success regardless\n * of whether a retrievable was actually present — `deleteRetrievable` is idempotent at the\n * ADK level.\n */\nexport const deleteRetrievableTool = new Tool({\n name: 'delete_retrievable',\n description: 'Delete a retrievable by id.',\n inputSchema: validator.object({\n id: validator.string().required().description('Id of the retrievable to delete.'),\n }),\n artifactConstructor: () => SpooledJsonArtifact,\n handler: async (args, ctx) => {\n const { id } = args as { id: string }\n try {\n await ctx.deleteRetrievable(id)\n return JSON.stringify({ ok: true, id }, null, 2)\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Convenience tuple of every retrievable CRUD tool. Spread into a {@link @nhtio/adk!ToolRegistry} to\n * register the entire category at once.\n */\nexport const retrievableTools = [\n listRetrievablesTool,\n storeRetrievableTool,\n updateRetrievableTool,\n deleteRetrievableTool,\n] as const\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAM,cAAc;CAAC;CAAe;CAAsB;AAAqB;AAG/E,IAAM,wBAAwB,OAA6C;CACzE,IAAI,EAAE;CACN,SAAS,EAAE,QAAQ,SAAS;CAC5B,WAAW,EAAE;CACb,QAAQ,EAAE;CACV,MAAM,EAAE;CACR,OAAO,EAAE;CACT,WAAW,EAAE,UAAU,MAAM;CAC7B,WAAW,EAAE,UAAU,MAAM;AAC/B;;;;;;;;AASA,IAAa,uBAAuB,IAAI,KAAK;CAC3C,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO,CAAC,CAAC;CAChC,2BAA2B;CAC3B,SAAS,OAAO,OAAO,QAAQ;EAC7B,IAAI;GACF,MAAM,eAAe,MAAM,IAAI,kBAAkB;GACjD,OAAO,KAAK,UAAU,aAAa,IAAI,oBAAoB,GAAG,MAAM,CAAC;EACvE,SAAS,KAAK;GACZ,OAAO,UAAU,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC;;;;;;;;;;;AAYD,IAAa,uBAAuB,IAAI,KAAK;CAC3C,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO;EAC5B,SAAS,UACN,OAAO,EACP,SAAS,EACT,YAAY,4CAA4C;EAC3D,WAAW,UACR,OAAO,EACP,MAAM,GAAG,WAAW,EACpB,SAAS,EACT,YACC,mKACF;EACF,QAAQ,UACL,OAAO,EACP,SAAS,EACT,YAAY,6DAA6D;EAC5E,MAAM,UACH,OAAO,EACP,SAAS,EACT,YAAY,yEAAyE;EACxF,OAAO,UACJ,OAAO,EACP,IAAI,CAAC,EACL,IAAI,CAAC,EACL,SAAS,EACT,YAAY,kDAAkD;EACjE,IAAI,UACD,OAAO,EACP,SAAS,EACT,YAAY,iDAAiD;CAClE,CAAC;CACD,2BAA2B;CAC3B,SAAS,OAAO,MAAM,QAAQ;EAC5B,MAAM,EAAE,SAAS,WAAW,QAAQ,MAAM,OAAO,OAAO;EAQxD,IAAI;GACF,MAAM,MAAM,SAAS,IAAI;GACzB,MAAM,cAAc,IAAI,YAAY;IAClC,IAAI,MAAM,GAAO;IACjB;IACA;IACA;IACA;IACA;IACA,WAAW;IACX,WAAW;GACb,CAAC;GACD,MAAM,IAAI,iBAAiB,WAAW;GACtC,OAAO,KAAK,UAAU;IAAE,IAAI;IAAM,aAAa,qBAAqB,WAAW;GAAE,GAAG,MAAM,CAAC;EAC7F,SAAS,KAAK;GACZ,OAAO,UAAU,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC;;;;;;;;;;AAWD,IAAa,wBAAwB,IAAI,KAAK;CAC5C,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO;EAC5B,IAAI,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,kCAAkC;EAChF,SAAS,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,sBAAsB;EACzE,WAAW,UACR,OAAO,EACP,MAAM,GAAG,WAAW,EACpB,SAAS,EACT,YAAY,yBAAyB;EACxC,QAAQ,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,gCAAgC;EAClF,MAAM,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,6BAA6B;EAC7E,OAAO,UAAU,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS,EAAE,YAAY,8BAA8B;CAC/F,CAAC;CACD,2BAA2B;CAC3B,SAAS,OAAO,MAAM,QAAQ;EAC5B,MAAM,EAAE,IAAI,SAAS,WAAW,QAAQ,MAAM,UAAU;EAQxD,IAAI;GAEF,MAAM,YAAW,MADU,IAAI,kBAAkB,GACnB,MAAM,MAAM,EAAE,OAAO,EAAE;GACrD,IAAI,CAAC,UACH,OAAO,wCAAwC,GAAG;GAEpD,MAAM,UAAU,IAAI,YAAY;IAC9B,IAAI,SAAS;IACb,SAAS,WAAW,SAAS;IAC7B,WAAW,aAAa,SAAS;IACjC,QAAQ,UAAU,SAAS;IAC3B,MAAM,QAAQ,SAAS;IACvB,OAAO,SAAS,SAAS;IACzB,WAAW,SAAS;IACpB,WAAW,SAAS,IAAI;GAC1B,CAAC;GACD,MAAM,IAAI,kBAAkB,OAAO;GACnC,OAAO,KAAK,UAAU;IAAE,IAAI;IAAM,aAAa,qBAAqB,OAAO;GAAE,GAAG,MAAM,CAAC;EACzF,SAAS,KAAK;GACZ,OAAO,UAAU,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC;;;;;;;;;AAUD,IAAa,wBAAwB,IAAI,KAAK;CAC5C,MAAM;CACN,aAAa;CACb,aAAa,UAAU,OAAO,EAC5B,IAAI,UAAU,OAAO,EAAE,SAAS,EAAE,YAAY,kCAAkC,EAClF,CAAC;CACD,2BAA2B;CAC3B,SAAS,OAAO,MAAM,QAAQ;EAC5B,MAAM,EAAE,OAAO;EACf,IAAI;GACF,MAAM,IAAI,kBAAkB,EAAE;GAC9B,OAAO,KAAK,UAAU;IAAE,IAAI;IAAM;GAAG,GAAG,MAAM,CAAC;EACjD,SAAS,KAAK;GACZ,OAAO,UAAU,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC;;;;;AAMD,IAAa,mBAAmB;CAC9B;CACA;CACA;CACA;AACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-constructed CRUD tools for model-visible standing instruction management.
|
|
3
|
+
*
|
|
4
|
+
* @module @nhtio/adk/batteries/tools/standing_instructions
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Pre-constructed CRUD tools that expose the ADK's standing-instruction surface to the
|
|
8
|
+
* model. Each tool delegates to the corresponding callback on the active
|
|
9
|
+
* {@link @nhtio/adk!DispatchContext} (`standingInstructions` getter, `storeStandingInstruction`,
|
|
10
|
+
* `deleteStandingInstruction`) — the persistence layer is whatever the consumer wired into
|
|
11
|
+
* the runner.
|
|
12
|
+
*
|
|
13
|
+
* Standing instructions are stored as a {@link Set} of {@link @nhtio/adk!Tokenizable} values keyed by
|
|
14
|
+
* identity, not by an `id` field — there is no separate "update by id" semantics. The tools
|
|
15
|
+
* therefore expose only `list` / `add` / `remove`. To replace an existing instruction the
|
|
16
|
+
* model should `remove` the old value and `add` the new one (the ADK's persistence layer
|
|
17
|
+
* is free to interpret that pair as an update if appropriate).
|
|
18
|
+
*
|
|
19
|
+
* Output is JSON for every tool so consumers can parse the result without re-tokenising —
|
|
20
|
+
* the artifact constructor is set to {@link @nhtio/adk!SpooledJsonArtifact}.
|
|
21
|
+
*
|
|
22
|
+
* Tools:
|
|
23
|
+
* - {@link listStandingInstructionsTool} — read-only list of every standing instruction
|
|
24
|
+
* currently held by the context (after refreshing from the persistence layer).
|
|
25
|
+
* - {@link addStandingInstructionTool} — add a new standing instruction.
|
|
26
|
+
* - {@link removeStandingInstructionTool} — remove a standing instruction by its content
|
|
27
|
+
* (exact string match).
|
|
28
|
+
*/
|
|
29
|
+
import { SpooledJsonArtifact, Tool } from "../../../common";
|
|
30
|
+
/**
|
|
31
|
+
* List every standing instruction currently held by the active execution context.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Calls `ctx.refreshStandingInstructions()` to ensure the local Set is in sync with the
|
|
35
|
+
* persistence layer, then serialises the resulting strings to a JSON array. The list is
|
|
36
|
+
* stringly-keyed; the same content string serves as the identifier for subsequent removes.
|
|
37
|
+
*/
|
|
38
|
+
export declare const listStandingInstructionsTool: Tool<SpooledJsonArtifact<unknown>>;
|
|
39
|
+
/**
|
|
40
|
+
* Add a new standing instruction to the active execution context.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* Delegates to `ctx.storeStandingInstruction(content)`. Standing instructions are stored as
|
|
44
|
+
* a `Set` — adding the same content twice is a no-op at the local level, though the
|
|
45
|
+
* consumer's persistence callback may interpret it differently.
|
|
46
|
+
*/
|
|
47
|
+
export declare const addStandingInstructionTool: Tool<SpooledJsonArtifact<unknown>>;
|
|
48
|
+
/**
|
|
49
|
+
* Remove an existing standing instruction by its content string.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* Delegates to `ctx.deleteStandingInstruction(content)`. Idempotent — succeeds even when
|
|
53
|
+
* no matching instruction is currently present.
|
|
54
|
+
*/
|
|
55
|
+
export declare const removeStandingInstructionTool: Tool<SpooledJsonArtifact<unknown>>;
|
|
56
|
+
/**
|
|
57
|
+
* Convenience tuple of every standing-instruction tool. Spread into a {@link @nhtio/adk!ToolRegistry}
|
|
58
|
+
* to register the entire category at once.
|
|
59
|
+
*/
|
|
60
|
+
export declare const standingInstructionTools: readonly [
|
|
61
|
+
Tool<SpooledJsonArtifact<unknown>>,
|
|
62
|
+
Tool<SpooledJsonArtifact<unknown>>,
|
|
63
|
+
Tool<SpooledJsonArtifact<unknown>>
|
|
64
|
+
];
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../../chunk-KmRHZBOW.js");
|
|
3
|
+
const require_tool_registry = require("../../tool_registry-Dkfprsck.js");
|
|
4
|
+
require("../../common-Od8edUXU.js");
|
|
5
|
+
const require_tool = require("../../tool-COSeH8I6.js");
|
|
6
|
+
const require_spooled_markdown_artifact = require("../../spooled_markdown_artifact-RRB113sy.js");
|
|
7
|
+
require("../../guards.cjs");
|
|
8
|
+
let _nhtio_validation = require("@nhtio/validation");
|
|
9
|
+
//#region src/batteries/tools/standing_instructions/index.ts
|
|
10
|
+
/**
|
|
11
|
+
* Pre-constructed CRUD tools for model-visible standing instruction management.
|
|
12
|
+
*
|
|
13
|
+
* @module @nhtio/adk/batteries/tools/standing_instructions
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Pre-constructed CRUD tools that expose the ADK's standing-instruction surface to the
|
|
17
|
+
* model. Each tool delegates to the corresponding callback on the active
|
|
18
|
+
* {@link @nhtio/adk!DispatchContext} (`standingInstructions` getter, `storeStandingInstruction`,
|
|
19
|
+
* `deleteStandingInstruction`) — the persistence layer is whatever the consumer wired into
|
|
20
|
+
* the runner.
|
|
21
|
+
*
|
|
22
|
+
* Standing instructions are stored as a {@link Set} of {@link @nhtio/adk!Tokenizable} values keyed by
|
|
23
|
+
* identity, not by an `id` field — there is no separate "update by id" semantics. The tools
|
|
24
|
+
* therefore expose only `list` / `add` / `remove`. To replace an existing instruction the
|
|
25
|
+
* model should `remove` the old value and `add` the new one (the ADK's persistence layer
|
|
26
|
+
* is free to interpret that pair as an update if appropriate).
|
|
27
|
+
*
|
|
28
|
+
* Output is JSON for every tool so consumers can parse the result without re-tokenising —
|
|
29
|
+
* the artifact constructor is set to {@link @nhtio/adk!SpooledJsonArtifact}.
|
|
30
|
+
*
|
|
31
|
+
* Tools:
|
|
32
|
+
* - {@link listStandingInstructionsTool} — read-only list of every standing instruction
|
|
33
|
+
* currently held by the context (after refreshing from the persistence layer).
|
|
34
|
+
* - {@link addStandingInstructionTool} — add a new standing instruction.
|
|
35
|
+
* - {@link removeStandingInstructionTool} — remove a standing instruction by its content
|
|
36
|
+
* (exact string match).
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* List every standing instruction currently held by the active execution context.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Calls `ctx.refreshStandingInstructions()` to ensure the local Set is in sync with the
|
|
43
|
+
* persistence layer, then serialises the resulting strings to a JSON array. The list is
|
|
44
|
+
* stringly-keyed; the same content string serves as the identifier for subsequent removes.
|
|
45
|
+
*/
|
|
46
|
+
var listStandingInstructionsTool = new require_tool.Tool({
|
|
47
|
+
name: "list_standing_instructions",
|
|
48
|
+
description: "List every standing instruction currently held by the agent. Returns a JSON array of strings. To replace an instruction, remove the old string and add a new one.",
|
|
49
|
+
inputSchema: _nhtio_validation.validator.object({}),
|
|
50
|
+
artifactConstructor: () => require_spooled_markdown_artifact.SpooledJsonArtifact,
|
|
51
|
+
handler: async (_args, ctx) => {
|
|
52
|
+
try {
|
|
53
|
+
const items = (await ctx.refreshStandingInstructions()).map((v) => typeof v === "string" ? v : v.toString());
|
|
54
|
+
return JSON.stringify(items, null, 2);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
return `Error: ${require_tool_registry.isError(err) ? err.message : String(err)}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Add a new standing instruction to the active execution context.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* Delegates to `ctx.storeStandingInstruction(content)`. Standing instructions are stored as
|
|
65
|
+
* a `Set` — adding the same content twice is a no-op at the local level, though the
|
|
66
|
+
* consumer's persistence callback may interpret it differently.
|
|
67
|
+
*/
|
|
68
|
+
var addStandingInstructionTool = new require_tool.Tool({
|
|
69
|
+
name: "add_standing_instruction",
|
|
70
|
+
description: "Add a new standing instruction. Returns the stored content. Adding an identical instruction that already exists is a no-op.",
|
|
71
|
+
inputSchema: _nhtio_validation.validator.object({ content: _nhtio_validation.validator.string().required().description("The standing-instruction content as a plain string.") }),
|
|
72
|
+
artifactConstructor: () => require_spooled_markdown_artifact.SpooledJsonArtifact,
|
|
73
|
+
handler: async (args, ctx) => {
|
|
74
|
+
const { content } = args;
|
|
75
|
+
try {
|
|
76
|
+
await ctx.storeStandingInstruction(content);
|
|
77
|
+
return JSON.stringify({
|
|
78
|
+
ok: true,
|
|
79
|
+
content
|
|
80
|
+
}, null, 2);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
return `Error: ${require_tool_registry.isError(err) ? err.message : String(err)}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* Remove an existing standing instruction by its content string.
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* Delegates to `ctx.deleteStandingInstruction(content)`. Idempotent — succeeds even when
|
|
91
|
+
* no matching instruction is currently present.
|
|
92
|
+
*/
|
|
93
|
+
var removeStandingInstructionTool = new require_tool.Tool({
|
|
94
|
+
name: "remove_standing_instruction",
|
|
95
|
+
description: "Remove a standing instruction by its exact content string. Idempotent — succeeds even when no match is present.",
|
|
96
|
+
inputSchema: _nhtio_validation.validator.object({ content: _nhtio_validation.validator.string().required().description("The exact content string of the instruction to remove.") }),
|
|
97
|
+
artifactConstructor: () => require_spooled_markdown_artifact.SpooledJsonArtifact,
|
|
98
|
+
handler: async (args, ctx) => {
|
|
99
|
+
const { content } = args;
|
|
100
|
+
try {
|
|
101
|
+
await ctx.deleteStandingInstruction(content);
|
|
102
|
+
return JSON.stringify({
|
|
103
|
+
ok: true,
|
|
104
|
+
content
|
|
105
|
+
}, null, 2);
|
|
106
|
+
} catch (err) {
|
|
107
|
+
return `Error: ${require_tool_registry.isError(err) ? err.message : String(err)}`;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* Convenience tuple of every standing-instruction tool. Spread into a {@link @nhtio/adk!ToolRegistry}
|
|
113
|
+
* to register the entire category at once.
|
|
114
|
+
*/
|
|
115
|
+
var standingInstructionTools = [
|
|
116
|
+
listStandingInstructionsTool,
|
|
117
|
+
addStandingInstructionTool,
|
|
118
|
+
removeStandingInstructionTool
|
|
119
|
+
];
|
|
120
|
+
//#endregion
|
|
121
|
+
exports.addStandingInstructionTool = addStandingInstructionTool;
|
|
122
|
+
exports.listStandingInstructionsTool = listStandingInstructionsTool;
|
|
123
|
+
exports.removeStandingInstructionTool = removeStandingInstructionTool;
|
|
124
|
+
exports.standingInstructionTools = standingInstructionTools;
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=standing_instructions.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standing_instructions.cjs","names":[],"sources":["../../../src/batteries/tools/standing_instructions/index.ts"],"sourcesContent":["/**\n * Pre-constructed CRUD tools for model-visible standing instruction management.\n *\n * @module @nhtio/adk/batteries/tools/standing_instructions\n *\n * @remarks\n * Pre-constructed CRUD tools that expose the ADK's standing-instruction surface to the\n * model. Each tool delegates to the corresponding callback on the active\n * {@link @nhtio/adk!DispatchContext} (`standingInstructions` getter, `storeStandingInstruction`,\n * `deleteStandingInstruction`) — the persistence layer is whatever the consumer wired into\n * the runner.\n *\n * Standing instructions are stored as a {@link Set} of {@link @nhtio/adk!Tokenizable} values keyed by\n * identity, not by an `id` field — there is no separate \"update by id\" semantics. The tools\n * therefore expose only `list` / `add` / `remove`. To replace an existing instruction the\n * model should `remove` the old value and `add` the new one (the ADK's persistence layer\n * is free to interpret that pair as an update if appropriate).\n *\n * Output is JSON for every tool so consumers can parse the result without re-tokenising —\n * the artifact constructor is set to {@link @nhtio/adk!SpooledJsonArtifact}.\n *\n * Tools:\n * - {@link listStandingInstructionsTool} — read-only list of every standing instruction\n * currently held by the context (after refreshing from the persistence layer).\n * - {@link addStandingInstructionTool} — add a new standing instruction.\n * - {@link removeStandingInstructionTool} — remove a standing instruction by its content\n * (exact string match).\n */\n\nimport { isError } from '@nhtio/adk/guards'\nimport { validator } from '@nhtio/validation'\nimport { SpooledJsonArtifact, Tool } from '@nhtio/adk/common'\n\n/**\n * List every standing instruction currently held by the active execution context.\n *\n * @remarks\n * Calls `ctx.refreshStandingInstructions()` to ensure the local Set is in sync with the\n * persistence layer, then serialises the resulting strings to a JSON array. The list is\n * stringly-keyed; the same content string serves as the identifier for subsequent removes.\n */\nexport const listStandingInstructionsTool = new Tool({\n name: 'list_standing_instructions',\n description:\n 'List every standing instruction currently held by the agent. Returns a JSON array of strings. To replace an instruction, remove the old string and add a new one.',\n inputSchema: validator.object({}),\n artifactConstructor: () => SpooledJsonArtifact,\n handler: async (_args, ctx) => {\n try {\n const refreshed = await ctx.refreshStandingInstructions()\n const items = refreshed.map((v) => (typeof v === 'string' ? v : v.toString()))\n return JSON.stringify(items, null, 2)\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Add a new standing instruction to the active execution context.\n *\n * @remarks\n * Delegates to `ctx.storeStandingInstruction(content)`. Standing instructions are stored as\n * a `Set` — adding the same content twice is a no-op at the local level, though the\n * consumer's persistence callback may interpret it differently.\n */\nexport const addStandingInstructionTool = new Tool({\n name: 'add_standing_instruction',\n description:\n 'Add a new standing instruction. Returns the stored content. Adding an identical instruction that already exists is a no-op.',\n inputSchema: validator.object({\n content: validator\n .string()\n .required()\n .description('The standing-instruction content as a plain string.'),\n }),\n artifactConstructor: () => SpooledJsonArtifact,\n handler: async (args, ctx) => {\n const { content } = args as { content: string }\n try {\n await ctx.storeStandingInstruction(content)\n return JSON.stringify({ ok: true, content }, null, 2)\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Remove an existing standing instruction by its content string.\n *\n * @remarks\n * Delegates to `ctx.deleteStandingInstruction(content)`. Idempotent — succeeds even when\n * no matching instruction is currently present.\n */\nexport const removeStandingInstructionTool = new Tool({\n name: 'remove_standing_instruction',\n description:\n 'Remove a standing instruction by its exact content string. Idempotent — succeeds even when no match is present.',\n inputSchema: validator.object({\n content: validator\n .string()\n .required()\n .description('The exact content string of the instruction to remove.'),\n }),\n artifactConstructor: () => SpooledJsonArtifact,\n handler: async (args, ctx) => {\n const { content } = args as { content: string }\n try {\n await ctx.deleteStandingInstruction(content)\n return JSON.stringify({ ok: true, content }, null, 2)\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Convenience tuple of every standing-instruction tool. Spread into a {@link @nhtio/adk!ToolRegistry}\n * to register the entire category at once.\n */\nexport const standingInstructionTools = [\n listStandingInstructionsTool,\n addStandingInstructionTool,\n removeStandingInstructionTool,\n] as const\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,+BAA+B,IAAI,aAAA,KAAK;CACnD,MAAM;CACN,aACE;CACF,aAAa,kBAAA,UAAU,OAAO,CAAC,CAAC;CAChC,2BAA2B,kCAAA;CAC3B,SAAS,OAAO,OAAO,QAAQ;EAC7B,IAAI;GAEF,MAAM,SAAQ,MADU,IAAI,4BAA4B,GAChC,KAAK,MAAO,OAAO,MAAM,WAAW,IAAI,EAAE,SAAS,CAAE;GAC7E,OAAO,KAAK,UAAU,OAAO,MAAM,CAAC;EACtC,SAAS,KAAK;GACZ,OAAO,UAAU,sBAAA,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC;;;;;;;;;AAUD,IAAa,6BAA6B,IAAI,aAAA,KAAK;CACjD,MAAM;CACN,aACE;CACF,aAAa,kBAAA,UAAU,OAAO,EAC5B,SAAS,kBAAA,UACN,OAAO,EACP,SAAS,EACT,YAAY,qDAAqD,EACtE,CAAC;CACD,2BAA2B,kCAAA;CAC3B,SAAS,OAAO,MAAM,QAAQ;EAC5B,MAAM,EAAE,YAAY;EACpB,IAAI;GACF,MAAM,IAAI,yBAAyB,OAAO;GAC1C,OAAO,KAAK,UAAU;IAAE,IAAI;IAAM;GAAQ,GAAG,MAAM,CAAC;EACtD,SAAS,KAAK;GACZ,OAAO,UAAU,sBAAA,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC;;;;;;;;AASD,IAAa,gCAAgC,IAAI,aAAA,KAAK;CACpD,MAAM;CACN,aACE;CACF,aAAa,kBAAA,UAAU,OAAO,EAC5B,SAAS,kBAAA,UACN,OAAO,EACP,SAAS,EACT,YAAY,wDAAwD,EACzE,CAAC;CACD,2BAA2B,kCAAA;CAC3B,SAAS,OAAO,MAAM,QAAQ;EAC5B,MAAM,EAAE,YAAY;EACpB,IAAI;GACF,MAAM,IAAI,0BAA0B,OAAO;GAC3C,OAAO,KAAK,UAAU;IAAE,IAAI;IAAM;GAAQ,GAAG,MAAM,CAAC;EACtD,SAAS,KAAK;GACZ,OAAO,UAAU,sBAAA,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC;;;;;AAMD,IAAa,2BAA2B;CACtC;CACA;CACA;AACF"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { o as isError } from "../../tool_registry-DqLOyGyG.mjs";
|
|
2
|
+
import "../../common-DeZaonK1.mjs";
|
|
3
|
+
import { t as Tool } from "../../tool-D2WB1EA1.mjs";
|
|
4
|
+
import { n as SpooledJsonArtifact } from "../../spooled_markdown_artifact-BpUJol0W.mjs";
|
|
5
|
+
import "../../guards.mjs";
|
|
6
|
+
import { validator } from "@nhtio/validation";
|
|
7
|
+
//#region src/batteries/tools/standing_instructions/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* Pre-constructed CRUD tools for model-visible standing instruction management.
|
|
10
|
+
*
|
|
11
|
+
* @module @nhtio/adk/batteries/tools/standing_instructions
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Pre-constructed CRUD tools that expose the ADK's standing-instruction surface to the
|
|
15
|
+
* model. Each tool delegates to the corresponding callback on the active
|
|
16
|
+
* {@link @nhtio/adk!DispatchContext} (`standingInstructions` getter, `storeStandingInstruction`,
|
|
17
|
+
* `deleteStandingInstruction`) — the persistence layer is whatever the consumer wired into
|
|
18
|
+
* the runner.
|
|
19
|
+
*
|
|
20
|
+
* Standing instructions are stored as a {@link Set} of {@link @nhtio/adk!Tokenizable} values keyed by
|
|
21
|
+
* identity, not by an `id` field — there is no separate "update by id" semantics. The tools
|
|
22
|
+
* therefore expose only `list` / `add` / `remove`. To replace an existing instruction the
|
|
23
|
+
* model should `remove` the old value and `add` the new one (the ADK's persistence layer
|
|
24
|
+
* is free to interpret that pair as an update if appropriate).
|
|
25
|
+
*
|
|
26
|
+
* Output is JSON for every tool so consumers can parse the result without re-tokenising —
|
|
27
|
+
* the artifact constructor is set to {@link @nhtio/adk!SpooledJsonArtifact}.
|
|
28
|
+
*
|
|
29
|
+
* Tools:
|
|
30
|
+
* - {@link listStandingInstructionsTool} — read-only list of every standing instruction
|
|
31
|
+
* currently held by the context (after refreshing from the persistence layer).
|
|
32
|
+
* - {@link addStandingInstructionTool} — add a new standing instruction.
|
|
33
|
+
* - {@link removeStandingInstructionTool} — remove a standing instruction by its content
|
|
34
|
+
* (exact string match).
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* List every standing instruction currently held by the active execution context.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* Calls `ctx.refreshStandingInstructions()` to ensure the local Set is in sync with the
|
|
41
|
+
* persistence layer, then serialises the resulting strings to a JSON array. The list is
|
|
42
|
+
* stringly-keyed; the same content string serves as the identifier for subsequent removes.
|
|
43
|
+
*/
|
|
44
|
+
var listStandingInstructionsTool = new Tool({
|
|
45
|
+
name: "list_standing_instructions",
|
|
46
|
+
description: "List every standing instruction currently held by the agent. Returns a JSON array of strings. To replace an instruction, remove the old string and add a new one.",
|
|
47
|
+
inputSchema: validator.object({}),
|
|
48
|
+
artifactConstructor: () => SpooledJsonArtifact,
|
|
49
|
+
handler: async (_args, ctx) => {
|
|
50
|
+
try {
|
|
51
|
+
const items = (await ctx.refreshStandingInstructions()).map((v) => typeof v === "string" ? v : v.toString());
|
|
52
|
+
return JSON.stringify(items, null, 2);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
return `Error: ${isError(err) ? err.message : String(err)}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Add a new standing instruction to the active execution context.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* Delegates to `ctx.storeStandingInstruction(content)`. Standing instructions are stored as
|
|
63
|
+
* a `Set` — adding the same content twice is a no-op at the local level, though the
|
|
64
|
+
* consumer's persistence callback may interpret it differently.
|
|
65
|
+
*/
|
|
66
|
+
var addStandingInstructionTool = new Tool({
|
|
67
|
+
name: "add_standing_instruction",
|
|
68
|
+
description: "Add a new standing instruction. Returns the stored content. Adding an identical instruction that already exists is a no-op.",
|
|
69
|
+
inputSchema: validator.object({ content: validator.string().required().description("The standing-instruction content as a plain string.") }),
|
|
70
|
+
artifactConstructor: () => SpooledJsonArtifact,
|
|
71
|
+
handler: async (args, ctx) => {
|
|
72
|
+
const { content } = args;
|
|
73
|
+
try {
|
|
74
|
+
await ctx.storeStandingInstruction(content);
|
|
75
|
+
return JSON.stringify({
|
|
76
|
+
ok: true,
|
|
77
|
+
content
|
|
78
|
+
}, null, 2);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
return `Error: ${isError(err) ? err.message : String(err)}`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* Remove an existing standing instruction by its content string.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* Delegates to `ctx.deleteStandingInstruction(content)`. Idempotent — succeeds even when
|
|
89
|
+
* no matching instruction is currently present.
|
|
90
|
+
*/
|
|
91
|
+
var removeStandingInstructionTool = new Tool({
|
|
92
|
+
name: "remove_standing_instruction",
|
|
93
|
+
description: "Remove a standing instruction by its exact content string. Idempotent — succeeds even when no match is present.",
|
|
94
|
+
inputSchema: validator.object({ content: validator.string().required().description("The exact content string of the instruction to remove.") }),
|
|
95
|
+
artifactConstructor: () => SpooledJsonArtifact,
|
|
96
|
+
handler: async (args, ctx) => {
|
|
97
|
+
const { content } = args;
|
|
98
|
+
try {
|
|
99
|
+
await ctx.deleteStandingInstruction(content);
|
|
100
|
+
return JSON.stringify({
|
|
101
|
+
ok: true,
|
|
102
|
+
content
|
|
103
|
+
}, null, 2);
|
|
104
|
+
} catch (err) {
|
|
105
|
+
return `Error: ${isError(err) ? err.message : String(err)}`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
/**
|
|
110
|
+
* Convenience tuple of every standing-instruction tool. Spread into a {@link @nhtio/adk!ToolRegistry}
|
|
111
|
+
* to register the entire category at once.
|
|
112
|
+
*/
|
|
113
|
+
var standingInstructionTools = [
|
|
114
|
+
listStandingInstructionsTool,
|
|
115
|
+
addStandingInstructionTool,
|
|
116
|
+
removeStandingInstructionTool
|
|
117
|
+
];
|
|
118
|
+
//#endregion
|
|
119
|
+
export { addStandingInstructionTool, listStandingInstructionsTool, removeStandingInstructionTool, standingInstructionTools };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=standing_instructions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standing_instructions.mjs","names":[],"sources":["../../../src/batteries/tools/standing_instructions/index.ts"],"sourcesContent":["/**\n * Pre-constructed CRUD tools for model-visible standing instruction management.\n *\n * @module @nhtio/adk/batteries/tools/standing_instructions\n *\n * @remarks\n * Pre-constructed CRUD tools that expose the ADK's standing-instruction surface to the\n * model. Each tool delegates to the corresponding callback on the active\n * {@link @nhtio/adk!DispatchContext} (`standingInstructions` getter, `storeStandingInstruction`,\n * `deleteStandingInstruction`) — the persistence layer is whatever the consumer wired into\n * the runner.\n *\n * Standing instructions are stored as a {@link Set} of {@link @nhtio/adk!Tokenizable} values keyed by\n * identity, not by an `id` field — there is no separate \"update by id\" semantics. The tools\n * therefore expose only `list` / `add` / `remove`. To replace an existing instruction the\n * model should `remove` the old value and `add` the new one (the ADK's persistence layer\n * is free to interpret that pair as an update if appropriate).\n *\n * Output is JSON for every tool so consumers can parse the result without re-tokenising —\n * the artifact constructor is set to {@link @nhtio/adk!SpooledJsonArtifact}.\n *\n * Tools:\n * - {@link listStandingInstructionsTool} — read-only list of every standing instruction\n * currently held by the context (after refreshing from the persistence layer).\n * - {@link addStandingInstructionTool} — add a new standing instruction.\n * - {@link removeStandingInstructionTool} — remove a standing instruction by its content\n * (exact string match).\n */\n\nimport { isError } from '@nhtio/adk/guards'\nimport { validator } from '@nhtio/validation'\nimport { SpooledJsonArtifact, Tool } from '@nhtio/adk/common'\n\n/**\n * List every standing instruction currently held by the active execution context.\n *\n * @remarks\n * Calls `ctx.refreshStandingInstructions()` to ensure the local Set is in sync with the\n * persistence layer, then serialises the resulting strings to a JSON array. The list is\n * stringly-keyed; the same content string serves as the identifier for subsequent removes.\n */\nexport const listStandingInstructionsTool = new Tool({\n name: 'list_standing_instructions',\n description:\n 'List every standing instruction currently held by the agent. Returns a JSON array of strings. To replace an instruction, remove the old string and add a new one.',\n inputSchema: validator.object({}),\n artifactConstructor: () => SpooledJsonArtifact,\n handler: async (_args, ctx) => {\n try {\n const refreshed = await ctx.refreshStandingInstructions()\n const items = refreshed.map((v) => (typeof v === 'string' ? v : v.toString()))\n return JSON.stringify(items, null, 2)\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Add a new standing instruction to the active execution context.\n *\n * @remarks\n * Delegates to `ctx.storeStandingInstruction(content)`. Standing instructions are stored as\n * a `Set` — adding the same content twice is a no-op at the local level, though the\n * consumer's persistence callback may interpret it differently.\n */\nexport const addStandingInstructionTool = new Tool({\n name: 'add_standing_instruction',\n description:\n 'Add a new standing instruction. Returns the stored content. Adding an identical instruction that already exists is a no-op.',\n inputSchema: validator.object({\n content: validator\n .string()\n .required()\n .description('The standing-instruction content as a plain string.'),\n }),\n artifactConstructor: () => SpooledJsonArtifact,\n handler: async (args, ctx) => {\n const { content } = args as { content: string }\n try {\n await ctx.storeStandingInstruction(content)\n return JSON.stringify({ ok: true, content }, null, 2)\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Remove an existing standing instruction by its content string.\n *\n * @remarks\n * Delegates to `ctx.deleteStandingInstruction(content)`. Idempotent — succeeds even when\n * no matching instruction is currently present.\n */\nexport const removeStandingInstructionTool = new Tool({\n name: 'remove_standing_instruction',\n description:\n 'Remove a standing instruction by its exact content string. Idempotent — succeeds even when no match is present.',\n inputSchema: validator.object({\n content: validator\n .string()\n .required()\n .description('The exact content string of the instruction to remove.'),\n }),\n artifactConstructor: () => SpooledJsonArtifact,\n handler: async (args, ctx) => {\n const { content } = args as { content: string }\n try {\n await ctx.deleteStandingInstruction(content)\n return JSON.stringify({ ok: true, content }, null, 2)\n } catch (err) {\n return `Error: ${isError(err) ? err.message : String(err)}`\n }\n },\n})\n\n/**\n * Convenience tuple of every standing-instruction tool. Spread into a {@link @nhtio/adk!ToolRegistry}\n * to register the entire category at once.\n */\nexport const standingInstructionTools = [\n listStandingInstructionsTool,\n addStandingInstructionTool,\n removeStandingInstructionTool,\n] as const\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,+BAA+B,IAAI,KAAK;CACnD,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO,CAAC,CAAC;CAChC,2BAA2B;CAC3B,SAAS,OAAO,OAAO,QAAQ;EAC7B,IAAI;GAEF,MAAM,SAAQ,MADU,IAAI,4BAA4B,GAChC,KAAK,MAAO,OAAO,MAAM,WAAW,IAAI,EAAE,SAAS,CAAE;GAC7E,OAAO,KAAK,UAAU,OAAO,MAAM,CAAC;EACtC,SAAS,KAAK;GACZ,OAAO,UAAU,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC;;;;;;;;;AAUD,IAAa,6BAA6B,IAAI,KAAK;CACjD,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO,EAC5B,SAAS,UACN,OAAO,EACP,SAAS,EACT,YAAY,qDAAqD,EACtE,CAAC;CACD,2BAA2B;CAC3B,SAAS,OAAO,MAAM,QAAQ;EAC5B,MAAM,EAAE,YAAY;EACpB,IAAI;GACF,MAAM,IAAI,yBAAyB,OAAO;GAC1C,OAAO,KAAK,UAAU;IAAE,IAAI;IAAM;GAAQ,GAAG,MAAM,CAAC;EACtD,SAAS,KAAK;GACZ,OAAO,UAAU,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC;;;;;;;;AASD,IAAa,gCAAgC,IAAI,KAAK;CACpD,MAAM;CACN,aACE;CACF,aAAa,UAAU,OAAO,EAC5B,SAAS,UACN,OAAO,EACP,SAAS,EACT,YAAY,wDAAwD,EACzE,CAAC;CACD,2BAA2B;CAC3B,SAAS,OAAO,MAAM,QAAQ;EAC5B,MAAM,EAAE,YAAY;EACpB,IAAI;GACF,MAAM,IAAI,0BAA0B,OAAO;GAC3C,OAAO,KAAK,UAAU;IAAE,IAAI;IAAM;GAAQ,GAAG,MAAM,CAAC;EACtD,SAAS,KAAK;GACZ,OAAO,UAAU,QAAQ,GAAG,IAAI,IAAI,UAAU,OAAO,GAAG;EAC1D;CACF;AACF,CAAC;;;;;AAMD,IAAa,2BAA2B;CACtC;CACA;CACA;AACF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-constructed tools for descriptive statistics, correlation, quantiles, and numeric summaries.
|
|
3
|
+
*
|
|
4
|
+
* @module @nhtio/adk/batteries/tools/statistics
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Pre-constructed bundled tools for the `statistics` category. Import individually, the whole
|
|
8
|
+
* category, or import every tool via `@nhtio/adk/batteries`.
|
|
9
|
+
*/
|
|
10
|
+
import { Tool, SpooledJsonArtifact } from "../../../common";
|
|
11
|
+
/**
|
|
12
|
+
* Compute descriptive statistics for a JSON array of numbers.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Returns count, sum, min/max/range, mean, median, mode, variance, standard deviation,
|
|
16
|
+
* quartiles (Q1/Q2/Q3), IQR, and key percentiles (P10/P90/P95/P99) as a pretty-printed JSON
|
|
17
|
+
* object. Non-numeric and non-finite entries are silently filtered.
|
|
18
|
+
*/
|
|
19
|
+
export declare const statsDescribeTool: Tool<SpooledJsonArtifact<unknown>>;
|
|
20
|
+
/**
|
|
21
|
+
* Compute the Pearson correlation coefficient between two numeric arrays.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Returns `r`, `r²` (as a percentage of explained variance), and a plain-English interpretation
|
|
25
|
+
* of strength and direction. Arrays must be the same length and contain at least two points.
|
|
26
|
+
*/
|
|
27
|
+
export declare const statsCorrelateTool: Tool<import("../../../common").SpooledArtifact>;
|
|
28
|
+
/**
|
|
29
|
+
* Transform a numeric array — normalise, smooth, rank, or detect outliers.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Supported operations: `normalize_min_max`, `normalize_z_score`, `normalize_percent_of_sum`,
|
|
33
|
+
* `running_total`, `rolling_avg`, `pct_change`, `rank`, `outliers_iqr`, `outliers_zscore`. Most
|
|
34
|
+
* operations return a JSON array of transformed values; outlier operations return a
|
|
35
|
+
* human-readable report.
|
|
36
|
+
*/
|
|
37
|
+
export declare const statsTransformTool: Tool<import("../../../common").SpooledArtifact>;
|
|
38
|
+
/**
|
|
39
|
+
* Bin a numeric array into equal-width histogram buckets.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Output is a text histogram showing each bin's range, count, percentage of total, and a bar
|
|
43
|
+
* chart. The last bin is inclusive on both ends; preceding bins are half-open. `bins` is clamped
|
|
44
|
+
* to `[2, 100]`.
|
|
45
|
+
*/
|
|
46
|
+
export declare const statsHistogramTool: Tool<import("../../../common").SpooledArtifact>;
|