import { createLogger } from "@eclipse-docks/core";
//#region src/ml-models.ts
/**
* Supported in-browser ML models for specific tasks
* These models are optimized for browser use and are well-tested with transformers.js
* All models use the Xenova quantized versions for optimal browser performance
*/
var MLModel = /* @__PURE__ */ function(MLModel) {
	/**
	* Zero-shot classification model for text classification tasks
	* Model: distilbert-base-uncased-mnli
	* Size: ~60-80MB quantized
	* Use case: Tool detection, text classification
	*/
	MLModel["ZERO_SHOT_CLASSIFICATION"] = "Xenova/distilbert-base-uncased-mnli";
	/**
	* Feature extraction model for embeddings
	* Model: all-MiniLM-L6-v2
	* Size: ~23MB quantized
	* Use case: Text embeddings, semantic search
	*/
	MLModel["FEATURE_EXTRACTION"] = "Xenova/all-MiniLM-L6-v2";
	/**
	* Text classification model
	* Model: distilbert-base-uncased-finetuned-sst-2-english
	* Size: ~67MB quantized
	* Use case: Sentiment analysis, text classification
	*/
	MLModel["TEXT_CLASSIFICATION"] = "Xenova/distilbert-base-uncased-finetuned-sst-2-english";
	/**
	* Question answering model
	* Model: distilbert-base-cased-distilled-squad
	* Size: ~125MB quantized
	* Use case: Question answering, reading comprehension
	*/
	MLModel["QUESTION_ANSWERING"] = "Xenova/distilbert-base-cased-distilled-squad";
	/**
	* Summarization model
	* Model: distilbart-cnn-6-6
	* Size: ~300MB quantized
	* Use case: Text summarization
	*/
	MLModel["SUMMARIZATION"] = "Xenova/distilbart-cnn-6-6";
	/**
	* Translation model (English to French)
	* Model: opus-mt-en-fr
	* Size: ~200MB quantized
	* Use case: Machine translation
	*/
	MLModel["TRANSLATION_EN_FR"] = "Xenova/opus-mt-en-fr";
	/**
	* Fill-mask model
	* Model: distilbert-base-uncased
	* Size: ~67MB quantized
	* Use case: Masked language modeling, text completion
	*/
	MLModel["FILL_MASK"] = "Xenova/distilbert-base-uncased";
	/**
	* Sentence similarity model
	* Model: all-MiniLM-L6-v2 (same as feature extraction)
	* Size: ~23MB quantized
	* Use case: Sentence similarity, semantic search
	*/
	MLModel["SENTENCE_SIMILARITY"] = "Xenova/all-MiniLM-L6-v2";
	/**
	* Named entity recognition (token classification)
	* Model: distilbert-base-uncased-finetuned-conll03-english
	* Size: ~67MB quantized
	* Use case: Named entity recognition, token classification
	*/
	MLModel["TOKEN_CLASSIFICATION"] = "Xenova/distilbert-base-uncased-finetuned-conll03-english";
	/**
	* Image classification model
	* Model: vit-base-patch16-224
	* Size: ~330MB quantized
	* Use case: Image classification
	*/
	MLModel["IMAGE_CLASSIFICATION"] = "Xenova/vit-base-patch16-224";
	/**
	* Object detection model
	* Model: detr-resnet-50
	* Size: ~160MB quantized
	* Use case: Object detection in images
	*/
	MLModel["OBJECT_DETECTION"] = "Xenova/detr-resnet-50";
	/**
	* Object detection model (YOLO-style, default for YOLO flows)
	* Uses YOLOS-tiny (public, no auth). For YOLOv9-web see OBJECT_DETECTION_YOLOV9_WEB (may require HF token).
	*/
	MLModel["OBJECT_DETECTION_YOLOV9"] = "Xenova/yolos-tiny";
	/**
	* Object detection model (YOLOv9 web). May require Hugging Face token if repo is gated.
	*/
	MLModel["OBJECT_DETECTION_YOLOV9_WEB"] = "Xenova/yolov9-web";
	/**
	* Object detection model (YOLOS tiny)
	* Model: yolos-tiny
	* Use case: Lightweight object detection, ViT-based
	*/
	MLModel["OBJECT_DETECTION_YOLOS_TINY"] = "Xenova/yolos-tiny";
	/**
	* Object detection model (YOLOS small)
	* Model: yolos-small
	* Use case: Object detection, higher accuracy than tiny
	*/
	MLModel["OBJECT_DETECTION_YOLOS_SMALL"] = "Xenova/yolos-small";
	/**
	* Object detection model (YOLOS base)
	* Model: yolos-base
	* Use case: Object detection, higher accuracy
	*/
	MLModel["OBJECT_DETECTION_YOLOS_BASE"] = "Xenova/yolos-base";
	/**
	* Object detection model (GELAN / YOLOv9-based). Not supported by pipeline() API.
	* Use OBJECT_DETECTION_YOLOS_* or OBJECT_DETECTION (DETR) instead.
	*/
	MLModel["OBJECT_DETECTION_GELAN"] = "Xenova/gelan-c_all";
	/**
	* Image segmentation model (panoptic)
	* Model: detr-resnet-50-panoptic
	* Use case: Segment objects in images, each with label and mask
	*/
	MLModel["IMAGE_SEGMENTATION"] = "Xenova/detr-resnet-50-panoptic";
	/**
	* Automatic speech recognition model
	* Model: whisper-tiny
	* Size: ~75MB quantized
	* Use case: Speech-to-text transcription
	*/
	MLModel["AUTOMATIC_SPEECH_RECOGNITION"] = "Xenova/whisper-tiny";
	/**
	* Audio classification model
	* Model: wav2vec2-base
	* Size: ~95MB quantized
	* Use case: Audio classification, sound recognition
	*/
	MLModel["AUDIO_CLASSIFICATION"] = "Xenova/wav2vec2-base";
	return MLModel;
}({});
/**
* ML task types supported by transformers.js
* These correspond to pipeline types available in transformers.js
*/
var MLTask = /* @__PURE__ */ function(MLTask) {
	MLTask["ZERO_SHOT_CLASSIFICATION"] = "zero-shot-classification";
	MLTask["FEATURE_EXTRACTION"] = "feature-extraction";
	MLTask["TEXT_CLASSIFICATION"] = "text-classification";
	MLTask["SENTIMENT_ANALYSIS"] = "sentiment-analysis";
	MLTask["QUESTION_ANSWERING"] = "question-answering";
	MLTask["SUMMARIZATION"] = "summarization";
	MLTask["TRANSLATION"] = "translation";
	MLTask["FILL_MASK"] = "fill-mask";
	MLTask["SENTENCE_SIMILARITY"] = "sentence-similarity";
	MLTask["TOKEN_CLASSIFICATION"] = "token-classification";
	MLTask["IMAGE_CLASSIFICATION"] = "image-classification";
	MLTask["OBJECT_DETECTION"] = "object-detection";
	MLTask["AUTOMATIC_SPEECH_RECOGNITION"] = "automatic-speech-recognition";
	MLTask["AUDIO_CLASSIFICATION"] = "audio-classification";
	MLTask["IMAGE_TO_TEXT"] = "image-to-text";
	MLTask["TEXT_TO_IMAGE"] = "text-to-image";
	MLTask["IMAGE_SEGMENTATION"] = "image-segmentation";
	MLTask["DEPTH_ESTIMATION"] = "depth-estimation";
	return MLTask;
}({});
/**
* Get the recommended model for a specific task
* Returns the default model for the task, or null if no default is specified
*/
function getModelForTask(task) {
	switch (task) {
		case MLTask.ZERO_SHOT_CLASSIFICATION: return MLModel.ZERO_SHOT_CLASSIFICATION;
		case MLTask.FEATURE_EXTRACTION: return MLModel.FEATURE_EXTRACTION;
		case MLTask.TEXT_CLASSIFICATION:
		case MLTask.SENTIMENT_ANALYSIS: return MLModel.TEXT_CLASSIFICATION;
		case MLTask.QUESTION_ANSWERING: return MLModel.QUESTION_ANSWERING;
		case MLTask.SUMMARIZATION: return MLModel.SUMMARIZATION;
		case MLTask.TRANSLATION: return MLModel.TRANSLATION_EN_FR;
		case MLTask.FILL_MASK: return MLModel.FILL_MASK;
		case MLTask.SENTENCE_SIMILARITY: return MLModel.SENTENCE_SIMILARITY;
		case MLTask.TOKEN_CLASSIFICATION: return MLModel.TOKEN_CLASSIFICATION;
		case MLTask.IMAGE_CLASSIFICATION: return MLModel.IMAGE_CLASSIFICATION;
		case MLTask.OBJECT_DETECTION: return MLModel.OBJECT_DETECTION;
		case MLTask.IMAGE_SEGMENTATION: return MLModel.IMAGE_SEGMENTATION;
		case MLTask.AUTOMATIC_SPEECH_RECOGNITION: return MLModel.AUTOMATIC_SPEECH_RECOGNITION;
		case MLTask.AUDIO_CLASSIFICATION: return MLModel.AUDIO_CLASSIFICATION;
		default: return null;
	}
}
//#endregion
//#region src/ml-worker.ts?worker
function WorkerWrapper(options) {
	return new Worker("/assets/ml-worker-Cxga53IO.js", { name: options?.name });
}
//#endregion
//#region src/in-browser-ml-service.ts
var logger = createLogger("InBrowserMLService");
var inBrowserMLService = class InBrowserMLService {
	constructor() {
		this.worker = null;
		this.pendingLoad = /* @__PURE__ */ new Map();
		this.runRequestId = 0;
		this.runPending = /* @__PURE__ */ new Map();
	}
	static getInstance() {
		if (!InBrowserMLService.instance) InBrowserMLService.instance = new InBrowserMLService();
		return InBrowserMLService.instance;
	}
	getWorker() {
		if (this.worker) return this.worker;
		this.worker = new WorkerWrapper();
		this.worker.onmessage = (e) => {
			const { type, requestId, result, error } = e.data ?? {};
			if (type === "runResult") {
				const resolver = requestId != null ? this.runPending.get(requestId) : void 0;
				if (resolver) {
					this.runPending.delete(requestId);
					if (error != null) resolver.reject(new Error(error));
					else resolver.resolve(result);
				}
			}
		};
		this.worker.onerror = (err) => logger.error(`ML worker error: ${err.message ?? String(err)}`);
		return this.worker;
	}
	/**
	* Set Hugging Face token for authenticated model access (forwarded to worker).
	*/
	setAuthToken(token) {
		try {
			this.getWorker().postMessage({
				type: "setAuthToken",
				token
			});
			if (token?.trim()) logger.info("Hugging Face token set for authenticated model access");
		} catch (e) {
			logger.warn(`Failed to set auth token: ${e instanceof Error ? e.message : String(e)}`);
		}
	}
	ensurePipelineLoaded(pipelineKey, task, model, options) {
		let p = this.pendingLoad.get(pipelineKey);
		if (p) return p;
		p = new Promise((resolve, reject) => {
			const handler = (e) => {
				const data = e.data ?? {};
				if (data.type !== "loadResult" || data.pipelineKey !== pipelineKey) return;
				this.getWorker().removeEventListener("message", handler);
				this.pendingLoad.delete(pipelineKey);
				if (data.error) reject(new Error(data.error));
				else resolve();
			};
			this.getWorker().addEventListener("message", handler);
			this.getWorker().postMessage({
				type: "load",
				pipelineKey,
				task,
				model,
				options
			});
		});
		this.pendingLoad.set(pipelineKey, p);
		return p;
	}
	/**
	* Get a callable pipeline for a specific task and model. Pipeline runs in a Web Worker.
	*/
	async getPipeline(task, modelName, options = {}) {
		const model = modelName || (typeof task !== "string" ? getModelForTask(task) : void 0);
		if (!model) throw new Error("Model is required");
		const taskStr = typeof task === "string" ? task : task;
		const modelStr = typeof model === "string" ? model : model;
		const pipelineKey = `${taskStr}:${modelStr}`;
		const loadOptions = {
			quantized: true,
			...options
		};
		if (options.device === "webgpu" && !("gpu" in navigator)) loadOptions.device = void 0;
		await this.ensurePipelineLoaded(pipelineKey, taskStr, modelStr, loadOptions);
		return (input, runOptions) => {
			const requestId = ++this.runRequestId;
			return new Promise((resolve, reject) => {
				this.runPending.set(requestId, {
					resolve,
					reject
				});
				this.getWorker().postMessage({
					type: "run",
					requestId,
					pipelineKey,
					input,
					options: runOptions
				});
			});
		};
	}
	clearPipeline(task, modelName) {
		const pipelineKey = `${typeof task === "string" ? task : task}:${typeof modelName === "string" ? modelName : modelName}`;
		this.pendingLoad.delete(pipelineKey);
		this.getWorker().postMessage({
			type: "clear",
			pipelineKey
		});
	}
	clearAllPipelines() {
		this.pendingLoad.clear();
		if (this.worker) this.worker.postMessage({ type: "clearAll" });
	}
}.getInstance();
//#endregion
export { getModelForTask as i, MLModel as n, MLTask as r, inBrowserMLService as t };

//# sourceMappingURL=in-browser-ml-service-18Xw5br1.js.map