Skip to main content

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

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 server
  • npm run start [port] - Start dev server on custom port

Package Syncing

  • npm run sync:all - Sync all local development packages
  • npm run sync:core - Sync @datalayer/core only
  • npm run sync:jupyter - Sync jupyter-ui packages only

Build & Type Check

  • npm run build - Build for production
  • npm run preview - Preview production build
  • npm 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 components
  • lexical - 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:

  1. Build the production bundle
  2. Configure JupyterHub to serve the app
  3. Set environment variables in JupyterHub config
  4. 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/libnode_modules/@datalayer/core/lib
  • ../jupyter-ui/packages/react/libnode_modules/@datalayer/jupyter-react/lib
  • ../jupyter-ui/packages/lexical/libnode_modules/@datalayer/jupyter-lexical/lib
  • ../jupyter-ui/packages/primer-addons/libnode_modules/@datalayer/primer-addons/lib

Making Changes to Dependencies

  1. Make changes in the source repository (e.g., ../jupyter-ui)
  2. Build the package: npm run build (in that repository)
  3. Sync to copilot-lexical: npm run sync:all
  4. 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 build in 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - Copyright (c) 2025-2026 Datalayer, Inc.

Links

Support

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)

Source distribution for copilot-lexical 0.1.0
File Size Uploaded
copilot_lexical-0.1.0.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for copilot-lexical 0.1.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page