agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
75 lines (74 loc) • 4.03 kB
TypeScript
/**
* BrowserAnthropicProvider — fetch-based Anthropic adapter for browsers.
*
* Pattern: Adapter (GoF). Zero peer dependencies — uses global `fetch`.
* Role: Outer ring. Same `LLMProvider` contract as `AnthropicProvider`,
* but skips `@anthropic-ai/sdk` (which doesn't bundle cleanly
* for browser). Aimed at playgrounds / prototypes where the
* user supplies their own key.
* Emits: N/A.
*
* Anthropic requires the `anthropic-dangerous-direct-browser-access: true`
* header for direct browser-to-API calls. This is intentional — production
* apps should proxy through a backend.
*
* ─── Limitations ────────────────────────────────────────────────────
*
* • Multi-modal NOT supported.
* • Browser CORS — works because Anthropic explicitly allows the
* dangerous-direct header. Future API changes could require a proxy.
*/
import type { LLMCallHooks, LLMChunk, LLMProvider, LLMRequest, LLMResponse, WireRole } from '../../provider-contract/types.js';
import type { ThinkingMode } from '../../thinking/types.js';
export interface BrowserAnthropicProviderOptions {
/** API key. REQUIRED — browser providers don't read env vars. */
readonly apiKey: string;
/** Default model when `LLMRequest.model` is `'anthropic'`. */
readonly defaultModel?: string;
/** Default max tokens. Default 4096. */
readonly defaultMaxTokens?: number;
/** Override the API URL (proxies, edge deployments, mocks). */
readonly apiUrl?: string;
/**
* May the model ask for several tools at once in a single reply?
* Mirror of `AnthropicProviderOptions.parallelToolCalls` — see there
* for the full rationale.
*
* Anthropic's default is `true` (batching allowed). `false` caps the
* model at one tool per reply, which keeps every tool result on its
* own agent iteration so per-iteration analysis can attribute and
* ablate each source separately. `true`/omitted sends nothing.
*
* @default undefined (Anthropic's default — batching allowed)
*/
readonly parallelToolCalls?: boolean;
/**
* Which thinking request a model takes, where the built-in table is not
* the answer you want — an id behind `apiUrl` it cannot read, or Opus 4.6 /
* Sonnet 4.6 wanted adaptive. Return `undefined` to use the table. Mirror of
* `AnthropicProviderOptions.thinkingMode` — see there.
*/
readonly thinkingMode?: (model: string) => ThinkingMode | undefined;
/** @internal Custom fetch implementation for tests / workers. */
readonly _fetch?: typeof fetch;
}
export declare function browserAnthropic(options: BrowserAnthropicProviderOptions): LLMProvider;
export declare class BrowserAnthropicProvider implements LLMProvider {
readonly name = "browser-anthropic";
readonly carriesInMessages: readonly WireRole[];
readonly carriesForcedToolChoice = true;
/** The inner declaration resolves this adapter's shorthand before looking up the model. */
readonly supportsForcedToolChoice: (model: string) => boolean;
readonly carriesNativeOutputSchema = true;
/** The inner declaration resolves this adapter's shorthand before looking up the model. */
readonly supportsNativeOutputSchema: (model: string) => boolean;
readonly supportsAutoNativeOutputSchema: (model: string) => boolean;
readonly promptCaching: import("../../cache/types.js").PromptCaching;
readonly thinkingHandler: import("../../thinking/types.js").ThinkingHandler;
/** The inner provider's own function — a closure, safe to forward unbound. */
readonly thinkingMode: (model: string) => ThinkingMode;
private readonly inner;
constructor(options: BrowserAnthropicProviderOptions);
complete(req: LLMRequest, hooks?: LLMCallHooks): Promise<LLMResponse>;
stream(req: LLMRequest, hooks?: LLMCallHooks): AsyncIterable<LLMChunk>;
}