ClientAgentJS is organized as a small browser-first runtime with separated responsibilities.
src/index.js
Exports only createAgent.
src/agent/createAgent.jssrc/agent/createSession.js
Responsibilities:
- build the public agent facade
- coordinate providers, storage, transport, tools and MCP
- expose
ask(),stream(), session creation and configuration methods
src/providers/openai.jssrc/providers/anthropic.jssrc/providers/google.jssrc/providers/index.js
Responsibilities:
- translate the normalized agent request into provider-specific HTTP payloads
- normalize provider responses into the public
{ text, raw }and chunk contracts - handle provider-specific streaming and tool-calling flows
⚠️ Security Warning (Anthropic): The Anthropic provider uses theanthropic-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.js
Responsibilities:
- keep session conversation history in memory (
src/memory) - persist profiles and MCP server configurations in browser storage (
src/storage) - sanitize corrupted persisted data into a valid runtime state
src/transport/fetchClient.js
Responsibilities:
- perform JSON requests
- stream SSE payloads
- compose timeouts with
AbortSignal
src/tools/registry.js
Responsibilities:
- register local tool handlers
- execute local tools by name
- expose the local tool list to providers that support tool-calling
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.js
Responsibilities:
- store and retrieve MCP server configuration references
- issue JSON-RPC requests to MCP servers
- list and call MCP tools
src/ui/profilePanel.js
Responsibilities:
- provide a built-in browser configuration panel for profiles and MCP servers
- use only the public agent API
- support basic i18n based on
<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.js
Responsibilities:
- build distributable ESM bundles from
src/ - keep examples pointed at the built runtime rather than internal source files
See license: ClientAgentJS