"use strict";exports.id=569,exports.ids=[569,4553],exports.modules={10569:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.r(b),c.d(b,{isDue:()=>q,startWidgetScheduler:()=>m,stopWidgetScheduler:()=>n});var e=c(53905),f=c(93554),g=c(51021),h=c(69509),i=c(1405),j=c(94553),k=a([f,g]);[f,g]=k.then?(await k)():k;let s="__reflexWidgetScheduler";function l(){return globalThis[s]||(globalThis[s]={intervalId:null,ticking:!1,startedAt:new Date().toISOString()}),globalThis[s]}function m(){let a=l();a.intervalId||(setTimeout(()=>{o().catch(a=>{console.error("[widget-scheduler] initial tick failed:",a)})},3e4),a.intervalId=setInterval(()=>{o().catch(a=>{console.error("[widget-scheduler] tick failed:",a)})},3e5))}function n(){let a=l();a.intervalId&&(clearInterval(a.intervalId),a.intervalId=null)}async function o(){let a=l();if(!a.ticking){a.ticking=!0;try{for(let a of(await (0,e.qV)()))try{await p(a.id,a.path)}catch(b){console.error(`[widget-scheduler] root ${a.id} failed:`,b instanceof Error?b.message:b)}}finally{a.ticking=!1}}}async function p(a,b){for(let c of(await (0,h.listWidgets)(b)))q(c)&&c.sourceTopicId&&(f.z.isActive(c.sourceTopicId)||await r(a,b,c))}function q(a){if(!a.refresh||"manual"===a.refresh)return!1;let b=i.VQ[a.refresh];if(!b)return!1;let c=a.lastRefreshAt??a.updatedAt,d=Date.now()-Date.parse(c);return Number.isFinite(d)&&d>=b}async function r(a,b,c){let d={...c,lastRefreshAt:new Date().toISOString()};await (0,h.writeWidget)(b,d);let e=await (0,j.buildRefreshPromptForWidget)(b,d),f=await (0,g.W)({rootId:a,topicId:c.sourceTopicId,message:e,attachments:[]});"error"in f&&console.error(`[widget-scheduler] couldn't start refresh for ${c.id}: ${f.error}`)}d()}catch(a){d(a)}})},94553:(a,b,c)=>{c.d(b,{buildRefreshPromptForWidget:()=>e});var d=c(69509);async function e(a,b){let c=b.memoryFile?await (0,d.iq)(a,b.memoryFile):null,e=[];return e.push(`[Reflex auto-refresh] Widget "${b.title}" (id: \`${b.id}\`, kind: \`${b.kind}\`) is due for an update.`),e.push(""),e.push("Current widget data:"),e.push("```json"),e.push(JSON.stringify(b.data,null,2)),e.push("```"),e.push(""),b.memory&&b.memory.trim()&&(e.push("Current inline memory:"),e.push("```"),e.push(b.memory),e.push("```"),e.push("")),b.memoryFile&&(e.push(`Memory file: \`${b.memoryFile}\``),c&&c.trim()?(e.push("```markdown"),e.push(c.slice(0,4e3)),e.push("```")):e.push("_(file is empty or does not exist — create it on the first update)_"),e.push("")),e.push("What to do:"),e.push(`- Emit \`<<reflex:widget-update>>\` with id="${b.id}" and fresh data.`),e.push("- If `memory` exists, update its contents (dedup links, value history, etc.). Do not reset it to empty."),b.memoryFile&&e.push(`- If it makes sense, append to memoryFile (\`${b.memoryFile}\`) via \`<<reflex:kb>>\` (kind="widget-memory", title="<title>"). Do not duplicate the widget's own data there.`),e.push("- Keep the chat reply short (one line) — this is an automatic refresh, no extended commentary needed."),e.push(`- Cadence: \`${b.refresh??"manual"}\`. Do not change it without an explicit request.`),e.join("\n")}}};