Implementation
Installation
To install Carbon Connect as a pre-built React component, use npm
as follows:
Prerequisites
The following packages will be added as peer dependencies:
@radix-ui/react-checkbox
@radix-ui/react-dialog
@radix-ui/react-dropdown-menu
@radix-ui/react-popover
@radix-ui/react-slot
class-variance-authority
clsx
next-themes
react
react-dom
react-dropzone
react-infinite-scroll-component
react-loader-spinner
tailwind-merge
Please check for the versions from package.json
if you encounter a version mismatch error.
Component Properties
The CarbonConnect
component accepts the following properties:
Property | Type | Required? | Description |
---|---|---|---|
brandIcon | String | Yes | A URL or a local path to your organization’s brand icon. |
orgName | String | Yes | The name of your organization. This is displayed in the initial announcement modal view. |
tokenFetcher | Function | Yes | A function that returns a promise which resolves with the access and refresh tokens. |
onSuccess | Function | No | A callback function that will be called after the file upload is successful. |
onError | Function | No | A callback function that will be called if there is any error in the file upload. |
children | React Node(JSX) | No | You can pass any valid React node that will be used as a trigger to open the component. |
entryPoint | String | No | The initial active step when the component loads. Default entry point is LOCAL_FILES . |
maxFileSize | Number | No | Maximum file size in bytes that is allowed to be uploaded. Defaults to 10 MB |
tags | Object | No | Any additional data you want to associate with the component’s state, such as an app ID. |
enabledIntegrations | dict | No | Let’s you choose which 3rd party integrations to show. See below for more details about this prop. |
primaryBackgroundColor | String | No | The primary background color of the component. Defaults to #000000 . |
primaryTextColor | String | No | The primary text color of the component. Defaults to #FFFFFF . |
secondaryBackgroundColor | String | No | The secondary background color of the component. Defaults to #FFFFFF . |
secondaryTextColor | String | No | The secondary text color of the component. Defaults to #000000 . |
allowMultipleFiles | Boolean | No | Whether or not to allow multiple files to be uploaded at once. Defaults to false . |
chunkSize | Number | No | The no.of tokens per chunk. Defaults to 1500. |
overlapSize | Number | No | The no.of tokens to overlap between chunks. Defaults to 20. |
open | Boolean | No | Whether or not to open the component. Defaults to false . |
setOpen | Function | No | A function that will be called to set the open state of the component. Defaults to None . |
alwaysOpen | Boolean | No | Whether or not to always keep the component open. Defaults to false . |
tosURL | String | No | A URL to your organization’s terms of service. Defaults to https://carbon.ai/terms . |
privacyPolicyURL | String | No | A URL to your organization’s privacy policy. Defaults to https://carbon.ai/privacy . |
navigateBackURL | String | No | A URL to your intended destination. Defaults to None . |
backButtonText | String | No | The label that you want to show on the back button. Defaults to Go back . |
zIndex | Number | No | Update the z-index of the Carbon Connect modal. |
embeddingModel | String | No | Specifies the embedding model used for the integration. The options are OPENAI , AZURE_OPENAI , or COHERE_MULTILINGUAL_V3 for text and audio files, and VERTEX_MULTIMODAL for image files. |
filePickerMode | String | No | Specifies whether users can locally upload files, folders, or both. The options are FILES , FOLDERS , or BOTH . |
prependFilenameToChunks | String | No | Adds the file title to each chunk. Defaults to false . |
showFilesTab | Boolean | No | Shows the synced files tab in Carbon Connect 2.0. Defaults to true . |
useRequestIds | Boolean | No | A request_id will be assigned to the uploaded files in that session. |
loadingIconColor | String | No | Defines the color of the loader icon. This can be specified using standard CSS color names, or directly as either a Hexadecimal (Hex) code or RGB color values. |
sendDeletionWebhooks | Boolean | No | When set to true , enables triggering a FILE_DELETED webhook event whenever a user deletes files within Carbon Connect. If set to false , deleting files will not generate any webhook notifications. |
fileSyncConfig | Array | No | Includes data source and file specific configurations. |
splitRows | Boolean | No | If splitRows is set to true , CSV rows will be automatically split if they exceed either the specified chunk size or the maximum token limit of the embedding model. For LOCAL_FILES , splitRows can be set on the integration or extension level. For third-party connectors, this value can be set under the fileSyncConfig as split_rows . Defaults to false . |
incrementalSync | Boolean | No | By setting incremental_sync to true , only new or updated files since the last sync will be re-synced. Defaults to false . |
filesTabColumns | Array | No | Specifies which columns are displayed in the file list view and accepts an array of strings which can have values "name" , "status" , "created_at" , "created_at" , "external_url" . |
theme | String | No | Specifies whether dark or light mode is enabled. The prop can have values "light" , "dark" , and "auto" . |
dataSourcePollingInterval | Number | No | Specifies how frequently data sources are polled for any updates and events. The value is specified in milliseconds (ms) and the minimum allowed value for this property is 3000 ms. Defaults to 8000 ms. |
openFilesTabTo | String | No | Specifies which tab (FILE_PICKER or FILES_LIST ) the user is taken to by default when they select an integration. Only applies when customer has enabled Carbon’s in-house file picker. |
apiURL | String | No | Defaults to https://api.carbon.ai but can be set to another URL value. For self-hosting customers, this URL value then acts as the base path for all of the requests made through Carbon Connect. |
dataSourceTags | String | No | Key-value pairs that will be added to all data sources connected through Carbon Connect as custom metadata. Example: {{"userId": "swapnil@carbon.ai"}} |
dataSourceTagsFilterQuery | String | No | This parameter filters for tags when querying data sources. It functions similarly to our documented file filters. If not provided, all data sources will be returned. Example: {{"key": "userId", "value": "swapnil@carbon.ai"}} |
When you do not pass open
or setOpen
, Carbon Connect will manage the open state internally. If you pass open
and setOpen
, you will have to manage the open state yourself.
Usage
This section demonstrates how to integrate the Carbon Connect component within a Next.js project.
Client Side Configuration
1. Import Libraries and Components:
2. Token Retrieval:
The tokenFetcher function is set up to request access tokens from Carbon directly via your backend:
In the example above, tokenFetcher is a helper function that retrieves the necessary tokens for authentication. This function should be implemented in your client-side code and is designed to make a request to an API on your backend server. The API then requests tokens from the Carbon token creation endpoint. The Carbon token creation endpoint is a secure endpoint that requires a valid API key and customer ID. The customer ID is a unique identifier for your end-user, and you can pass any string as the customer ID. The API key is a secret key provided to you by Carbon. Please contact us to obtain your API key.
3. Implement Carbon Connect Component:
Here’s a concise usage example. Customize according to your requirements:
4. Specify an Embedding Model (Optional)
If you are using Carbon to generate embeddings, in the Carbon Connect component, the specification of an embedding model (view available models) can be set at different levels:
Global Level: Here, the Embedding Model (embeddingModel) prop applies universally across the entire system or application. It serves as the default unless overridden at other levels.
Per Connector Level: This setting applies to a specific connector (ie: Google Drive), allowing customization for a particular connector’s behavior, which takes precedence over the global setting for that connector.
Per File Type Level: The most specific setting, it applies at the individual file level, allowing granular control over embedding models for particular file types. This setting supersedes both connector and global settings, providing the highest priority. This is applicable for local file uploads only.
The order of precedence is: File Level > Connector Level > Global Level. Meaning, if a specific embedding model is defined at the file level, it takes priority over the connector-level setting, and the connector-level setting takes priority over the global setting. We default to OPENAI
if no value is provided.
Server Side Configuration
Your backend should handle token requests like this:
Return Value
Ensure that your tokenFetcher returns an object structured as:
Enabling Connectors
You can enable connectors users can access via the enabledIntegrations
property. The property also allows additional configuration per connector.
Here’s the list of connectors available for activation:
Callback Function Props
onSuccess
Responds to successful events: file upload, 3rd party account connection, file selection, and web scraping initiation.
Event Types
INITIATE
: This event type is triggered when a user enters the integration flow (either for auth or file selection)ADD
: This event type is triggered when a user authenticates an account under an integration.UPDATE
: This event type is triggered when a user adds or removes files for an integration.CANCEL
: This event type is triggered when when a user exits the integration flow without taking any action.
Callback Response
The data passed to the onSuccess callback prop will be:
LOCAL_FILES
:
WEB_SCRAPER
:
3rd Party Connectors
Each files
object follows this format:
onError
Triggered during file upload errors.
Structure: