"use strict"; /** * OllamaProvider — AI enrichment using local Ollama API. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.OllamaProvider = void 0; const DEFAULT_MODEL = 'llama3.2'; const DEFAULT_URL = 'http://localhost:11434'; function buildPrompt(anomaly, context) { return `Analyze this bug and respond ONLY with JSON {"rootCause":"...","userImpact":"...","suggestedFix":"...","confidence":"low|medium|high"}. Bug: ${anomaly.type} (${anomaly.severity}) at ${context.url} Description: ${anomaly.description} Last actions: ${anomaly.actionTrace.slice(-3).map((a) => `${a.type} ${a.selector ?? a.url ?? ''}`).join(' → ')}`; } class OllamaProvider { constructor(baseUrl = DEFAULT_URL, model = DEFAULT_MODEL) { this.name = 'ollama'; this.baseUrl = baseUrl; this.model = model; } async enrich(anomaly, context) { const prompt = buildPrompt(anomaly, context); const res = await fetch(`${this.baseUrl}/api/generate`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ model: this.model, prompt, stream: false }), }); if (!res.ok) { throw new Error(`Ollama API error: ${res.status}`); } const data = await res.json(); const text = data.response ?? ''; try { const match = text.match(/\{[\s\S]*\}/); if (match) { const p = JSON.parse(match[0]); return { rootCause: p['rootCause'] ?? 'Unknown', userImpact: p['userImpact'] ?? 'Unknown', suggestedFix: p['suggestedFix'] ?? 'None', debugPrompt: text, confidence: p['confidence'] ?? 'low', generatedAt: Date.now(), provider: 'ollama', model: this.model, }; } } catch { /* fallback */ } return { rootCause: text.slice(0, 200), userImpact: 'See response', suggestedFix: 'See response', debugPrompt: text, confidence: 'low', generatedAt: Date.now(), provider: 'ollama', model: this.model, }; } } exports.OllamaProvider = OllamaProvider;