API ReferenceSocket.IO Events

Socket.IO Events

KULVEX uses Socket.IO for real-time bidirectional communication between clients and the server.

Connection

import { io } from "socket.io-client";
 
const socket = io("http://localhost:9100", {
  auth: { token: "your-jwt-token" },
});

Authenticated connections store user info in the session. Unauthenticated connections are allowed but have limited access.

Chat Events

EventDirectionPayloadDescription
chat:sendclient → server{ message, task_type?, history?, use_rag?, project? }Send a chat message
chat:tokenserver → client{ token }Streaming token
chat:doneserver → client{ response, model }Complete response

Example

socket.emit("chat:send", {
  message: "What's the weather?",
  task_type: "chat",
  history: [],
  use_rag: true,
});
 
socket.on("chat:token", ({ token }) => {
  process.stdout.write(token);
});
 
socket.on("chat:done", ({ response, model }) => {
  console.log(`\n[Model: ${model}]`);
});

Voice Events

EventDirectionPayloadDescription
voice:startclient → server{ language?, engine? }Start voice session
voice:audio_chunkclient → server{ audio } (base64)Audio data
voice:stopclient → server{}End voice session
voice:playback_doneclient → server{}TTS playback finished
voice:transcriptserver → client{ text, language }STT result
voice:responseserver → client{ text }AI response
voice:audioserver → client{ audio, format }TTS audio

Terminal Events

EventDirectionPayloadDescription
terminal:createclient → server{ mode?, cols?, rows? }Create PTY session
terminal:databoth{ session_id, data }Terminal I/O
terminal:resizeclient → server{ session_id, cols, rows }Resize terminal
terminal:destroyclient → server{ session_id }Destroy PTY

Terminal Modes

  • shell — Standard shell (bash/zsh)
  • kcode — Launches KCode interactive REPL

Disconnect Behavior

On disconnect:

  • Voice sessions are cleaned up immediately
  • Terminal PTY sessions have a 5-second grace period for reconnection before cleanup
  • Remote code sessions are detached from the Socket.IO sid