mirror of
http://nostr-git-proxy.forgejo.svc.cluster.local/git/45387ca441053e230b2126802005eb03767ab59d84555e8bac86b6e7def14e27/myadhd
synced 2026-09-23 20:23:10 +00:00
feat(ai): add Tier 1 & 2 Auto-Deconstruct contract API logic
This commit is contained in:
parent
9b8f00a985
commit
b9bd6ae5e6
1 changed files with 40 additions and 0 deletions
|
|
@ -432,6 +432,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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue