"use strict";(self.webpackChunkjupyter_openwebui=self.webpackChunkjupyter_openwebui||[]).push([[497],{497:(e,n,o)=>{o.r(n),o.d(n,{default:()=>c});var t=o(771),a=o(256),l=o(760);const i=JSON.parse('{"cF":"http://localhost:8080","DD":"🤖 Open WebUI Agent & Chat","qK":"jp-Icon jp-Ic on-32"}'),c={id:"jupyter-openwebui:plugin",description:"Open webui frontend to JupyterLab extension.",autoStart:!0,requires:[t.ILauncher],activate:async(e,n)=>{console.log("JupyterLab extension jupyter-openwebui is activated!");const o=async()=>{try{const e=await fetch("/open_webui_url.txt"),n=(await e.text()).trim();return console.log(`Open WebUI URL: ${n}`),n}catch(e){return console.warn("URL file not found, using fallback"),"http://localhost:8080"}},t=await o()||i.cF||"http://localhost:8080",c=new a.Widget;c.id="openwebui-chat",c.title.label=i.DD||"Open WebUI",c.title.closable=!0,c.title.iconClass=i.qK||"";let d,r,s=0,p=!1;const u=async()=>{d&&clearTimeout(d),r&&clearTimeout(r),s++,console.log("Before loading, showing loading page"),c.node.innerHTML=`\n        <div style="display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; padding: 20px; color: #666;">\n          <div style="font-size: 18px; margin-bottom: 10px;">🤖 Loading OpenWebUI...</div>\n          <div style="font-size: 14px;">Connecting to ${t}</div>\n          <div style="margin-top: 15px; font-size: 12px;">Attempt ${s+1} of 8</div>\n          <div style="margin-top: 10px; font-size: 12px; color: #999;">Please wait...</div>\n        </div>\n      `,setTimeout(()=>{console.log("Creating iframe");const e=document.createElement("iframe");e.src=t,e.style.width="100%",e.style.height="100%",e.style.border="none",e.style.display="none";let n=!1;e.onload=()=>{console.log("OpenWebUI loaded successfully"),d&&clearTimeout(d),r&&clearTimeout(r),n=!0,e.onload=null,c.node.innerHTML="",e.style.display="block",c.node.appendChild(e)},c.node.appendChild(e),d=setTimeout(()=>{n||(console.log(`OpenWebUI load timeout, attempt ${s}/8`),e.parentNode&&e.parentNode.removeChild(e),s<8?r=setTimeout(()=>{u()},4e3):c.node.innerHTML=`\n                <div style="padding: 20px; text-align: center; color: #d32f2f;">\n                  <h3>❌ Unable to connect to OpenWebUI</h3>\n                  <p>URL: ${t}</p>\n                  <p>Service may not be running. Please start OpenWebUI and refresh.</p>\n                  <button onclick="location.reload()" style="margin-top: 10px; padding: 8px 16px; background: #1976d2; color: white; border: none; border-radius: 4px; cursor: pointer;">\n                    Refresh Page\n                  </button>\n                </div>\n              `)},2e4)},3e3)};console.log("Adding command to launcher"),e.commands.addCommand("openwebui:activate",{label:"OpenWebUI Frontend",caption:"Open WebUI Chat Agent & Chat",icon:l.buildIcon,execute:async()=>{const e=await o();console.log(`Opening: ${e}`),window.open(e,"_blank")}}),console.log("Command added to launcher"),n.add({command:"openwebui:activate",category:"Other",rank:1}),console.log("Launcher item added"),console.log("Initializing iframe"),p||(console.log("Launcher setup complete"),e.shell.add(c,"left",{rank:0}),console.log("Content added to shell"),e.restored.then(()=>{e.shell.activateById(c.id),u()}).catch(e=>{console.error("Failed to restore JupyterLab:",e),u()}),p=!0)}}}}]);