React SDK Reference
The Moss React SDK provides a set of React components and hooks to integrate a powerful AI assistant into your web application. It handles state management, communication with the backend, and UI rendering, all encapsulated within a Shadow DOM to prevent style conflicts.Installation
Install the SDK package from the GitHub Package Registry. Make sure you have authenticated with GitHub Packages.AgentProvider
The AgentProvider is the core component of the SDK. It sets up the context, manages the connection to the backend, and should wrap the part of your application where you want the assistant to be available.
Usage
config.js
Configuration (MossSDKConfig)
The AgentProvider accepts a config object with the following properties:
The base HTTP URL of your backend agent service.
A unique identifier for the client application integrating the SDK.
A unique identifier for the end-user within your application.
An optional API key for authenticating with the backend service.
The CSS selector for the root element to observe for DOM changes.
Sets the minimum log level for the SDK’s internal logger.
Can be
LogLevel.DEBUG, LogLevel.INFO, LogLevel.WARN, LogLevel.ERROR, or LogLevel.SILENT.Enables or disables debug features in the SDK.
Controls the screenshot capture mode when vision is enabled. Can be
'fullpage' or 'viewport'.Configuration for the DOM stability detection strategy. See
StabilityConfig section below.An optional function that runs to sanitize the DOM before context capture. Use this to remove or modify elements that might confuse the AI.
Sets a fixed language for the SDK UI. Supported values are
'en' and 'ko'. If not provided, the language is auto-detected.useAgent Hook
The useAgent hook provides access to the SDK’s state and core functionalities. It must be used within a component that is a child of AgentProvider.
Usage
Return Value (AgentState)
The hook returns an AgentState object with the following properties:
Indicates if the SDK is successfully connected to the backend.
Indicates if the main chat modal is currently open.
An array of chat messages in the current session.
A function to send a message from the user to the assistant.
A function to open or close the chat modal.
A function to clear the current session and start a new one.
Indicates if the SDK is currently waiting for a response from the backend.
Indicates if vision-based features are enabled for the current application.
Components
The SDK includes pre-built components for a quick setup.FloatingActionBar
A ready-to-use floating action button that contains the main assistant button. It is rendered automatically within the AgentProvider.
AssistantButton
A standalone button component that can be used to toggle the chat interface. Use this if you want to place the entry point manually instead of using the FloatingActionBar.
Type Definitions
ChatMessage
A unique identifier for the message.
Indicates whether the message was sent by the user or the assistant.
The content of the message.
The Unix timestamp when the message was created.