Files
upstream-mirror a774ac673a
Some checks failed
Deploy analytics worker / Deploy analytics worker to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
i18n upload strings / Upload latest strings (push) Failing after 1s
Deploy bemo / Deploy bemo to ${{ (github.ref == 'refs/heads/bemo-production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
Deploy grafana resources / ${{ github.event_name == 'push' && 'Deploy grafana resources' || 'Validate grafana resources (dry run)' }} (push) Failing after 0s
End to end tests (dotcom) / Check for relevant changes (push) Failing after 0s
End to end tests (examples) / Check for relevant changes (push) Failing after 0s
End to end tests (mermaid readability) / Check for relevant changes (push) Failing after 1s
End to end tests (perf) / Check for relevant changes (push) Failing after 0s
Publish editor extensions / Publish editor extensions (push) Failing after 1s
Publish SDK packages / Remove the publish-packages label (push) Has been skipped
Checks / Tests & checks (push) Has been cancelled
Checks / Build all projects (push) Has been cancelled
Deploy templates / Deploy templates (push) Has been cancelled
End to end tests (dotcom) / End to end tests (dotcom) (push) Has been cancelled
End to end tests (mermaid readability) / End to end tests (mermaid readability) (push) Has been cancelled
End to end tests (perf) / End to end tests (perf) (push) Has been cancelled
Deploy .com / Deploy dotcom to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Has been cancelled
End to end tests (examples) / End to end tests (examples) (push) Has been cancelled
Publish SDK packages / Publish SDK packages (push) Has been cancelled
Publish SDK packages / Tell user released version (push) Has been cancelled
Publish SDK packages / Publishes code templates to separate repositories (push) Has been cancelled
Publish SDK packages / Deploys the template demos with the new SDK version (push) Has been cancelled
snapshot of https://github.com/tldraw/tldraw.git (main, 2026-09-23; blobs > 131072B omitted)
2026-09-23 16:12:52 +05:00

4.6 KiB

Branching Chat Template

tldraw

A visual branching conversation interface built with tldraw that lets you create interactive chat trees with AI integration.

What is this?

This template demonstrates how to build a node-based conversational UI where:

  • Visual Chat Trees: Create branching conversation flows on an infinite canvas
  • AI Integration: Stream responses from AI models with real-time updates
  • Interactive Nodes: Drag, connect, and organize conversation messages visually
  • Context Awareness: AI responses consider the entire conversation branch history
  • Full Stack: Complete implementation with Cloudflare Workers backend

Perfect for building chatbots, interactive storytelling, conversation design tools, or any application that needs visual conversation flows.

Quick Start

1. Install Dependencies

yarn install

2. Environment setup

Create a .env file in the root directory and add your Google Generative API key:

GOOGLE_GENERATIVE_AI_API_KEY=your_gemini_api_key_here

Get your API key from Google AI Studio. You can also switch to a different provider using the Vercel AI SDK.

3. Start Development

yarn dev

Open http://localhost:5173 to see your branching chat interface.

How to Use

  1. Create Message Nodes: Click the message icon in the toolbar to add chat nodes
  2. Connect Conversations: Drag from output ports to input ports to create conversation branches
  3. Send Messages: Type in any node and click send to get AI responses
  4. Branch Conversations: Create multiple paths by connecting nodes in different ways
  5. Build Context: The AI considers all connected previous messages when responding

Architecture

This template showcases advanced tldraw concepts:

Frontend (/client)

  • Custom Shapes: NodeShapeUtil for chat message nodes
  • Custom Tools: Interactive port connections for linking conversations
  • Custom UI: Workflow-specific toolbar and components
  • Streaming Updates: Real-time AI response rendering

Backend (/worker)

  • Cloudflare Workers: Edge computing for global performance
  • Durable Objects: Stateful operations and session management
  • AI Integration: Vercel AI SDK with streaming support
  • API Routes: RESTful endpoints for chat operations

Deployment

Ready to deploy to Cloudflare Workers:

# Build the frontend
yarn build

# Deploy to Cloudflare (requires wrangler CLI)
npx wrangler deploy

Make sure to set your GOOGLE_GENERATIVE_AI_API_KEY in your Cloudflare Workers environment variables.

Customization

Adding New Node Types

  1. Create a new node definition in /client/nodes/types/
  2. Add to the NodeDefinitions array in nodeTypes.tsx
  3. Implement required methods: Component, getPorts, etc.

Changing AI Providers

Modify /worker/worker.ts to use different AI providers supported by the Vercel AI SDK:

import { anthropic } from '@ai-sdk/anthropic'
import { google } from '@ai-sdk/google'
// ... other providers

UI Customization

Override tldraw components via the components prop in App.tsx. Customize the toolbar in WorkflowToolbar.tsx.

License

This project is provided under the MIT license found here. The tldraw SDK is provided under the tldraw license.

Trademarks

Copyright (c) 2024-present tldraw Inc. The tldraw name and logo are trademarks of tldraw. Please see our trademark guidelines for info on acceptable usage.

Distributions

You can find tldraw on npm here.

Contribution

Found a bug? Please submit an issue.

Community

Have questions, comments or feedback? Join our discord. For the latest news and release notes, visit tldraw.dev.

Contact

Find us on Twitter/X at @tldraw.