dea67c0d86
Fixes #371, #369 **Issue #371: MCP server fails when Bun not in PATH** - Changed MCP server shebang from `#!/usr/bin/env bun` to `#!/usr/bin/env node` - MCP server now works regardless of whether Bun is in PATH - Worker service correctly uses getBunPath() to find Bun in common install locations **Issue #369: Web UI returns ENOENT error** - Fixed hardcoded 'plugin/' path in ViewerRoutes - Now checks both cache structure (ui/viewer.html) and marketplace structure (plugin/ui/viewer.html) - Web UI now works from both ~/.claude/plugins/cache and ~/.claude/plugins/marketplaces **Technical Details:** - Updated build-hooks.js to use Node shebang for MCP server (line 169) - Enhanced ViewerRoutes.handleViewerUI() to try multiple path patterns - Added existsSync check to find viewer.html in either location 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
92 lines
2.8 KiB
TypeScript
92 lines
2.8 KiB
TypeScript
/**
|
|
* Viewer Routes
|
|
*
|
|
* Handles health check, viewer UI, and SSE stream endpoints.
|
|
* These are used by the web viewer UI at http://localhost:37777
|
|
*/
|
|
|
|
import express, { Request, Response } from 'express';
|
|
import path from 'path';
|
|
import { readFileSync, existsSync } from 'fs';
|
|
import { getPackageRoot } from '../../../../shared/paths.js';
|
|
import { SSEBroadcaster } from '../../SSEBroadcaster.js';
|
|
import { DatabaseManager } from '../../DatabaseManager.js';
|
|
import { SessionManager } from '../../SessionManager.js';
|
|
import { BaseRouteHandler } from '../BaseRouteHandler.js';
|
|
|
|
export class ViewerRoutes extends BaseRouteHandler {
|
|
constructor(
|
|
private sseBroadcaster: SSEBroadcaster,
|
|
private dbManager: DatabaseManager,
|
|
private sessionManager: SessionManager
|
|
) {
|
|
super();
|
|
}
|
|
|
|
setupRoutes(app: express.Application): void {
|
|
app.get('/health', this.handleHealth.bind(this));
|
|
app.get('/', this.handleViewerUI.bind(this));
|
|
app.get('/stream', this.handleSSEStream.bind(this));
|
|
}
|
|
|
|
/**
|
|
* Health check endpoint
|
|
*/
|
|
private handleHealth = this.wrapHandler((req: Request, res: Response): void => {
|
|
res.json({ status: 'ok', timestamp: Date.now() });
|
|
});
|
|
|
|
/**
|
|
* Serve viewer UI
|
|
*/
|
|
private handleViewerUI = this.wrapHandler((req: Request, res: Response): void => {
|
|
const packageRoot = getPackageRoot();
|
|
|
|
// Try cache structure first (ui/viewer.html), then marketplace structure (plugin/ui/viewer.html)
|
|
const viewerPaths = [
|
|
path.join(packageRoot, 'ui', 'viewer.html'),
|
|
path.join(packageRoot, 'plugin', 'ui', 'viewer.html')
|
|
];
|
|
|
|
const viewerPath = viewerPaths.find(p => existsSync(p));
|
|
|
|
if (!viewerPath) {
|
|
throw new Error('Viewer UI not found at any expected location');
|
|
}
|
|
|
|
const html = readFileSync(viewerPath, 'utf-8');
|
|
res.setHeader('Content-Type', 'text/html');
|
|
res.send(html);
|
|
});
|
|
|
|
/**
|
|
* SSE stream endpoint
|
|
*/
|
|
private handleSSEStream = this.wrapHandler((req: Request, res: Response): void => {
|
|
// Setup SSE headers
|
|
res.setHeader('Content-Type', 'text/event-stream');
|
|
res.setHeader('Cache-Control', 'no-cache');
|
|
res.setHeader('Connection', 'keep-alive');
|
|
|
|
// Add client to broadcaster
|
|
this.sseBroadcaster.addClient(res);
|
|
|
|
// Send initial_load event with projects list
|
|
const allProjects = this.dbManager.getSessionStore().getAllProjects();
|
|
this.sseBroadcaster.broadcast({
|
|
type: 'initial_load',
|
|
projects: allProjects,
|
|
timestamp: Date.now()
|
|
});
|
|
|
|
// Send initial processing status (based on queue depth + active generators)
|
|
const isProcessing = this.sessionManager.isAnySessionProcessing();
|
|
const queueDepth = this.sessionManager.getTotalActiveWork(); // Includes queued + actively processing
|
|
this.sseBroadcaster.broadcast({
|
|
type: 'processing_status',
|
|
isProcessing,
|
|
queueDepth
|
|
});
|
|
});
|
|
}
|