Project Files
src / detect-server-manager.ts
import {
ensureFastvlmServerRunning,
stopFastvlmServer,
type FastVLMServerConfig,
} from "./fastvlm-server-manager.js";
export interface DetectServerConfig {
port: number;
/**
* FastVLM config for the shared server process.
* The detect endpoint and the vision endpoint run in the same process.
*/
mlxVisionModelPath: string;
mlxVisionEnabled: boolean;
/** Absolute path to the Florence-2 model directory. */
florence2ModelPath?: string;
/** Backend mode: 'ane' or 'mlx'. */
backend?: string;
maxTokens?: number;
temperature?: number;
/** Object detection backend: 'florence2' or 'qwen3-vl'. Default: 'florence2'. */
detectBackend?: string;
/** Absolute path to the Qwen3-VL model directory. Required when detectBackend='qwen3-vl'. */
qwen3VlModelPath?: string;
}
/**
* Ensures the shared server process is running and the /detect endpoint is reachable.
*
* Internally delegates to ensureFastvlmServerRunning — there is only one server
* process serving both /analyze and /detect.
*/
export async function ensureDetectServerRunning(
config: DetectServerConfig,
onStatus: (msg: string) => void
): Promise<void> {
const shared: FastVLMServerConfig = {
port: config.port,
modelPath: config.mlxVisionModelPath,
mlxVisionEnabled: config.mlxVisionEnabled,
florence2ModelPath: config.florence2ModelPath,
backend: config.backend,
maxTokens: config.maxTokens,
temperature: config.temperature,
detectBackend: config.detectBackend,
qwen3VlModelPath: config.qwen3VlModelPath,
};
await ensureFastvlmServerRunning(shared, onStatus);
}
/**
* Shuts down the shared server process.
* Delegates to stopFastvlmServer.
*/
export async function stopDetectServer(port: number): Promise<void> {
await stopFastvlmServer(port);
}