UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

49 lines • 3.5 kB
/** * Pure path/asset helpers for serving the `@adonis-agora/agent-dashboard` governance SPA — extracted * so they can be unit-tested without booting an AdonisJS app. Both dashboard providers compose these; * each holds only the router wiring + I/O. Owned here (rather than in `@adonis-agora/agent-dashboard`) * so `packages/adonis`'s OWN embedded dashboard provider (`providers/dashboard_provider.ts`) can reuse * them without depending on the dashboard package at runtime — the dashboard package already depends * on THIS one (for `AgentConfig`/`ActorResolver`/...), and a package.json edge the other way would be * circular. See `providers/dashboard_provider.ts`'s module doc for the full story. */ /** Collapse duplicate slashes and strip leading/trailing ones: `/agent//` → `agent`. */ export declare function trimSlashes(path: string): string; /** The agent API base as an absolute path with a single leading slash: `agent` → `/agent`. */ export declare function apiBaseFor(agentPath: string): string; /** * The canonical dashboard mount path (no trailing slash), default `<agentPath>/dashboard`. A caller * may override with an explicit `dashboardPath`; both are normalized to a single leading slash. */ export declare function mountPathFor(agentPath: string, dashboardPath?: string): string; /** MIME type for a filename by extension; `application/octet-stream` for anything unknown. */ export declare function contentTypeFor(filename: string): string; /** * Reject a wildcard asset request that tries to escape the SPA root via `..` or an absolute path. * Returns the safe, normalized relative segments (never starting with `..`), or `null` to deny. */ export declare function safeAssetSegments(wildcard: string | string[] | undefined): string[] | null; /** `id` of the JSON data block {@link injectApiBase} emits; the SPA's `resolveApiBase()` reads it. */ export declare const CONFIG_ELEMENT_ID = "agent-dashboard-config"; /** * Hand the resolved agent API base to the served `index.html`, so the client calls the exact base * the provider mounted (no build-time coupling). Inserted right before `</head>`. * * It goes in as a JSON DATA BLOCK (`<script type="application/json">{"apiBase":…}</script>`), not * as an inline script assigning `window.__AGENT_DASHBOARD_BASE__`. A data block is never executed, * so no Content-Security-Policy can refuse it; an inline script IS, and a host with * `script-src 'self' 'nonce-…'` (`@adonisjs/shield`'s `@nonce`, the recommended setup) silently * dropped ours — the SPA then derived a base from its own URL, which is right only for the default * mount, and on any other every request from a console that had rendered perfectly answered 404. * The global is still read by the SPA as a fallback, but this is no longer how the provider speaks. */ export declare function injectApiBase(html: string, apiBase: string): string; /** * Inject a `<base href="${mount}/">` as the FIRST thing inside `<head>`, so the SPA's relative * `./assets/*` URLs (Vite `base: './'`) resolve against the mount directory no matter whether the * browser's URL carries a trailing slash. This replaces the old trailing-slash redirect, which the * AdonisJS router (it normalizes trailing slashes) turned into a duplicate-route crash. `mount` is a * leading-slash, no-trailing-slash path (e.g. `/agent/dashboard`). */ export declare function injectBaseHref(html: string, mount: string): string; //# sourceMappingURL=paths.d.ts.map