ClientAgentJS is organized as a small browser-first runtime with separated responsibilities.
src/index.jsExports only createAgent.
src/agent/createAgent.jssrc/agent/createSession.jsResponsibilities:
ask(), stream(), session creation and configuration methodssrc/providers/openai.jssrc/providers/anthropic.jssrc/providers/google.jssrc/providers/index.jsResponsibilities:
{ text, raw } and chunk contracts⚠️ Security Warning (Anthropic): The Anthropic provider uses the
anthropic-dangerous-direct-browser-accessheader to bypass CORS limitations. This means the API Key is exposed directly to the client browser. This fits the “Zero-Backend” direct deployment model, but you must ensure you have proper billing limits, or only use this model for personal projects / BYOK (Bring Your Own Key) scenarios.
src/memory/conversationMemory.jssrc/storage/profileStorage.jssrc/storage/mcpStorage.jssrc/storage/adapters/localStorage.jssrc/storage/adapters/sessionStorage.jsResponsibilities:
src/memory)src/storage)src/transport/fetchClient.jsResponsibilities:
AbortSignalsrc/tools/registry.jsResponsibilities:
Design boundary: Local tools are strictly for simple, dependency-free frontend interactions. For advanced capabilities or interactions with external services, use MCP servers instead.
src/mcp/client.jssrc/mcp/registry.jsResponsibilities:
src/ui/profilePanel.jsResponsibilities:
<html lang>Styling Strategy:
The UI modules include a FALLBACK_CSS constant that is injected into the document head when the panel opens. To ensure these styles are easily overridable by the host application, all built-in rules use the :where() CSS pseudo-class, which reduces their specificity to zero. Developers can provide their own styles by targeting the same classes (e.g., .client-agent-js-profile-dlg) without needing to use !important or high-specificity selectors.
scripts/build.mjsdist/clientagentjs.esm.jsdist/clientagentjs.esm.min.jsResponsibilities:
src/See license: ClientAgentJS