@nhtio/adk 0.1.0-master-e04b0eba → 0.1.0-master-bd43a4ea
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/CHANGELOG.md +27 -0
- package/batteries/embeddings/index.d.ts +25 -0
- package/batteries/embeddings/openai/adapter.cjs +185 -0
- package/batteries/embeddings/openai/adapter.cjs.map +1 -0
- package/batteries/embeddings/openai/adapter.d.ts +74 -0
- package/batteries/embeddings/openai/adapter.mjs +183 -0
- package/batteries/embeddings/openai/adapter.mjs.map +1 -0
- package/batteries/embeddings/openai/exceptions.cjs +48 -0
- package/batteries/embeddings/openai/exceptions.cjs.map +1 -0
- package/batteries/embeddings/openai/exceptions.d.ts +45 -0
- package/batteries/embeddings/openai/exceptions.mjs +43 -0
- package/batteries/embeddings/openai/exceptions.mjs.map +1 -0
- package/batteries/embeddings/openai/helpers.cjs +25 -0
- package/batteries/embeddings/openai/helpers.cjs.map +1 -0
- package/batteries/embeddings/openai/helpers.d.ts +25 -0
- package/batteries/embeddings/openai/helpers.mjs +23 -0
- package/batteries/embeddings/openai/helpers.mjs.map +1 -0
- package/batteries/embeddings/openai/index.d.ts +17 -0
- package/batteries/embeddings/openai/types.cjs +2 -0
- package/batteries/embeddings/openai/types.d.ts +123 -0
- package/batteries/embeddings/openai/types.mjs +0 -0
- package/batteries/embeddings/openai/validation.cjs +56 -0
- package/batteries/embeddings/openai/validation.cjs.map +1 -0
- package/batteries/embeddings/openai/validation.d.ts +24 -0
- package/batteries/embeddings/openai/validation.mjs +53 -0
- package/batteries/embeddings/openai/validation.mjs.map +1 -0
- package/batteries/embeddings/openai.cjs +14 -0
- package/batteries/embeddings/openai.mjs +5 -0
- package/batteries/embeddings/webllm/adapter.cjs +147 -0
- package/batteries/embeddings/webllm/adapter.cjs.map +1 -0
- package/batteries/embeddings/webllm/adapter.d.ts +74 -0
- package/batteries/embeddings/webllm/adapter.mjs +145 -0
- package/batteries/embeddings/webllm/adapter.mjs.map +1 -0
- package/batteries/embeddings/webllm/exceptions.cjs +31 -0
- package/batteries/embeddings/webllm/exceptions.cjs.map +1 -0
- package/batteries/embeddings/webllm/exceptions.d.ts +25 -0
- package/batteries/embeddings/webllm/exceptions.mjs +28 -0
- package/batteries/embeddings/webllm/exceptions.mjs.map +1 -0
- package/batteries/embeddings/webllm/index.d.ts +15 -0
- package/batteries/embeddings/webllm/types.cjs +2 -0
- package/batteries/embeddings/webllm/types.d.ts +52 -0
- package/batteries/embeddings/webllm/types.mjs +0 -0
- package/batteries/embeddings/webllm/validation.cjs +43 -0
- package/batteries/embeddings/webllm/validation.cjs.map +1 -0
- package/batteries/embeddings/webllm/validation.d.ts +25 -0
- package/batteries/embeddings/webllm/validation.mjs +40 -0
- package/batteries/embeddings/webllm/validation.mjs.map +1 -0
- package/batteries/embeddings/webllm.cjs +10 -0
- package/batteries/embeddings/webllm.mjs +4 -0
- package/batteries/embeddings.cjs +15 -0
- package/batteries/embeddings.mjs +6 -0
- package/batteries/index.d.ts +1 -0
- package/batteries/llm/openai_chat_completions/adapter.cjs +14 -73
- package/batteries/llm/openai_chat_completions/adapter.cjs.map +1 -1
- package/batteries/llm/openai_chat_completions/adapter.mjs +8 -67
- package/batteries/llm/openai_chat_completions/adapter.mjs.map +1 -1
- package/batteries/llm/openai_chat_completions/helpers.cjs +2 -2
- package/batteries/llm/openai_chat_completions/helpers.mjs +2 -2
- package/batteries/llm/openai_chat_completions/validation.cjs +1 -1
- package/batteries/llm/openai_chat_completions/validation.mjs +1 -1
- package/batteries/llm/webllm_chat_completions/adapter.cjs +7 -6
- package/batteries/llm/webllm_chat_completions/adapter.cjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/adapter.mjs +7 -6
- package/batteries/llm/webllm_chat_completions/adapter.mjs.map +1 -1
- package/batteries/llm/webllm_chat_completions/validation.cjs +1 -1
- package/batteries/llm/webllm_chat_completions/validation.mjs +1 -1
- package/batteries/storage/flydrive.cjs +1 -1
- package/batteries/storage/flydrive.mjs +1 -1
- package/batteries/storage/in_memory.cjs +1 -1
- package/batteries/storage/in_memory.mjs +1 -1
- package/batteries/storage/opfs.cjs +1 -1
- package/batteries/storage/opfs.mjs +1 -1
- package/batteries/tools/color.cjs +2 -2
- package/batteries/tools/color.mjs +2 -2
- package/batteries/tools/comparison.cjs +3 -3
- package/batteries/tools/comparison.mjs +3 -3
- package/batteries/tools/data_structure.cjs +3 -3
- package/batteries/tools/data_structure.mjs +3 -3
- package/batteries/tools/datetime_extended.cjs +2 -2
- package/batteries/tools/datetime_extended.mjs +2 -2
- package/batteries/tools/datetime_math.cjs +2 -2
- package/batteries/tools/datetime_math.mjs +2 -2
- package/batteries/tools/encoding.cjs +3 -3
- package/batteries/tools/encoding.mjs +3 -3
- package/batteries/tools/formatting.cjs +3 -3
- package/batteries/tools/formatting.mjs +3 -3
- package/batteries/tools/geo_basics.cjs +2 -2
- package/batteries/tools/geo_basics.mjs +2 -2
- package/batteries/tools/math.cjs +3 -3
- package/batteries/tools/math.mjs +3 -3
- package/batteries/tools/memory.cjs +5 -5
- package/batteries/tools/memory.mjs +5 -5
- package/batteries/tools/parsing.cjs +4 -4
- package/batteries/tools/parsing.mjs +4 -4
- package/batteries/tools/retrievables.cjs +4 -4
- package/batteries/tools/retrievables.mjs +4 -4
- package/batteries/tools/standing_instructions.cjs +4 -4
- package/batteries/tools/standing_instructions.mjs +4 -4
- package/batteries/tools/statistics.cjs +4 -4
- package/batteries/tools/statistics.mjs +4 -4
- package/batteries/tools/string_processing.cjs +3 -3
- package/batteries/tools/string_processing.mjs +3 -3
- package/batteries/tools/structured_data.cjs +3 -3
- package/batteries/tools/structured_data.mjs +3 -3
- package/batteries/tools/text_analysis.cjs +3 -3
- package/batteries/tools/text_analysis.mjs +3 -3
- package/batteries/tools/text_comparison.cjs +2 -2
- package/batteries/tools/text_comparison.mjs +2 -2
- package/batteries/tools/time.cjs +2 -2
- package/batteries/tools/time.mjs +2 -2
- package/batteries/tools/unit_conversion.cjs +2 -2
- package/batteries/tools/unit_conversion.mjs +2 -2
- package/batteries.cjs +13 -0
- package/batteries.mjs +8 -3
- package/{common-DuKWGTVd.js → common-D_e5zYsG.js} +8 -8
- package/{common-DuKWGTVd.js.map → common-D_e5zYsG.js.map} +1 -1
- package/{common-ClCHam5-.mjs → common-lMrnzoyn.mjs} +8 -8
- package/{common-ClCHam5-.mjs.map → common-lMrnzoyn.mjs.map} +1 -1
- package/common.cjs +7 -7
- package/common.mjs +7 -7
- package/{dispatch_runner-uNtS-XSP.mjs → dispatch_runner-CDF3X0nv.mjs} +3 -3
- package/{dispatch_runner-uNtS-XSP.mjs.map → dispatch_runner-CDF3X0nv.mjs.map} +1 -1
- package/{dispatch_runner-CEFHXRJZ.js → dispatch_runner-CpuyATj1.js} +3 -3
- package/{dispatch_runner-CEFHXRJZ.js.map → dispatch_runner-CpuyATj1.js.map} +1 -1
- package/dispatch_runner.cjs +1 -1
- package/dispatch_runner.mjs +1 -1
- package/exceptions.cjs +1 -1
- package/exceptions.mjs +1 -1
- package/forge.cjs +4 -4
- package/forge.mjs +4 -4
- package/guards.cjs +8 -8
- package/guards.mjs +8 -8
- package/index.cjs +12 -12
- package/index.mjs +12 -12
- package/lib/exceptions/runtime.d.ts +5 -0
- package/lib/utils/retry.cjs +107 -0
- package/lib/utils/retry.cjs.map +1 -0
- package/lib/utils/retry.d.ts +63 -0
- package/lib/utils/retry.mjs +102 -0
- package/lib/utils/retry.mjs.map +1 -0
- package/mcp/adk-docs-corpus.json +1 -1
- package/package.json +138 -73
- package/{runtime-DyD9oQjH.js → runtime-MFFcJrRv.js} +6 -2
- package/runtime-MFFcJrRv.js.map +1 -0
- package/{runtime-CDIZwCT0.mjs → runtime-j92CNi5z.mjs} +6 -2
- package/runtime-j92CNi5z.mjs.map +1 -0
- package/skills/adk-assembly/SKILL.md +2 -2
- package/{spooled_artifact-CHvDDYGA.js → spooled_artifact-B8gIIn9h.js} +4 -4
- package/{spooled_artifact-CHvDDYGA.js.map → spooled_artifact-B8gIIn9h.js.map} +1 -1
- package/{spooled_artifact-D-JrpY4W.mjs → spooled_artifact-CWoKUDEm.mjs} +4 -4
- package/{spooled_artifact-D-JrpY4W.mjs.map → spooled_artifact-CWoKUDEm.mjs.map} +1 -1
- package/spooled_artifact.cjs +2 -2
- package/spooled_artifact.mjs +2 -2
- package/{spooled_markdown_artifact-B4eWOfCX.mjs → spooled_markdown_artifact-CNle4jXN.mjs} +3 -3
- package/{spooled_markdown_artifact-B4eWOfCX.mjs.map → spooled_markdown_artifact-CNle4jXN.mjs.map} +1 -1
- package/{spooled_markdown_artifact-BYfPqFvk.js → spooled_markdown_artifact-DQX0RCdI.js} +3 -3
- package/{spooled_markdown_artifact-BYfPqFvk.js.map → spooled_markdown_artifact-DQX0RCdI.js.map} +1 -1
- package/{thought-DBNsR6l8.js → thought-BD6AkkOr.js} +4 -4
- package/{thought-DBNsR6l8.js.map → thought-BD6AkkOr.js.map} +1 -1
- package/{thought-D9IS11b5.mjs → thought-B_P8LiB6.mjs} +4 -4
- package/{thought-D9IS11b5.mjs.map → thought-B_P8LiB6.mjs.map} +1 -1
- package/{tool-CsYuHhiS.mjs → tool-CRZSUcdP.mjs} +3 -3
- package/{tool-CsYuHhiS.mjs.map → tool-CRZSUcdP.mjs.map} +1 -1
- package/{tool-DIHzOZiV.js → tool-CX9vNHAw.js} +3 -3
- package/{tool-DIHzOZiV.js.map → tool-CX9vNHAw.js.map} +1 -1
- package/{tool_call-CkOVOhg0.js → tool_call--7ti-frB.js} +4 -4
- package/{tool_call-CkOVOhg0.js.map → tool_call--7ti-frB.js.map} +1 -1
- package/{tool_call-Bs_Q5LOG.mjs → tool_call-BUeMuCc6.mjs} +4 -4
- package/{tool_call-Bs_Q5LOG.mjs.map → tool_call-BUeMuCc6.mjs.map} +1 -1
- package/{tool_registry-CX3ofUh9.mjs → tool_registry-BGHg6KTq.mjs} +2 -2
- package/{tool_registry-CX3ofUh9.mjs.map → tool_registry-BGHg6KTq.mjs.map} +1 -1
- package/{tool_registry-CKk5ooxm.js → tool_registry-CtCQ4Xoz.js} +2 -2
- package/{tool_registry-CKk5ooxm.js.map → tool_registry-CtCQ4Xoz.js.map} +1 -1
- package/{turn_runner-D0qGIrRI.js → turn_runner-BJTtAORU.js} +7 -6
- package/turn_runner-BJTtAORU.js.map +1 -0
- package/{turn_runner-C1-mup84.mjs → turn_runner-C02LZHjt.mjs} +8 -7
- package/turn_runner-C02LZHjt.mjs.map +1 -0
- package/turn_runner.cjs +1 -1
- package/turn_runner.mjs +1 -1
- package/runtime-CDIZwCT0.mjs.map +0 -1
- package/runtime-DyD9oQjH.js.map +0 -1
- package/turn_runner-C1-mup84.mjs.map +0 -1
- package/turn_runner-D0qGIrRI.js.map +0 -1
package/batteries.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { E_INVALID_OPENAI_CHAT_COMPLETIONS_OPTIONS, E_OPENAI_CHAT_COMPLETIONS_CONTEXT_OVERFLOW, E_OPENAI_CHAT_COMPLETIONS_HTTP_ERROR, E_OPENAI_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS, E_OPENAI_CHAT_COMPLETIONS_REQUEST_TIMEOUT, E_OPENAI_CHAT_COMPLETIONS_STREAM_ERROR, E_OPENAI_CHAT_COMPLETIONS_STREAM_STALLED } from "./batteries/llm/openai_chat_completions/exceptions.mjs";
|
|
2
|
-
import { openAIChatCompletionsOptionsSchema, validateOptions } from "./batteries/llm/openai_chat_completions/validation.mjs";
|
|
2
|
+
import { openAIChatCompletionsOptionsSchema, validateOptions as validateOptions$1 } from "./batteries/llm/openai_chat_completions/validation.mjs";
|
|
3
3
|
import { buildChatCompletionsHistory, createChatCompletionsToolCallDeltaAccumulator, defaultBuildChatCompletionsHistory, defaultCreateChatCompletionsToolCallDeltaAccumulator, defaultDescriptionToChatCompletionsJsonSchema, defaultFilterThoughts, defaultRenderChatCompletionsSystemPrompt, defaultRenderChatCompletionsToolCallResult, defaultRenderFirstPartyRetrievables, defaultRenderMemories, defaultRenderRetrievableSafetyDirective, defaultRenderRetrievables, defaultRenderStandingInstructions, defaultRenderThirdPartyPrivateRetrievables, defaultRenderThirdPartyPublicRetrievables, defaultRenderThought, defaultRenderTimelineMessage, defaultRenderTrustedContent, defaultRenderUntrustedContent, defaultToolsToChatCompletionsTools, descriptionToChatCompletionsJsonSchema, filterThoughts, renderChatCompletionsSystemPrompt, renderChatCompletionsToolCallResult, renderFirstPartyRetrievables, renderMemories, renderRetrievableSafetyDirective, renderRetrievables, renderStandingInstructions, renderThirdPartyPrivateRetrievables, renderThirdPartyPublicRetrievables, renderThought, renderTimelineMessage, renderTrustedContent, renderUntrustedContent, toolsToChatCompletionsTools } from "./batteries/llm/openai_chat_completions/helpers.mjs";
|
|
4
4
|
import { OpenAIChatCompletionsAdapter } from "./batteries/llm/openai_chat_completions/adapter.mjs";
|
|
5
5
|
import { E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS, E_WEBLLM_CHAT_COMPLETIONS_CONTEXT_OVERFLOW, E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS, E_WEBLLM_CHAT_COMPLETIONS_STREAM_ERROR } from "./batteries/llm/webllm_chat_completions/exceptions.mjs";
|
|
6
|
-
import { validateOptions as validateOptions$
|
|
6
|
+
import { validateOptions as validateOptions$2, webLLMChatCompletionsOptionsSchema } from "./batteries/llm/webllm_chat_completions/validation.mjs";
|
|
7
7
|
import { WebLLMChatCompletionsAdapter } from "./batteries/llm/webllm_chat_completions/adapter.mjs";
|
|
8
8
|
import "./batteries/llm.mjs";
|
|
9
9
|
import { colorAdjustTool, colorContrastTool, colorSchemeTool } from "./batteries/tools/color.mjs";
|
|
@@ -27,4 +27,9 @@ import { stringSimilarityTool, textDiffTool } from "./batteries/tools/text_compa
|
|
|
27
27
|
import { convertTimeTool, getCurrentTimeTool } from "./batteries/tools/time.mjs";
|
|
28
28
|
import { convertUnitTool } from "./batteries/tools/unit_conversion.mjs";
|
|
29
29
|
import "./batteries/tools.mjs";
|
|
30
|
-
|
|
30
|
+
import { E_INVALID_OPENAI_EMBEDDINGS_OPTIONS, E_OPENAI_EMBEDDINGS_HTTP_ERROR, E_OPENAI_EMBEDDINGS_MALFORMED_RESPONSE, E_OPENAI_EMBEDDINGS_REQUEST_TIMEOUT } from "./batteries/embeddings/openai/exceptions.mjs";
|
|
31
|
+
import { openAIEmbeddingsOptionsSchema, validateOptions } from "./batteries/embeddings/openai/validation.mjs";
|
|
32
|
+
import { applyEmbeddingPrefix } from "./batteries/embeddings/openai/helpers.mjs";
|
|
33
|
+
import { OpenAIEmbeddingsAdapter } from "./batteries/embeddings/openai/adapter.mjs";
|
|
34
|
+
import "./batteries/embeddings.mjs";
|
|
35
|
+
export { E_INVALID_OPENAI_CHAT_COMPLETIONS_OPTIONS, E_INVALID_OPENAI_EMBEDDINGS_OPTIONS, E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS, E_OPENAI_CHAT_COMPLETIONS_CONTEXT_OVERFLOW, E_OPENAI_CHAT_COMPLETIONS_HTTP_ERROR, E_OPENAI_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS, E_OPENAI_CHAT_COMPLETIONS_REQUEST_TIMEOUT, E_OPENAI_CHAT_COMPLETIONS_STREAM_ERROR, E_OPENAI_CHAT_COMPLETIONS_STREAM_STALLED, E_OPENAI_EMBEDDINGS_HTTP_ERROR, E_OPENAI_EMBEDDINGS_MALFORMED_RESPONSE, E_OPENAI_EMBEDDINGS_REQUEST_TIMEOUT, E_WEBLLM_CHAT_COMPLETIONS_CONTEXT_OVERFLOW, E_WEBLLM_CHAT_COMPLETIONS_INVALID_TOOL_CALL_ARGS, E_WEBLLM_CHAT_COMPLETIONS_STREAM_ERROR, OpenAIChatCompletionsAdapter, OpenAIEmbeddingsAdapter, WebLLMChatCompletionsAdapter, addStandingInstructionTool, applyEmbeddingPrefix, buildChatCompletionsHistory, calculateTool, colorAdjustTool, colorContrastTool, colorSchemeTool, compareRecordsTool, compareValuesTool, convertTimeTool, convertUnitTool, createChatCompletionsToolCallDeltaAccumulator, dateAddTool, dateBusinessDaysTool, dateCalendarInfoTool, dateDiffTool, dateNthWeekdayTool, dateParseTool, datePeriodTool, defaultBuildChatCompletionsHistory, defaultCreateChatCompletionsToolCallDeltaAccumulator, defaultDescriptionToChatCompletionsJsonSchema, defaultFilterThoughts, defaultRenderChatCompletionsSystemPrompt, defaultRenderChatCompletionsToolCallResult, defaultRenderFirstPartyRetrievables, defaultRenderMemories, defaultRenderRetrievableSafetyDirective, defaultRenderRetrievables, defaultRenderStandingInstructions, defaultRenderThirdPartyPrivateRetrievables, defaultRenderThirdPartyPublicRetrievables, defaultRenderThought, defaultRenderTimelineMessage, defaultRenderTrustedContent, defaultRenderUntrustedContent, defaultToolsToChatCompletionsTools, deleteMemoryTool, deleteRetrievableTool, descriptionToChatCompletionsJsonSchema, detectDelimiterTool, durationFormatTool, encodeTextTool, evaluateKatexTool, filterThoughts, formatListTool, formatNumberTool, formatTableTool, geoBboxContainsTool, geoDistanceTool, geoWithinRadiusTool, getCurrentTimeTool, jsonFormatTool, jsonTransformTool, listMemoriesTool, listRetrievablesTool, listStandingInstructionsTool, memoryTools, openAIChatCompletionsOptionsSchema, openAIEmbeddingsOptionsSchema, parseCsvTool, parseKvTool, parseYamlTool, removeStandingInstructionTool, renderChatCompletionsSystemPrompt, renderChatCompletionsToolCallResult, renderFirstPartyRetrievables, renderMemories, renderRetrievableSafetyDirective, renderRetrievables, renderStandingInstructions, renderThirdPartyPrivateRetrievables, renderThirdPartyPublicRetrievables, renderThought, renderTimelineMessage, renderTrustedContent, renderUntrustedContent, retrievableTools, setOperationsTool, standingInstructionTools, statsCorrelateTool, statsDescribeTool, statsHistogramTool, statsTransformTool, storeMemoryTool, storeRetrievableTool, stringExtractTool, stringSimilarityTool, stringTransformTool, textAnalyzeTool, textDiffTool, textEscapeTool, textLinesTool, toolsToChatCompletionsTools, unicodeNormalizeTool, updateMemoryTool, updateRetrievableTool, validateFormatTool, validateOptions as validateOpenAIEmbeddingsOptions, validateOptions$1 as validateOptions, validateOptions$2 as validateWebLLMChatCompletionsOptions, webLLMChatCompletionsOptionsSchema };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
require("./chunk-Ble4zEEl.js");
|
|
2
2
|
const require_exceptions = require("./exceptions-CitH5wZI.js");
|
|
3
|
-
const require_tool_registry = require("./tool_registry-
|
|
4
|
-
const require_runtime = require("./runtime-
|
|
5
|
-
require("./thought-
|
|
6
|
-
require("./tool-
|
|
7
|
-
const require_spooled_artifact = require("./spooled_artifact-
|
|
8
|
-
require("./tool_call-
|
|
9
|
-
require("./spooled_markdown_artifact-
|
|
3
|
+
const require_tool_registry = require("./tool_registry-CtCQ4Xoz.js");
|
|
4
|
+
const require_runtime = require("./runtime-MFFcJrRv.js");
|
|
5
|
+
require("./thought-BD6AkkOr.js");
|
|
6
|
+
require("./tool-CX9vNHAw.js");
|
|
7
|
+
const require_spooled_artifact = require("./spooled_artifact-B8gIIn9h.js");
|
|
8
|
+
require("./tool_call--7ti-frB.js");
|
|
9
|
+
require("./spooled_markdown_artifact-DQX0RCdI.js");
|
|
10
10
|
let _nhtio_validation = require("@nhtio/validation");
|
|
11
11
|
//#region src/lib/classes/retrievable.ts
|
|
12
12
|
/**
|
|
@@ -307,4 +307,4 @@ Object.defineProperty(exports, "inMemoryMediaReader", {
|
|
|
307
307
|
}
|
|
308
308
|
});
|
|
309
309
|
|
|
310
|
-
//# sourceMappingURL=common-
|
|
310
|
+
//# sourceMappingURL=common-D_e5zYsG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-DuKWGTVd.js","names":["#id","#content","#trustTier","#source","#kind","#score","#createdAt","#updatedAt"],"sources":["../src/lib/classes/retrievable.ts","../src/lib/contracts/byte_store.ts","../src/lib/helpers/media_readers.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { SpooledArtifact } from './spooled_artifact'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_RETRIEVABLE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { TokenEncoding } from './tokenizable'\n\n/**\n * Trust-tier discriminator declared by the retrieval middleware at construction time. Drives\n * which envelope the LLM battery wraps the record in.\n *\n * @remarks\n * Vocabulary deliberately mirrors the published security-research taxonomy (\"first-party /\n * third-party\" per *Hidden-in-Plain-Text* WWW '26 and *When AI Meets the Web* IEEE S&P 2026)\n * and explicitly avoids the words \"user\" or \"system\" so the names cannot leak into the model's\n * OpenAI-Model-Spec role-tier authority resolution.\n *\n * - `'first-party'` — deployer-vetted corpora (signed internal docs, policy KBs, curated\n * reference material). Rendered as a `<retrieved_corpus>` parent with per-record nonce-keyed\n * `<retrieved>` children. The label \"first-party\" never appears in the envelope itself.\n * - `'third-party-public'` — open-web scrapes, search results, public APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-public'`.\n * - `'third-party-private'` — user uploads, pasted attachments, partner APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-private'`.\n */\nexport type RetrievableTrustTier = 'first-party' | 'third-party-public' | 'third-party-private'\n\n/**\n * Plain input object supplied to {@link Retrievable} at construction time.\n *\n * @remarks\n * Validated against `rawRetrievableSchema` before the `Retrievable` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawRetrievable {\n /**\n * Stable unique identifier for this retrieved record. Used as the closing-tag nonce in the\n * rendered envelope, so it must be unguessable from the payload.\n */\n id: string\n /**\n * The retrieved content. A plain `string` or {@link @nhtio/adk!Tokenizable} for small inline text, or a\n * {@link @nhtio/adk!SpooledArtifact} when the extracted text is large and lives in a consumer\n * {@link @nhtio/adk!ByteStore} (persist it via {@link @nhtio/adk!DispatchContext.storeRetrievableBytes}, wrap\n * the returned reader in a `SpooledArtifact`, and pass it here). Reader-backed content keeps the\n * body out of the permanent heap, but token estimation and render still materialise it\n * transiently (see {@link Retrievable.estimateTokens}).\n */\n content: string | Tokenizable | SpooledArtifact\n /**\n * Trust tier declared by the retrieval middleware at construction time. Required — there is\n * NO default. The decision must be conscious. See {@link RetrievableTrustTier}.\n */\n trustTier: RetrievableTrustTier\n /** Optional provenance string: URL, document path, knowledge-base id, etc. */\n source?: string\n /** Optional semantic label: 'policy' | 'reference' | 'web-page' | 'pdf' | etc. */\n kind?: string\n /** Optional relevance / similarity score in `[0, 1]` from the retrieval middleware. */\n score?: number\n /** When the source record was created (publication date, upload date, etc.). */\n createdAt: string | number | Date | DateTime\n /** When the source record was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawRetrievable} where all fields have been validated and temporal\n * values normalised to Luxon `DateTime` instances.\n */\ninterface ResolvedRetrievable {\n id: string\n content: Tokenizable | SpooledArtifact\n trustTier: RetrievableTrustTier\n source?: string\n kind?: string\n score?: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawRetrievable} before constructing a\n * {@link Retrievable}.\n *\n * @remarks\n * - `id` — required non-empty string.\n * - `content` — required {@link @nhtio/adk!Tokenizable.schema}.\n * - `trustTier` — required, one of `'first-party'`, `'third-party-public'`,\n * `'third-party-private'`. Unknown / missing values reject.\n * - `source` / `kind` — optional strings.\n * - `score` — optional number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values.\n *\n * Throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} (via the {@link Retrievable} constructor)\n * when validation fails.\n */\nconst contentSchema = validator.alternatives(\n validator.string(),\n validator.custom((value, helpers) => {\n if (Tokenizable.isTokenizable(value) || SpooledArtifact.isSpooledArtifact(value)) {\n return value\n }\n return helpers.error('any.invalid')\n })\n)\n\nconst rawRetrievableSchema = validator.object<RawRetrievable>({\n id: validator.string().required(),\n content: contentSchema.required(),\n trustTier: validator\n .string()\n .valid('first-party', 'third-party-public', 'third-party-private')\n .required(),\n source: validator.string().optional(),\n kind: validator.string().optional(),\n score: validator.number().min(0).max(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated retrieved record (RAG content) held by the agent.\n *\n * @remarks\n * Peer of {@link @nhtio/adk!Memory} / `Message` / `Thought` / `ToolCall`. Carries an explicit `trustTier`\n * that LLM batteries branch on to choose the rendering envelope. The retrieval middleware that\n * produced the record is the only party that knows its provenance — batteries MUST NOT\n * auto-classify or infer the tier from `source`.\n */\nexport class Retrievable {\n /**\n * Validator schema that accepts a {@link RawRetrievable} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a retrievable record.\n */\n public static schema = rawRetrievableSchema\n\n /**\n * Returns `true` if `value` is a {@link Retrievable} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.\n */\n public static isRetrievable(value: unknown): value is Retrievable {\n return isInstanceOf(value, 'Retrievable', Retrievable)\n }\n\n /** Stable unique identifier for this retrieved record. */\n declare readonly id: string\n /**\n * The retrieved content: a {@link @nhtio/adk!Tokenizable} (inline text) or a\n * {@link @nhtio/adk!SpooledArtifact} (reader-backed, large text living in a consumer store). Use\n * {@link Retrievable.estimateTokens} for budgeting and {@link Retrievable.contentString} to\n * materialise the body at render time.\n */\n declare readonly content: Tokenizable | SpooledArtifact\n /** Trust tier declared by the retrieval middleware. */\n declare readonly trustTier: RetrievableTrustTier\n /** Optional provenance string. */\n declare readonly source: string | undefined\n /** Optional semantic label. */\n declare readonly kind: string | undefined\n /** Optional relevance / similarity score in `[0, 1]`. */\n declare readonly score: number | undefined\n /** When the source record was created. */\n declare readonly createdAt: DateTime\n /** When the source record was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable | SpooledArtifact\n #trustTier: RetrievableTrustTier\n #source: string | undefined\n #kind: string | undefined\n #score: number | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw retrievable input validated against `rawRetrievableSchema`.\n * @throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawRetrievable) {\n let resolved: ResolvedRetrievable\n try {\n resolved = validateOrThrow<ResolvedRetrievable>(rawRetrievableSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_RETRIEVABLE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content =\n Tokenizable.isTokenizable(resolved.content) ||\n SpooledArtifact.isSpooledArtifact(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#trustTier = resolved.trustTier\n this.#source = resolved.source\n this.#kind = resolved.kind\n this.#score = resolved.score\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n trustTier: {\n get: () => this.#trustTier,\n enumerable: true,\n configurable: false,\n },\n source: {\n get: () => this.#source,\n enumerable: true,\n configurable: false,\n },\n kind: {\n get: () => this.#kind,\n enumerable: true,\n configurable: false,\n },\n score: {\n get: () => this.#score,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Estimates the token count of the content under `encoding`.\n *\n * @remarks\n * Delegates to the content's own `estimateTokens`: synchronous for a {@link @nhtio/adk!Tokenizable}\n * (returns `number`), asynchronous for a {@link @nhtio/adk!SpooledArtifact} (returns\n * `Promise<number>`, reading the bytes from the backing store on demand). Both shapes satisfy the\n * adapter's token-budget path, which already awaits estimates.\n *\n * Note: the `SpooledArtifact` branch materialises the full decoded string transiently to count\n * tokens — reader-backing keeps the body off the *permanent* heap, but does not eliminate the\n * transient allocation at budgeting time.\n *\n * @param encoding - The encoding identifier to use for counting.\n * @returns The estimated token count.\n */\n estimateTokens(encoding: TokenEncoding): number | Promise<number> {\n return this.#content.estimateTokens(encoding)\n }\n\n /**\n * Returns the content body as a single string.\n *\n * @remarks\n * For a {@link @nhtio/adk!Tokenizable} this is synchronous in effect (resolved immediately); for a\n * {@link @nhtio/adk!SpooledArtifact} it reads the full body from the backing store via\n * {@link @nhtio/adk!SpooledArtifact.asString}. Always returns a `Promise` so callers have one\n * code path; render helpers `await` it at the point the trust-tier envelope is built.\n *\n * @returns The full content body as a string.\n */\n async contentString(): Promise<string> {\n return SpooledArtifact.isSpooledArtifact(this.#content)\n ? this.#content.asString()\n : this.#content.toString()\n }\n}\n","import { validator } from '@nhtio/validation'\nimport { passesSchema } from '../utils/validation'\nimport type { SpoolReader } from './spool_reader'\nimport type { MediaReader } from './media_reader'\n\n/**\n * Unified \"give bytes, get a reader\" persistence contract.\n *\n * @remarks\n * For the purposes of storage there is no meaningful distinction between text and binary — bytes\n * are bytes. `ByteStore` is the single low-level shape every ADK storage layer implements: hand it\n * bytes under an `id`, get back a replayable reader `R`; read or delete by the same `id` later. The\n * generic `R` is the reader the store hands out — different reader contracts (line-indexed\n * {@link @nhtio/adk!SpoolReader} vs binary-streamed {@link @nhtio/adk!MediaReader}) are\n * distinguished by the `R` instantiation, not by separate store interfaces. See the {@link SpoolStore}\n * and {@link MediaStore} aliases for the two concrete semantics.\n *\n * `write` accepts a `string`, a `Uint8Array`, or a `ReadableStream<Uint8Array>`. The stream form is\n * the point of the contract: a durable store can persist an arbitrarily large payload straight to\n * disk/object storage without first materializing it in memory. **String input is encoded as\n * UTF-8.** The returned reader is only guaranteed readable once the `write` result has resolved.\n *\n * All three methods may be synchronous or asynchronous so that in-memory implementations are not\n * forced to pay promise overhead while I/O-backed implementations stay async. Note that any\n * implementation accepting a `ReadableStream` must return a `Promise` for that input — draining a\n * stream cannot be synchronous.\n */\nexport interface ByteStore<R> {\n /**\n * Persists `bytes` under `id` and returns a reader over them.\n *\n * @remarks\n * Re-writing the same `id` replaces the prior entry. `string` input is encoded as UTF-8;\n * `Uint8Array` and `ReadableStream<Uint8Array>` are stored byte-faithfully. Stream input\n * necessarily resolves asynchronously.\n *\n * @param id - Identifier used to retrieve or delete the bytes later.\n * @param bytes - The payload, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A reader over the stored bytes (or a `Promise` of one).\n */\n write(id: string, bytes: string | Uint8Array | ReadableStream<Uint8Array>): R | Promise<R>\n\n /**\n * Returns a reader over the bytes previously written under `id`, or `undefined` if no entry\n * exists.\n *\n * @param id - Identifier supplied to a prior {@link ByteStore.write} call.\n * @returns A reader over the stored bytes, `undefined`, or a `Promise` of either.\n */\n read(id: string): R | undefined | Promise<R | undefined>\n\n /**\n * Removes the entry under `id`.\n *\n * @param id - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise (or a `Promise` of one).\n */\n delete(id: string): boolean | Promise<boolean>\n}\n\n/**\n * A {@link ByteStore} that hands out line-indexed text readers ({@link @nhtio/adk!SpoolReader}).\n *\n * @remarks\n * The store backing tool-output artifacts. Stored bytes are decoded as UTF-8 text for line-oriented\n * reads; binary input is stored byte-faithfully but `SpoolReader.readAll()` interprets it as text,\n * so opaque binary belongs in a {@link MediaStore} / `Media`, not here.\n */\nexport type SpoolStore = ByteStore<SpoolReader>\n\n/**\n * A {@link ByteStore} that hands out binary-streamed readers ({@link @nhtio/adk!MediaReader}).\n *\n * @remarks\n * The store backing persisted media bytes. Stored bytes are opaque and replayable via\n * `MediaReader.stream()`; no text decoding is implied.\n */\nexport type MediaStore = ByteStore<MediaReader>\n\n/**\n * Validator schema used to validate a {@link ByteStore} value.\n *\n * @remarks\n * Because `ByteStore` is a structural interface with no associated constructor, validation is\n * duck-typed: the value must be non-null with `write`, `read`, and `delete` present as callable\n * properties. Arity is not enforced — implementations may add optional parameters beyond the\n * contract. The reader type `R` cannot be checked structurally here; conformance of the reader is\n * the caller's concern at the point of use.\n */\nexport const byteStoreSchema = validator.any().custom((value, helpers) => {\n if (\n value !== null &&\n value !== undefined &&\n typeof (value as any).write === 'function' &&\n typeof (value as any).read === 'function' &&\n typeof (value as any).delete === 'function'\n ) {\n return value\n }\n return helpers.error('any.invalid')\n})\n\n/**\n * Returns `true` if `value` implements the {@link ByteStore} interface.\n *\n * @remarks\n * Duck-typed: checks that `value` is non-null with `write`, `read`, and `delete` as callable\n * functions. Does not use `instanceof` — there is no `ByteStore` constructor.\n *\n * @param value - The value to test.\n * @returns `true` when `value` conforms to the {@link ByteStore} interface.\n */\nexport const implementsByteStore = <R = unknown>(value: unknown): value is ByteStore<R> => {\n return passesSchema(byteStoreSchema, value)\n}\n","import type { MediaReader } from '../contracts/media_reader'\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by an in-memory `Uint8Array`.\n *\n * @remarks\n * Each `stream()` call returns a fresh single-chunk `ReadableStream` over the same buffer. The\n * reader is re-openable by construction — call `stream()` as many times as needed.\n *\n * @param bytes - The buffer to serve.\n * @returns A {@link @nhtio/adk!MediaReader} that re-reads `bytes` on every call.\n */\nexport const inMemoryMediaReader = (bytes: Uint8Array): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.enqueue(bytes)\n controller.close()\n },\n })\n },\n byteLength(): number {\n return bytes.byteLength\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a fetch call.\n *\n * @remarks\n * Each `stream()` call re-issues the fetch. Tool authors whose underlying source is rate-limited\n * or expensive must cache locally before constructing the reader — the framework cannot make\n * that decision for them.\n *\n * `byteLength()` returns `undefined` because most remote sources do not promise it without an\n * extra HEAD request; consumers that need a byte size should resolve it out-of-band.\n *\n * @param url - The URL to fetch on each call.\n * @param init - Optional `fetch` init forwarded verbatim.\n * @returns A {@link @nhtio/adk!MediaReader} that re-issues `fetch(url, init)` on every call.\n */\nexport const fromFetch = (url: string | URL, init?: RequestInit): MediaReader => {\n return {\n async stream(): Promise<ReadableStream<Uint8Array>> {\n const response = await fetch(url, init)\n if (!response.ok) {\n throw new Error(`fromFetch: fetch failed with status ${response.status}`)\n }\n if (!response.body) {\n throw new Error('fromFetch: response has no body')\n }\n return response.body as ReadableStream<Uint8Array>\n },\n byteLength(): undefined {\n return undefined\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a browser `File` or `Blob`.\n *\n * @remarks\n * Each `stream()` call re-streams the underlying File via `File.stream()`. `byteLength()`\n * resolves from `file.size`.\n *\n * @param file - The browser `File` or `Blob` to stream.\n * @returns A {@link @nhtio/adk!MediaReader} that re-streams `file` on every call.\n */\nexport const fromWebFile = (file: Blob): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return file.stream() as ReadableStream<Uint8Array>\n },\n byteLength(): number {\n return file.size\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGA,IAAM,gBAAgB,kBAAA,UAAU,aAC9B,kBAAA,UAAU,OAAO,GACjB,kBAAA,UAAU,QAAQ,OAAO,YAAY;CACnC,IAAI,sBAAA,YAAY,cAAc,KAAK,KAAK,yBAAA,gBAAgB,kBAAkB,KAAK,GAC7E,OAAO;CAET,OAAO,QAAQ,MAAM,aAAa;AACpC,CAAC,CACH;AAEA,IAAM,uBAAuB,kBAAA,UAAU,OAAuB;CAC5D,IAAI,kBAAA,UAAU,OAAO,EAAE,SAAS;CAChC,SAAS,cAAc,SAAS;CAChC,WAAW,kBAAA,UACR,OAAO,EACP,MAAM,eAAe,sBAAsB,qBAAqB,EAChE,SAAS;CACZ,QAAQ,kBAAA,UAAU,OAAO,EAAE,SAAS;CACpC,MAAM,kBAAA,UAAU,OAAO,EAAE,SAAS;CAClC,OAAO,kBAAA,UAAU,OAAO,EAAE,IAAI,CAAC,EAAE,I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;;;;;;;;AAYA,IAAa,eAAe,SAA4B;CACtD,OAAO;EACL,SAAqC;GACnC,OAAO,KAAK,OAAO;EACrB;EACA,aAAqB;GACnB,OAAO,KAAK;EACd;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"common-D_e5zYsG.js","names":["#id","#content","#trustTier","#source","#kind","#score","#createdAt","#updatedAt"],"sources":["../src/lib/classes/retrievable.ts","../src/lib/contracts/byte_store.ts","../src/lib/helpers/media_readers.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { SpooledArtifact } from './spooled_artifact'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_RETRIEVABLE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { TokenEncoding } from './tokenizable'\n\n/**\n * Trust-tier discriminator declared by the retrieval middleware at construction time. Drives\n * which envelope the LLM battery wraps the record in.\n *\n * @remarks\n * Vocabulary deliberately mirrors the published security-research taxonomy (\"first-party /\n * third-party\" per *Hidden-in-Plain-Text* WWW '26 and *When AI Meets the Web* IEEE S&P 2026)\n * and explicitly avoids the words \"user\" or \"system\" so the names cannot leak into the model's\n * OpenAI-Model-Spec role-tier authority resolution.\n *\n * - `'first-party'` — deployer-vetted corpora (signed internal docs, policy KBs, curated\n * reference material). Rendered as a `<retrieved_corpus>` parent with per-record nonce-keyed\n * `<retrieved>` children. The label \"first-party\" never appears in the envelope itself.\n * - `'third-party-public'` — open-web scrapes, search results, public APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-public'`.\n * - `'third-party-private'` — user uploads, pasted attachments, partner APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-private'`.\n */\nexport type RetrievableTrustTier = 'first-party' | 'third-party-public' | 'third-party-private'\n\n/**\n * Plain input object supplied to {@link Retrievable} at construction time.\n *\n * @remarks\n * Validated against `rawRetrievableSchema` before the `Retrievable` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawRetrievable {\n /**\n * Stable unique identifier for this retrieved record. Used as the closing-tag nonce in the\n * rendered envelope, so it must be unguessable from the payload.\n */\n id: string\n /**\n * The retrieved content. A plain `string` or {@link @nhtio/adk!Tokenizable} for small inline text, or a\n * {@link @nhtio/adk!SpooledArtifact} when the extracted text is large and lives in a consumer\n * {@link @nhtio/adk!ByteStore} (persist it via {@link @nhtio/adk!DispatchContext.storeRetrievableBytes}, wrap\n * the returned reader in a `SpooledArtifact`, and pass it here). Reader-backed content keeps the\n * body out of the permanent heap, but token estimation and render still materialise it\n * transiently (see {@link Retrievable.estimateTokens}).\n */\n content: string | Tokenizable | SpooledArtifact\n /**\n * Trust tier declared by the retrieval middleware at construction time. Required — there is\n * NO default. The decision must be conscious. See {@link RetrievableTrustTier}.\n */\n trustTier: RetrievableTrustTier\n /** Optional provenance string: URL, document path, knowledge-base id, etc. */\n source?: string\n /** Optional semantic label: 'policy' | 'reference' | 'web-page' | 'pdf' | etc. */\n kind?: string\n /** Optional relevance / similarity score in `[0, 1]` from the retrieval middleware. */\n score?: number\n /** When the source record was created (publication date, upload date, etc.). */\n createdAt: string | number | Date | DateTime\n /** When the source record was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawRetrievable} where all fields have been validated and temporal\n * values normalised to Luxon `DateTime` instances.\n */\ninterface ResolvedRetrievable {\n id: string\n content: Tokenizable | SpooledArtifact\n trustTier: RetrievableTrustTier\n source?: string\n kind?: string\n score?: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawRetrievable} before constructing a\n * {@link Retrievable}.\n *\n * @remarks\n * - `id` — required non-empty string.\n * - `content` — required {@link @nhtio/adk!Tokenizable.schema}.\n * - `trustTier` — required, one of `'first-party'`, `'third-party-public'`,\n * `'third-party-private'`. Unknown / missing values reject.\n * - `source` / `kind` — optional strings.\n * - `score` — optional number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values.\n *\n * Throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} (via the {@link Retrievable} constructor)\n * when validation fails.\n */\nconst contentSchema = validator.alternatives(\n validator.string(),\n validator.custom((value, helpers) => {\n if (Tokenizable.isTokenizable(value) || SpooledArtifact.isSpooledArtifact(value)) {\n return value\n }\n return helpers.error('any.invalid')\n })\n)\n\nconst rawRetrievableSchema = validator.object<RawRetrievable>({\n id: validator.string().required(),\n content: contentSchema.required(),\n trustTier: validator\n .string()\n .valid('first-party', 'third-party-public', 'third-party-private')\n .required(),\n source: validator.string().optional(),\n kind: validator.string().optional(),\n score: validator.number().min(0).max(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated retrieved record (RAG content) held by the agent.\n *\n * @remarks\n * Peer of {@link @nhtio/adk!Memory} / `Message` / `Thought` / `ToolCall`. Carries an explicit `trustTier`\n * that LLM batteries branch on to choose the rendering envelope. The retrieval middleware that\n * produced the record is the only party that knows its provenance — batteries MUST NOT\n * auto-classify or infer the tier from `source`.\n */\nexport class Retrievable {\n /**\n * Validator schema that accepts a {@link RawRetrievable} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a retrievable record.\n */\n public static schema = rawRetrievableSchema\n\n /**\n * Returns `true` if `value` is a {@link Retrievable} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.\n */\n public static isRetrievable(value: unknown): value is Retrievable {\n return isInstanceOf(value, 'Retrievable', Retrievable)\n }\n\n /** Stable unique identifier for this retrieved record. */\n declare readonly id: string\n /**\n * The retrieved content: a {@link @nhtio/adk!Tokenizable} (inline text) or a\n * {@link @nhtio/adk!SpooledArtifact} (reader-backed, large text living in a consumer store). Use\n * {@link Retrievable.estimateTokens} for budgeting and {@link Retrievable.contentString} to\n * materialise the body at render time.\n */\n declare readonly content: Tokenizable | SpooledArtifact\n /** Trust tier declared by the retrieval middleware. */\n declare readonly trustTier: RetrievableTrustTier\n /** Optional provenance string. */\n declare readonly source: string | undefined\n /** Optional semantic label. */\n declare readonly kind: string | undefined\n /** Optional relevance / similarity score in `[0, 1]`. */\n declare readonly score: number | undefined\n /** When the source record was created. */\n declare readonly createdAt: DateTime\n /** When the source record was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable | SpooledArtifact\n #trustTier: RetrievableTrustTier\n #source: string | undefined\n #kind: string | undefined\n #score: number | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw retrievable input validated against `rawRetrievableSchema`.\n * @throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawRetrievable) {\n let resolved: ResolvedRetrievable\n try {\n resolved = validateOrThrow<ResolvedRetrievable>(rawRetrievableSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_RETRIEVABLE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content =\n Tokenizable.isTokenizable(resolved.content) ||\n SpooledArtifact.isSpooledArtifact(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#trustTier = resolved.trustTier\n this.#source = resolved.source\n this.#kind = resolved.kind\n this.#score = resolved.score\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n trustTier: {\n get: () => this.#trustTier,\n enumerable: true,\n configurable: false,\n },\n source: {\n get: () => this.#source,\n enumerable: true,\n configurable: false,\n },\n kind: {\n get: () => this.#kind,\n enumerable: true,\n configurable: false,\n },\n score: {\n get: () => this.#score,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Estimates the token count of the content under `encoding`.\n *\n * @remarks\n * Delegates to the content's own `estimateTokens`: synchronous for a {@link @nhtio/adk!Tokenizable}\n * (returns `number`), asynchronous for a {@link @nhtio/adk!SpooledArtifact} (returns\n * `Promise<number>`, reading the bytes from the backing store on demand). Both shapes satisfy the\n * adapter's token-budget path, which already awaits estimates.\n *\n * Note: the `SpooledArtifact` branch materialises the full decoded string transiently to count\n * tokens — reader-backing keeps the body off the *permanent* heap, but does not eliminate the\n * transient allocation at budgeting time.\n *\n * @param encoding - The encoding identifier to use for counting.\n * @returns The estimated token count.\n */\n estimateTokens(encoding: TokenEncoding): number | Promise<number> {\n return this.#content.estimateTokens(encoding)\n }\n\n /**\n * Returns the content body as a single string.\n *\n * @remarks\n * For a {@link @nhtio/adk!Tokenizable} this is synchronous in effect (resolved immediately); for a\n * {@link @nhtio/adk!SpooledArtifact} it reads the full body from the backing store via\n * {@link @nhtio/adk!SpooledArtifact.asString}. Always returns a `Promise` so callers have one\n * code path; render helpers `await` it at the point the trust-tier envelope is built.\n *\n * @returns The full content body as a string.\n */\n async contentString(): Promise<string> {\n return SpooledArtifact.isSpooledArtifact(this.#content)\n ? this.#content.asString()\n : this.#content.toString()\n }\n}\n","import { validator } from '@nhtio/validation'\nimport { passesSchema } from '../utils/validation'\nimport type { SpoolReader } from './spool_reader'\nimport type { MediaReader } from './media_reader'\n\n/**\n * Unified \"give bytes, get a reader\" persistence contract.\n *\n * @remarks\n * For the purposes of storage there is no meaningful distinction between text and binary — bytes\n * are bytes. `ByteStore` is the single low-level shape every ADK storage layer implements: hand it\n * bytes under an `id`, get back a replayable reader `R`; read or delete by the same `id` later. The\n * generic `R` is the reader the store hands out — different reader contracts (line-indexed\n * {@link @nhtio/adk!SpoolReader} vs binary-streamed {@link @nhtio/adk!MediaReader}) are\n * distinguished by the `R` instantiation, not by separate store interfaces. See the {@link SpoolStore}\n * and {@link MediaStore} aliases for the two concrete semantics.\n *\n * `write` accepts a `string`, a `Uint8Array`, or a `ReadableStream<Uint8Array>`. The stream form is\n * the point of the contract: a durable store can persist an arbitrarily large payload straight to\n * disk/object storage without first materializing it in memory. **String input is encoded as\n * UTF-8.** The returned reader is only guaranteed readable once the `write` result has resolved.\n *\n * All three methods may be synchronous or asynchronous so that in-memory implementations are not\n * forced to pay promise overhead while I/O-backed implementations stay async. Note that any\n * implementation accepting a `ReadableStream` must return a `Promise` for that input — draining a\n * stream cannot be synchronous.\n */\nexport interface ByteStore<R> {\n /**\n * Persists `bytes` under `id` and returns a reader over them.\n *\n * @remarks\n * Re-writing the same `id` replaces the prior entry. `string` input is encoded as UTF-8;\n * `Uint8Array` and `ReadableStream<Uint8Array>` are stored byte-faithfully. Stream input\n * necessarily resolves asynchronously.\n *\n * @param id - Identifier used to retrieve or delete the bytes later.\n * @param bytes - The payload, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A reader over the stored bytes (or a `Promise` of one).\n */\n write(id: string, bytes: string | Uint8Array | ReadableStream<Uint8Array>): R | Promise<R>\n\n /**\n * Returns a reader over the bytes previously written under `id`, or `undefined` if no entry\n * exists.\n *\n * @param id - Identifier supplied to a prior {@link ByteStore.write} call.\n * @returns A reader over the stored bytes, `undefined`, or a `Promise` of either.\n */\n read(id: string): R | undefined | Promise<R | undefined>\n\n /**\n * Removes the entry under `id`.\n *\n * @param id - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise (or a `Promise` of one).\n */\n delete(id: string): boolean | Promise<boolean>\n}\n\n/**\n * A {@link ByteStore} that hands out line-indexed text readers ({@link @nhtio/adk!SpoolReader}).\n *\n * @remarks\n * The store backing tool-output artifacts. Stored bytes are decoded as UTF-8 text for line-oriented\n * reads; binary input is stored byte-faithfully but `SpoolReader.readAll()` interprets it as text,\n * so opaque binary belongs in a {@link MediaStore} / `Media`, not here.\n */\nexport type SpoolStore = ByteStore<SpoolReader>\n\n/**\n * A {@link ByteStore} that hands out binary-streamed readers ({@link @nhtio/adk!MediaReader}).\n *\n * @remarks\n * The store backing persisted media bytes. Stored bytes are opaque and replayable via\n * `MediaReader.stream()`; no text decoding is implied.\n */\nexport type MediaStore = ByteStore<MediaReader>\n\n/**\n * Validator schema used to validate a {@link ByteStore} value.\n *\n * @remarks\n * Because `ByteStore` is a structural interface with no associated constructor, validation is\n * duck-typed: the value must be non-null with `write`, `read`, and `delete` present as callable\n * properties. Arity is not enforced — implementations may add optional parameters beyond the\n * contract. The reader type `R` cannot be checked structurally here; conformance of the reader is\n * the caller's concern at the point of use.\n */\nexport const byteStoreSchema = validator.any().custom((value, helpers) => {\n if (\n value !== null &&\n value !== undefined &&\n typeof (value as any).write === 'function' &&\n typeof (value as any).read === 'function' &&\n typeof (value as any).delete === 'function'\n ) {\n return value\n }\n return helpers.error('any.invalid')\n})\n\n/**\n * Returns `true` if `value` implements the {@link ByteStore} interface.\n *\n * @remarks\n * Duck-typed: checks that `value` is non-null with `write`, `read`, and `delete` as callable\n * functions. Does not use `instanceof` — there is no `ByteStore` constructor.\n *\n * @param value - The value to test.\n * @returns `true` when `value` conforms to the {@link ByteStore} interface.\n */\nexport const implementsByteStore = <R = unknown>(value: unknown): value is ByteStore<R> => {\n return passesSchema(byteStoreSchema, value)\n}\n","import type { MediaReader } from '../contracts/media_reader'\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by an in-memory `Uint8Array`.\n *\n * @remarks\n * Each `stream()` call returns a fresh single-chunk `ReadableStream` over the same buffer. The\n * reader is re-openable by construction — call `stream()` as many times as needed.\n *\n * @param bytes - The buffer to serve.\n * @returns A {@link @nhtio/adk!MediaReader} that re-reads `bytes` on every call.\n */\nexport const inMemoryMediaReader = (bytes: Uint8Array): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.enqueue(bytes)\n controller.close()\n },\n })\n },\n byteLength(): number {\n return bytes.byteLength\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a fetch call.\n *\n * @remarks\n * Each `stream()` call re-issues the fetch. Tool authors whose underlying source is rate-limited\n * or expensive must cache locally before constructing the reader — the framework cannot make\n * that decision for them.\n *\n * `byteLength()` returns `undefined` because most remote sources do not promise it without an\n * extra HEAD request; consumers that need a byte size should resolve it out-of-band.\n *\n * @param url - The URL to fetch on each call.\n * @param init - Optional `fetch` init forwarded verbatim.\n * @returns A {@link @nhtio/adk!MediaReader} that re-issues `fetch(url, init)` on every call.\n */\nexport const fromFetch = (url: string | URL, init?: RequestInit): MediaReader => {\n return {\n async stream(): Promise<ReadableStream<Uint8Array>> {\n const response = await fetch(url, init)\n if (!response.ok) {\n throw new Error(`fromFetch: fetch failed with status ${response.status}`)\n }\n if (!response.body) {\n throw new Error('fromFetch: response has no body')\n }\n return response.body as ReadableStream<Uint8Array>\n },\n byteLength(): undefined {\n return undefined\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a browser `File` or `Blob`.\n *\n * @remarks\n * Each `stream()` call re-streams the underlying File via `File.stream()`. `byteLength()`\n * resolves from `file.size`.\n *\n * @param file - The browser `File` or `Blob` to stream.\n * @returns A {@link @nhtio/adk!MediaReader} that re-streams `file` on every call.\n */\nexport const fromWebFile = (file: Blob): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return file.stream() as ReadableStream<Uint8Array>\n },\n byteLength(): number {\n return file.size\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGA,IAAM,gBAAgB,kBAAA,UAAU,aAC9B,kBAAA,UAAU,OAAO,GACjB,kBAAA,UAAU,QAAQ,OAAO,YAAY;CACnC,IAAI,sBAAA,YAAY,cAAc,KAAK,KAAK,yBAAA,gBAAgB,kBAAkB,KAAK,GAC7E,OAAO;CAET,OAAO,Q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,CAAC;EACH;EACA,aAAqB;GACnB,OAAO,MAAM;EACf;CACF;AACF;;;;;;;;;;;;;;;;AAiBA,IAAa,aAAa,KAAmB,SAAoC;CAC/E,OAAO;EACL,MAAM,SAA8C;GAClD,MAAM,WAAW,MAAM,MAAM,KAAK,IAAI;GACtC,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,uCAAuC,SAAS,QAAQ;GAE1E,IAAI,CAAC,SAAS,MACZ,MAAM,IAAI,MAAM,iCAAiC;GAEnD,OAAO,SAAS;EAClB;EACA,aAAwB,CAExB;CACF;AACF;;;;;;;;;;;AAYA,IAAa,eAAe,SAA4B;CACtD,OAAO;EACL,SAAqC;GACnC,OAAO,KAAK,OAAO;EACrB;EACA,aAAqB;GACnB,OAAO,KAAK;EACd;CACF;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { a as validateOrThrow, i as passesSchema } from "./exceptions-BeWH2FwP.mjs";
|
|
2
|
-
import { a as Tokenizable, o as isError, s as isInstanceOf } from "./tool_registry-
|
|
3
|
-
import { c as E_INVALID_INITIAL_RETRIEVABLE_VALUE } from "./runtime-
|
|
4
|
-
import "./thought-
|
|
5
|
-
import "./tool-
|
|
6
|
-
import { t as SpooledArtifact } from "./spooled_artifact-
|
|
7
|
-
import "./tool_call-
|
|
8
|
-
import "./spooled_markdown_artifact-
|
|
2
|
+
import { a as Tokenizable, o as isError, s as isInstanceOf } from "./tool_registry-BGHg6KTq.mjs";
|
|
3
|
+
import { c as E_INVALID_INITIAL_RETRIEVABLE_VALUE } from "./runtime-j92CNi5z.mjs";
|
|
4
|
+
import "./thought-B_P8LiB6.mjs";
|
|
5
|
+
import "./tool-CRZSUcdP.mjs";
|
|
6
|
+
import { t as SpooledArtifact } from "./spooled_artifact-CWoKUDEm.mjs";
|
|
7
|
+
import "./tool_call-BUeMuCc6.mjs";
|
|
8
|
+
import "./spooled_markdown_artifact-CNle4jXN.mjs";
|
|
9
9
|
import { validator } from "@nhtio/validation";
|
|
10
10
|
//#region src/lib/classes/retrievable.ts
|
|
11
11
|
/**
|
|
@@ -271,4 +271,4 @@ var fromWebFile = (file) => {
|
|
|
271
271
|
//#endregion
|
|
272
272
|
export { implementsByteStore as a, byteStoreSchema as i, fromWebFile as n, Retrievable as o, inMemoryMediaReader as r, fromFetch as t };
|
|
273
273
|
|
|
274
|
-
//# sourceMappingURL=common-
|
|
274
|
+
//# sourceMappingURL=common-lMrnzoyn.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-ClCHam5-.mjs","names":["#id","#content","#trustTier","#source","#kind","#score","#createdAt","#updatedAt"],"sources":["../src/lib/classes/retrievable.ts","../src/lib/contracts/byte_store.ts","../src/lib/helpers/media_readers.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { SpooledArtifact } from './spooled_artifact'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_RETRIEVABLE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { TokenEncoding } from './tokenizable'\n\n/**\n * Trust-tier discriminator declared by the retrieval middleware at construction time. Drives\n * which envelope the LLM battery wraps the record in.\n *\n * @remarks\n * Vocabulary deliberately mirrors the published security-research taxonomy (\"first-party /\n * third-party\" per *Hidden-in-Plain-Text* WWW '26 and *When AI Meets the Web* IEEE S&P 2026)\n * and explicitly avoids the words \"user\" or \"system\" so the names cannot leak into the model's\n * OpenAI-Model-Spec role-tier authority resolution.\n *\n * - `'first-party'` — deployer-vetted corpora (signed internal docs, policy KBs, curated\n * reference material). Rendered as a `<retrieved_corpus>` parent with per-record nonce-keyed\n * `<retrieved>` children. The label \"first-party\" never appears in the envelope itself.\n * - `'third-party-public'` — open-web scrapes, search results, public APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-public'`.\n * - `'third-party-private'` — user uploads, pasted attachments, partner APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-private'`.\n */\nexport type RetrievableTrustTier = 'first-party' | 'third-party-public' | 'third-party-private'\n\n/**\n * Plain input object supplied to {@link Retrievable} at construction time.\n *\n * @remarks\n * Validated against `rawRetrievableSchema` before the `Retrievable` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawRetrievable {\n /**\n * Stable unique identifier for this retrieved record. Used as the closing-tag nonce in the\n * rendered envelope, so it must be unguessable from the payload.\n */\n id: string\n /**\n * The retrieved content. A plain `string` or {@link @nhtio/adk!Tokenizable} for small inline text, or a\n * {@link @nhtio/adk!SpooledArtifact} when the extracted text is large and lives in a consumer\n * {@link @nhtio/adk!ByteStore} (persist it via {@link @nhtio/adk!DispatchContext.storeRetrievableBytes}, wrap\n * the returned reader in a `SpooledArtifact`, and pass it here). Reader-backed content keeps the\n * body out of the permanent heap, but token estimation and render still materialise it\n * transiently (see {@link Retrievable.estimateTokens}).\n */\n content: string | Tokenizable | SpooledArtifact\n /**\n * Trust tier declared by the retrieval middleware at construction time. Required — there is\n * NO default. The decision must be conscious. See {@link RetrievableTrustTier}.\n */\n trustTier: RetrievableTrustTier\n /** Optional provenance string: URL, document path, knowledge-base id, etc. */\n source?: string\n /** Optional semantic label: 'policy' | 'reference' | 'web-page' | 'pdf' | etc. */\n kind?: string\n /** Optional relevance / similarity score in `[0, 1]` from the retrieval middleware. */\n score?: number\n /** When the source record was created (publication date, upload date, etc.). */\n createdAt: string | number | Date | DateTime\n /** When the source record was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawRetrievable} where all fields have been validated and temporal\n * values normalised to Luxon `DateTime` instances.\n */\ninterface ResolvedRetrievable {\n id: string\n content: Tokenizable | SpooledArtifact\n trustTier: RetrievableTrustTier\n source?: string\n kind?: string\n score?: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawRetrievable} before constructing a\n * {@link Retrievable}.\n *\n * @remarks\n * - `id` — required non-empty string.\n * - `content` — required {@link @nhtio/adk!Tokenizable.schema}.\n * - `trustTier` — required, one of `'first-party'`, `'third-party-public'`,\n * `'third-party-private'`. Unknown / missing values reject.\n * - `source` / `kind` — optional strings.\n * - `score` — optional number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values.\n *\n * Throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} (via the {@link Retrievable} constructor)\n * when validation fails.\n */\nconst contentSchema = validator.alternatives(\n validator.string(),\n validator.custom((value, helpers) => {\n if (Tokenizable.isTokenizable(value) || SpooledArtifact.isSpooledArtifact(value)) {\n return value\n }\n return helpers.error('any.invalid')\n })\n)\n\nconst rawRetrievableSchema = validator.object<RawRetrievable>({\n id: validator.string().required(),\n content: contentSchema.required(),\n trustTier: validator\n .string()\n .valid('first-party', 'third-party-public', 'third-party-private')\n .required(),\n source: validator.string().optional(),\n kind: validator.string().optional(),\n score: validator.number().min(0).max(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated retrieved record (RAG content) held by the agent.\n *\n * @remarks\n * Peer of {@link @nhtio/adk!Memory} / `Message` / `Thought` / `ToolCall`. Carries an explicit `trustTier`\n * that LLM batteries branch on to choose the rendering envelope. The retrieval middleware that\n * produced the record is the only party that knows its provenance — batteries MUST NOT\n * auto-classify or infer the tier from `source`.\n */\nexport class Retrievable {\n /**\n * Validator schema that accepts a {@link RawRetrievable} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a retrievable record.\n */\n public static schema = rawRetrievableSchema\n\n /**\n * Returns `true` if `value` is a {@link Retrievable} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.\n */\n public static isRetrievable(value: unknown): value is Retrievable {\n return isInstanceOf(value, 'Retrievable', Retrievable)\n }\n\n /** Stable unique identifier for this retrieved record. */\n declare readonly id: string\n /**\n * The retrieved content: a {@link @nhtio/adk!Tokenizable} (inline text) or a\n * {@link @nhtio/adk!SpooledArtifact} (reader-backed, large text living in a consumer store). Use\n * {@link Retrievable.estimateTokens} for budgeting and {@link Retrievable.contentString} to\n * materialise the body at render time.\n */\n declare readonly content: Tokenizable | SpooledArtifact\n /** Trust tier declared by the retrieval middleware. */\n declare readonly trustTier: RetrievableTrustTier\n /** Optional provenance string. */\n declare readonly source: string | undefined\n /** Optional semantic label. */\n declare readonly kind: string | undefined\n /** Optional relevance / similarity score in `[0, 1]`. */\n declare readonly score: number | undefined\n /** When the source record was created. */\n declare readonly createdAt: DateTime\n /** When the source record was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable | SpooledArtifact\n #trustTier: RetrievableTrustTier\n #source: string | undefined\n #kind: string | undefined\n #score: number | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw retrievable input validated against `rawRetrievableSchema`.\n * @throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawRetrievable) {\n let resolved: ResolvedRetrievable\n try {\n resolved = validateOrThrow<ResolvedRetrievable>(rawRetrievableSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_RETRIEVABLE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content =\n Tokenizable.isTokenizable(resolved.content) ||\n SpooledArtifact.isSpooledArtifact(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#trustTier = resolved.trustTier\n this.#source = resolved.source\n this.#kind = resolved.kind\n this.#score = resolved.score\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n trustTier: {\n get: () => this.#trustTier,\n enumerable: true,\n configurable: false,\n },\n source: {\n get: () => this.#source,\n enumerable: true,\n configurable: false,\n },\n kind: {\n get: () => this.#kind,\n enumerable: true,\n configurable: false,\n },\n score: {\n get: () => this.#score,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Estimates the token count of the content under `encoding`.\n *\n * @remarks\n * Delegates to the content's own `estimateTokens`: synchronous for a {@link @nhtio/adk!Tokenizable}\n * (returns `number`), asynchronous for a {@link @nhtio/adk!SpooledArtifact} (returns\n * `Promise<number>`, reading the bytes from the backing store on demand). Both shapes satisfy the\n * adapter's token-budget path, which already awaits estimates.\n *\n * Note: the `SpooledArtifact` branch materialises the full decoded string transiently to count\n * tokens — reader-backing keeps the body off the *permanent* heap, but does not eliminate the\n * transient allocation at budgeting time.\n *\n * @param encoding - The encoding identifier to use for counting.\n * @returns The estimated token count.\n */\n estimateTokens(encoding: TokenEncoding): number | Promise<number> {\n return this.#content.estimateTokens(encoding)\n }\n\n /**\n * Returns the content body as a single string.\n *\n * @remarks\n * For a {@link @nhtio/adk!Tokenizable} this is synchronous in effect (resolved immediately); for a\n * {@link @nhtio/adk!SpooledArtifact} it reads the full body from the backing store via\n * {@link @nhtio/adk!SpooledArtifact.asString}. Always returns a `Promise` so callers have one\n * code path; render helpers `await` it at the point the trust-tier envelope is built.\n *\n * @returns The full content body as a string.\n */\n async contentString(): Promise<string> {\n return SpooledArtifact.isSpooledArtifact(this.#content)\n ? this.#content.asString()\n : this.#content.toString()\n }\n}\n","import { validator } from '@nhtio/validation'\nimport { passesSchema } from '../utils/validation'\nimport type { SpoolReader } from './spool_reader'\nimport type { MediaReader } from './media_reader'\n\n/**\n * Unified \"give bytes, get a reader\" persistence contract.\n *\n * @remarks\n * For the purposes of storage there is no meaningful distinction between text and binary — bytes\n * are bytes. `ByteStore` is the single low-level shape every ADK storage layer implements: hand it\n * bytes under an `id`, get back a replayable reader `R`; read or delete by the same `id` later. The\n * generic `R` is the reader the store hands out — different reader contracts (line-indexed\n * {@link @nhtio/adk!SpoolReader} vs binary-streamed {@link @nhtio/adk!MediaReader}) are\n * distinguished by the `R` instantiation, not by separate store interfaces. See the {@link SpoolStore}\n * and {@link MediaStore} aliases for the two concrete semantics.\n *\n * `write` accepts a `string`, a `Uint8Array`, or a `ReadableStream<Uint8Array>`. The stream form is\n * the point of the contract: a durable store can persist an arbitrarily large payload straight to\n * disk/object storage without first materializing it in memory. **String input is encoded as\n * UTF-8.** The returned reader is only guaranteed readable once the `write` result has resolved.\n *\n * All three methods may be synchronous or asynchronous so that in-memory implementations are not\n * forced to pay promise overhead while I/O-backed implementations stay async. Note that any\n * implementation accepting a `ReadableStream` must return a `Promise` for that input — draining a\n * stream cannot be synchronous.\n */\nexport interface ByteStore<R> {\n /**\n * Persists `bytes` under `id` and returns a reader over them.\n *\n * @remarks\n * Re-writing the same `id` replaces the prior entry. `string` input is encoded as UTF-8;\n * `Uint8Array` and `ReadableStream<Uint8Array>` are stored byte-faithfully. Stream input\n * necessarily resolves asynchronously.\n *\n * @param id - Identifier used to retrieve or delete the bytes later.\n * @param bytes - The payload, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A reader over the stored bytes (or a `Promise` of one).\n */\n write(id: string, bytes: string | Uint8Array | ReadableStream<Uint8Array>): R | Promise<R>\n\n /**\n * Returns a reader over the bytes previously written under `id`, or `undefined` if no entry\n * exists.\n *\n * @param id - Identifier supplied to a prior {@link ByteStore.write} call.\n * @returns A reader over the stored bytes, `undefined`, or a `Promise` of either.\n */\n read(id: string): R | undefined | Promise<R | undefined>\n\n /**\n * Removes the entry under `id`.\n *\n * @param id - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise (or a `Promise` of one).\n */\n delete(id: string): boolean | Promise<boolean>\n}\n\n/**\n * A {@link ByteStore} that hands out line-indexed text readers ({@link @nhtio/adk!SpoolReader}).\n *\n * @remarks\n * The store backing tool-output artifacts. Stored bytes are decoded as UTF-8 text for line-oriented\n * reads; binary input is stored byte-faithfully but `SpoolReader.readAll()` interprets it as text,\n * so opaque binary belongs in a {@link MediaStore} / `Media`, not here.\n */\nexport type SpoolStore = ByteStore<SpoolReader>\n\n/**\n * A {@link ByteStore} that hands out binary-streamed readers ({@link @nhtio/adk!MediaReader}).\n *\n * @remarks\n * The store backing persisted media bytes. Stored bytes are opaque and replayable via\n * `MediaReader.stream()`; no text decoding is implied.\n */\nexport type MediaStore = ByteStore<MediaReader>\n\n/**\n * Validator schema used to validate a {@link ByteStore} value.\n *\n * @remarks\n * Because `ByteStore` is a structural interface with no associated constructor, validation is\n * duck-typed: the value must be non-null with `write`, `read`, and `delete` present as callable\n * properties. Arity is not enforced — implementations may add optional parameters beyond the\n * contract. The reader type `R` cannot be checked structurally here; conformance of the reader is\n * the caller's concern at the point of use.\n */\nexport const byteStoreSchema = validator.any().custom((value, helpers) => {\n if (\n value !== null &&\n value !== undefined &&\n typeof (value as any).write === 'function' &&\n typeof (value as any).read === 'function' &&\n typeof (value as any).delete === 'function'\n ) {\n return value\n }\n return helpers.error('any.invalid')\n})\n\n/**\n * Returns `true` if `value` implements the {@link ByteStore} interface.\n *\n * @remarks\n * Duck-typed: checks that `value` is non-null with `write`, `read`, and `delete` as callable\n * functions. Does not use `instanceof` — there is no `ByteStore` constructor.\n *\n * @param value - The value to test.\n * @returns `true` when `value` conforms to the {@link ByteStore} interface.\n */\nexport const implementsByteStore = <R = unknown>(value: unknown): value is ByteStore<R> => {\n return passesSchema(byteStoreSchema, value)\n}\n","import type { MediaReader } from '../contracts/media_reader'\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by an in-memory `Uint8Array`.\n *\n * @remarks\n * Each `stream()` call returns a fresh single-chunk `ReadableStream` over the same buffer. The\n * reader is re-openable by construction — call `stream()` as many times as needed.\n *\n * @param bytes - The buffer to serve.\n * @returns A {@link @nhtio/adk!MediaReader} that re-reads `bytes` on every call.\n */\nexport const inMemoryMediaReader = (bytes: Uint8Array): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.enqueue(bytes)\n controller.close()\n },\n })\n },\n byteLength(): number {\n return bytes.byteLength\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a fetch call.\n *\n * @remarks\n * Each `stream()` call re-issues the fetch. Tool authors whose underlying source is rate-limited\n * or expensive must cache locally before constructing the reader — the framework cannot make\n * that decision for them.\n *\n * `byteLength()` returns `undefined` because most remote sources do not promise it without an\n * extra HEAD request; consumers that need a byte size should resolve it out-of-band.\n *\n * @param url - The URL to fetch on each call.\n * @param init - Optional `fetch` init forwarded verbatim.\n * @returns A {@link @nhtio/adk!MediaReader} that re-issues `fetch(url, init)` on every call.\n */\nexport const fromFetch = (url: string | URL, init?: RequestInit): MediaReader => {\n return {\n async stream(): Promise<ReadableStream<Uint8Array>> {\n const response = await fetch(url, init)\n if (!response.ok) {\n throw new Error(`fromFetch: fetch failed with status ${response.status}`)\n }\n if (!response.body) {\n throw new Error('fromFetch: response has no body')\n }\n return response.body as ReadableStream<Uint8Array>\n },\n byteLength(): undefined {\n return undefined\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a browser `File` or `Blob`.\n *\n * @remarks\n * Each `stream()` call re-streams the underlying File via `File.stream()`. `byteLength()`\n * resolves from `file.size`.\n *\n * @param file - The browser `File` or `Blob` to stream.\n * @returns A {@link @nhtio/adk!MediaReader} that re-streams `file` on every call.\n */\nexport const fromWebFile = (file: Blob): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return file.stream() as ReadableStream<Uint8Array>\n },\n byteLength(): number {\n return file.size\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoGA,IAAM,gBAAgB,UA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ACnB,EACF,CAAC;EACH;EACA,aAAqB;GACnB,OAAO,MAAM;EACf;CACF;AACF;;;;;;;;;;;;;;;;AAiBA,IAAa,aAAa,KAAmB,SAAoC;CAC/E,OAAO;EACL,MAAM,SAA8C;GAClD,MAAM,WAAW,MAAM,MAAM,KAAK,IAAI;GACtC,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,uCAAuC,SAAS,QAAQ;GAE1E,IAAI,CAAC,SAAS,MACZ,MAAM,IAAI,MAAM,iCAAiC;GAEnD,OAAO,SAAS;EAClB;EACA,aAAwB,CAExB;CACF;AACF;;;;;;;;;;;AAYA,IAAa,eAAe,SAA4B;CACtD,OAAO;EACL,SAAqC;GACnC,OAAO,KAAK,OAAO;EACrB;EACA,aAAqB;GACnB,OAAO,KAAK;EACd;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"common-lMrnzoyn.mjs","names":["#id","#content","#trustTier","#source","#kind","#score","#createdAt","#updatedAt"],"sources":["../src/lib/classes/retrievable.ts","../src/lib/contracts/byte_store.ts","../src/lib/helpers/media_readers.ts"],"sourcesContent":["import { Tokenizable } from './tokenizable'\nimport { validator } from '@nhtio/validation'\nimport { SpooledArtifact } from './spooled_artifact'\nimport { validateOrThrow } from '../utils/validation'\nimport { isInstanceOf, isError } from '../utils/guards'\nimport { E_INVALID_INITIAL_RETRIEVABLE_VALUE } from '../exceptions/runtime'\nimport type { DateTime } from 'luxon'\nimport type { TokenEncoding } from './tokenizable'\n\n/**\n * Trust-tier discriminator declared by the retrieval middleware at construction time. Drives\n * which envelope the LLM battery wraps the record in.\n *\n * @remarks\n * Vocabulary deliberately mirrors the published security-research taxonomy (\"first-party /\n * third-party\" per *Hidden-in-Plain-Text* WWW '26 and *When AI Meets the Web* IEEE S&P 2026)\n * and explicitly avoids the words \"user\" or \"system\" so the names cannot leak into the model's\n * OpenAI-Model-Spec role-tier authority resolution.\n *\n * - `'first-party'` — deployer-vetted corpora (signed internal docs, policy KBs, curated\n * reference material). Rendered as a `<retrieved_corpus>` parent with per-record nonce-keyed\n * `<retrieved>` children. The label \"first-party\" never appears in the envelope itself.\n * - `'third-party-public'` — open-web scrapes, search results, public APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-public'`.\n * - `'third-party-private'` — user uploads, pasted attachments, partner APIs. Rendered through\n * the untrusted-content envelope with `kind: 'retrieved-third-party-private'`.\n */\nexport type RetrievableTrustTier = 'first-party' | 'third-party-public' | 'third-party-private'\n\n/**\n * Plain input object supplied to {@link Retrievable} at construction time.\n *\n * @remarks\n * Validated against `rawRetrievableSchema` before the `Retrievable` instance is created.\n * Temporal fields accept any value that Luxon can parse — ISO strings, Unix timestamps,\n * `Date` objects, or existing `DateTime` instances.\n */\nexport interface RawRetrievable {\n /**\n * Stable unique identifier for this retrieved record. Used as the closing-tag nonce in the\n * rendered envelope, so it must be unguessable from the payload.\n */\n id: string\n /**\n * The retrieved content. A plain `string` or {@link @nhtio/adk!Tokenizable} for small inline text, or a\n * {@link @nhtio/adk!SpooledArtifact} when the extracted text is large and lives in a consumer\n * {@link @nhtio/adk!ByteStore} (persist it via {@link @nhtio/adk!DispatchContext.storeRetrievableBytes}, wrap\n * the returned reader in a `SpooledArtifact`, and pass it here). Reader-backed content keeps the\n * body out of the permanent heap, but token estimation and render still materialise it\n * transiently (see {@link Retrievable.estimateTokens}).\n */\n content: string | Tokenizable | SpooledArtifact\n /**\n * Trust tier declared by the retrieval middleware at construction time. Required — there is\n * NO default. The decision must be conscious. See {@link RetrievableTrustTier}.\n */\n trustTier: RetrievableTrustTier\n /** Optional provenance string: URL, document path, knowledge-base id, etc. */\n source?: string\n /** Optional semantic label: 'policy' | 'reference' | 'web-page' | 'pdf' | etc. */\n kind?: string\n /** Optional relevance / similarity score in `[0, 1]` from the retrieval middleware. */\n score?: number\n /** When the source record was created (publication date, upload date, etc.). */\n createdAt: string | number | Date | DateTime\n /** When the source record was last modified. */\n updatedAt: string | number | Date | DateTime\n}\n\n/**\n * A fully-resolved {@link RawRetrievable} where all fields have been validated and temporal\n * values normalised to Luxon `DateTime` instances.\n */\ninterface ResolvedRetrievable {\n id: string\n content: Tokenizable | SpooledArtifact\n trustTier: RetrievableTrustTier\n source?: string\n kind?: string\n score?: number\n createdAt: DateTime\n updatedAt: DateTime\n}\n\n/**\n * Validator schema used to validate a {@link RawRetrievable} before constructing a\n * {@link Retrievable}.\n *\n * @remarks\n * - `id` — required non-empty string.\n * - `content` — required {@link @nhtio/adk!Tokenizable.schema}.\n * - `trustTier` — required, one of `'first-party'`, `'third-party-public'`,\n * `'third-party-private'`. Unknown / missing values reject.\n * - `source` / `kind` — optional strings.\n * - `score` — optional number in `[0, 1]`.\n * - `createdAt` / `updatedAt` — required datetime-parseable values.\n *\n * Throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} (via the {@link Retrievable} constructor)\n * when validation fails.\n */\nconst contentSchema = validator.alternatives(\n validator.string(),\n validator.custom((value, helpers) => {\n if (Tokenizable.isTokenizable(value) || SpooledArtifact.isSpooledArtifact(value)) {\n return value\n }\n return helpers.error('any.invalid')\n })\n)\n\nconst rawRetrievableSchema = validator.object<RawRetrievable>({\n id: validator.string().required(),\n content: contentSchema.required(),\n trustTier: validator\n .string()\n .valid('first-party', 'third-party-public', 'third-party-private')\n .required(),\n source: validator.string().optional(),\n kind: validator.string().optional(),\n score: validator.number().min(0).max(1).optional(),\n createdAt: validator.datetime().required(),\n updatedAt: validator.datetime().required(),\n})\n\n/**\n * An immutable, validated retrieved record (RAG content) held by the agent.\n *\n * @remarks\n * Peer of {@link @nhtio/adk!Memory} / `Message` / `Thought` / `ToolCall`. Carries an explicit `trustTier`\n * that LLM batteries branch on to choose the rendering envelope. The retrieval middleware that\n * produced the record is the only party that knows its provenance — batteries MUST NOT\n * auto-classify or infer the tier from `source`.\n */\nexport class Retrievable {\n /**\n * Validator schema that accepts a {@link RawRetrievable} object.\n *\n * @remarks\n * Reusable fragment for any schema that needs to validate or nest a retrievable record.\n */\n public static schema = rawRetrievableSchema\n\n /**\n * Returns `true` if `value` is a {@link Retrievable} instance.\n *\n * @remarks\n * Uses {@link @nhtio/adk!isInstanceOf} for cross-realm safety.\n */\n public static isRetrievable(value: unknown): value is Retrievable {\n return isInstanceOf(value, 'Retrievable', Retrievable)\n }\n\n /** Stable unique identifier for this retrieved record. */\n declare readonly id: string\n /**\n * The retrieved content: a {@link @nhtio/adk!Tokenizable} (inline text) or a\n * {@link @nhtio/adk!SpooledArtifact} (reader-backed, large text living in a consumer store). Use\n * {@link Retrievable.estimateTokens} for budgeting and {@link Retrievable.contentString} to\n * materialise the body at render time.\n */\n declare readonly content: Tokenizable | SpooledArtifact\n /** Trust tier declared by the retrieval middleware. */\n declare readonly trustTier: RetrievableTrustTier\n /** Optional provenance string. */\n declare readonly source: string | undefined\n /** Optional semantic label. */\n declare readonly kind: string | undefined\n /** Optional relevance / similarity score in `[0, 1]`. */\n declare readonly score: number | undefined\n /** When the source record was created. */\n declare readonly createdAt: DateTime\n /** When the source record was last modified. */\n declare readonly updatedAt: DateTime\n\n #id: string\n #content: Tokenizable | SpooledArtifact\n #trustTier: RetrievableTrustTier\n #source: string | undefined\n #kind: string | undefined\n #score: number | undefined\n #createdAt: DateTime\n #updatedAt: DateTime\n\n /**\n * @param raw - The raw retrievable input validated against `rawRetrievableSchema`.\n * @throws {@link @nhtio/adk/exceptions!E_INVALID_INITIAL_RETRIEVABLE_VALUE} when `raw` does not satisfy the schema.\n */\n constructor(raw: RawRetrievable) {\n let resolved: ResolvedRetrievable\n try {\n resolved = validateOrThrow<ResolvedRetrievable>(rawRetrievableSchema, raw, true)\n } catch (err) {\n throw new E_INVALID_INITIAL_RETRIEVABLE_VALUE({ cause: isError(err) ? err : undefined })\n }\n this.#id = resolved.id\n this.#content =\n Tokenizable.isTokenizable(resolved.content) ||\n SpooledArtifact.isSpooledArtifact(resolved.content)\n ? resolved.content\n : new Tokenizable(resolved.content)\n this.#trustTier = resolved.trustTier\n this.#source = resolved.source\n this.#kind = resolved.kind\n this.#score = resolved.score\n this.#createdAt = resolved.createdAt\n this.#updatedAt = resolved.updatedAt\n\n Object.defineProperties(this, {\n id: {\n get: () => this.#id,\n enumerable: true,\n configurable: false,\n },\n content: {\n get: () => this.#content,\n enumerable: true,\n configurable: false,\n },\n trustTier: {\n get: () => this.#trustTier,\n enumerable: true,\n configurable: false,\n },\n source: {\n get: () => this.#source,\n enumerable: true,\n configurable: false,\n },\n kind: {\n get: () => this.#kind,\n enumerable: true,\n configurable: false,\n },\n score: {\n get: () => this.#score,\n enumerable: true,\n configurable: false,\n },\n createdAt: {\n get: () => this.#createdAt,\n enumerable: true,\n configurable: false,\n },\n updatedAt: {\n get: () => this.#updatedAt,\n enumerable: true,\n configurable: false,\n },\n })\n }\n\n /**\n * Estimates the token count of the content under `encoding`.\n *\n * @remarks\n * Delegates to the content's own `estimateTokens`: synchronous for a {@link @nhtio/adk!Tokenizable}\n * (returns `number`), asynchronous for a {@link @nhtio/adk!SpooledArtifact} (returns\n * `Promise<number>`, reading the bytes from the backing store on demand). Both shapes satisfy the\n * adapter's token-budget path, which already awaits estimates.\n *\n * Note: the `SpooledArtifact` branch materialises the full decoded string transiently to count\n * tokens — reader-backing keeps the body off the *permanent* heap, but does not eliminate the\n * transient allocation at budgeting time.\n *\n * @param encoding - The encoding identifier to use for counting.\n * @returns The estimated token count.\n */\n estimateTokens(encoding: TokenEncoding): number | Promise<number> {\n return this.#content.estimateTokens(encoding)\n }\n\n /**\n * Returns the content body as a single string.\n *\n * @remarks\n * For a {@link @nhtio/adk!Tokenizable} this is synchronous in effect (resolved immediately); for a\n * {@link @nhtio/adk!SpooledArtifact} it reads the full body from the backing store via\n * {@link @nhtio/adk!SpooledArtifact.asString}. Always returns a `Promise` so callers have one\n * code path; render helpers `await` it at the point the trust-tier envelope is built.\n *\n * @returns The full content body as a string.\n */\n async contentString(): Promise<string> {\n return SpooledArtifact.isSpooledArtifact(this.#content)\n ? this.#content.asString()\n : this.#content.toString()\n }\n}\n","import { validator } from '@nhtio/validation'\nimport { passesSchema } from '../utils/validation'\nimport type { SpoolReader } from './spool_reader'\nimport type { MediaReader } from './media_reader'\n\n/**\n * Unified \"give bytes, get a reader\" persistence contract.\n *\n * @remarks\n * For the purposes of storage there is no meaningful distinction between text and binary — bytes\n * are bytes. `ByteStore` is the single low-level shape every ADK storage layer implements: hand it\n * bytes under an `id`, get back a replayable reader `R`; read or delete by the same `id` later. The\n * generic `R` is the reader the store hands out — different reader contracts (line-indexed\n * {@link @nhtio/adk!SpoolReader} vs binary-streamed {@link @nhtio/adk!MediaReader}) are\n * distinguished by the `R` instantiation, not by separate store interfaces. See the {@link SpoolStore}\n * and {@link MediaStore} aliases for the two concrete semantics.\n *\n * `write` accepts a `string`, a `Uint8Array`, or a `ReadableStream<Uint8Array>`. The stream form is\n * the point of the contract: a durable store can persist an arbitrarily large payload straight to\n * disk/object storage without first materializing it in memory. **String input is encoded as\n * UTF-8.** The returned reader is only guaranteed readable once the `write` result has resolved.\n *\n * All three methods may be synchronous or asynchronous so that in-memory implementations are not\n * forced to pay promise overhead while I/O-backed implementations stay async. Note that any\n * implementation accepting a `ReadableStream` must return a `Promise` for that input — draining a\n * stream cannot be synchronous.\n */\nexport interface ByteStore<R> {\n /**\n * Persists `bytes` under `id` and returns a reader over them.\n *\n * @remarks\n * Re-writing the same `id` replaces the prior entry. `string` input is encoded as UTF-8;\n * `Uint8Array` and `ReadableStream<Uint8Array>` are stored byte-faithfully. Stream input\n * necessarily resolves asynchronously.\n *\n * @param id - Identifier used to retrieve or delete the bytes later.\n * @param bytes - The payload, as a `string`, `Uint8Array`, or `ReadableStream<Uint8Array>`.\n * @returns A reader over the stored bytes (or a `Promise` of one).\n */\n write(id: string, bytes: string | Uint8Array | ReadableStream<Uint8Array>): R | Promise<R>\n\n /**\n * Returns a reader over the bytes previously written under `id`, or `undefined` if no entry\n * exists.\n *\n * @param id - Identifier supplied to a prior {@link ByteStore.write} call.\n * @returns A reader over the stored bytes, `undefined`, or a `Promise` of either.\n */\n read(id: string): R | undefined | Promise<R | undefined>\n\n /**\n * Removes the entry under `id`.\n *\n * @param id - Identifier whose entry should be removed.\n * @returns `true` if an entry existed and was removed; `false` otherwise (or a `Promise` of one).\n */\n delete(id: string): boolean | Promise<boolean>\n}\n\n/**\n * A {@link ByteStore} that hands out line-indexed text readers ({@link @nhtio/adk!SpoolReader}).\n *\n * @remarks\n * The store backing tool-output artifacts. Stored bytes are decoded as UTF-8 text for line-oriented\n * reads; binary input is stored byte-faithfully but `SpoolReader.readAll()` interprets it as text,\n * so opaque binary belongs in a {@link MediaStore} / `Media`, not here.\n */\nexport type SpoolStore = ByteStore<SpoolReader>\n\n/**\n * A {@link ByteStore} that hands out binary-streamed readers ({@link @nhtio/adk!MediaReader}).\n *\n * @remarks\n * The store backing persisted media bytes. Stored bytes are opaque and replayable via\n * `MediaReader.stream()`; no text decoding is implied.\n */\nexport type MediaStore = ByteStore<MediaReader>\n\n/**\n * Validator schema used to validate a {@link ByteStore} value.\n *\n * @remarks\n * Because `ByteStore` is a structural interface with no associated constructor, validation is\n * duck-typed: the value must be non-null with `write`, `read`, and `delete` present as callable\n * properties. Arity is not enforced — implementations may add optional parameters beyond the\n * contract. The reader type `R` cannot be checked structurally here; conformance of the reader is\n * the caller's concern at the point of use.\n */\nexport const byteStoreSchema = validator.any().custom((value, helpers) => {\n if (\n value !== null &&\n value !== undefined &&\n typeof (value as any).write === 'function' &&\n typeof (value as any).read === 'function' &&\n typeof (value as any).delete === 'function'\n ) {\n return value\n }\n return helpers.error('any.invalid')\n})\n\n/**\n * Returns `true` if `value` implements the {@link ByteStore} interface.\n *\n * @remarks\n * Duck-typed: checks that `value` is non-null with `write`, `read`, and `delete` as callable\n * functions. Does not use `instanceof` — there is no `ByteStore` constructor.\n *\n * @param value - The value to test.\n * @returns `true` when `value` conforms to the {@link ByteStore} interface.\n */\nexport const implementsByteStore = <R = unknown>(value: unknown): value is ByteStore<R> => {\n return passesSchema(byteStoreSchema, value)\n}\n","import type { MediaReader } from '../contracts/media_reader'\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by an in-memory `Uint8Array`.\n *\n * @remarks\n * Each `stream()` call returns a fresh single-chunk `ReadableStream` over the same buffer. The\n * reader is re-openable by construction — call `stream()` as many times as needed.\n *\n * @param bytes - The buffer to serve.\n * @returns A {@link @nhtio/adk!MediaReader} that re-reads `bytes` on every call.\n */\nexport const inMemoryMediaReader = (bytes: Uint8Array): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.enqueue(bytes)\n controller.close()\n },\n })\n },\n byteLength(): number {\n return bytes.byteLength\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a fetch call.\n *\n * @remarks\n * Each `stream()` call re-issues the fetch. Tool authors whose underlying source is rate-limited\n * or expensive must cache locally before constructing the reader — the framework cannot make\n * that decision for them.\n *\n * `byteLength()` returns `undefined` because most remote sources do not promise it without an\n * extra HEAD request; consumers that need a byte size should resolve it out-of-band.\n *\n * @param url - The URL to fetch on each call.\n * @param init - Optional `fetch` init forwarded verbatim.\n * @returns A {@link @nhtio/adk!MediaReader} that re-issues `fetch(url, init)` on every call.\n */\nexport const fromFetch = (url: string | URL, init?: RequestInit): MediaReader => {\n return {\n async stream(): Promise<ReadableStream<Uint8Array>> {\n const response = await fetch(url, init)\n if (!response.ok) {\n throw new Error(`fromFetch: fetch failed with status ${response.status}`)\n }\n if (!response.body) {\n throw new Error('fromFetch: response has no body')\n }\n return response.body as ReadableStream<Uint8Array>\n },\n byteLength(): undefined {\n return undefined\n },\n }\n}\n\n/**\n * Constructs a {@link @nhtio/adk!MediaReader} backed by a browser `File` or `Blob`.\n *\n * @remarks\n * Each `stream()` call re-streams the underlying File via `File.stream()`. `byteLength()`\n * resolves from `file.size`.\n *\n * @param file - The browser `File` or `Blob` to stream.\n * @returns A {@link @nhtio/adk!MediaReader} that re-streams `file` on every call.\n */\nexport const fromWebFile = (file: Blob): MediaReader => {\n return {\n stream(): ReadableStream<Uint8Array> {\n return file.stream() as ReadableStream<Uint8Array>\n },\n byteLength(): number {\n return file.size\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoGA,IAAM,gBAAgB,UAAU,aAC9B,UAAU,OAAO,GACjB,UAAU,QAAQ,OAAO,YAAY;CACnC,IAAI,YAAY,cAAc,KAAK,KAAK,gBAAgB,kBAAkB,KAAK,GAC7E,OAAO;CAET,OAAO,QAAQ,MAAM,aAAa;AACpC,CAAC,CACH;AAEA,IAAM,uBAAuB,UAAU,OAAuB;CAC5D,IAAI,UAAU,OAAO,EAAE,SAAS;CAChC,SAAS,cAAc,SAAS;CAChC,WAAW,UACR,OAAO,EACP,MAAM,eAAe,sBAAsB,qBAAqB,EAChE,SAAS;CACZ,QAAQ,UAAU,OAAO,EAAE,SAAS;CACpC,MAAM,UAAU,OAAO,EAAE,SAAS;CAClC,OAAO,UAAU,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;CACjD,WAAW,UAAU,SAAS,EAAE,SAAS;CACzC,WAAW,UAAU,SAAS,EAAE,SAAS;AAC3C,CAAC;;;;;;;;;;AAWD,IAAa,cAAb,MAAa,YAAY;;;;;;;CAOvB,OAAc,SAAS;;;;;;;CAQvB,OAAc,cAAc,OAAsC;EAChE,OAAO,aAAa,OAAO,eAAe,WAAW;CACvD;CAwBA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;CAMA,YAAY,KAAqB;EAC/B,IAAI;EACJ,IAAI;GACF,WAAW,gBAAqC,sBAAsB,KAAK,IAAI;EACjF,SAAS,KAAK;GACZ,MAAM,IAAI,oCAAoC,EAAE,OAAO,QAAQ,GAAG,IAAI,MAAM,KAAA,EAAU,CAAC;EACzF;EACA,KAAKA,MAAM,SAAS;EACpB,KAAKC,WACH,YAAY,cAAc,SAAS,OAAO,KAC1C,gBAAgB,kBA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A0C;CACzF,OAAO,aAAa,iBAAiB,KAAK;AAC5C;;;;;;;;;;;;;ACtGA,IAAa,uBAAuB,UAAmC;CACrE,OAAO;EACL,SAAqC;GACnC,OAAO,IAAI,eAA2B,EACpC,MAAM,YAAY;IAChB,WAAW,QAAQ,KAAK;IACxB,WAAW,MAAM;GACnB,EACF,CAAC;EACH;EACA,aAAqB;GACnB,OAAO,MAAM;EACf;CACF;AACF;;;;;;;;;;;;;;;;AAiBA,IAAa,aAAa,KAAmB,SAAoC;CAC/E,OAAO;EACL,MAAM,SAA8C;GAClD,MAAM,WAAW,MAAM,MAAM,KAAK,IAAI;GACtC,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,uCAAuC,SAAS,QAAQ;GAE1E,IAAI,CAAC,SAAS,MACZ,MAAM,IAAI,MAAM,iCAAiC;GAEnD,OAAO,SAAS;EAClB;EACA,aAAwB,CAExB;CACF;AACF;;;;;;;;;;;AAYA,IAAa,eAAe,SAA4B;CACtD,OAAO;EACL,SAAqC;GACnC,OAAO,KAAK,OAAO;EACrB;EACA,aAAqB;GACnB,OAAO,KAAK;EACd;CACF;AACF"}
|
package/common.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("./chunk-Ble4zEEl.js");
|
|
3
|
-
const require_tool_registry = require("./tool_registry-
|
|
4
|
-
const require_thought = require("./thought-
|
|
5
|
-
const require_tool = require("./tool-
|
|
6
|
-
const require_spooled_artifact = require("./spooled_artifact-
|
|
7
|
-
const require_common = require("./common-
|
|
8
|
-
const require_tool_call = require("./tool_call-
|
|
9
|
-
const require_spooled_markdown_artifact = require("./spooled_markdown_artifact-
|
|
3
|
+
const require_tool_registry = require("./tool_registry-CtCQ4Xoz.js");
|
|
4
|
+
const require_thought = require("./thought-BD6AkkOr.js");
|
|
5
|
+
const require_tool = require("./tool-CX9vNHAw.js");
|
|
6
|
+
const require_spooled_artifact = require("./spooled_artifact-B8gIIn9h.js");
|
|
7
|
+
const require_common = require("./common-D_e5zYsG.js");
|
|
8
|
+
const require_tool_call = require("./tool_call--7ti-frB.js");
|
|
9
|
+
const require_spooled_markdown_artifact = require("./spooled_markdown_artifact-DQX0RCdI.js");
|
|
10
10
|
exports.ArtifactTool = require_spooled_artifact.ArtifactTool;
|
|
11
11
|
exports.Identity = require_thought.Identity;
|
|
12
12
|
exports.Media = require_tool_call.Media;
|
package/common.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as Tokenizable, i as TokenEncoding, r as Registry, t as ToolRegistry } from "./tool_registry-
|
|
2
|
-
import { i as Identity, n as Message, r as Memory, t as Thought } from "./thought-
|
|
3
|
-
import { t as Tool } from "./tool-
|
|
4
|
-
import { i as ArtifactTool, r as implementsSpoolReader, t as SpooledArtifact } from "./spooled_artifact-
|
|
5
|
-
import { a as implementsByteStore, i as byteStoreSchema, n as fromWebFile, o as Retrievable, r as inMemoryMediaReader, t as fromFetch } from "./common-
|
|
6
|
-
import { a as mediaReaderSchema, i as implementsMediaReader, n as Media, r as isMedia, t as ToolCall } from "./tool_call-
|
|
7
|
-
import { n as SpooledJsonArtifact, t as SpooledMarkdownArtifact } from "./spooled_markdown_artifact-
|
|
1
|
+
import { a as Tokenizable, i as TokenEncoding, r as Registry, t as ToolRegistry } from "./tool_registry-BGHg6KTq.mjs";
|
|
2
|
+
import { i as Identity, n as Message, r as Memory, t as Thought } from "./thought-B_P8LiB6.mjs";
|
|
3
|
+
import { t as Tool } from "./tool-CRZSUcdP.mjs";
|
|
4
|
+
import { i as ArtifactTool, r as implementsSpoolReader, t as SpooledArtifact } from "./spooled_artifact-CWoKUDEm.mjs";
|
|
5
|
+
import { a as implementsByteStore, i as byteStoreSchema, n as fromWebFile, o as Retrievable, r as inMemoryMediaReader, t as fromFetch } from "./common-lMrnzoyn.mjs";
|
|
6
|
+
import { a as mediaReaderSchema, i as implementsMediaReader, n as Media, r as isMedia, t as ToolCall } from "./tool_call-BUeMuCc6.mjs";
|
|
7
|
+
import { n as SpooledJsonArtifact, t as SpooledMarkdownArtifact } from "./spooled_markdown_artifact-CNle4jXN.mjs";
|
|
8
8
|
export { ArtifactTool, Identity, Media, Memory, Message, Registry, Retrievable, SpooledArtifact, SpooledJsonArtifact, SpooledMarkdownArtifact, Thought, TokenEncoding, Tokenizable, Tool, ToolCall, ToolRegistry, byteStoreSchema, fromFetch, fromWebFile, implementsByteStore, implementsMediaReader, implementsSpoolReader, inMemoryMediaReader, isMedia, mediaReaderSchema };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as validateOrThrow } from "./exceptions-BeWH2FwP.mjs";
|
|
2
|
-
import { a as Tokenizable, n as canonicalStringify, o as isError, r as Registry, s as isInstanceOf, t as ToolRegistry } from "./tool_registry-
|
|
3
|
-
import { T as E_PIPELINE_SHORT_CIRCUITED, b as E_LLM_EXECUTION_EXECUTOR_ERROR, g as E_INVALID_TURN_CONTEXT, m as E_INVALID_LLM_EXECUTION_CONTEXT, p as E_INVALID_LLM_DISPATCH_INPUT, t as E_DISPATCH_PIPELINE_ERROR, x as E_LLM_EXECUTION_GATE_NOT_SUPPORTED, y as E_LLM_EXECUTION_ALREADY_SIGNALLED } from "./runtime-
|
|
2
|
+
import { a as Tokenizable, n as canonicalStringify, o as isError, r as Registry, s as isInstanceOf, t as ToolRegistry } from "./tool_registry-BGHg6KTq.mjs";
|
|
3
|
+
import { T as E_PIPELINE_SHORT_CIRCUITED, b as E_LLM_EXECUTION_EXECUTOR_ERROR, g as E_INVALID_TURN_CONTEXT, m as E_INVALID_LLM_EXECUTION_CONTEXT, p as E_INVALID_LLM_DISPATCH_INPUT, t as E_DISPATCH_PIPELINE_ERROR, x as E_LLM_EXECUTION_GATE_NOT_SUPPORTED, y as E_LLM_EXECUTION_ALREADY_SIGNALLED } from "./runtime-j92CNi5z.mjs";
|
|
4
4
|
import { validator } from "@nhtio/validation";
|
|
5
5
|
import { DateTime } from "luxon";
|
|
6
6
|
import { sha256 } from "js-sha256";
|
|
@@ -1638,4 +1638,4 @@ var DispatchRunner = class DispatchRunner {
|
|
|
1638
1638
|
//#endregion
|
|
1639
1639
|
export { DispatchContext as n, TurnContext as r, DispatchRunner as t };
|
|
1640
1640
|
|
|
1641
|
-
//# sourceMappingURL=dispatch_runner-
|
|
1641
|
+
//# sourceMappingURL=dispatch_runner-CDF3X0nv.mjs.map
|