Gateway

Gateway क्या है?

Gateway Neotask का heart है — एक single long-running service जो सभी agent sessions, messaging channels, tool execution, और device connections manage करती है। सब कुछ Gateway के माध्यम से होता है।

यह एक WebSocket server है जो clients (desktop app, mobile apps, web dashboard) से connections के लिए listen करता है और पूरे AI assistant lifecycle को manage करता है।

Architecture

Components

  • WebSocket Server — Client connections accept करता है (default port 18789)
  • HTTP Server — Control UI, canvas host, और health endpoints serve करता है
  • Channel Adapters — Messaging platforms (WhatsApp, Telegram, Discord, आदि) से connections maintain करते हैं
  • Session Manager — Agent conversation state persist और manage करता है
  • Cron Scheduler — Scheduled jobs और heartbeat wakeups run करता है
  • Plugin Runtime — Plugin lifecycle load और manage करता है
  • Browser Service — Web automation के लिए Chromium instances control करता है

Binding Modes

Modeविवरण
LoopbackDefault। केवल localhost (127.0.0.1) से accessible
LANआपके local network पर accessible। Bonjour/mDNS के माध्यम से Auto-discoverable
TailnetMagicDNS के साथ Tailscale VPN के माध्यम से accessible
Customएक specific address पर Bind करें

Authentication

Methodविवरण
TokenWebSocket bearer token (UUID या custom string)
PasswordPassword-based auth (bcrypt hashed)
Trusted ProxyPre-auth headers वाले reverse proxies के लिए
Local TrustLoopback connections auto-approved

Configuration

Gateway neotask.json (JSON5 format) के माध्यम से configure होता है। Key sections:

SectionControls
agentsAgent list, defaults, workspaces
gatewayPort, bind mode, auth, reload behavior
channelsPer-channel config और credentials
toolsTool permissions, profiles, security
pluginsPlugin loading, enabling, per-plugin config
modelsProvider auth, fallbacks, provider settings
skillsSkill directories, per-skill configuration
browserBrowser profiles, ports, headless mode
cronScheduler configuration
sessionReset rules, compaction thresholds
messagesTTS settings, media policies
memoryMemory indexing configuration
securitySandboxing, elevated mode, approvals

Hot Reload

Configuration changes बिना restart किए apply की जा सकती हैं:

ModeBehavior
Hybrid (default)Safe changes hot-apply करें, बाकियों के लिए restart
Hotकेवल hot-safe changes apply करें, बाकियों को ignore करें
Restartकिसी भी reload-required change पर restart
Offकोई automatic reload नहीं

Remote Access

Tailscale secure, zero-config remote access provide करता है:

  • Gateway को आपके Tailnet से bind करें
  • Same Tailscale network पर किसी भी device से access करें
  • MagicDNS के माध्यम से Automatic DNS
  • Tailscale Serve HTTPS के साथ dashboard expose कर सकता है

SSH Tunnel

SSH के माध्यम से Gateway port forward करें:

  • Simple, secure, कोई configuration changes आवश्यक नहीं
  • किसी भी SSH-capable machine के साथ काम करता है
  • Full WebSocket protocol और Control UI support करता है

Security Rules

  • Loopback + SSH/Tailscale सबसे safe combination है
  • Non-loopback binding को auth token configuration आवश्यक है
  • Extra security के लिए TLS fingerprint pinning उपलब्ध है
  • Browser control default रूप से remote connections के लिए disabled है

Health Monitoring

Health Endpoint

/health HTTP endpoint return करता है:

  • Gateway status
  • RPC liveness
  • Per-channel health (connected, auth status, account count)
  • Browser readiness
  • Active agents और connected nodes
  • Uptime

Probes

  • RPC liveness — WebSocket connect + echo test
  • Channel health — Auth check + API ping per channel
  • Browser readiness — Port check, process check
  • Node connectivity — Last heartbeat timestamp

Discovery

Bonjour/mDNS

LAN से bound होने पर, Gateway multicast DNS के माध्यम से खुद को advertise करता है:

  • Service type: _neotask-gw._tcp
  • Port, transport, TLS status, और Tailscale DNS info शामिल है
  • Companion apps automatically Gateway discover करते हैं

Wide-Area Discovery

Configurable timeouts के साथ अपने network में gateways discover करें। Local Bonjour और Tailscale DNS discovery दोनों support करता है।

Multiple Gateways

आप profiles का उपयोग करके same machine पर multiple Gateway instances run कर सकते हैं:

  • प्रत्येक profile का separate config, workspace, sessions, और state है
  • प्रत्येक Gateway के लिए different ports
  • Isolation (personal vs work) या testing के लिए useful

Diagnostics

Doctor

Built-in diagnostic tool check करता है:

  • Configuration validity
  • File permissions
  • Channel connectivity
  • Model auth status
  • Node.js version compatibility
  • Common misconfigurations

यह permission दिए जाने पर कई issues automatically fix कर सकता है।

Logging

Gateway logs daily JSONL files में लिखे जाते हैं:

  • Per-completion token usage tracking
  • Channel event logs
  • Structured context के साथ Error logging
  • Configurable log levels