ArlopassProvider
The root context provider. Wrap your app (or the subtree that needs AI) with <ArlopassProvider> to enable all hooks and guard components.
import { ArlopassProvider } from "@arlopass/react";
Props
| Prop | Type | Default | Description |
|---|---|---|---|
appId |
string |
— | Full reverse-domain app identifier. Auto-derived from the page origin if omitted. |
appSuffix |
string |
— | Suffix appended to the auto-derived domain prefix. Ignored when appId is set. |
appName |
string |
— | Human-readable app name sent during the connect handshake. |
appDescription |
string |
— | Short app description sent during the connect handshake. |
appIcon |
string |
— | URL to a square icon/logo (https:// or data: URI). |
defaultProvider |
string |
— | Provider ID to auto-select after connecting. Must be paired with defaultModel. |
defaultModel |
string |
— | Model ID to auto-select after connecting. Must be paired with defaultProvider. |
autoConnect |
boolean |
true |
Connect to the Arlopass extension automatically on mount. |
onError |
(error: ArlopassSDKError) => void |
— | Called when a connection or auto-select error occurs. |
childrenrequired |
ReactNode |
— | Child components that consume the Arlopass context. |
Mount sequence
- Detects the injected transport from
window.arlopass(set by the browser extension). - Creates a
ArlopassClientinstance bound to that transport. - If
autoConnectistrueand the transport is available, callsclient.connect()with the configured app identity. - If
defaultProvideranddefaultModelare set, callsclient.selectProvider()after connecting. - Publishes the store via React context so child hooks can read snapshot state.
Unmount / cleanup
On unmount the provider calls client.disconnect() and destroys the internal store. Any in-flight operations are cancelled.
Examples
Basic usage
import { ArlopassProvider } from "@arlopass/react";
function App() {
return (
<ArlopassProvider>
<MyChat />
</ArlopassProvider>
);
}
Auto-select provider and model
<ArlopassProvider defaultProvider="openai" defaultModel="gpt-4o">
<MyChat />
</ArlopassProvider>
App identity
<ArlopassProvider
appSuffix="my-chat"
appName="My Chat App"
appDescription="A demo chat application"
appIcon="https://example.com/icon.png"
>
<MyChat />
</ArlopassProvider>
Manual connect with error callback
<ArlopassProvider
onError={(err) => console.error(err.machineCode, err.message)}
autoConnect={false}
>
<MyChat />
</ArlopassProvider>