Cedar is opinionated on the best way to organize files and folders for the optimal development experience. Following these conventions will help with debugging, observability, and onboarding new team members to your Cedar implementation. This is based on our experience building copilots in customersβ products with necessary two-way visibility.
We recommend creating a dedicated cedar/ folder at the same level as your app/ directory (in Next.js projects) or equivalent in other frameworks:
Copy
Ask AI
your-project/βββ app/ # Your Next.js app directoryβββ cedar/ # Cedar configuration and components βββ components/ # Directory for all downloaded cedar components βββ messageStorageAdapter.ts βββ messageRenderers.ts βββ responseHandlers.tsβββ package.jsonβββ ...
Define all Cedar configurations in the cedar/ folder
Import and pass configuration objects directly to CedarCopilot during initialization
Keep configuration objects in dedicated files for better organization and debugging
Copy
Ask AI
// cedar/messageRenderers.tsexport const messageRenderers = { // Your custom message renderers};// cedar/responseHandlers.tsexport const responseHandlers = { // Your response handling logic};// In your main componentimport { messageRenderers } from '../cedar/messageRenderers';import { responseHandlers } from '../cedar/responseHandlers';<CedarCopilot messageRenderers={messageRenderers} responseHandlers={responseHandlers} // other props.../>;
The centralized configuration pattern has one important exception: state-related functionality must be defined where the state lives.When registering state with Cedar, this must happen in the component code that owns that state:
Copy
Ask AI
// This MUST happen in the component where the state is definedconst [myState, setMyState] = useState();// Register with Cedar in the same componentuseRegisterState('myState', myState, setMyState);