import{J as c}from"./bootstrap-DlNJH-GE.js";const l="intent-replay",u="1.0";function d(t){const r=t.filter(e=>e.action),a=r.map(e=>({verb:e.action,args:e.args??{},rationale:"replayed from recording"})),n=[...new Set(r.map(e=>e.action.replace(/^my\.wkms\.ui\./,"")))];return{intent:r.length?`Reproduce ${r.length} UI action(s): ${n.slice(0,6).join(", ")}`:"Empty recording (no UI actions captured)",plan:a}}function p(t,r){const a=r.map(o=>`- ${o.uid}: ${o.description}`).join(`
`),n=t.map((o,e)=>`${e+1}. ${o.action} ${o.args?JSON.stringify(o.args):""}`.trim()).join(`
`);return[{role:"system",content:`You are an agent that watches a user drive a web app and re-does their task. You are given (a) the catalog of callable UI intent-verbs and (b) the user's recorded verb stream. Infer the user's high-level INTENT, then output a SMART plan of verb calls that accomplishes the same goal — dedupe redundant steps, drop pure navigation noise, and keep only meaningful actions. Use ONLY verbs from the catalog. Respond with STRICT JSON: {"intent": string, "plan": [{"verb": string, "args": object, "rationale": string}]}.`},{role:"user",content:`# Verb catalog
${a}

# Recorded user actions
${n}

Return the JSON plan.`}]}function g(t,r){if(typeof t!="object"||t===null)return null;const a=t;if(typeof a.intent!="string"||!Array.isArray(a.plan))return null;const n=new Set(r.map(e=>e.uid)),o=[];for(const e of a.plan){if(typeof e!="object"||e===null)continue;const s=e;typeof s.verb=="string"&&(n.size>0&&!n.has(s.verb)||o.push({verb:s.verb,args:typeof s.args=="object"&&s.args!==null?s.args:{},rationale:typeof s.rationale=="string"?s.rationale:void 0}))}return o.length===0?null:{intent:a.intent,plan:o}}async function m(t){const r=t.events.filter(i=>i.action),a=d(r);if(r.length===0)return{...a,source:"heuristic"};let n;try{n=await t.complete({model:t.model,messages:p(r,t.catalog),responseFormat:"json_object",temperature:0,maxTokens:1200,promptId:l,promptVersion:u,tag:"intent_replay"})}catch{return{...a,source:"heuristic"}}const e=(t.healer??new c).heal(n.text),s=e.ok?g(e.value,t.catalog):null;return s?{...s,source:"llm",modelUsed:n.model,cacheHit:n.cacheHit}:{...a,source:"heuristic",modelUsed:n.model,cacheHit:n.cacheHit}}export{l as INTENT_PROMPT_ID,u as INTENT_PROMPT_VERSION,p as buildUnderstandMessages,d as heuristicIntentPlan,m as understandIntent};
//# sourceMappingURL=understand_intent-D3CIkops.js.map
