/** * Brave Provider Adapter (brave-tech-plan §2, §5, §6). * * T2 wires the Search Capability (web + news). The descriptor * advertises `"search"` and `create()` returns an Adapter whose * `search` Capability owns credentials, transport, Provider field * mapping, and failure normalization. Credentials, the direct-HTTP GET * transport, and the header-bearing fetch seam come from T1; later * tickets widen the capability set (reader, etc.). T5 wires the * Diagnostics Capability (one-query doctor probe); T6 wires the Quota * Capability (1-query rate-limit-header probe with a spend caveat). * * Boundary rules (ARCHITECTURE.md §2): * - May import capability types, normalized errors, Provider identity * types, and the Adapter-local credential and transport Modules. * - Must NOT import command presentation, output mode, or another * Provider's Adapter. */ import type { ProviderDescriptor } from "../types.js"; import { type BraveTransportDeps } from "./client.js"; import type { BraveRateLimitHeaders } from "./client.js"; /** * Dependencies the Brave Adapter accepts. The unified `transport` * seam carries `fetch` and timer injection; the Search Capability * threads it through to the direct-HTTP transport. * * `onRateLimitHarvest` (PB-T1) is the passive-harvest callback invoked * with Brave's `X-RateLimit-*` headers after every successful web * search. Production wires a default that normalizes the headers via * `normalizeBraveQuota` and writes a raw-category snapshot to * `~/.scoutline/state.json` through `writeQuotaSnapshot`; the write is * awaited (so it survives the bin's immediate `process.exit`) and * fail-open (a write error is isolated to a stderr warning and never * converts the search success into a fallback). Tests inject a double * to keep harvest assertions hermetic. `undefined` disables the * harvest (used by tests that only exercise search-result * normalization). */ export interface BraveAdapterDependencies { /** Optional transport injection (fetch, timers, env). */ readonly transport?: BraveTransportDeps; /** * Optional passive-harvest callback fired with Brave's * `X-RateLimit-*` headers after a successful web search. Production * wires a default (see {@link createDefaultBraveHarvest}); tests * inject a recorder or `undefined` to disable. */ readonly onRateLimitHarvest?: (headers: BraveRateLimitHeaders) => Promise | void; } /** * Build the Brave Provider Descriptor. The descriptor advertises the * Search (T2), Diagnostics (T5), and Quota (T6) capabilities and * constructs an Adapter whose `search`/`diagnostics`/`quota` * Capabilities own credentials, transport, Provider field mapping, and * failure normalization. Construction is side-effect-free; the * transport is invoked per Capability call. Tests pass `transport` * (typically a fake-fetch wrapper); production uses the no-argument * factory which resolves to the global `fetch` and timers inside the * transport Module. * * PB-T1: the no-argument factory wires the production passive-harvest * callback ({@link createDefaultBraveHarvest}) so every successful web * search writes a rate-limit snapshot to `state.json`. Tests inject * `onRateLimitHarvest` (or `undefined` to disable) through * `BraveAdapterDependencies`. */ export declare function createBraveDescriptor(dependencies?: BraveAdapterDependencies): ProviderDescriptor; //# sourceMappingURL=adapter.d.ts.map