CopilotKit Lexical Example
A standalone example showcasing the integration of Datalayer's Jupyter Lexical Editor with CopilotKit AI sidebar.
Features
- 📝 Rich Lexical Editor - Full-featured editor based on Meta's Lexical framework
- 🤖 AI Copilot Integration - CopilotKit sidebar for AI-assisted editing
- 🚀 Jupyter Runtime Support - Toggle between runtime and non-runtime modes
- 🎨 Primer Design System - Beautiful UI with GitHub's Primer components
- ⚡ Fast Dev Server - Powered by Vite for instant HMR
Prerequisites
- Node.js >= 22.0.0
- npm or yarn
- CopilotKit API key (get from cloud.copilotkit.ai)
Quick Start
1. Install Dependencies
cd /Users/goanpeca/Desktop/develop/datalayer/copilot-lexical
npm install
2. Sync Local Development Packages (Optional)
If you're developing locally and want to use the latest code from sibling repositories:
# Sync all local packages
npm run sync:all
# Or sync individually
npm run sync:core # Sync @datalayer/core
npm run sync:jupyter # Sync jupyter-ui packages
3. Configure Environment
cd copilot-lexical
cp .env.example .env
# Edit .env and add your CopilotKit API key
VITE_COPILOT_KIT_API_KEY=your_api_key_here
4. Run Development Server
# Start on default port (3000)
npm run dev
# Or sync local packages and start dev server
npm run dev:sync
# Or specify a custom port
npm run start 8080
5. Open in Browser
Navigate to http://localhost:3000
Usage
Toggle Kernel Mode
Use the header buttons to toggle between:
- Without Runtime - Static editor without Jupyter kernel
- With Runtime - Full Jupyter notebook capabilities with code execution
AI Copilot
The CopilotKit sidebar provides AI-assisted editing:
- Ask the AI to insert content
- Format text and structure
- Manipulate the document
- Get writing suggestions
Example prompts:
- "Insert a heading"
- "Add a code block with Python code"
- "Create a bulleted list"
- "Format this text as bold"
Development
Project Structure
copilot-lexical/
├── src/
│ ├── App.tsx # Main application component
│ ├── App.css # Application styles
│ ├── main.tsx # Entry point
│ └── index.css # Global styles
├── index.html # HTML template
├── vite.config.ts # Vite configuration
├── tsconfig.json # TypeScript config
├── package.json # Dependencies and scripts
└── README.md # This file
Scripts
Dev Server
npm run dev- Start development server (default port 3000)npm run dev:sync- Sync local packages and start dev servernpm run start [port]- Start dev server on custom port
Package Syncing
npm run sync:all- Sync all local development packagesnpm run sync:core- Sync @datalayer/core onlynpm run sync:jupyter- Sync jupyter-ui packages only
Build & Type Check
npm run build- Build for productionnpm run preview- Preview production buildnpm run type-check- Run TypeScript type checking
Dependencies
Core:
@datalayer/jupyter-lexical- Lexical editor with Jupyter integration@datalayer/jupyter-react- Jupyter React components@copilotkit/react-core- CopilotKit core functionality@copilotkit/react-ui- CopilotKit UI componentslexical- Meta's Lexical editor framework
UI:
@primer/react- GitHub's Primer design system@primer/octicons-react- GitHub icons
Deployment
Build for Production
npm run build
This creates an optimized production build in the dist/ directory.
Deploy as JupyterHub App
This example can be deployed as a JupyterHub managed service:
- Build the production bundle
- Configure JupyterHub to serve the app
- Set environment variables in JupyterHub config
- Users can access via:
https://your-hub.com/services/copilot-lexical/
See JupyterHub documentation for deployment details.
Environment Variables
| Variable | Required | Description |
|---|---|---|
VITE_COPILOT_KIT_API_KEY |
Yes | CopilotKit API key for AI features |
VITE_DATALAYER_API_TOKEN |
No | Datalayer token (only for runtime mode) |
Development Workflow
Using Local Development Packages
This project can use either published npm packages or local development versions:
Option 1: Use Published Packages (default)
npm install # Installs from npm registry
npm run dev
Option 2: Use Local Development Packages
npm install
npm run sync:all # Sync from ../core, ../jupyter-ui
npm run dev
The sync scripts copy built lib/ directories from sibling repositories:
../core/lib→node_modules/@datalayer/core/lib../jupyter-ui/packages/react/lib→node_modules/@datalayer/jupyter-react/lib../jupyter-ui/packages/lexical/lib→node_modules/@datalayer/jupyter-lexical/lib../jupyter-ui/packages/primer-addons/lib→node_modules/@datalayer/primer-addons/lib
Making Changes to Dependencies
- Make changes in the source repository (e.g.,
../jupyter-ui) - Build the package:
npm run build(in that repository) - Sync to copilot-lexical:
npm run sync:all - Restart dev server if needed
Troubleshooting
CopilotKit not working
- Verify your API key is correct in
.env - Check browser console for errors
- Ensure you've configured an LLM provider in CopilotKit dashboard
Local packages not syncing
- Ensure sibling repositories exist:
../core,../jupyter-ui - Build packages first: Run
npm run buildin those repos - Check sync script output for warnings
Port already in use
- Specify a different port:
npm run start 3001 - Or kill the process using the port
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License - Copyright (c) 2025-2026 Datalayer, Inc.
Links
Support
- 📧 Email: support@datalayer.io
- 💬 GitHub Issues: github.com/datalayer/copilot-lexical/issues
- 📖 Documentation: docs.datalayer.io
Release files for copilot-lexical 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| copilot_lexical-0.1.0.tar.gz | 5.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| copilot_lexical-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.1 kB
Release files / copilot_lexical-0.1.0.tar.gz
| Download URL | copilot_lexical-0.1.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
801bc103a608406a3b12c8c0a83971225f4ac5a269077f826c04e32dace05384
|
|
BLAKE2b-256 checksum How to use checksums |
641e4cf253bc16f77a85d65db3931f8b94f569dfbc4dbeb198bc572a13299a39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / copilot_lexical-0.1.0-py3-none-any.whl
| Download URL | copilot_lexical-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
851d516b7e3e8a050560ddddafce06d447314af426eac8b21722037417f0a3c7
|
|
BLAKE2b-256 checksum How to use checksums |
03c1344104efc76173f67dfe2ed230b7cfb56e282414b695a7b164681cc4c81a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|