@rekayasa/erica-bubble
v1.4.13
Published
Erica AI Chat Widget - A self-contained React component for integrating Erica AI assistant
Maintainers
Readme
@rekayasa/erica-bubble
React chat widget with conversation history, attachments/OCR, charts, reports and template downloads.
Install
npm install @rekayasa/erica-bubble @copilotkit/[email protected] @copilotkit/[email protected]React/React DOM 18 or 19 and ECharts 5 or 6 are peer dependencies. Import @rekayasa/erica-bubble/styles.css once.
Procsi gateway authentication
The host owns authentication and token storage. Obtain the runtime URL from trusted host/bootstrap configuration, not from a user-controlled link. The account comes from this URL and server configuration; browser identity, language and agent identifiers grant no permissions.
import { EricaProvider, EricaChat, EricaDrawer } from '@rekayasa/erica-bubble';
import '@rekayasa/erica-bubble/styles.css';
// session is the host's authenticated session manager, not widget storage.
function Assistant({ session }) {
if (!session.loggedIn) return null;
return (
<EricaProvider
authMode="gateway"
runtimeUrl={session.widgetRuntimeUrl} // https://gateway.example/api/erica/<account>
sessionKey={`${session.userId}:${session.accountId}:${session.loginGeneration}`}
getToken={() => session.getAccessToken()}
onTokenRefreshed={token => session.setAccessToken(token)}
onAuthError={status => session.endWidgetSession(status)}
language="id"
>
<EricaDrawer>
<EricaChat />
</EricaDrawer>
</EricaProvider>
);
}Gateway provider props:
| Prop | Contract |
| --- | --- |
| authMode | Required literal "gateway"; never falls back to PAT/guest authentication |
| runtimeUrl | Required trusted HTTP(S) single-route endpoint ending /api/erica/<account>; no credentials, query or fragment |
| sessionKey | Required nonempty user/account/login-generation isolation key; not a permission claim |
| getToken | Fresh lookup before every request; returns token, null/undefined, or a Promise of either |
| onTokenRefreshed | Latest host callback receives normalized bearer token (without Bearer ) from response Authorization |
| onAuthError | Latest host callback, once per terminal session, with 401 or 403 |
| language | Optional "id" or "en", sent as Accept-Language preference only |
pat, user and scopingEnable are disallowed in gateway mode. There is no frontend role/division/access policy registration in this mode. Backend policy remains authoritative; this widget does not implement row filtering.
Change sessionKey on every login generation/user/account change. On logout, unmount the provider (or change its key); returning no token also blocks the next request and terminates the widget. Simply replacing a JWT must not change sessionKey: refreshed tokens do not reset the thread. Callback/getter updates do not remount the session. Changing the normalized runtime URL also resets it. If EricaChat.runtimeUrl is provided in gateway mode it must match the provider URL; mismatches render nothing.
Each provider/session owns its SDK client and query/artifact/thread/tool state. Ending a session aborts requests and discards late response callbacks. A 401/403 ends the session, clears its cache and UI, with no retry, replay, guest-token exchange or token-refresh loop. Change sessionKey after host reauthentication to restart. Missing credentials send no request. Tokens are not persisted by the widget.
The same authenticated transport covers explicit runtime info, agent run/connect/stop and SDK requests (including binary downloads and multipart uploads). It replaces Authorization per request, strips guest/account headers, rejects redirects and pins credentials to the configured gateway origin and /api/erica/ path. Response bodies are not read or cloned to observe refresh headers. Gateway deployment must allow the widget origin, permit request Authorization/Accept-Language, and expose Authorization via Access-Control-Expose-Headers; otherwise refresh headers are not readable by browsers.
The supported gateway protocol is single-route SSE: POST {method:"info"}, agent/run and agent/connect envelopes with params.agentId="default" and AG-UI body, plus agent/stop with params.threadId. The server pins forwarded properties. CopilotKit uses a self-managed local agent with no runtimeUrl, preventing hidden registry/fallback requests and remote-agent collisions. Intelligence/WebSocket runtimes are not supported by this transport. AG-UI/RxJS are internal bundled implementation details, not additional public peers.
Legacy integrations
Existing EricaProvider calls with pat, user, language, optional scopingEnable and EricaChat runtimeUrl remain supported with authMode omitted (or "legacy"). They retain the existing Canvas /api/widget/<account> runtime, guest-token exchange/refresh, account header and legacy XML context behavior. Do not use that browser-supplied context as a server authorization boundary. New gateway integrations must use the gateway union above, not PAT credentials.
Chat and UI
EricaChat.runtimeUrl: required operationally for legacy; optional in gateway mode.EricaChat.requiresSandbox: defaults tofalse; opt in only for agents requiring a workspace.EricaDrawer: displays chart/report artifacts alongside chat.- History can select prior conversations or start a new thread; file uploads support deferred OCR submission.
- Existing persisted XML in thread messages is hidden from displayed/copied user messages.
Public TypeScript exports include EricaChatProps, EricaProviderProps, EricaGatewayProviderProps, EricaLegacyProviderProps and EricaProviderUserProps.
