/**
 * Local DWN discovery — discovers a running `@enbox/dwn-server` instance
 * so the agent can route traffic to it.
 *
 * Discovery channels (tried in order):
 * 1. **In-memory cache** — serves a recent positive or negative result.
 * 2. **Discovery file** (`~/.enbox/dwn.json`) — written by `electrobun-dwn`
 *    on startup. Fast filesystem read, no network. Available for CLI and
 *    native apps; skipped in browsers.
 * 3. **Injected endpoint** — in browsers, the `dwn://connect` redirect
 *    flow delivers the endpoint, which is injected via
 *    {@link LocalDwnDiscovery.setCachedEndpoint | setCachedEndpoint()}.
 *
 * @see https://github.com/enboxorg/enbox/issues/677
 * @module
 */
import type { EnboxRpc } from '@enbox/dwn-clients';
import type { DwnDiscoveryFile } from './dwn-discovery-file.js';
/**
 * Controls how the agent discovers and routes to a local DWN server.
 *
 * - `'off'`    — (default) skip local discovery entirely.
 * - `'prefer'` — try local DWN first; fall back to DID-document endpoints.
 * - `'only'`   — require a local server; throw if none is found.
 */
export type LocalDwnStrategy = 'prefer' | 'only' | 'off';
/** The `server` field returned by `GET /info` on `@enbox/dwn-server`. */
export declare const localDwnServerName = "@enbox/dwn-server";
/** Strips a trailing slash from a URL so endpoint comparisons are consistent. */
export declare function normalizeBaseUrl(url: string): string;
/**
 * Discovers a running local DWN server.
 *
 * Results are cached for {@link _cacheTtlMs} milliseconds (default 10 s) to
 * avoid repeated I/O on hot paths such as sync.
 *
 * @example Discovery with file-based channel (CLI / native)
 * ```ts
 * import { DwnDiscoveryFile } from './dwn-discovery-file.js';
 *
 * const discoveryFile = new DwnDiscoveryFile();
 * const discovery = new LocalDwnDiscovery(rpcClient, 10_000, discoveryFile);
 * const endpoint = await discovery.getEndpoint();
 * ```
 *
 * @example Browser: inject cached endpoint from `dwn://connect` redirect
 * ```ts
 * const discovery = new LocalDwnDiscovery(rpcClient);
 * discovery.setCachedEndpoint('http://127.0.0.1:55557');
 * ```
 */
export declare class LocalDwnDiscovery {
    private readonly _rpcClient;
    private readonly _cacheTtlMs;
    private readonly _discoveryFile?;
    private _cachedEndpoint?;
    private _cacheExpiry;
    constructor(_rpcClient: EnboxRpc, _cacheTtlMs?: number, _discoveryFile?: DwnDiscoveryFile | undefined);
    /**
     * Returns the base URL of a local DWN server, or `undefined` if none
     * is discoverable.
     *
     * The discovery order is:
     * 1. In-memory cache (if not expired).
     * 2. `~/.enbox/dwn.json` discovery file (if a {@link DwnDiscoveryFile}
     *    was provided). The endpoint from the file is validated via
     *    `GET /info` to ensure the server is still running.
     *
     * If neither channel finds an endpoint, the result (`undefined`) is
     * cached to avoid repeated discovery file reads on hot paths.
     *
     * In browser environments (where no discovery file is available), the
     * endpoint must be injected externally via
     * {@link setCachedEndpoint | setCachedEndpoint()} — typically after a
     * `dwn://connect` redirect delivers the endpoint in the URL fragment.
     */
    getEndpoint(): Promise<string | undefined>;
    /**
     * Inject a cached endpoint (e.g. from a `dwn://connect` browser redirect
     * or from `localStorage`). The endpoint is validated via `GET /info` before
     * caching.
     *
     * @returns `true` if the endpoint was validated and cached, `false` otherwise.
     */
    setCachedEndpoint(endpoint: string): Promise<boolean>;
    /**
     * Clear the in-memory cache, forcing the next {@link getEndpoint} call
     * to perform a fresh discovery.
     */
    clearCache(): void;
    /**
     * Try the `~/.enbox/dwn.json` discovery file. Returns the endpoint if
     * the file exists, is valid, and the endpoint passes `GET /info`
     * validation. Returns `undefined` otherwise.
     */
    private _tryDiscoveryFile;
    /**
     * Call `GET /info` on the endpoint and check that
     * `serverInfo.server === '@enbox/dwn-server'`.
     */
    private _validateEndpoint;
    /** Update the in-memory cache entry. */
    private _setCacheEntry;
}
//# sourceMappingURL=local-dwn.d.ts.map