import { ProviderAdapter } from '../provider-adapter.js'; import { LlmProvider } from '@ggui-ai/mcp-server-core'; import '@ggui-ai/protocol'; interface AnthropicAdapterOptions { /** Override for tests + self-hosted proxies. */ readonly endpoint?: string; /** Override `anthropic-version` header. */ readonly apiVersion?: string; /** Optional fetch override for tests / instrumentation. */ readonly fetch?: typeof globalThis.fetch; } declare function createAnthropicAdapter(options?: AnthropicAdapterOptions): ProviderAdapter; interface GoogleAdapterOptions { /** Override the API base URL. Test harnesses point at a local mock. */ readonly baseUrl?: string; readonly fetch?: typeof globalThis.fetch; } declare function createGoogleAdapter(options?: GoogleAdapterOptions): ProviderAdapter; /** * Concrete OpenAI `ProviderAdapter`. * * Hits `POST https://api.openai.com/v1/chat/completions` with native * `fetch`. No `openai` SDK dep — same leanness reason as the * Anthropic adapter. * * Wire shape (chat completions v1, stable): * * Request: * POST /v1/chat/completions * authorization: Bearer * content-type: application/json * { * model, max_tokens?, messages: [ * {role:'system', content: systemPrompt}, * {role:'user', content: userPrompt}, * ] * } * * Response (200): * { * choices: [{ * message: { role: 'assistant', content: '...' }, * finish_reason: 'stop'|'length'|'content_filter'|'tool_calls'|..., * }], * usage: { prompt_tokens, completion_tokens, total_tokens } * } * * `finish_reason` → `finishReason` normalization: * * - `'stop'` → `'stop'` * - `'length'` → `'length'` * - `'content_filter'` → `'content-filter'` * - everything else → `'other'` */ interface OpenAiAdapterOptions { readonly endpoint?: string; readonly fetch?: typeof globalThis.fetch; } declare function createOpenAiAdapter(options?: OpenAiAdapterOptions): ProviderAdapter; interface OpenRouterAdapterOptions { readonly endpoint?: string; readonly referer?: string; readonly title?: string; readonly fetch?: typeof globalThis.fetch; } declare function createOpenRouterAdapter(options?: OpenRouterAdapterOptions): ProviderAdapter; /** * Which Bedrock endpoint a model id resolves to. The namespaces are * disjoint (see the docstring above), so the shape of the id fully * determines the endpoint — no configuration knob needed. */ type BedrockEndpoint = 'runtime' | 'mantle'; /** * Structural slice of the two SDK clients the adapter actually drives — * the seam that lets tests inject a stub without standing up a real * AWS client. Both `AnthropicBedrock` and `AnthropicBedrockMantle` * satisfy it (the adapter's single-completion contract only ever calls * non-streaming `messages.create`; the response is parsed from * `unknown` by `parseAnthropicMessagesResponse`, so the SDK's * version-volatile `Message` type is deliberately not part of the * seam). */ interface BedrockMessagesClient { readonly messages: { create(body: { model: string; max_tokens: number; system?: string; messages: Array<{ role: 'user'; content: string; }>; }, options?: { signal?: AbortSignal; }): Promise; }; } /** * Constructor options for the Bedrock adapter. * * `region` is the only required option in the common case — IAM * credentials come from the standard AWS chain (IRSA pod token in * EKS, instance role on EC2, env vars or shared credentials file * locally). Tests pass `clientFactory` to inject a mock SDK client. */ interface BedrockAdapterOptions { /** * AWS region for Bedrock invocations. Required for IAM-scoped * resource ARNs to resolve (model ARNs include the region; * cross-region inference profiles do their own internal failover * but the request still has to land in ONE region). Common values: * `'us-east-1'`, `'us-west-2'`. Reads from `process.env.AWS_REGION` * by default to match the rest of the AWS SDK chain. */ readonly region?: string; /** * Optional client factory override — used by tests to inject a * mock or stub client without actually hitting AWS. Called with the * endpoint the request's model id routed to (`'runtime'` → * `AnthropicBedrock`, `'mantle'` → `AnthropicBedrockMantle`). * Production callers leave this unset; the adapter constructs the * real client lazily on first `complete(...)` call per endpoint. */ readonly clientFactory?: (region: string, endpoint: BedrockEndpoint) => BedrockMessagesClient; } /** * Construct an AWS Bedrock provider adapter. * * No API key — IAM is the auth boundary. The returned `ProviderAdapter` * satisfies the same contract as `createAnthropicAdapter`, so it * slots into any one-shot `ProviderAdapter` caller (e.g. `selectAdapter`) * interchangeably (modulo the per-provider model-id namespace * differences). */ declare function createBedrockAdapter(options?: BedrockAdapterOptions): ProviderAdapter; /** * Public barrel for `@ggui-ai/ui-gen/providers`. * * Concrete {@link ProviderAdapter} implementations for the LLM * providers ggui supports today: Anthropic (direct API), Google, * OpenAI, OpenRouter, and AWS Bedrock (Anthropic models via IAM). * * **Real role:** a provider-agnostic one-shot LLM caller for * lightweight callers that need a single `complete()` round-trip — NOT * the generation dispatch path. `createUiGenerator()` accepts no * adapter option; generation-call retry/backoff lives entirely in * `harness/llm-router.ts`'s `apiCall()`. The primary consumer is the * negotiator's LLM seam (`@ggui-ai/mcp-server`'s * `llm-backed-negotiator.ts`, via {@link selectAdapter}); other * lightweight one-shot callers use it the same way. * * Every adapter satisfies the structural * {@link import('../provider-adapter.js').ProviderAdapter} contract. * The four direct-API adapters compose * `defaultValidateConfig` + `makeProviderError` + `statusToErrorKind` * + the shared helpers in `./http.ts` and pull NO vendor SDK (~10MB * savings). Bedrock is the exception — it pulls * `@anthropic-ai/bedrock-sdk` (a zero-dep package over native fetch) * because rolling our own AWS SigV4 signer for one provider isn't a * reasonable trade. * * Typical usage — a one-shot completion: * * ```ts * import { createAnthropicAdapter } from '@ggui-ai/ui-gen/providers'; * * const adapter = createAnthropicAdapter(); * const result = await adapter.complete({ * apiKey, * route: { provider: 'anthropic', model: 'claude-haiku-4-5-20251001' }, * systemPrompt, * userPrompt, * }); * ``` * * Bedrock pool path (no API key — IAM at process boot): * * ```ts * import { createBedrockAdapter } from '@ggui-ai/ui-gen/providers'; * const adapter = createBedrockAdapter({ region: 'us-east-1' }); * // pass `providerKey: { provider: 'bedrock', key: 'bedrock-iam' }` * // (sentinel — adapter ignores; satisfies the non-empty contract). * ``` */ /** * Construct the default adapter for a given provider. Every entry in * the `LlmProvider` union now has a concrete adapter — Bedrock joined * the open surface because it's the cleanest pool-path * (`mcp.ggui.ai` free-credit) story (IAM auth, no API key in flight, * AWS-managed cost reporting). * * Callers that want custom options (test fetch, proxy endpoint, * OpenRouter referer, Bedrock region) should construct the concrete * adapter directly — this helper is a sensible default for the * common case. */ declare function selectAdapter(provider: LlmProvider): ProviderAdapter; export { type AnthropicAdapterOptions, type BedrockAdapterOptions, type GoogleAdapterOptions, type OpenAiAdapterOptions, type OpenRouterAdapterOptions, createAnthropicAdapter, createBedrockAdapter, createGoogleAdapter, createOpenAiAdapter, createOpenRouterAdapter, selectAdapter };