Output
📄 konui/src/router.ts
📏 2,824 lines
📘 TypeScript
🔧 Request Router
📋 File Overview
Main request routing for Konui. Handles both API (JSON) and HTML routes. This is the central dispatcher for all HTTP requests to the Konui service.
🔧 Key Functions
// Config & Session Helpers getConfig() :51 - Load/cache config getKonsoleSessionFile() :62 - Per-user konsole session path getClaudeSessionFile() :72 - Per-user Claude session path getDashboardSessionFile() :88 - Legacy dashboard session path // Response Helpers jsonResponse() :104 - JSON API response htmlResponse() :117 - HTML page response redirect() :132 - 303 redirect response parseJsonBody() :142 - Safe JSON body parser parseFormBody() :153 - Form data parser // Main Route Handlers handleApiRoute() :173 - API routes (~2200 lines) handleHtmlRoute() :2406 - HTML page routes handleRequest() :2611 - Main entry point (exported)
🌐 API Routes
GET /api/kontasks List kontasks (filtered by role) POST /api/kontasks Create kontask GET /api/kontasks/:id Get single kontask PATCH /api/kontasks/:id Update kontask DELETE /api/kontasks/:id Delete kontask GET /api/dashboard/kontasks Recent kontasks for dashboard POST /api/client-log Client-side logging POST /api/kontasks/progress Update progress (from konsole) GET /api/kontasks/progress Get progress by requestId POST /api/statusline Token usage from StatusLine hook POST /api/login User authentication POST /api/logout Session logout ... plus SSE streams, reports, metrics, console endpoints
📄 HTML Routes
GET / Dashboard (console) GET /login Login page (no auth) GET /reports Reports list GET /reports/:type Report detail GET /kontasks Kontasks list GET /kontasks/:id Kontask detail GET /kontasks/new New kontask form GET /claude Claude console (legacy) GET /sessions Sessions page GET /telemetry Telemetry dashboard GET /logs Logs viewer GET /static/* Static files (no auth)
📦 Imports
import { loadConfig } from "./config.ts" import { requireAuth, getAuthUsername, getAuthRole } from "./auth.ts" import { createSession, deleteSession, validateCredentials } from "./session.ts" import * as kontaskStore from "./kontask-db.ts" import * as reports from "./reports.ts" import { dashboardPage } from "./views/layout.ts" import { createSSEStream, emitTaskEvent, eventBus } from "./streaming.ts" import { isKonsoleHealthy, sendPromptToKonsole, ... } from "./konsole-client.ts"
🔐 Auth Flow
- Static files (
/static/*) and login page serve without auth /api/loginvalidates credentials, creates session token- All other routes call
requireAuth()- redirects to login if invalid - Progress/StatusLine endpoints skip auth (internal server-to-server)
- Kontask filtering respects role: admin/ai see all, users see only targeted
Quick Actions
Original Request
No layout configured
Details
Type
General
Status
Completed
Scope
vibetools
Tags
konuicode
Created
7 Jan 2026, 4:28 pm
Updated
7 Jan 2026, 4:28 pm
Timing
⏱️ 103.8s
0 tools
● TTFE 0%
● Thinking 100%
● Tools 0%
Created By
claude
Raw Data
{
"id": "5cf72ecb-25ee-4035-9929-0215981eecc7",
"type": "general",
"status": "completed",
"title": "File: konui/src/router.ts",
"description": "Viewing router.ts - the main request router for Konui",
"context": {
"output": "<div style=\"background:#1e1e1e;color:#e0e0e0;padding:20px;border-radius:8px;font-family:'Consolas','Monaco',monospace;\">\n<h2 style=\"font-family:sans-serif;color:#fff;margin:0 0 16px 0;\">📄 konui/src/router.ts</h2>\n<div style=\"display:flex;gap:16px;flex-wrap:wrap;margin-bottom:16px;font-size:0.85rem;\">\n <span style=\"background:#3d3d3d;padding:4px 10px;border-radius:4px;\">📏 2,824 lines</span>\n <span style=\"background:#3d3d3d;padding:4px 10px;border-radius:4px;\">📘 TypeScript</span>\n <span style=\"background:#3d3d3d;padding:4px 10px;border-radius:4px;\">🔧 Request Router</span>\n</div>\n\n<div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\">\n<h3 style=\"color:#c99542;margin:0 0 12px 0;font-size:1rem;\">📋 File Overview</h3>\n<p style=\"color:#9ca3af;margin:0;line-height:1.6;\">Main request routing for Konui. Handles both API (JSON) and HTML routes. This is the central dispatcher for all HTTP requests to the Konui service.</p>\n</div>\n\n<div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\">\n<h3 style=\"color:#c99542;margin:0 0 12px 0;font-size:1rem;\">🔧 Key Functions</h3>\n<pre style=\"background:#1e1e1e;padding:12px;border-radius:4px;overflow-x:auto;line-height:1.8;margin:0;\">\n<span style=\"color:#7f848e;\">// Config & Session Helpers</span>\n<span style=\"color:#61afef;\">getConfig()</span> <span style=\"color:#7f848e;\">:51 - Load/cache config</span>\n<span style=\"color:#61afef;\">getKonsoleSessionFile()</span> <span style=\"color:#7f848e;\">:62 - Per-user konsole session path</span>\n<span style=\"color:#61afef;\">getClaudeSessionFile()</span> <span style=\"color:#7f848e;\">:72 - Per-user Claude session path</span>\n<span style=\"color:#61afef;\">getDashboardSessionFile()</span> <span style=\"color:#7f848e;\">:88 - Legacy dashboard session path</span>\n\n<span style=\"color:#7f848e;\">// Response Helpers</span>\n<span style=\"color:#61afef;\">jsonResponse()</span> <span style=\"color:#7f848e;\">:104 - JSON API response</span>\n<span style=\"color:#61afef;\">htmlResponse()</span> <span style=\"color:#7f848e;\">:117 - HTML page response</span>\n<span style=\"color:#61afef;\">redirect()</span> <span style=\"color:#7f848e;\">:132 - 303 redirect response</span>\n<span style=\"color:#61afef;\">parseJsonBody()</span> <span style=\"color:#7f848e;\">:142 - Safe JSON body parser</span>\n<span style=\"color:#61afef;\">parseFormBody()</span> <span style=\"color:#7f848e;\">:153 - Form data parser</span>\n\n<span style=\"color:#7f848e;\">// Main Route Handlers</span>\n<span style=\"color:#98c379;\">handleApiRoute()</span> <span style=\"color:#7f848e;\">:173 - API routes (~2200 lines)</span>\n<span style=\"color:#98c379;\">handleHtmlRoute()</span> <span style=\"color:#7f848e;\">:2406 - HTML page routes</span>\n<span style=\"color:#e5c07b;\">handleRequest()</span> <span style=\"color:#7f848e;\">:2611 - Main entry point (exported)</span>\n</pre>\n</div>\n\n<div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\">\n<h3 style=\"color:#c99542;margin:0 0 12px 0;font-size:1rem;\">🌐 API Routes</h3>\n<pre style=\"background:#1e1e1e;padding:12px;border-radius:4px;overflow-x:auto;line-height:1.8;margin:0;\">\n<span style=\"color:#98c379;\">GET /api/kontasks</span> <span style=\"color:#7f848e;\">List kontasks (filtered by role)</span>\n<span style=\"color:#56b6c2;\">POST /api/kontasks</span> <span style=\"color:#7f848e;\">Create kontask</span>\n<span style=\"color:#98c379;\">GET /api/kontasks/:id</span> <span style=\"color:#7f848e;\">Get single kontask</span>\n<span style=\"color:#e5c07b;\">PATCH /api/kontasks/:id</span> <span style=\"color:#7f848e;\">Update kontask</span>\n<span style=\"color:#e06c75;\">DELETE /api/kontasks/:id</span> <span style=\"color:#7f848e;\">Delete kontask</span>\n\n<span style=\"color:#98c379;\">GET /api/dashboard/kontasks</span> <span style=\"color:#7f848e;\">Recent kontasks for dashboard</span>\n<span style=\"color:#56b6c2;\">POST /api/client-log</span> <span style=\"color:#7f848e;\">Client-side logging</span>\n\n<span style=\"color:#56b6c2;\">POST /api/kontasks/progress</span> <span style=\"color:#7f848e;\">Update progress (from konsole)</span>\n<span style=\"color:#98c379;\">GET /api/kontasks/progress</span> <span style=\"color:#7f848e;\">Get progress by requestId</span>\n\n<span style=\"color:#56b6c2;\">POST /api/statusline</span> <span style=\"color:#7f848e;\">Token usage from StatusLine hook</span>\n<span style=\"color:#56b6c2;\">POST /api/login</span> <span style=\"color:#7f848e;\">User authentication</span>\n<span style=\"color:#56b6c2;\">POST /api/logout</span> <span style=\"color:#7f848e;\">Session logout</span>\n\n<span style=\"color:#7f848e;\">... plus SSE streams, reports, metrics, console endpoints</span>\n</pre>\n</div>\n\n<div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\">\n<h3 style=\"color:#c99542;margin:0 0 12px 0;font-size:1rem;\">📄 HTML Routes</h3>\n<pre style=\"background:#1e1e1e;padding:12px;border-radius:4px;overflow-x:auto;line-height:1.8;margin:0;\">\n<span style=\"color:#98c379;\">GET /</span> <span style=\"color:#7f848e;\">Dashboard (console)</span>\n<span style=\"color:#98c379;\">GET /login</span> <span style=\"color:#7f848e;\">Login page (no auth)</span>\n<span style=\"color:#98c379;\">GET /reports</span> <span style=\"color:#7f848e;\">Reports list</span>\n<span style=\"color:#98c379;\">GET /reports/:type</span> <span style=\"color:#7f848e;\">Report detail</span>\n<span style=\"color:#98c379;\">GET /kontasks</span> <span style=\"color:#7f848e;\">Kontasks list</span>\n<span style=\"color:#98c379;\">GET /kontasks/:id</span> <span style=\"color:#7f848e;\">Kontask detail</span>\n<span style=\"color:#98c379;\">GET /kontasks/new</span> <span style=\"color:#7f848e;\">New kontask form</span>\n<span style=\"color:#98c379;\">GET /claude</span> <span style=\"color:#7f848e;\">Claude console (legacy)</span>\n<span style=\"color:#98c379;\">GET /sessions</span> <span style=\"color:#7f848e;\">Sessions page</span>\n<span style=\"color:#98c379;\">GET /telemetry</span> <span style=\"color:#7f848e;\">Telemetry dashboard</span>\n<span style=\"color:#98c379;\">GET /logs</span> <span style=\"color:#7f848e;\">Logs viewer</span>\n<span style=\"color:#98c379;\">GET /static/*</span> <span style=\"color:#7f848e;\">Static files (no auth)</span>\n</pre>\n</div>\n\n<div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\">\n<h3 style=\"color:#c99542;margin:0 0 12px 0;font-size:1rem;\">📦 Imports</h3>\n<pre style=\"background:#1e1e1e;padding:12px;border-radius:4px;overflow-x:auto;line-height:1.6;margin:0;font-size:0.85rem;\">\n<span style=\"color:#c678dd;\">import</span> { loadConfig } <span style=\"color:#c678dd;\">from</span> <span style=\"color:#98c379;\">\"./config.ts\"</span>\n<span style=\"color:#c678dd;\">import</span> { requireAuth, getAuthUsername, getAuthRole } <span style=\"color:#c678dd;\">from</span> <span style=\"color:#98c379;\">\"./auth.ts\"</span>\n<span style=\"color:#c678dd;\">import</span> { createSession, deleteSession, validateCredentials } <span style=\"color:#c678dd;\">from</span> <span style=\"color:#98c379;\">\"./session.ts\"</span>\n<span style=\"color:#c678dd;\">import</span> * <span style=\"color:#c678dd;\">as</span> kontaskStore <span style=\"color:#c678dd;\">from</span> <span style=\"color:#98c379;\">\"./kontask-db.ts\"</span>\n<span style=\"color:#c678dd;\">import</span> * <span style=\"color:#c678dd;\">as</span> reports <span style=\"color:#c678dd;\">from</span> <span style=\"color:#98c379;\">\"./reports.ts\"</span>\n<span style=\"color:#c678dd;\">import</span> { dashboardPage } <span style=\"color:#c678dd;\">from</span> <span style=\"color:#98c379;\">\"./views/layout.ts\"</span>\n<span style=\"color:#c678dd;\">import</span> { createSSEStream, emitTaskEvent, eventBus } <span style=\"color:#c678dd;\">from</span> <span style=\"color:#98c379;\">\"./streaming.ts\"</span>\n<span style=\"color:#c678dd;\">import</span> { isKonsoleHealthy, sendPromptToKonsole, ... } <span style=\"color:#c678dd;\">from</span> <span style=\"color:#98c379;\">\"./konsole-client.ts\"</span>\n</pre>\n</div>\n\n<div style=\"background:#2d2d2d;padding:16px;border-radius:6px;\">\n<h3 style=\"color:#c99542;margin:0 0 12px 0;font-size:1rem;\">🔐 Auth Flow</h3>\n<ol style=\"color:#9ca3af;margin:0;padding-left:20px;line-height:1.8;\">\n<li>Static files (<code>/static/*</code>) and login page serve without auth</li>\n<li><code>/api/login</code> validates credentials, creates session token</li>\n<li>All other routes call <code>requireAuth()</code> - redirects to login if invalid</li>\n<li>Progress/StatusLine endpoints skip auth (internal server-to-server)</li>\n<li>Kontask filtering respects role: admin/ai see all, users see only targeted</li>\n</ol>\n</div>\n</div>",
"requestedAt": "2026-01-07T02:35:00Z",
"requestId": "63ec684f-5751-4c44-b327-73e938f9d432",
"choices": [
{
"label": "View more",
"value": "Show me more of router.ts - specifically the handleApiRoute function",
"primary": true
},
{
"label": "Continue JS plan",
"value": "FileTree test passed - continue to Step 7 (FileViewer component)"
}
],
"turnTiming": {
"totalMs": 103785,
"ttfeMs": 391,
"thinkingMs": 103394,
"toolExecutionMs": 0,
"toolCallCount": 0,
"thinkingPct": 100,
"toolsPct": 0,
"ttfePct": 0
}
},
"createdBy": "claude",
"createdAt": "2026-01-07T06:28:19.422Z",
"updatedAt": "2026-01-07T06:28:26.577Z",
"requestId": "63ec684f-5751-4c44-b327-73e938f9d432",
"scope": "vibetools",
"tags": [
"konui",
"code"
],
"targetUser": "claude"
}