khoj 2.0.0b13.dev23__py3-none-any.whl → 2.0.0b14__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. khoj/database/admin.py +2 -2
  2. khoj/interface/compiled/404/index.html +2 -2
  3. khoj/interface/compiled/_next/static/chunks/9808-c0742b05e1ef29ba.js +1 -0
  4. khoj/interface/compiled/_next/static/chunks/app/agents/layout-0114c87d7ccf6d9b.js +1 -0
  5. khoj/interface/compiled/_next/static/chunks/app/automations/layout-8639ff99d6c2fec6.js +1 -0
  6. khoj/interface/compiled/_next/static/chunks/app/automations/{page-198b26df6e09bbb0.js → page-1047097af99d31c7.js} +1 -1
  7. khoj/interface/compiled/_next/static/chunks/app/chat/layout-2ff3e18a6feae92a.js +1 -0
  8. khoj/interface/compiled/_next/static/chunks/app/chat/page-ac7ed0a1aff1b145.js +1 -0
  9. khoj/interface/compiled/_next/static/chunks/app/search/layout-78dd7cdd97510485.js +1 -0
  10. khoj/interface/compiled/_next/static/chunks/app/share/chat/layout-8addeb8079c3215b.js +1 -0
  11. khoj/interface/compiled/_next/static/chunks/app/share/chat/{page-e0dcb1762f8c8f88.js → page-819c6536c15e3d31.js} +1 -1
  12. khoj/interface/compiled/_next/static/css/5c7a72bad47e50b3.css +25 -0
  13. khoj/interface/compiled/_next/static/css/{c34713c98384ee87.css → 821d0d60b0b6871d.css} +1 -1
  14. khoj/interface/compiled/_next/static/css/ecea704005ba630c.css +1 -0
  15. khoj/interface/compiled/agents/index.html +2 -2
  16. khoj/interface/compiled/agents/index.txt +1 -1
  17. khoj/interface/compiled/automations/index.html +2 -2
  18. khoj/interface/compiled/automations/index.txt +3 -3
  19. khoj/interface/compiled/chat/index.html +2 -2
  20. khoj/interface/compiled/chat/index.txt +5 -4
  21. khoj/interface/compiled/index.html +2 -2
  22. khoj/interface/compiled/index.txt +1 -1
  23. khoj/interface/compiled/search/index.html +2 -2
  24. khoj/interface/compiled/search/index.txt +1 -1
  25. khoj/interface/compiled/settings/index.html +2 -2
  26. khoj/interface/compiled/settings/index.txt +1 -1
  27. khoj/interface/compiled/share/chat/index.html +2 -2
  28. khoj/interface/compiled/share/chat/index.txt +2 -2
  29. khoj/processor/conversation/google/gemini_chat.py +1 -1
  30. khoj/processor/conversation/google/utils.py +62 -19
  31. khoj/processor/conversation/openai/utils.py +58 -22
  32. khoj/processor/conversation/prompts.py +37 -25
  33. khoj/processor/conversation/utils.py +2 -1
  34. khoj/processor/tools/run_code.py +15 -22
  35. khoj/routers/api_chat.py +8 -3
  36. khoj/routers/api_content.py +1 -1
  37. khoj/routers/helpers.py +44 -38
  38. khoj/routers/research.py +7 -5
  39. khoj/utils/constants.py +6 -1
  40. khoj/utils/helpers.py +55 -15
  41. {khoj-2.0.0b13.dev23.dist-info → khoj-2.0.0b14.dist-info}/METADATA +1 -1
  42. {khoj-2.0.0b13.dev23.dist-info → khoj-2.0.0b14.dist-info}/RECORD +47 -47
  43. khoj/interface/compiled/_next/static/chunks/7127-97b83757db125ba6.js +0 -1
  44. khoj/interface/compiled/_next/static/chunks/app/agents/layout-e00fb81dca656a10.js +0 -1
  45. khoj/interface/compiled/_next/static/chunks/app/automations/layout-63603d2cb33279f7.js +0 -1
  46. khoj/interface/compiled/_next/static/chunks/app/chat/layout-33934fc2d6ae6838.js +0 -1
  47. khoj/interface/compiled/_next/static/chunks/app/chat/page-dfcc1e8e2ad62873.js +0 -1
  48. khoj/interface/compiled/_next/static/chunks/app/search/layout-c02531d586972d7d.js +0 -1
  49. khoj/interface/compiled/_next/static/chunks/app/share/chat/layout-e8e5db7830bf3f47.js +0 -1
  50. khoj/interface/compiled/_next/static/css/23b26df423cd8a9c.css +0 -1
  51. khoj/interface/compiled/_next/static/css/3090706713c12a32.css +0 -25
  52. /khoj/interface/compiled/_next/static/{Q7tm150g44Fs4H1CGytNf → Qn_2XyeVWxjaIRks7rzM-}/_buildManifest.js +0 -0
  53. /khoj/interface/compiled/_next/static/{Q7tm150g44Fs4H1CGytNf → Qn_2XyeVWxjaIRks7rzM-}/_ssgManifest.js +0 -0
  54. {khoj-2.0.0b13.dev23.dist-info → khoj-2.0.0b14.dist-info}/WHEEL +0 -0
  55. {khoj-2.0.0b13.dev23.dist-info → khoj-2.0.0b14.dist-info}/entry_points.txt +0 -0
  56. {khoj-2.0.0b13.dev23.dist-info → khoj-2.0.0b14.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1929],{39929:function(e,t,s){Promise.resolve().then(s.bind(s,42780))},42780:function(e,t,s){"use strict";s.r(t),s.d(t,{default:function(){return ec}});var a=s(57437),n=s(63136),i=s.n(n),l=s(2265),r=s(2208),o=s(29808),d=s(99376),c=s(14308),u=s(59199);s(2446);var h=s(7436),m=s(5477),f=s(56937),x=s(55287),p=s(60729),g=s(34124),j=s(6512),v=s(37104),N=s(62869),y=s(91890),b=s(77992),w=s(68772),_=s(79603),S=s(23594),C=s(34153),O=s(43551),k=s(32046),I=s(5223),T=s(76818),M=s(75256),E=s(24148),A=s(94508),z=s(23518),B=s(57054),R=s(16605);let L=R.fC,F=R.xz,P=l.forwardRef((e,t)=>{let{className:s,align:n="center",sideOffset:i=4,...l}=e;return(0,a.jsx)(R.VY,{ref:t,align:n,sideOffset:i,className:(0,A.cn)("z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s),...l})});P.displayName=R.VY.displayName;var D=s(54036);function W(e){var t,s;let{...n}=e,[i,r]=l.useState(!1),[o,d]=(0,l.useState)(void 0),[c,u]=(0,l.useState)(void 0),{data:m,error:x,isLoading:p}=(0,f.h2)(!0),[g,j]=(0,l.useState)([]),v=(0,h.IC)();return((0,l.useEffect)(()=>{if(!p&&m){if(j(m.chat_model_options),n.initialModel)u(m.chat_model_options.find(e=>e.name===n.initialModel));else{let e=m.chat_model_options.find(e=>e.id===m.selected_chat_model_config);!e&&m.chat_model_options.length>0?u(m.chat_model_options[0]):u(e)}}},[m,n.initialModel,p]),(0,l.useEffect)(()=>{c&&m&&n.onSelect(c)},[c,m,n.onSelect]),p)?(0,a.jsx)(D.O,{className:"w-full h-10"}):x?(0,a.jsx)("div",{className:"text-sm text-error",children:x.message}):(0,a.jsx)("div",{className:"grid gap-2 w-[250px]",children:(0,a.jsxs)(B.J2,{open:i,onOpenChange:r,...n,children:[(0,a.jsx)(B.xo,{asChild:!0,children:(0,a.jsxs)(N.z,{variant:"outline",role:"combobox","aria-expanded":i,"aria-label":"Select a model",className:"w-full justify-between text-left",disabled:null!==(s=n.disabled)&&void 0!==s&&s,children:[(0,a.jsx)("p",{className:"truncate",children:c?null===(t=c.name)||void 0===t?void 0:t.substring(0,20):"Select a model..."}),(0,a.jsx)(M.K,{className:"opacity-50"})]})}),(0,a.jsx)(B.yk,{align:"end",className:"w-[250px] p-0",children:v?(0,a.jsx)("div",{children:(0,a.jsx)(z.mY,{loop:!0,children:(0,a.jsxs)(z.e8,{className:"h-[var(--cmdk-list-height)]",children:[(0,a.jsx)(z.sZ,{placeholder:"Search Models..."}),(0,a.jsx)(z.rb,{children:"No Models found."}),(0,a.jsx)(z.fu,{heading:"Models",children:g&&g.length>0&&g.map(e=>(0,a.jsx)(Z,{model:e,isSelected:(null==c?void 0:c.id)===e.id,onPeek:e=>d(e),onSelect:()=>{u(e),r(!1)},isActive:n.isActive},e.id))},"models")]})})}):(0,a.jsxs)(L,{children:[(0,a.jsx)(P,{side:"left",align:"start",forceMount:!0,className:"min-h-[280px]",children:(0,a.jsxs)("div",{className:"grid gap-2",children:[(0,a.jsx)("h4",{className:"font-medium leading-none",children:null==o?void 0:o.name}),(0,a.jsx)("div",{className:"text-sm text-muted-foreground",children:null==o?void 0:o.description}),(null==o?void 0:o.strengths)?(0,a.jsxs)("div",{className:"mt-4 grid gap-2",children:[(0,a.jsx)("h5",{className:"text-sm font-medium leading-none",children:"Strengths"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:o.strengths})]}):null]})}),(0,a.jsxs)("div",{children:[(0,a.jsx)(F,{}),(0,a.jsx)(z.mY,{loop:!0,children:(0,a.jsxs)(z.e8,{className:"h-[var(--cmdk-list-height)]",children:[(0,a.jsx)(z.sZ,{placeholder:"Search Models..."}),(0,a.jsx)(z.rb,{children:"No Models found."}),(0,a.jsx)(z.fu,{heading:"Models",children:g&&g.length>0&&g.map(e=>(0,a.jsx)(Z,{model:e,isSelected:(null==c?void 0:c.id)===e.id,onPeek:e=>d(e),onSelect:()=>{u(e),r(!1)},isActive:n.isActive},e.id))},"models")]})})]})]})})]})})}function Z(e){let{model:t,isSelected:s,onSelect:n,onPeek:i,isActive:r}=e,o=l.useRef(null);return(0,h.Iy)(o,e=>{e.forEach(e=>{var s;"attributes"===e.type&&"aria-selected"===e.attributeName&&(null===(s=o.current)||void 0===s?void 0:s.getAttribute("aria-selected"))==="true"&&i(t)})}),(0,a.jsxs)(z.di,{onSelect:n,ref:o,className:"data-[selected=true]:bg-muted data-[selected=true]:text-secondary-foreground",disabled:!r&&"free"!==t.tier,children:[t.name," ","standard"===t.tier&&(0,a.jsx)("span",{className:"text-green-500 ml-2",children:"(Futurist)"}),(0,a.jsx)(E.J,{className:(0,A.cn)("ml-auto",s?"opacity-100":"opacity-0")})]},t.id)}var J=s(17200),V=s(6952),U=s(69304),K=s(42225),H=s(26815),G=s(9270),Q=s(30401);let q=l.forwardRef((e,t)=>{let{className:s,...n}=e;return(0,a.jsx)(G.fC,{ref:t,className:(0,A.cn)("peer h-4 w-4 shrink-0 rounded-sm border border-secondary-foreground ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-gray-500 data-[state=checked]:text-primary-foreground",s),...n,children:(0,a.jsx)(G.z$,{className:(0,A.cn)("flex items-center justify-center text-current"),children:(0,a.jsx)(Q.Z,{className:"h-4 w-4"})})})});q.displayName=G.fC.displayName;var Y=s(81103),$=s(61312),X=s(26110),ee=s(53647),et=s(84671),es=s(95186),ea=s(27648),en=s(98239);let ei=e=>fetch(e).then(e=>e.json());function el(e){let{...t}=e;return t.isMobileWidth?(0,a.jsx)(U.yo,{open:t.isOpen,onOpenChange:t.onOpenChange,children:(0,a.jsx)(U.ue,{className:"w-[300px] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",children:(0,a.jsx)(eo,{...t})})}):(0,a.jsx)("div",{className:"relative h-full",children:(0,a.jsx)(eo,{...t})})}function er(e){let t=(0,K.BI)(),s=et.xF,[n,i]=(0,l.useState)(!1),[r,o]=(0,l.useState)(),[d,c]=(0,l.useState)(),[u,h]=(0,l.useState)(),[m,f]=(0,l.useState)(!1),[x,p]=(0,l.useState)(),[g,j]=(0,l.useState)(!1),[v,y]=(0,l.useState)();return(0,l.useEffect)(()=>{r&&d&&u?j(!0):j(!1)},[r,d,u]),(0,a.jsxs)(X.Vq,{children:[(0,a.jsx)(X.hg,{asChild:!0,children:(0,a.jsx)(N.z,{className:"w-full",variant:"secondary",children:"Create Agent"})}),(0,a.jsxs)(X.cZ,{children:[(0,a.jsxs)(X.fK,{children:[m&&x?(0,a.jsxs)(X.$N,{children:["Created ",r]}):(0,a.jsx)(X.$N,{children:"Create a New Agent"}),(0,a.jsx)(X.GG,{}),(0,a.jsx)(X.Be,{children:"If these settings have been helpful, create a dedicated agent you can re-use across conversations."})]}),(0,a.jsx)("div",{className:"py-4",children:m&&x?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-8",children:[(0,a.jsx)(en.E.div,{initial:{scale:0},animate:{scale:1},transition:{type:"spring",stiffness:260,damping:20},children:(0,a.jsx)(w.f,{className:"w-16 h-16 text-green-500",weight:"fill"})}),(0,a.jsx)(en.E.p,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.2},className:"text-center text-lg font-medium text-accent-foreground",children:"Created successfully!"}),(0,a.jsx)(en.E.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.4},children:(0,a.jsx)(ea.default,{href:"/agents?agent=".concat(x),children:(0,a.jsx)(N.z,{variant:"secondary",className:"mt-2",children:"Manage Agent"})})})]}):(0,a.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(H._,{htmlFor:"agent_name",children:"Name"}),(0,a.jsx)(es.I,{id:"agent_name",className:"w-full p-2 border mt-4 border-slate-500 rounded-lg",disabled:n,value:r,onChange:e=>o(e.target.value)})]}),(0,a.jsxs)("div",{className:"flex gap-4",children:[(0,a.jsx)("div",{className:"flex-1",children:(0,a.jsxs)(ee.Ph,{onValueChange:h,defaultValue:u,children:[(0,a.jsx)(ee.i4,{className:"w-full dark:bg-muted",disabled:n,children:(0,a.jsx)(ee.ki,{placeholder:"Color"})}),(0,a.jsx)(ee.Bw,{className:"items-center space-y-1 inline-flex flex-col",children:s.map(e=>(0,a.jsx)(ee.Ql,{value:e,children:(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,a.jsx)(_.C,{className:"w-6 h-6 mr-2 ".concat((0,et.oz)(e)),weight:"fill"}),e]})},e))})]})}),(0,a.jsx)("div",{className:"flex-1",children:(0,a.jsxs)(ee.Ph,{onValueChange:c,defaultValue:d,children:[(0,a.jsx)(ee.i4,{className:"w-full dark:bg-muted",disabled:n,children:(0,a.jsx)(ee.ki,{placeholder:"Icon"})}),(0,a.jsx)(ee.Bw,{className:"items-center space-y-1 inline-flex flex-col",children:t.map(e=>(0,a.jsx)(ee.Ql,{value:e,children:(0,a.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,K.TI)(e,null!=u?u:"gray","w-6","h-6"),e]})},e))})]})})]})]})}),(0,a.jsxs)(X.cN,{children:[v&&(0,a.jsx)("div",{className:"text-red-500 text-sm",children:v}),!m&&(0,a.jsxs)(N.z,{type:"submit",onClick:()=>void(!n&&(i(!0),fetch("/api/agents",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r,icon:d,color:u,persona:e.customPrompt,chat_model:e.selectedModel,input_tools:e.inputTools,output_modes:e.outputModes,privacy_level:"private"})}).then(e=>e.json()).then(e=>{if(console.log("Success:",e),"detail"in e){y("Error creating agent: ".concat(e.detail)),i(!1);return}f(!0),p(e.slug),i(!1)}).catch(e=>{console.error("Error:",e),y("Error creating agent: ".concat(e)),i(!1)}))),disabled:n||!g,children:[n?(0,a.jsx)(S.U,{className:"animate-spin"}):(0,a.jsx)(C.R,{}),"Create"]}),(0,a.jsx)(X.GG,{})]})]})]})}function eo(e){var t,s,n,i,r;let{...o}=e,[d,c]=(0,l.useState)(!1),{data:u,error:h}=(0,J.ZP)("/api/agents/options",ei),{data:m,isLoading:g,error:j}=(0,J.ZP)("/api/agents/conversation?conversation_id=".concat(o.conversationId),ei),{data:v,error:y,isLoading:b}=(0,f.GW)(),[w,_]=(0,l.useState)(),[C,M]=(0,l.useState)(),[E,A]=(0,l.useState)(),[z,R]=(0,l.useState)(),[L,F]=(0,l.useState)(!1),[P,D]=(0,l.useState)(!m||(null==m?void 0:null===(t=m.slug)||void 0===t?void 0:t.toLowerCase())==="khoj"),[Z,U]=(0,l.useState)(),[G,Q]=(0,l.useState)(),[X,ee]=(0,l.useState)(!1),et=null!==(s=null==v?void 0:v.is_active)&&void 0!==s&&s;function es(){if(m){var e,t;A(m.input_tools),U(m.input_tools),(void 0===m.input_tools||0===m.input_tools.length)&&U((null==u?void 0:u.input_tools)?Object.keys(u.input_tools):[]),R(m.output_modes),Q(m.output_modes),(void 0===m.output_modes||0===m.output_modes.length)&&Q((null==u?void 0:u.output_modes)?Object.keys(u.output_modes):[]),((null===(e=m.name)||void 0===e?void 0:e.toLowerCase())==="khoj"||!0===m.is_hidden)&&c(!0),(null===(t=m.slug)||void 0===t?void 0:t.toLowerCase())==="khoj"?(M(void 0),_(void 0),D(!0)):(D(!1),_(m.persona),M(m.chat_model))}}function ea(e,t){return t.includes(e)?t.filter(t=>t!==e):[...t,e]}return(0,l.useEffect)(()=>{es(),F(!1)},[m]),(0,l.useEffect)(()=>{var e,t;if(!m||g)return;let s=!!C&&C!==m.chat_model,a=!!w&&w!==m.persona,n=JSON.stringify((null==E?void 0:E.sort())||[])!==JSON.stringify(null===(e=m.input_tools)||void 0===e?void 0:e.sort()),i=JSON.stringify((null==z?void 0:z.sort())||[])!==JSON.stringify(null===(t=m.output_modes)||void 0===t?void 0:t.sort());F(s||a||n||i)},[C,w,E,z,m,g]),(0,a.jsxs)(p.DD,{collapsible:"none",className:"ml-auto opacity-30 rounded-lg p-2 transition-all transform duration-300 ease-in-out\n ".concat(o.isOpen?"translate-x-0 opacity-100 w-[300px] relative":"translate-x-full opacity-100 w-0 p-0 m-0","\n "),variant:"floating",children:[(0,a.jsxs)(p.TZ,{children:[(0,a.jsx)(p.$l,{children:m&&!d?(0,a.jsx)("div",{className:"flex items-center relative text-sm",children:(0,a.jsxs)("a",{className:"text-lg font-bold flex flex-row items-center",href:"/agents?agent=".concat(m.slug),children:[(0,K.TI)(m.icon,m.color),m.name]})}):(0,a.jsx)("div",{className:"flex items-center relative text-sm justify-between",children:(0,a.jsx)("p",{children:"Chat Options"})})}),(0,a.jsx)(p.Hz,{className:"border-b last:border-none",children:(0,a.jsx)(p.Ks,{className:"gap-0",children:(0,a.jsx)(p.w3,{className:"p-0 m-0",children:m&&m.has_files?(0,a.jsx)(p.LO,{className:"list-none",children:(0,a.jsxs)("div",{className:"flex items-center space-x-2 rounded-full",children:[(0,a.jsx)("div",{className:"text-muted-foreground",children:(0,a.jsx)(O.J,{})}),(0,a.jsx)("div",{className:"text-muted-foreground text-sm",children:"Using custom knowledge base"})]})},"agent_knowledge"):null})})},"knowledge"),(0,a.jsx)(p.Hz,{children:(0,a.jsxs)(p.Ks,{children:[(0,a.jsx)(p.nO,{children:"Instructions"}),(0,a.jsx)(p.w3,{className:"p-0 m-0",children:(0,a.jsx)(p.LO,{className:"list-none",children:(0,a.jsx)(T.g,{className:"w-full h-32 resize-none hover:resize-y",value:w||"",onChange:e=>{_(e.target.value)},readOnly:!d,disabled:!d})})})]})},"instructions"),!g&&m&&(0,a.jsx)(p.Hz,{children:(0,a.jsxs)(p.Ks,{children:[(0,a.jsxs)(p.nO,{children:["Model",!et&&(0,a.jsx)("a",{href:"/settings",className:"hover:font-bold text-accent-foreground m-2 bg-accent bg-opacity-10 p-1 rounded-lg",children:"Upgrade"})]}),(0,a.jsx)(p.w3,{className:"p-0 m-0",children:(0,a.jsx)(p.LO,{className:"list-none",children:(0,a.jsx)(W,{disabled:!d,onSelect:e=>{M(e.name)},initialModel:P?void 0:null==m?void 0:m.chat_model,isActive:o.isActive})},"model")})]})},"model"),(0,a.jsx)(B.J2,{defaultOpen:!1,children:(0,a.jsxs)(p.Hz,{children:[(0,a.jsx)(p.nO,{asChild:!0,children:(0,a.jsxs)(B.xo,{children:["Tools",(0,a.jsx)(k._,{className:"ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180"})]})}),(0,a.jsx)(B.yk,{children:(0,a.jsx)(p.Ks,{children:(0,a.jsxs)(p.w3,{className:"p-1 m-0",children:[Object.entries(null!==(n=null==u?void 0:u.input_tools)&&void 0!==n?n:{}).map(e=>{let[t,s]=e;return(0,a.jsx)(p.LO,{className:"list-none",children:(0,a.jsxs)(Y.u,{children:[(0,a.jsx)(Y.aJ,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center space-x-2 py-1 justify-between",children:[(0,a.jsxs)(H._,{htmlFor:t,className:"flex items-center gap-2 text-accent-foreground p-1 cursor-pointer",children:[(0,K.vH)(t),(0,a.jsx)("p",{className:"text-sm my-auto flex items-center",children:t})]}),(0,a.jsx)(q,{id:t,className:"".concat(d?"cursor-pointer":""),checked:(null!=Z?Z:[]).includes(t),onCheckedChange:()=>{let e=ea(t,null!=Z?Z:[]);A(e),U(e)},disabled:!d,children:t})]})},t),(0,a.jsx)($._v,{sideOffset:5,side:"left",align:"start",className:"text-sm bg-background text-foreground shadow-sm border border-slate-500 border-opacity-20 p-2 rounded-lg",children:s})]})},t)}),Object.entries(null!==(i=null==u?void 0:u.output_modes)&&void 0!==i?i:{}).map(e=>{let[t,s]=e;return(0,a.jsx)(p.LO,{className:"list-none",children:(0,a.jsxs)(Y.u,{children:[(0,a.jsx)(Y.aJ,{asChild:!0,children:(0,a.jsxs)("div",{className:"flex items-center space-x-2 py-1 justify-between",children:[(0,a.jsxs)(H._,{htmlFor:t,className:"flex items-center gap-2 p-1 rounded-lg cursor-pointer",children:[(0,K.vH)(t),(0,a.jsx)("p",{className:"text-sm my-auto flex items-center",children:t})]}),(0,a.jsx)(q,{id:t,className:"".concat(d?"cursor-pointer":""),checked:(null!=G?G:[]).includes(t),onCheckedChange:()=>{let e=ea(t,null!=G?G:[]);R(e),Q(e)},disabled:!d,children:t})]})},t),(0,a.jsx)($._v,{sideOffset:5,side:"left",align:"start",className:"text-sm bg-background text-foreground shadow-sm border border-slate-500 border-opacity-20 p-2 rounded-lg",children:s})]})},t)})]})})})]})}),(0,a.jsx)(p.Hz,{children:(0,a.jsxs)(p.Ks,{children:[(0,a.jsx)(p.nO,{children:"Files"}),(0,a.jsx)(p.w3,{className:"p-0 m-0",children:(0,a.jsx)(p.LO,{className:"list-none",children:(0,a.jsx)(x.J_,{conversationId:o.conversationId,uploadedFiles:[],isMobileWidth:null!==(r=o.isMobileWidth)&&void 0!==r&&r})},"files-conversation")})]})},"files")]}),o.isOpen&&(0,a.jsx)(p.ZW,{children:(0,a.jsx)(p.w3,{className:"p-0 m-0",children:m&&!d&&m.is_creator?(0,a.jsx)(p.LO,{children:(0,a.jsx)(p.bb,{asChild:!0,children:(0,a.jsx)(N.z,{className:"w-full",variant:"ghost",onClick:()=>window.location.href="/agents?agent=".concat(null==m?void 0:m.slug),children:"Manage"})})}):(0,a.jsxs)(a.Fragment,{children:[!L&&d&&w&&!P&&C&&(0,a.jsx)(p.LO,{children:(0,a.jsx)(p.bb,{asChild:!0,children:(0,a.jsx)(er,{customPrompt:w,selectedModel:C,inputTools:null!=Z?Z:[],outputModes:null!=G?G:[]})})}),(0,a.jsx)(p.LO,{children:(0,a.jsx)(p.bb,{asChild:!0,children:(0,a.jsx)(N.z,{className:"w-full",onClick:()=>void(es(),F(!1)),variant:"ghost",disabled:!d||!L,children:"Reset"})})}),(0,a.jsx)(p.LO,{children:(0,a.jsx)(p.bb,{asChild:!0,children:(0,a.jsxs)(N.z,{className:"w-full ".concat(L?"bg-accent-foreground text-accent":""),variant:"secondary",onClick:()=>(function(){if(L){if(!P&&(null==m?void 0:m.is_hidden)===!1){alert("This agent is not a hidden agent. It cannot be modified from this interface.");return}let e="PATCH";P&&(e="POST");let t={persona:w,chat_model:C,input_tools:E,output_modes:z,...P?{}:{slug:null==m?void 0:m.slug}};ee(!0),fetch(P?"/api/agents/hidden?conversation_id=".concat(o.conversationId):"/api/agents/hidden",{method:e,headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then(e=>{ee(!1),e.json()}).then(e=>{(0,V.j)("/api/agents/conversation?conversation_id=".concat(o.conversationId)),F(!1)}).catch(e=>{console.error("Error:",e),ee(!1)})}})(),disabled:!d||!L||X,children:[X?(0,a.jsx)(S.U,{className:"animate-spin"}):(0,a.jsx)(I.Z,{}),X?"Saving":"Save"]})})})]})})},"actions")]})}function ed(e){let t=(0,d.useSearchParams)().get("conversationId"),[s,n]=(0,l.useState)(""),[r,c]=(0,l.useState)([]),[u,h]=(0,l.useState)(!1),[f,x]=(0,l.useState)(null),[p,g]=(0,l.useState)(!1),j=(0,l.useRef)(null),v=e.setQueryToProcess,N=e.onConversationIdChange,y=e.isMobileWidth?"w-full":"w-4/6";if((0,l.useEffect)(()=>{if(r.length>0){let t=r.map(e=>encodeURIComponent(e));e.setImages(t)}},[r,e.setImages]),(0,l.useEffect)(()=>{let t=localStorage.getItem("images");if(t){let s=JSON.parse(t);c(s);let a=s.map(e=>encodeURIComponent(e));e.setImages(a),localStorage.removeItem("images")}let s=localStorage.getItem("message");s&&(h(!0),v(s),s.trim().startsWith("/research")&&g(!0));let a=localStorage.getItem("uploadedFiles");if(a){let t=a?JSON.parse(a):[],s=[];for(let e of t)s.push({name:e.name,file_type:e.file_type,content:e.content,size:e.size});localStorage.removeItem("uploadedFiles"),e.setUploadedFiles(s)}},[v,e.setImages,t]),(0,l.useEffect)(()=>{s&&(h(!0),v(s))},[s,v]),(0,l.useEffect)(()=>{t&&(null==N||N(t))},[t,N]),(0,l.useEffect)(()=>{e.streamedMessages&&e.streamedMessages.length>0&&e.streamedMessages[e.streamedMessages.length-1].completed?(h(!1),c([]),e.setUploadedFiles(void 0)):n("")},[e.streamedMessages]),!t){window.location.href="/";return}return(0,a.jsxs)("div",{className:"flex flex-row h-full w-full",children:[(0,a.jsxs)("div",{className:"flex flex-col h-full w-full",children:[(0,a.jsx)("div",{className:i().chatBodyFull,children:(0,a.jsx)(o.Z,{conversationId:t,setTitle:e.setTitle,setAgent:x,pendingMessage:u?s:"",incomingMessages:e.streamedMessages,setIncomingMessages:e.setStreamedMessages,customClassName:y,setIsChatSideBarOpen:e.setIsChatSideBarOpen,onRetryMessage:e.onRetryMessage})}),(0,a.jsx)("div",{className:"".concat(i().inputBox," print-hidden p-1 md:px-2 shadow-md bg-background align-middle items-center justify-center dark:bg-neutral-700 dark:border-0 dark:shadow-sm rounded-2xl md:rounded-xl h-fit ").concat(y," mr-auto ml-auto mt-auto"),children:(0,a.jsx)(m.a,{agentColor:null==f?void 0:f.color,isLoggedIn:e.isLoggedIn,sendMessage:e=>n(e),sendImage:e=>c(t=>[...t,e]),sendDisabled:e.isParentProcessing||!1,chatOptionsData:e.chatOptionsData,conversationId:t,isMobileWidth:e.isMobileWidth,setUploadedFiles:e.setUploadedFiles,ref:j,isResearchModeEnabled:p,setTriggeredAbort:e.setTriggeredAbort})})]}),(0,a.jsx)("div",{className:"print-hidden",children:(0,a.jsx)(el,{conversationId:t,isActive:e.isActive,isOpen:e.isChatSideBarOpen,onOpenChange:e.setIsChatSideBarOpen,isMobileWidth:e.isMobileWidth})})]})}function ec(){let e="Khoj AI - Chat",[t,s]=(0,l.useState)(null),[n,o]=(0,l.useState)(!0),[d,m]=(0,l.useState)(e),[w,_]=(0,l.useState)(null),[S,C]=(0,l.useState)([]),[O,k]=(0,l.useState)(""),[I,T]=(0,l.useState)(!1),[M,E]=(0,l.useState)(void 0),[A,z]=(0,l.useState)([]),[B,R]=(0,l.useState)(!1),[L,F]=(0,l.useState)(""),P=(0,l.useRef)(""),D=(0,l.useRef)(null),{locationData:W,locationDataError:Z,locationDataLoading:J}=(0,h.k6)()||{locationData:{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}},{data:V,error:U,isLoading:K}=(0,f.GW)(),H=(0,h.IC)(),[G,Q]=(0,l.useState)(!1),[q,Y]=(0,l.useState)(null),$=(0,l.useRef)(!1),X=(0,l.useRef)(!1),ee=(0,l.useCallback)(()=>{D.current&&clearTimeout(D.current),X.current=!0,Y(null),console.log("WebSocket disconnected due to inactivity.")},[]),et=(0,l.useCallback)(()=>{D.current&&clearTimeout(D.current),D.current=setTimeout(ee,6e5)},[ee]),{toast:es}=(0,b.pm)(),{sendMessage:ea,lastMessage:en}=(0,r.ZP)(q,{share:!0,shouldReconnect:e=>!0,reconnectAttempts:10,reconnectInterval:e=>Math.min(1e3*Math.pow(2,e)+1e3*Math.random(),2e4),onOpen:()=>{console.log("WebSocket connection established."),et(),$.current=!1,X.current=!1},onClose:e=>{console.log("WebSocket connection closed."),D.current&&clearTimeout(D.current),X.current||(null==e?void 0:e.code)===1e3||(null==e?void 0:e.code)===1001||!O||$.current||(es({title:"Network issue",description:"Connection lost. Please check your network and try again when ready.",variant:"destructive",duration:6e3}),$.current=!0),C(e=>{if(!e||0===e.length)return e;let t=[...e],s=t[t.length-1];return s&&!s.completed&&(s.completed=!0),t}),T(!1),k("")},onError:e=>{console.error("WebSocket error",e),C(e=>{if(!e||0===e.length)return e;let t=[...e],s=t[t.length-1];return s&&!s.completed&&(s.completed=!0),t}),T(!1),k(""),X.current||$.current||(es({title:"Network error",description:"Connection lost. Please check your network and try again when ready.",variant:"destructive",duration:5e3}),$.current=!0)}});async function ei(){if(localStorage.removeItem("message"),!O||!w){T(!1);return}if(et(),!q){let e="https:"===window.location.protocol?"wss:":"ws:";Y("".concat(e,"//").concat(window.location.host,"/api/chat/ws?client=web"))}ea(JSON.stringify({q:O,conversation_id:w,stream:!0,...W&&{city:W.city,region:W.region,country:W.country,country_code:W.countryCode,timezone:W.timezone},...A.length>0&&{images:A},...M&&{files:M}}))}return(0,l.useEffect)(()=>{let e=()=>{X.current=!0};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]),(0,l.useEffect)(()=>{if(null!==en){let e;et();try{let e=JSON.parse(en.data);if("interrupt_acknowledged"===e.type){console.log("Interrupt acknowledged by server"),T(!1);return}if("interrupt_message_acknowledged"===e.type){console.log("Interrupt message acknowledged by server"),T(!1);return}if(e.error){console.error("WebSocket error:",e.error),T(!1);return}}catch(e){}let t="␃\uD83D\uDD1A␗";for(P.current+=en.data;-1!==(e=P.current.indexOf(t));){let s=P.current.slice(0,e);P.current=P.current.slice(e+t.length),s&&C(e=>{let t=[...e],a=t[t.length-1];if(!a||a.completed)return e;let{context:n,onlineContext:i,codeContext:l}=(0,u.VK)(s,a,a.context||[],a.onlineContext||{},a.codeContext||{});return a.context=n,a.onlineContext=i,a.codeContext=l,a.completed&&(k(""),T(!1),z([]),w&&(0,u.tQ)(w,m)),t})}}},[en,C]),(0,l.useEffect)(()=>{fetch("/api/chat/options").then(e=>e.json()).then(e=>{o(!1),e&&s(e)}).catch(e=>{console.error(e)}),(0,h.EK)()},[]),((0,l.useEffect)(()=>{B&&(ea(JSON.stringify({type:"interrupt",query:L})),console.log("Sent interrupt message via WebSocket:",L),C(e=>{let t=[...e],s=t[t.length-1];return s&&(s.completed=!0),t}),k(L),R(!1),F(""))},[B,ea]),(0,l.useEffect)(()=>{if(O){let e={rawResponse:"",trainOfThought:[],context:[],onlineContext:{},codeContext:{},completed:!1,timestamp:new Date().toISOString(),rawQuery:O||"",images:A,queryFiles:M};C(t=>[...t,e]),T(!0)}},[O]),(0,l.useEffect)(()=>{I&&!J&&ei()},[I,J]),(0,l.useEffect)(()=>{if(!w)return;let e="https:"===window.location.protocol?"wss:":"ws:";return Y("".concat(e,"//").concat(window.location.host,"/api/chat/ws?client=web")),()=>{D.current&&clearTimeout(D.current)}},[w]),n)?(0,a.jsx)(c.Z,{}):(0,a.jsxs)(p.Hn,{children:[(0,a.jsx)("div",{className:"print-hidden",children:(0,a.jsx)(g.S,{conversationId:w||""})}),(0,a.jsxs)(p.kV,{children:[(0,a.jsxs)("header",{className:"flex h-16 shrink-0 items-center gap-2 border-b px-4 print-hidden",children:[(0,a.jsx)(p.vP,{className:"-ml-1"}),(0,a.jsx)(j.Z,{orientation:"vertical",className:"mr-2 h-4"}),w&&(0,a.jsx)("div",{className:"".concat(i().chatTitleWrapper," text-nowrap text-ellipsis overflow-hidden max-w-screen-md grid items-top font-bold mx-2 md:mr-8 col-auto h-fit"),children:H?(0,a.jsx)("a",{className:"p-0 no-underline",href:"/",children:(0,a.jsx)(v.VO,{className:"h-auto w-16"})}):d&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("h2",{className:"text-lg text-ellipsis whitespace-nowrap overflow-x-hidden mr-4",children:d}),(0,a.jsx)(x.En,{conversationId:w,setTitle:m,sizing:"md"})]})}),(0,a.jsx)("div",{className:"flex justify-end items-start gap-2 text-sm ml-auto",children:(0,a.jsx)(N.z,{variant:"ghost",size:"icon",className:"h-12 w-12 data-[state=open]:bg-accent print-hidden",onClick:()=>Q(!G),children:(0,a.jsx)(y.T,{className:"w-6 h-6"})})})]}),(0,a.jsxs)("div",{className:"".concat(i().main," ").concat(i().chatLayout),children:[(0,a.jsx)("title",{children:"".concat(e).concat(d&&d!==e?": ".concat(d):"")}),(0,a.jsx)("div",{className:i().chatBox,children:(0,a.jsx)("div",{className:i().chatBoxBody,children:(0,a.jsx)(l.Suspense,{fallback:(0,a.jsx)(c.Z,{}),children:(0,a.jsx)(ed,{isLoggedIn:!!V,streamedMessages:S,setStreamedMessages:C,chatOptionsData:t,setTitle:m,setQueryToProcess:k,setUploadedFiles:E,isMobileWidth:H,onConversationIdChange:e=>{_(e)},setImages:z,setTriggeredAbort:(e,t)=>{e&&F(t||""),R(e)},isChatSideBarOpen:G,setIsChatSideBarOpen:Q,isActive:null==V?void 0:V.is_active,isParentProcessing:I,onRetryMessage:(e,t)=>{if(!e){console.warn("No query provided for retry");return}t&&(C(e=>e.filter(e=>e.turnId!==t)),fetch("/api/chat/conversation/message",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({conversation_id:w,turn_id:t})}).catch(e=>{console.error("Failed to delete message for retry:",e)})),k(e)}})})})})]})]})]})}},26815:function(e,t,s){"use strict";s.d(t,{_:function(){return d}});var a=s(57437),n=s(2265),i=s(6394),l=s(90535),r=s(94508);let o=(0,l.j)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),d=n.forwardRef((e,t)=>{let{className:s,...n}=e;return(0,a.jsx)(i.f,{ref:t,className:(0,r.cn)(o(),s),...n})});d.displayName=i.f.displayName},53647:function(e,t,s){"use strict";s.d(t,{Bw:function(){return x},Ph:function(){return c},Ql:function(){return p},i4:function(){return h},ki:function(){return u}});var a=s(57437),n=s(2265),i=s(56873),l=s(40875),r=s(22135),o=s(30401),d=s(94508);let c=i.fC;i.ZA;let u=i.B4,h=n.forwardRef((e,t)=>{let{className:s,children:n,...r}=e;return(0,a.jsxs)(i.xz,{ref:t,className:(0,d.cn)("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",s),...r,children:[n,(0,a.jsx)(i.JO,{asChild:!0,children:(0,a.jsx)(l.Z,{className:"h-4 w-4 opacity-50"})})]})});h.displayName=i.xz.displayName;let m=n.forwardRef((e,t)=>{let{className:s,...n}=e;return(0,a.jsx)(i.u_,{ref:t,className:(0,d.cn)("flex cursor-default items-center justify-center py-1",s),...n,children:(0,a.jsx)(r.Z,{className:"h-4 w-4"})})});m.displayName=i.u_.displayName;let f=n.forwardRef((e,t)=>{let{className:s,...n}=e;return(0,a.jsx)(i.$G,{ref:t,className:(0,d.cn)("flex cursor-default items-center justify-center py-1",s),...n,children:(0,a.jsx)(l.Z,{className:"h-4 w-4"})})});f.displayName=i.$G.displayName;let x=n.forwardRef((e,t)=>{let{className:s,children:n,position:l="popper",...r}=e;return(0,a.jsx)(i.h_,{children:(0,a.jsxs)(i.VY,{ref:t,className:(0,d.cn)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2","popper"===l&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",s),position:l,...r,children:[(0,a.jsx)(m,{}),(0,a.jsx)(i.l_,{className:(0,d.cn)("p-1","popper"===l&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:n}),(0,a.jsx)(f,{})]})})});x.displayName=i.VY.displayName,n.forwardRef((e,t)=>{let{className:s,...n}=e;return(0,a.jsx)(i.__,{ref:t,className:(0,d.cn)("py-1.5 pl-8 pr-2 text-sm font-semibold",s),...n})}).displayName=i.__.displayName;let p=n.forwardRef((e,t)=>{let{className:s,children:n,...l}=e;return(0,a.jsxs)(i.ck,{ref:t,className:(0,d.cn)("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...l,children:[(0,a.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,a.jsx)(i.wU,{children:(0,a.jsx)(o.Z,{className:"h-4 w-4"})})}),(0,a.jsx)(i.eT,{children:n})]})});p.displayName=i.ck.displayName,n.forwardRef((e,t)=>{let{className:s,...n}=e;return(0,a.jsx)(i.Z0,{ref:t,className:(0,d.cn)("-mx-1 my-1 h-px bg-muted",s),...n})}).displayName=i.Z0.displayName},77992:function(e,t,s){"use strict";s.d(t,{pm:function(){return h}});var a=s(2265);let n=0,i=new Map,l=e=>{if(i.has(e))return;let t=setTimeout(()=>{i.delete(e),c({type:"REMOVE_TOAST",toastId:e})},1e6);i.set(e,t)},r=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,1)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(e=>e.id===t.toast.id?{...e,...t.toast}:e)};case"DISMISS_TOAST":{let{toastId:s}=t;return s?l(s):e.toasts.forEach(e=>{l(e.id)}),{...e,toasts:e.toasts.map(e=>e.id===s||void 0===s?{...e,open:!1}:e)}}case"REMOVE_TOAST":if(void 0===t.toastId)return{...e,toasts:[]};return{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}},o=[],d={toasts:[]};function c(e){d=r(d,e),o.forEach(e=>{e(d)})}function u(e){let{...t}=e,s=(n=(n+1)%Number.MAX_SAFE_INTEGER).toString(),a=()=>c({type:"DISMISS_TOAST",toastId:s});return c({type:"ADD_TOAST",toast:{...t,id:s,open:!0,onOpenChange:e=>{e||a()}}}),{id:s,dismiss:a,update:e=>c({type:"UPDATE_TOAST",toast:{...e,id:s}})}}function h(){let[e,t]=a.useState(d);return a.useEffect(()=>(o.push(t),()=>{let e=o.indexOf(t);e>-1&&o.splice(e,1)}),[e]),{...e,toast:u,dismiss:e=>c({type:"DISMISS_TOAST",toastId:e})}}},63136:function(e){e.exports={main:"chat_main__8xQu5",suggestions:"chat_suggestions__m8n2t",inputBox:"chat_inputBox__LOFws",chatBodyFull:"chat_chatBodyFull__FfKEK",chatBody:"chat_chatBody__sS1LX",chatLayout:"chat_chatLayout__pR203",chatBox:"chat_chatBox__FBct_",titleBar:"chat_titleBar__R5QlK",chatBoxBody:"chat_chatBoxBody__qT_SC",agentIndicator:"chat_agentIndicator__8V55w",chatTitleWrapper:"chat_chatTitleWrapper__6ChWq",chatHistory:"chat_chatHistory__EzBJM"}}},function(e){e.O(0,[4842,5638,3954,9183,2939,7200,8667,1327,4447,3592,3260,9139,2327,5477,9808,2971,2117,1744],function(){return e(e.s=39929)}),_N_E=e.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[244,8459,7138],{63521:function(){}},function(n){n.O(0,[2971,2117,1744],function(){return n(n.s=63521)}),_N_E=n.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7138,8459,244],{63521:function(){}},function(n){n.O(0,[2971,2117,1744],function(){return n(n.s=63521)}),_N_E=n.O()}]);
@@ -1 +1 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3111],{91955:function(e,t,s){Promise.resolve().then(s.bind(s,41694))},41694:function(e,t,s){"use strict";s.r(t),s.d(t,{default:function(){return j}});var a=s(57437),o=s(22515),n=s.n(o),i=s(2265),r=s(27127),l=s(14308);s(2446);var c=s(7436),d=s(56937),h=s(5477),u=s(60729),m=s(34124),g=s(6512),x=s(37104),p=s(62869),f=s(96620);function _(e){let{slug:t,className:s}=e,o=async()=>{try{(await fetch("/api/chat/share?public_conversation_slug=".concat(t),{method:"DELETE"})).redirected?window.location.reload():console.error("Failed to unshare conversation")}catch(e){console.error("Error unsharing conversation:",e)}};return(0,a.jsx)("div",{className:"flex items-center gap-2",children:(0,a.jsx)(p.z,{className:"p-0 text-sm h-auto text-rose-500 hover:text-rose-600",variant:"ghost",title:"Unshare conversation",onClick:o,children:(0,a.jsx)(f.r,{className:"".concat(s)})})})}function v(e){let[t,s]=(0,i.useState)(""),[o,l]=(0,i.useState)([]),[c,d]=(0,i.useState)(!1),[u,m]=(0,i.useState)(null),g=(0,i.useRef)(null),x=e.setQueryToProcess,p=e.streamedMessages,f=e.isMobileWidth?"w-full":"w-4/6";return((0,i.useEffect)(()=>{if(o.length>0){let t=o.map(e=>encodeURIComponent(e));e.setImages(t)}},[o,e.setImages]),(0,i.useEffect)(()=>{t&&(d(!0),x(t))},[t,x]),(0,i.useEffect)(()=>{p&&p.length>0&&p[p.length-1].completed?d(!1):s("")},[p]),e.publicConversationSlug||e.conversationId)?(0,a.jsx)("div",{className:"flex flex-row h-full w-full",children:(0,a.jsxs)("div",{className:"flex flex-col h-full w-full",children:[(0,a.jsx)("div",{className:n().chatBodyFull,children:(0,a.jsx)(r.Z,{publicConversationSlug:e.publicConversationSlug,conversationId:e.conversationId||"",setAgent:m,setTitle:e.setTitle,setIsOwner:e.setIsOwner,pendingMessage:c?t:"",incomingMessages:e.streamedMessages,customClassName:f})}),(0,a.jsx)("div",{className:"".concat(n().inputBox," p-1 md:px-2 shadow-md bg-background align-middle items-center justify-center dark:bg-neutral-700 dark:border-0 dark:shadow-sm rounded-2xl md:rounded-xl h-fit ").concat(f," mr-auto ml-auto mt-auto"),children:(0,a.jsx)(h.a,{isLoggedIn:e.isLoggedIn,sendMessage:e=>s(e),sendImage:e=>l(t=>[...t,e]),sendDisabled:c,chatOptionsData:e.chatOptionsData,conversationId:e.conversationId,agentColor:null==u?void 0:u.color,isMobileWidth:e.isMobileWidth,setUploadedFiles:e.setUploadedFiles,setTriggeredAbort:()=>{},ref:g})})]})}):(0,a.jsx)("div",{className:n().suggestions,children:"Whoops, nothing to see here!"})}function j(){let[e,t]=(0,i.useState)(null),[s,o]=(0,i.useState)(!0),[r,h]=(0,i.useState)("Khoj AI - Chat"),[p,f]=(0,i.useState)(void 0),[j,w]=(0,i.useState)([]),[N,I]=(0,i.useState)(""),[S,C]=(0,i.useState)(null),[b,y]=(0,i.useState)(void 0),[B,O]=(0,i.useState)([]),[k,E]=(0,i.useState)(!1),{data:T,error:M,isLoading:W}=(0,d.GW)(),F=(0,c.IC)();return((0,i.useEffect)(()=>{fetch("/api/chat/options").then(e=>e.json()).then(e=>{o(!1),e&&t(e)}).catch(e=>{console.error(e)}),(0,c.EK)(),y(window.location.pathname.split("/").pop()||"")},[]),(0,i.useEffect)(()=>{S&&localStorage.setItem("uploadedFiles",JSON.stringify(S))},[S]),(0,i.useEffect)(()=>{if(N&&!p){fetch("/api/chat/share/fork?public_conversation_slug=".concat(b),{method:"POST",headers:{"Content-Type":"application/json"}}).then(e=>e.json()).then(e=>{f(e.conversation_id),localStorage.setItem("message",N),B.length>0&&localStorage.setItem("images",JSON.stringify(B)),window.location.href="/chat?conversationId=".concat(e.conversation_id)}).catch(e=>{console.error(e)});return}},[N,p,b]),s)?(0,a.jsx)(l.Z,{}):b?(0,a.jsxs)(u.Hn,{children:[(0,a.jsx)(m.S,{conversationId:p||""}),(0,a.jsxs)(u.kV,{children:[(0,a.jsxs)("header",{className:"flex h-16 shrink-0 items-center gap-2 border-b px-4",children:[(0,a.jsx)(u.vP,{className:"-ml-1"}),(0,a.jsx)(g.Z,{orientation:"vertical",className:"mr-2 h-4"}),b&&(0,a.jsx)("div",{className:"".concat(n().chatTitleWrapper," text-nowrap text-ellipsis overflow-hidden max-w-screen-md grid items-top font-bold mx-2 md:mr-8 col-auto h-fit"),children:F?(0,a.jsx)("a",{className:"p-0 no-underline",href:"/",children:(0,a.jsx)(x.VO,{className:"h-auto w-16"})}):r&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("h2",{className:"text-lg text-ellipsis whitespace-nowrap overflow-x-hidden mr-4",children:r}),k&&T&&(0,a.jsx)(_,{slug:b,className:"h-4 w-4 mt-1"})]})})]}),(0,a.jsxs)("div",{className:"".concat(n().main," ").concat(n().chatLayout),children:[(0,a.jsx)("title",{children:r}),(0,a.jsx)("div",{className:n().chatBox,children:(0,a.jsx)("div",{className:n().chatBoxBody,children:(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(l.Z,{}),children:(0,a.jsx)(v,{conversationId:p,streamedMessages:j,setQueryToProcess:I,isLoggedIn:!!T,publicConversationSlug:b,chatOptionsData:e,setTitle:h,setUploadedFiles:C,isMobileWidth:F,setImages:O,setIsOwner:E})})})})]})]})]}):(0,a.jsx)("div",{className:n().suggestions,children:"Whoops, nothing to see here!"})}},22515:function(e){e.exports={main:"sharedChat_main__7Nayy",suggestions:"sharedChat_suggestions__V8kr_",inputBox:"sharedChat_inputBox__wRW5A",chatBodyFull:"sharedChat_chatBodyFull__O1MOv",chatBody:"sharedChat_chatBody__OnHDL",chatLayout:"sharedChat_chatLayout__gutlc",chatBox:"sharedChat_chatBox__PmAPg",titleBar:"sharedChat_titleBar__vOHp_",chatBoxBody:"sharedChat_chatBoxBody__ef2Nl",agentIndicator:"sharedChat_agentIndicator__ORCl4",chatTitleWrapper:"sharedChat_chatTitleWrapper__rVdYj"}}},function(e){e.O(0,[9346,4842,5638,3954,9183,2939,7200,8667,1327,3592,3260,2327,5477,7127,2971,2117,1744],function(){return e(e.s=91955)}),_N_E=e.O()}]);
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3111],{91955:function(e,t,s){Promise.resolve().then(s.bind(s,41694))},41694:function(e,t,s){"use strict";s.r(t),s.d(t,{default:function(){return j}});var a=s(57437),o=s(22515),n=s.n(o),i=s(2265),r=s(29808),l=s(14308);s(2446);var c=s(7436),d=s(56937),h=s(5477),u=s(60729),m=s(34124),g=s(6512),x=s(37104),p=s(62869),f=s(96620);function _(e){let{slug:t,className:s}=e,o=async()=>{try{(await fetch("/api/chat/share?public_conversation_slug=".concat(t),{method:"DELETE"})).redirected?window.location.reload():console.error("Failed to unshare conversation")}catch(e){console.error("Error unsharing conversation:",e)}};return(0,a.jsx)("div",{className:"flex items-center gap-2",children:(0,a.jsx)(p.z,{className:"p-0 text-sm h-auto text-rose-500 hover:text-rose-600",variant:"ghost",title:"Unshare conversation",onClick:o,children:(0,a.jsx)(f.r,{className:"".concat(s)})})})}function v(e){let[t,s]=(0,i.useState)(""),[o,l]=(0,i.useState)([]),[c,d]=(0,i.useState)(!1),[u,m]=(0,i.useState)(null),g=(0,i.useRef)(null),x=e.setQueryToProcess,p=e.streamedMessages,f=e.isMobileWidth?"w-full":"w-4/6";return((0,i.useEffect)(()=>{if(o.length>0){let t=o.map(e=>encodeURIComponent(e));e.setImages(t)}},[o,e.setImages]),(0,i.useEffect)(()=>{t&&(d(!0),x(t))},[t,x]),(0,i.useEffect)(()=>{p&&p.length>0&&p[p.length-1].completed?d(!1):s("")},[p]),e.publicConversationSlug||e.conversationId)?(0,a.jsx)("div",{className:"flex flex-row h-full w-full",children:(0,a.jsxs)("div",{className:"flex flex-col h-full w-full",children:[(0,a.jsx)("div",{className:n().chatBodyFull,children:(0,a.jsx)(r.Z,{publicConversationSlug:e.publicConversationSlug,conversationId:e.conversationId||"",setAgent:m,setTitle:e.setTitle,setIsOwner:e.setIsOwner,pendingMessage:c?t:"",incomingMessages:e.streamedMessages,customClassName:f})}),(0,a.jsx)("div",{className:"".concat(n().inputBox," p-1 md:px-2 shadow-md bg-background align-middle items-center justify-center dark:bg-neutral-700 dark:border-0 dark:shadow-sm rounded-2xl md:rounded-xl h-fit ").concat(f," mr-auto ml-auto mt-auto"),children:(0,a.jsx)(h.a,{isLoggedIn:e.isLoggedIn,sendMessage:e=>s(e),sendImage:e=>l(t=>[...t,e]),sendDisabled:c,chatOptionsData:e.chatOptionsData,conversationId:e.conversationId,agentColor:null==u?void 0:u.color,isMobileWidth:e.isMobileWidth,setUploadedFiles:e.setUploadedFiles,setTriggeredAbort:()=>{},ref:g})})]})}):(0,a.jsx)("div",{className:n().suggestions,children:"Whoops, nothing to see here!"})}function j(){let[e,t]=(0,i.useState)(null),[s,o]=(0,i.useState)(!0),[r,h]=(0,i.useState)("Khoj AI - Chat"),[p,f]=(0,i.useState)(void 0),[j,w]=(0,i.useState)([]),[N,I]=(0,i.useState)(""),[S,C]=(0,i.useState)(null),[b,y]=(0,i.useState)(void 0),[B,O]=(0,i.useState)([]),[k,E]=(0,i.useState)(!1),{data:T,error:M,isLoading:W}=(0,d.GW)(),F=(0,c.IC)();return((0,i.useEffect)(()=>{fetch("/api/chat/options").then(e=>e.json()).then(e=>{o(!1),e&&t(e)}).catch(e=>{console.error(e)}),(0,c.EK)(),y(window.location.pathname.split("/").pop()||"")},[]),(0,i.useEffect)(()=>{S&&localStorage.setItem("uploadedFiles",JSON.stringify(S))},[S]),(0,i.useEffect)(()=>{if(N&&!p){fetch("/api/chat/share/fork?public_conversation_slug=".concat(b),{method:"POST",headers:{"Content-Type":"application/json"}}).then(e=>e.json()).then(e=>{f(e.conversation_id),localStorage.setItem("message",N),B.length>0&&localStorage.setItem("images",JSON.stringify(B)),window.location.href="/chat?conversationId=".concat(e.conversation_id)}).catch(e=>{console.error(e)});return}},[N,p,b]),s)?(0,a.jsx)(l.Z,{}):b?(0,a.jsxs)(u.Hn,{children:[(0,a.jsx)(m.S,{conversationId:p||""}),(0,a.jsxs)(u.kV,{children:[(0,a.jsxs)("header",{className:"flex h-16 shrink-0 items-center gap-2 border-b px-4",children:[(0,a.jsx)(u.vP,{className:"-ml-1"}),(0,a.jsx)(g.Z,{orientation:"vertical",className:"mr-2 h-4"}),b&&(0,a.jsx)("div",{className:"".concat(n().chatTitleWrapper," text-nowrap text-ellipsis overflow-hidden max-w-screen-md grid items-top font-bold mx-2 md:mr-8 col-auto h-fit"),children:F?(0,a.jsx)("a",{className:"p-0 no-underline",href:"/",children:(0,a.jsx)(x.VO,{className:"h-auto w-16"})}):r&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("h2",{className:"text-lg text-ellipsis whitespace-nowrap overflow-x-hidden mr-4",children:r}),k&&T&&(0,a.jsx)(_,{slug:b,className:"h-4 w-4 mt-1"})]})})]}),(0,a.jsxs)("div",{className:"".concat(n().main," ").concat(n().chatLayout),children:[(0,a.jsx)("title",{children:r}),(0,a.jsx)("div",{className:n().chatBox,children:(0,a.jsx)("div",{className:n().chatBoxBody,children:(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(l.Z,{}),children:(0,a.jsx)(v,{conversationId:p,streamedMessages:j,setQueryToProcess:I,isLoggedIn:!!T,publicConversationSlug:b,chatOptionsData:e,setTitle:h,setUploadedFiles:C,isMobileWidth:F,setImages:O,setIsOwner:E})})})})]})]})]}):(0,a.jsx)("div",{className:n().suggestions,children:"Whoops, nothing to see here!"})}},22515:function(e){e.exports={main:"sharedChat_main__7Nayy",suggestions:"sharedChat_suggestions__V8kr_",inputBox:"sharedChat_inputBox__wRW5A",chatBodyFull:"sharedChat_chatBodyFull__O1MOv",chatBody:"sharedChat_chatBody__OnHDL",chatLayout:"sharedChat_chatLayout__gutlc",chatBox:"sharedChat_chatBox__PmAPg",titleBar:"sharedChat_titleBar__vOHp_",chatBoxBody:"sharedChat_chatBoxBody__ef2Nl",agentIndicator:"sharedChat_agentIndicator__ORCl4",chatTitleWrapper:"sharedChat_chatTitleWrapper__rVdYj"}}},function(e){e.O(0,[9346,4842,5638,3954,9183,2939,7200,8667,1327,3592,3260,2327,5477,9808,2971,2117,1744],function(){return e(e.s=91955)}),_N_E=e.O()}]);