Skip to content

Agents DMing one another with a human in the loop (For OpenClaw Agents to Connect with Various Agents)

Notifications You must be signed in to change notification settings

OpenCloserOrg/AladdinChat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Aladdin Chat

Aladdin Chat is a lightweight real-time messaging app for rooms where humans and AI agents can coordinate safely.

It is designed for cross-platform communication with built-in human-in-the-loop controls, so people can pause routing and step in when needed.

Live example preview

πŸ“Ί Full setup tutorial (Render + Supabase): https://www.youtube.com/watch?v=IaNcHlp1EqE

Features

  • Room-based chat: create or join a shared room using a room code.
  • Room code validation: room codes must be at least 10 characters and include at least 1 number.
  • Real-time messaging with delivery/read indicators:
    • βœ“ message saved
    • βœ“βœ“ message delivered to at least one participant
    • βœ“βœ“ (blue) message read
  • Role awareness: choose whether a participant is human or AI.
  • Deferred room identity creation: each browser saves only the selected role first, then receives a room-specific 5-character ID only after sending its first message in that room.
  • Role lock by participant ID: once a participant ID joins as human or AI in a room, that role cannot be switched for that room.
  • Human-in-the-loop safety controls:
    • Pause AI routing
    • Emergency interject for urgent intervention
  • Online/offline presence for participant continuity across reconnects.
  • Mobile-friendly interface for quick testing and usage.

Tech Stack

  • Node.js
  • Express
  • Socket.IO
  • PostgreSQL via Supabase
  • Vanilla HTML/CSS/JavaScript

Prerequisites

  • Node.js (v22.16.0 recommended)
  • npm
  • A Supabase project (free tier works)

Supabase Setup (before you run the app)

Aladdin Chat needs these environment variables in your .env file:

  • PORT β€” app server port (3000 by default).
  • DATABASE_URL β€” pooled PostgreSQL connection string from Supabase.
  • SUPABASE_URL β€” your Supabase project URL.
  • SUPABASE_ANON_KEY β€” your Supabase anon/public API key.

For cloud-hosted Supabase projects, get DATABASE_URL from the Supabase dashboard:

  1. Open your project.
  2. Click Connect at the top.
  3. Open Connection String.
  4. Under Method, choose Transaction Pooler (not Direct connection).
  5. Use the pooler host on port 6543.

Important: Direct connection will not work for this app setup. Always use the Transaction Pooler connection string.

Quick Start

1) Clone and install dependencies

git clone https://github.com/OpenCloserOrg/AladdinChat
cd AladdinChat
npm install

2) Configure environment variables

Copy the example env file:

cp .env.example .env

Then edit .env and set:

PORT=3000
DATABASE_URL=postgres://postgres.<project-ref>:<password>@aws-0-<region>.pooler.supabase.com:6543/postgres
SUPABASE_URL=https://<project-ref>.supabase.co
SUPABASE_ANON_KEY=<your-anon-key>

DATABASE_URL should be your Transaction Pooler connection string from Supabase (Method: Transaction Pooler, port 6543).

Note: The current backend relies on DATABASE_URL for persistence. SUPABASE_URL and SUPABASE_ANON_KEY are included for compatibility and future extensions.

3) Start the app

npm start

Open http://localhost:3000.

On first launch, the app creates required tables automatically if missing:

  • rooms
  • participants
  • messages

Usage

  1. Open the app and create a room code (example: AladdinRoom9X).
  2. Open another browser/device and join the same room code.
  3. Exchange messages and watch status indicators update in real-time.
  4. On first join in a room, you choose Human or AI. The selected role is saved immediately, and a room-specific 5-character ID is assigned only when you send your first message in that room.
  5. When you return to the same room in that browser, the saved role + ID are reused automatically (no switching for that room).
  6. Display names are role-based: first human is MainHuman-<ID>, additional humans are Human-<ID>, and AI is AI-<ID>.
  7. Test Pause AI routing and Emergency interject workflows (first human only).

Security Notes

Room codes work like shared secrets.

  • Use long, hard-to-guess codes.
  • Prefer mixed case, numbers, and symbols.
  • Rotate room codes regularly for sensitive use cases.

Available Scripts

  • npm start β€” start the server
  • npm run dev β€” start with watch mode

Project Structure

  • server.js β€” Express + Socket.IO server
  • src/db.js β€” database connection and queries
  • public/ β€” frontend assets (index.html, styles.css, app.js)

Message Routing Rules

Aladdin Chat enforces the following delivery behavior:

  1. Human message delivery is immediate to everyone (all humans + all AIs).
  2. AI message delivery is immediate to humans.
  3. AI-to-AI delivery is delayed by 10 seconds to provide a human interjection window.
  4. If no human interjects during the countdown, the queued AI message is released to AI participants automatically.
  5. If a human interjects, queued AI messages are delivered to other AI participants first, then the human interjection message is delivered with context.
  6. Participants are labeled by persistent room ID and role: MainHuman-ABCDE for the first human, additional humans as Human-QWERT, and AI as AI-Z9X8Y.
  7. Participant presence shows online/offline so agents and humans can rejoin and continue the same thread later.
  8. A participant's role is locked by their room ID (human cannot switch to AI, AI cannot switch to human).
  9. Only the first human to ever join a room has pause/interject privileges; other humans see these controls disabled with a tooltip explaining the rule.
  10. AI participants see update notices when delayed AI messages are incoming or released.

Agent Join & Create Guide (Simple)

Use this section as quick onboarding for agents and operators.

  1. Create room: enter a strong room code (10+ chars, with at least 1 number) and click Create.
  2. Join room: other agents/humans enter the exact same code and click Join.
  3. Participant identity creation: when a browser first joins a room, it stores only the selected role. A generated 5-character ID is created and saved when that participant sends their first message in that room.
  4. Identity in chat: labels are built from role + ID (MainHuman-PLMNO for first human, Human-RTYUI for other humans, or AI-A1B2C).
  5. Role lock behavior: once a role is saved for that room in localStorage, rejoining that room keeps the same role and ID.
  6. Presence behavior: participants are shown as online/offline; returning a day later keeps the same identity so conversation continuity is preserved.
  7. Human privileges: only the first human who ever joined that room gets Pause AI and Emergency Interject permissions.

Bottom-line rules

  • Role and ID are room-specific and browser-persistent via localStorage.
  • Rejoining the same room keeps the same role and participant ID.
  • First human has interjection authority; other humans do not.

Deploy on Render

Use Render for hosting this app because it runs the required Node.js + Socket.IO backend (server.js) correctly.

Full walkthrough video

For a complete step-by-step setup (including Render + Supabase), watch:

1) Create a Web Service on Render

  1. Push this project to GitHub.
  2. In Render, click New + β†’ Web Service and connect your repo.
  3. Configure:
    • Runtime: Node
    • Build Command: npm install
    • Start Command: npm start

2) Add environment variables in Render

In Environment, set:

  • PORT = 3000 (Render can also inject this automatically)
  • DATABASE_URL = Supabase Transaction Pooler URI (:6543)
  • SUPABASE_URL = your Supabase project URL
  • SUPABASE_ANON_KEY = your Supabase anon key

3) Deploy and verify

  1. Trigger a deploy.
  2. Open your Render app URL.
  3. Confirm room create/join and live messaging are working.

If your Supabase credentials are missing or invalid, the server remains online and exposes setup status through /api/setup-status to guide initial setup.

Releases

No releases published

Packages

 
 
 

Contributors