@agent-provider/ai-sdk
v0.1.5
Published
AI SDK LanguageModel fulfilled through the Agent Provider extension.
Maintainers
Readme
@agent-provider/ai-sdk
An AI SDK LanguageModel provider backed by the user-controlled Agent Provider
browser extension.
npm install @agent-provider/ai-sdk aiProvider credentials remain in the extension. The page selects a configured model alias and receives structured bridge failures when permission or policy requirements are not met.
What it does
This package implements the AI SDK LanguageModelV4 interface
(@ai-sdk/provider) on top of the Agent Provider extension bridge. Instead of
calling a model API directly, the page sends sanitized requests to the
extension over a scoped postMessage protocol; the extension applies the
user's origin grants, quotas, and policy, then brokers the call to a
user-configured provider using credentials the page never sees.
Page code passes only allowlisted call options across the boundary: headers and
provider-controlled URLs are stripped, non-function tools are dropped, and raw
chunk inclusion is disabled. The extension re-checks all of this. Failures
(permission denied, quota exhausted, bridge unavailable, timeouts) surface as
typed AgentProviderBridgeError instances with code, retryable, and
details fields, or as AbortError DOMExceptions on cancellation.
Requirements
- A browser with the Agent Provider extension installed, and an exact-origin
grant for the calling page. Without the bridge,
connect()fails with aBRIDGE_UNAVAILABLEerror. - A DOM environment: the default transport uses
window.postMessage,ReadableStream,crypto.randomUUID, andDOMException. For non-window contexts, supply a customAgentProviderBridgeTransport. ai(AI SDK) version 7 or newer,>=7.0.34 <8.- ESM only; the package ships a single ESM entry point with TypeScript types.
Quick start
import { generateText } from "ai";
import { createAgentProviderProvider } from "@agent-provider/ai-sdk";
const agentProvider = createAgentProviderProvider({ appName: "My App" });
const { text } = await generateText({
model: agentProvider("default"),
prompt: "Summarize the current page selection.",
});The argument to the provider is a model alias configured in the extension, not
a provider model ID; it defaults to "default". Streaming works through the
standard AI SDK APIs (streamText and friends) with no extra configuration.
API
createAgentProviderProvider(options?)— returns a provider callable:provider(alias?)orprovider.languageModel(alias?)produces an AI SDKLanguageModelV4;provider.bridgeexposes the underlyingAgentProviderBridge. Options:defaultAlias,appName,clientId,connectTimeoutMs(default 3000),requestTimeoutMs(default 90000), a pre-builtbridge, or a customtransport.createAgentProviderModel(options?)— convenience escape hatch returning aLanguageModeldirectly; acceptsaliasplus the bridge options above.AgentProviderBridge— lower-level session object.connect()opens the session and resolves the extension-reportedBridgeCapabilities;requestPermission()andrefreshPermission()drive the consent flow;requestToolApproval()andreportToolExecution()support the tool-use contract;snapshotholds the latest capabilities;dispose()tears down all pending work.AgentProviderBridgeError— structured failure withcode,retryable, anddetails.AgentProviderBridgeTransport/WindowAgentProviderTransport— transport interface and the default window-based implementation.- Re-exported protocol types:
BridgeCapabilities,BridgeLimits,PermissionState.
Links
- Repository — extension, threat model, and implementation status.
@agent-provider/protocol— the wire protocol and capability types this bridge speaks.
License
CC0-1.0 OR Unlicense.
