agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
31 lines (30 loc) • 1.86 kB
TypeScript
/**
* transportUrl — read `transport.url` the way the runtime it is running in
* would read it.
*
* ── Why ──────────────────────────────────────────────────────────────────────
* `new URL('/py/mcp')` throws `TypeError: Invalid URL`. In Node that is the
* right answer: there is no document, so there is no base, and a path on its
* own names nothing. In a browser it is the wrong answer twice over — the page
* HAS a base, and `/py/mcp` is the single most ordinary way to name a sidecar
* behind the same origin (which is also how you avoid a CORS preflight
* entirely). Before this, a browser consumer's first attempt died on a
* `TypeError` from deep inside the transport constructor, with nothing in the
* message naming the URL or the fix.
*
* ── The rule ─────────────────────────────────────────────────────────────────
* An ABSOLUTE url takes the identical first branch it always took, so every
* existing caller is byte-identical. A relative one resolves against
* `globalThis.location.href` when there is one. With neither, the refusal says
* which of the two worlds it is in, because "Invalid URL" does not.
*
* Pattern: pure function. Role: Layer-3 tool transport.
*/
/**
* Resolve a transport URL, honouring a document base when the runtime has one.
*
* @param raw the `url` from an `http` or `gateway` transport descriptor
* @param caller the function to name in the refusal, e.g. `'mcpClient'`
* @throws when `raw` is neither absolute nor resolvable against a base
*/
export declare function transportUrl(raw: string, caller: string): URL;