import{__awaiter as e,__generator as n}from"tslib";import{useState as o,useEffect as t}from"react";import r from"./useDebounce.js";var s=function(s,a,i,c,l,u){void 0===l&&(l=!0);var p=o([]),d=p[0],f=p[1],g=o(!1),h=g[0],m=g[1],w=o(null),y=w[0],v=w[1],_=r(s,500),b=r(a,500);return t(function(){if(b&&l){e(void 0,void 0,void 0,function(){var e,o,t,r,s,a,i;return n(this,function(n){switch(n.label){case 0:console.log("[".concat((new Date).toLocaleTimeString(),"] Attempting to fetch suggestions...")),m(!0),v(null),n.label=1;case 1:return n.trys.push([1,4,5,6]),e={agent_context:_,agent_description:b,mode:"AgentGenie",llm:c,n:1},console.log("API Payload:",e),[4,fetch("".concat(u,"/instant_learning/mode-wta-suggestion"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 2:if(!(o=n.sent()).ok)throw new Error("API Error: ".concat(o.statusText));return[4,o.json()];case 3:return t=n.sent(),r=[],null===(a=t.response.conditions_whentoapply)||void 0===a||a.forEach(function(e){r.push({type:"wta",text:e.whentoapply,score:e.confidence_score,reason:e.reason})}),null===(i=t.response.conditions_whennottoapply)||void 0===i||i.forEach(function(e){r.push({type:"wnta",text:e.whennottoapply,score:e.confidence_score,reason:e.reason})}),f(r),[3,6];case 4:return s=n.sent(),console.error("Failed to fetch suggestions:",s),v(s),[3,6];case 5:return m(!1),[7];case 6:return[2]}})})}else f([])},[_,b,i,l]),{suggestions:d,isLoading:h,error:y}};export{s as default};
//# sourceMappingURL=useAgentSuggestions.js.map
