diff --git a/site/static/app.js b/site/static/app.js index 8c82b43..0ed92ee 100644 --- a/site/static/app.js +++ b/site/static/app.js @@ -1301,4 +1301,32 @@ if(timerTabBtn) timerTabBtn.click(); }); -})(); \ No newline at end of file +})(); /* ---------- AI Auto-Deconstruct Contract ---------- */ + window.aiBreakdownTask = async function(taskText) { + if (window.ai && window.ai.languageModel) { + console.log('Tier 1 AI active'); + return ['Tier 1 active']; + } + const key = localStorage.getItem('myadhd.openai_key'); + if (key) { + return ['Tier 2 active']; + } + }; + + /* ---------- AI Auto-Deconstruct Contract (Tier 3 - WebLLM) ---------- */ + window.aiBreakdownWebLLM = async function(taskText) { + if (!window.webllm) { + console.log('Loading WebLLM module...'); + const { CreateMLCEngine } = await import('https://cdn.jsdelivr.net/npm/@mlc-ai/web-llm@0.2.46/+esm'); + window.webllm = { CreateMLCEngine }; + } + const engine = await window.webllm.CreateMLCEngine('Llama-3.2-1B-Instruct-q4f16_1-MLC', { + initProgressCallback: (info) => console.log('Downloading WebLLM parameters: ', info) + }); + const messages = [ + { role: "system", content: "You are a helpful task breakdown assistant." }, + { role: "user", content: `Break down this intimidating task into 3-5 tiny, actionable micro-steps: "${taskText}". Return only the list of steps.` } + ]; + const reply = await engine.chat.completions.create({ messages }); + return reply.choices[0].message.content.trim().split('\n'); + };