"use strict";(self.webpackChunkjupyter_openwebui=self.webpackChunkjupyter_openwebui||[]).push([[497],{497:(e,n,o)=>{o.r(n),o.d(n,{default:()=>a});var t=o(771),l=o(256);const i=JSON.parse('{"y_":"http://localhost:8080","DD":"🤖 Open WebUI Agent & Chat","qK":"jp-Icon jp-Ic on-32"}'),a={id:"jupyter-openwebui:plugin",description:"Open webui frontend to JupyterLab extension.",autoStart:!0,requires:[t.ILauncher],activate:(e,n)=>{console.log("JupyterLab extension jupyter-openwebui is activated!");const o=i.y_||"http://localhost:8080";console.log(`Open WebUI URL: ${o}`);const t=new l.Widget;t.id="openwebui-chat",t.title.label=i.DD||"Open WebUI",t.title.closable=!0,t.title.iconClass=i.qK||"";let a,d,c=0,r=!1;const s=()=>{a&&clearTimeout(a),d&&clearTimeout(d),c++,console.log("Before loading, showing loading page"),t.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 ${o}</div>\n          <div style="margin-top: 15px; font-size: 12px;">Attempt ${c+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=o,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"),a&&clearTimeout(a),d&&clearTimeout(d),n=!0,e.onload=null,t.node.innerHTML="",e.style.display="block",t.node.appendChild(e)},t.node.appendChild(e),a=setTimeout(()=>{n||(console.log(`OpenWebUI load timeout, attempt ${c}/8`),e.parentNode&&e.parentNode.removeChild(e),c<8?d=setTimeout(()=>{s()},4e3):t.node.innerHTML=`\n                <div style="padding: 20px; text-align: center; color: #d32f2f;">\n                  <h3>❌ Unable to connect to OpenWebUI</h3>\n                  <p>URL: ${o}</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",iconLabel:"🤖",execute:()=>{e.shell.activateById("openwebui-chat")}}),console.log("Command added to launcher"),n.add({command:"openwebui:activate",category:"Other",rank:1}),console.log("Launcher item added"),console.log("Initializing iframe"),r||(console.log("Launcher setup complete"),e.shell.add(t,"left",{rank:0}),console.log("Content added to shell"),e.restored.then(()=>{e.shell.activateById(t.id),s()}).catch(e=>{console.error("Failed to restore JupyterLab:",e),s()}),r=!0)}}}}]);