diff --git a/site/static/app.js b/site/static/app.js index cfb72d2..3954209 100644 --- a/site/static/app.js +++ b/site/static/app.js @@ -475,6 +475,46 @@ timerPersist(); timerPaint(); } + /* ---------- AI Auto-Deconstruct Contract (Tier 1 & 2) ---------- */ + window.aiBreakdownTask = async function(taskText) { + // Shared Interface for Sibyl's Tier 3 + const prompt = `Break down this intimidating task into 3-5 tiny, actionable micro-steps: "${taskText}". Return only the list of steps.`; + + // Tier 1: Browser Native (window.ai) + if (window.ai && window.ai.languageModel) { + try { + const caps = await window.ai.languageModel.capabilities(); + if (caps.available !== 'no') { + const session = await window.ai.languageModel.create(); + const result = await session.prompt(prompt); + return result.split('\n').filter(s => s.trim().length > 0); + } + } catch (e) { + console.warn("window.ai failed, falling back", e); + } + } + + // Tier 2: BYOK (Bring Your Own Key) Fallback + const key = store('byok_key'); + if (!key) { + throw new Error("NO_AI_AVAILABLE"); // Let UI prompt for key or let Tier 3 try + } + const resp = await fetch('https://api.openai.com/v1/chat/completions', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + key + }, + body: JSON.stringify({ + model: 'gpt-4o-mini', + messages: [{ role: 'user', content: prompt }] + }) + }); + if (!resp.ok) throw new Error("API_ERROR"); + const data = await resp.json(); + return data.choices[0].message.content.split('\n').filter(s => s.trim().length > 0); + }; + $('#timer-reset').addEventListener('click', timerReset); $$('.preset').forEach(function (p) {