@nhtio/adk/batteries/tools/_shared
Cross-battery helpers shared by the configured HTTP tool batteries (SearXNG, Scrapper, …).
Remarks
These are internal building blocks for the factory-style tool batteries — the ones that talk to a configured HTTP instance behind custom auth and expose input/output middleware pipelines. Rather than each battery carry its own copy, the common machinery lives here:
- resolveArtifact / resolveArtifactSync — turn an ArtifactResolver (a constructor, a sync resolver, or an async / dynamic-import resolver) into the sync
() => SpooledArtifactConstructorthatTool.artifactConstructorrequires. Mirrors the vector battery'sresolveClientCtor. - resolveHeaders — collapse a static header object or a (sync/async) resolver into a plain header record for one request (refreshable-auth friendly).
- runInputPipeline / runOutputPipeline — the onion middleware runners (fresh runner per call, short-circuit + non-terminal detection), generic over the context type.
This module imports harness primitives only through their specific subpath barrels (@nhtio/adk/spooled_artifact, @nhtio/adk/forge, @nhtio/adk/guards) per the batteries barrel-only rule.
Type Aliases
| Type Alias | Description |
|---|---|
| ArtifactResolver | The artifact configuration accepted by a factory: a constructor, a sync resolver, or an async / dynamic-import resolver (which may yield a module namespace whose default is the constructor). |
| MiddlewareFn | A generic onion middleware stage over a mutable context C. |
| SpooledArtifactCtor | Convenience alias for the spooled-artifact constructor a tool wraps its output in. |
| SyncArtifactResolver | The sync subset of ArtifactResolver — a constructor or a sync resolver (no Promise). |
| ToolHeaders | A static set of request headers (used for custom instance authentication). |
| ToolHeadersResolver | A resolver returning request headers, sync or async. Use this form when the auth token is refreshable — the resolver runs on every request, so a fresh token can be minted per call. |
Functions
| Function | Description |
|---|---|
| isShortCircuit | true when value is the short-circuit sentinel produced by makeShortCircuit. |
| makeShortCircuit | Build a shortCircuit(result) function for an input-pipeline context. Calling it throws the internal sentinel, which runInputPipeline catches and converts into the verbatim result (skipping the HTTP request entirely — e.g. a cache hit). |
| resolveArtifact | Resolve an ArtifactResolver to the sync () => SpooledArtifactCtor that Tool.artifactConstructor requires (the wrap-site and the construction-time validator both invoke it synchronously, so an async resolver cannot be passed straight through). |
| resolveArtifactSync | Synchronous resolveArtifact: accepts only the SyncArtifactResolver subset and throws (via onInvalid) on an async resolver — a runtime guard for JS callers who bypass the compile-time narrowing. |
| resolveHeaders | Resolve the configured headers (a static object or a sync/async resolver) for a single request. |
| runInputPipeline | Run an input pipeline over ctx. Returns the short-circuit string when a stage short-circuited, or undefined when the pipeline reached its terminal handler. A non-terminal pipeline (a stage that neither called next() nor short-circuited) throws — the caller converts it to an Error: string. |
| runOutputPipeline | Run an output pipeline over ctx; rethrow any stage error to the caller's try/catch. A non-terminal pipeline (no next()) throws. |