From ed5fc5113d14cf326f150678ac94229c87f2289a Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 23 May 2024 13:18:13 -0700 Subject: [PATCH] fix --- extension/dist/main.js | 2 +- extension/src/lib/components/SpotlightSearch.svelte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extension/dist/main.js b/extension/dist/main.js index 8d1b15d..b67685b 100644 --- a/extension/dist/main.js +++ b/extension/dist/main.js @@ -1,4 +1,4 @@ -var ye=Object.defineProperty;var ve=(e,t,l)=>t in e?ye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[t]=l;var W=(e,t,l)=>(ve(e,typeof t!="symbol"?t+"":t,l),l);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))n(o);new MutationObserver(o=>{for(const r of o)if(r.type==="childList")for(const s of r.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&n(s)}).observe(document,{childList:!0,subtree:!0});function l(o){const r={};return o.integrity&&(r.integrity=o.integrity),o.referrerPolicy&&(r.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?r.credentials="include":o.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(o){if(o.ep)return;o.ep=!0;const r=l(o);fetch(o.href,r)}})();function T(){}function de(e){return e()}function Y(){return Object.create(null)}function A(e){e.forEach(de)}function ce(e){return typeof e=="function"}function ae(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function be(e){return Object.keys(e).length===0}function w(e,t){e.appendChild(t)}function j(e,t,l){e.insertBefore(t,l||null)}function O(e){e.parentNode&&e.parentNode.removeChild(e)}function ke(e,t){for(let l=0;le.removeEventListener(t,l,n)}function a(e,t,l){l==null?e.removeAttribute(t):e.getAttribute(t)!==l&&e.setAttribute(t,l)}function Se(e){return Array.from(e.childNodes)}function Ce(e,t){t=""+t,e.data!==t&&(e.data=t)}function M(e,t){e.value=t??""}function Q(e,t,l){for(let n=0;ne.indexOf(n)===-1?t.push(n):l.push(n)),l.forEach(n=>n()),L=t}const q=new Set;let Te;function fe(e,t){e&&e.i&&(q.delete(e),e.i(t))}function Ae(e,t,l,n){if(e&&e.o){if(q.has(e))return;q.add(e),Te.c.push(()=>{q.delete(e)}),e.o(t)}}function te(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function Ne(e){e&&e.c()}function we(e,t,l){const{fragment:n,after_update:o}=e.$$;n&&n.m(t,l),D(()=>{const r=e.$$.on_mount.map(de).filter(ce);e.$$.on_destroy?e.$$.on_destroy.push(...r):A(r),e.$$.on_mount=[]}),o.forEach(D)}function pe(e,t){const l=e.$$;l.fragment!==null&&(Le(l.after_update),A(l.on_destroy),l.fragment&&l.fragment.d(t),l.on_destroy=l.fragment=null,l.ctx=[])}function Be(e,t){e.$$.dirty[0]===-1&&($.push(e),Ie(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<{const f=_.length?_[0]:c;return d.ctx&&o(d.ctx[u],d.ctx[u]=f)&&(!d.skip_bound&&d.bound[u]&&d.bound[u](f),g&&Be(e,u)),c}):[],d.update(),g=!0,A(d.before_update),d.fragment=n?n(d.ctx):!1,t.target){if(t.hydrate){const u=Se(t.target);d.fragment&&d.fragment.l(u),u.forEach(O)}else d.fragment&&d.fragment.c();t.intro&&fe(e.$$.fragment),we(e,t.target,t.anchor),ue()}N(m)}class he{constructor(){W(this,"$$");W(this,"$$set")}$destroy(){pe(this,1),this.$destroy=T}$on(t,l){if(!ce(l))return T;const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(l),()=>{const o=n.indexOf(l);o!==-1&&n.splice(o,1)}}$set(t){this.$$set&&!be(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Pe="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Pe);const le=async(e="",t="")=>{let l=null;const n=await fetch(`${t}/models`,{method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",...e&&{authorization:`Bearer ${e}`}}}).then(async r=>{if(!r.ok)throw await r.json();return r.json()}).catch(r=>{var s;return l=`OpenAI: ${((s=r==null?void 0:r.error)==null?void 0:s.message)??"Network Problem"}`,[]});if(l)throw l;const o=Array.isArray(n)?n:(n==null?void 0:n.data)??null;return o&&o.map(r=>({id:r.id,name:r.name??r.id,url:t,custom_info:r.custom_info})).sort((r,s)=>r.name.localeCompare(s.name))},ne=async(e,t)=>{let l=await Promise.all([le(e,`${t}/ollama/v1`).catch(n=>(console.log(n),null)),le(e,`${t}/openai/api`).catch(n=>(console.log(n),null))]);return l=l.filter(n=>n).reduce((n,o,r,s)=>n.concat(o),[]),console.log(l),l},He=async(e="",t={},l="http://localhost:8080")=>{const n=new AbortController;let o=null;const r=await fetch(`${l}/chat/completions`,{signal:n.signal,method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(t)}).catch(s=>(console.log(s),o=s,null));if(o)throw o;return[r,n]},ze=e=>{let t="";return new TransformStream({transform(l,n){t+=l;const o=t.split(e);o.slice(0,-1).forEach(r=>n.enqueue(r)),t=o[o.length-1]},flush(l){t&&l.enqueue(t)}})};function oe(e,t,l){const n=e.slice();return n[6]=t[l],n}function re(e){let t,l,n;function o(i,m){return i[1]?qe:Ke}let r=o(e),s=r(e);return{c(){t=p("div"),s.c(),a(t,"class","tlwd-fixed tlwd-top-0 tlwd-right-0 tlwd-left-0 tlwd-bottom-0 tlwd-w-full tlwd-min-h-screen tlwd-h-screen tlwd-flex tlwd-justify-center tlwd-z-[9999999999] tlwd-overflow-hidden tlwd-overscroll-contain")},m(i,m){j(i,t,m),s.m(t,null),l||(n=S(t,"mousedown",e[15]),l=!0)},p(i,m){r===(r=o(i))&&s?s.p(i,m):(s.d(1),s=r(i),s&&(s.c(),s.m(t,null)))},d(i){i&&O(t),s.d(),l=!1,n()}}}function Ke(e){let t,l,n,o,r,s,i,m,d,g,u,c,_,f;return{c(){t=p("div"),l=p("div"),n=p("form"),o=p("div"),r=p("div"),r.innerHTML=``,s=C(),i=p("input"),m=C(),d=p("div"),g=p("div"),g.textContent="Press ⌘Space+Shift to toggle",u=C(),c=p("button"),c.innerHTML=``,a(r,"class","tlwd-flex tlwd-items-center"),a(i,"id","open-webui-search-input"),a(i,"placeholder","Search Open WebUI"),a(i,"class","tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"),a(i,"autocomplete","one-time-code"),a(o,"class","tlwd-flex tlwd-items-center tlwd-gap-2 tlwd-w-full"),a(g,"class","tlwd-text-right tlwd-text-[0.7rem] tlwd-p-0 tlwd-m-0 tlwd-text-neutral-300 tlwd-h-fit"),a(c,"class","tlwd-h-fit tlwd-flex tlwd-items-center tlwd-bg-transparent tlwd-text-neutral-100 tlwd-cursor-pointer tlwd-p-0 tlwd-m-0 tlwd-outline-none tlwd-border-none"),a(c,"type","button"),a(d,"class","tlwd-flex tlwd-justify-end tlwd-gap-1 tlwd-items-center"),a(n,"class","tlwd-text-gray-200 tlwd-w-full tlwd-p-0 tlwd-m-0"),a(n,"autocomplete","off"),a(l,"class","tlwd-w-full tlwd-flex tlwd-flex-col tlwd-justify-between tlwd-py-2.5 tlwd-px-3.5 tlwd-rounded-2xl tlwd-outline tlwd-outline-1 tlwd-outline-gray-850 tlwd-backdrop-blur-3xl tlwd-bg-gray-850/70 shadow-4xl modal-animation"),a(t,"class","tlwd-m-auto tlwd-max-w-xl tlwd-w-full tlwd-pb-32")},m(k,E){j(k,t,E),w(t,l),w(l,n),w(n,o),w(o,r),w(o,s),w(o,i),M(i,e[4]),w(n,m),w(n,d),w(d,g),w(d,u),w(d,c),_||(f=[S(i,"input",e[13]),S(c,"click",e[14]),S(n,"submit",e[7]),S(n,"mousedown",Ve)],_=!0)},p(k,E){E&16&&i.value!==k[4]&&M(i,k[4])},d(k){k&&O(t),_=!1,A(f)}}}function qe(e){let t,l,n,o,r,s,i,m,d,g,u,c,_,f,k,E,P,b=e[5]&&e[5].length>0&&se(e);return{c(){t=p("div"),l=p("div"),n=p("form"),o=p("div"),r=p("div"),r.innerHTML=``,s=C(),i=p("input"),m=C(),d=p("div"),g=p("div"),g.innerHTML=``,u=C(),c=p("input"),_=C(),f=p("button"),f.innerHTML=``,k=C(),b&&b.c(),a(r,"class","tlwd-flex tlwd-items-center"),a(i,"id","open-webui-url-input"),a(i,"placeholder","Open WebUI URL"),a(i,"class","tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"),a(i,"autocomplete","one-time-code"),i.required=!0,a(o,"class","tlwd-flex tlwd-items-center tlwd-gap-2 tlwd-w-full"),a(g,"class","tlwd-flex tlwd-items-center"),a(c,"placeholder","Open WebUI API Key"),a(c,"class","tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"),a(c,"autocomplete","one-time-code"),c.required=!0,a(f,"class","tlwd-flex tlwd-items-center tlwd-bg-transparent tlwd-text-neutral-100 tlwd-cursor-pointer tlwd-p-0 tlwd-m-0 tlwd-outline-none tlwd-border-none"),a(f,"type","button"),a(d,"class","tlwd-flex tlwd-items-center tlwd-gap-2 tlwd-w-full tlwd-mt-2"),a(n,"class","tlwd-text-gray-200 tlwd-w-full tlwd-p-0 tlwd-m-0"),a(n,"autocomplete","off"),a(l,"class","tlwd-w-full tlwd-flex tlwd-flex-col tlwd-justify-between tlwd-py-2.5 tlwd-px-3.5 tlwd-rounded-2xl tlwd-outline tlwd-outline-1 tlwd-outline-gray-850 tlwd-backdrop-blur-3xl tlwd-bg-gray-850/70 shadow-4xl modal-animation"),a(t,"class","tlwd-m-auto tlwd-max-w-sm tlwd-w-full tlwd-pb-32")},m(x,h){j(x,t,h),w(t,l),w(l,n),w(n,o),w(o,r),w(o,s),w(o,i),M(i,e[2]),w(n,m),w(n,d),w(d,g),w(d,u),w(d,c),M(c,e[3]),w(d,_),w(d,f),w(n,k),b&&b.m(n,null),E||(P=[S(i,"input",e[9]),S(c,"input",e[10]),S(f,"click",e[11]),S(n,"submit",e[8]),S(n,"mousedown",Ue)],E=!0)},p(x,h){h&4&&i.value!==x[2]&&M(i,x[2]),h&8&&c.value!==x[3]&&M(c,x[3]),x[5]&&x[5].length>0?b?b.p(x,h):(b=se(x),b.c(),b.m(n,null)):b&&(b.d(1),b=null)},d(x){x&&O(t),b&&b.d(),E=!1,A(P)}}}function se(e){let t,l,n,o,r,s,i,m,d,g=te(e[5]),u=[];for(let c=0;c`,n=C(),o=p("select"),r=p("option"),r.textContent="Select a model";for(let c=0;c`,a(l,"class","tlwd-flex tlwd-items-center"),r.__value="",M(r,r.__value),a(o,"id","open-webui-model-input"),a(o,"class","tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"),a(o,"autocomplete","off"),o.required=!0,e[6]===void 0&&D(()=>e[12].call(o)),a(i,"class","tlwd-flex tlwd-items-center tlwd-bg-transparent tlwd-text-neutral-100 tlwd-cursor-pointer tlwd-p-0 tlwd-m-0 tlwd-outline-none tlwd-border-none"),a(i,"type","submit"),a(t,"class","tlwd-flex tlwd-items-center tlwd-gap-2 tlwd-w-full tlwd-mt-2")},m(c,_){j(c,t,_),w(t,l),w(t,n),w(t,o),w(o,r);for(let f=0;f{e.stopPropagation()},Ve=e=>{e.stopPropagation()};function Re(e,t,l){let n=!1,o=!1,r="",s="",i="",m="",d=[];const g=()=>{console.log("resetConfig");try{chrome.storage.local.clear().then(()=>{console.log("Value is cleared")})}catch(h){console.log(h),localStorage.setItem("url",""),localStorage.setItem("key",""),localStorage.setItem("model","")}l(2,r=""),l(3,s=""),l(6,i=""),l(1,o=!0)},u=h=>{h.preventDefault(),window.open(`${r}/?q=${encodeURIComponent(m)}&models=${i}`,"_blank"),l(4,m=""),l(0,n=!1)},c=h=>{h.preventDefault();try{chrome.storage.local.set({url:r,key:s,model:i}).then(()=>{console.log("Value is set")})}catch(H){console.log(H),localStorage.setItem("url",r),localStorage.setItem("key",s),localStorage.setItem("model",i)}l(1,o=!1)};Oe(async()=>{let h=null;try{h=await chrome.storage.local.get()}catch(y){console.log(y)}h&&(l(2,r=h.url??""),l(3,s=h.key??""),l(6,i=h.model??""),h.url&&h.key&&h.model&&(l(5,d=await ne(h.key,h.url)),l(1,o=!1)));const H=async y=>{var G;if(n&&y.shiftKey&&y.key==="Escape"?g():y.key==="Escape"&&l(0,n=!1),y.key===" "&&(y.metaKey||y.ctrlKey)&&(y.shiftKey||y.altKey)){y.preventDefault();try{const v=await chrome.runtime.sendMessage({action:"getSelection"});((v==null?void 0:v.data)??!1)&&l(4,m=v.data)}catch(v){console.log("catch",v)}l(0,n=!n),setTimeout(()=>{const v=document.getElementById("open-webui-search-input");v&&v.focus()},0)}if(s!==""&&r!==""&&y.key==="Enter"&&(y.metaKey||y.ctrlKey)&&(y.shiftKey||y.altKey)){y.preventDefault();try{const v=await chrome.runtime.sendMessage({action:"getSelection"});if((v==null?void 0:v.data)??!1){await chrome.runtime.sendMessage({action:"writeText",text:` +var ye=Object.defineProperty;var ve=(e,t,l)=>t in e?ye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[t]=l;var W=(e,t,l)=>(ve(e,typeof t!="symbol"?t+"":t,l),l);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))n(o);new MutationObserver(o=>{for(const r of o)if(r.type==="childList")for(const s of r.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&n(s)}).observe(document,{childList:!0,subtree:!0});function l(o){const r={};return o.integrity&&(r.integrity=o.integrity),o.referrerPolicy&&(r.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?r.credentials="include":o.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(o){if(o.ep)return;o.ep=!0;const r=l(o);fetch(o.href,r)}})();function T(){}function de(e){return e()}function Y(){return Object.create(null)}function A(e){e.forEach(de)}function ce(e){return typeof e=="function"}function ae(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function be(e){return Object.keys(e).length===0}function w(e,t){e.appendChild(t)}function j(e,t,l){e.insertBefore(t,l||null)}function O(e){e.parentNode&&e.parentNode.removeChild(e)}function ke(e,t){for(let l=0;le.removeEventListener(t,l,n)}function a(e,t,l){l==null?e.removeAttribute(t):e.getAttribute(t)!==l&&e.setAttribute(t,l)}function Se(e){return Array.from(e.childNodes)}function Ce(e,t){t=""+t,e.data!==t&&(e.data=t)}function M(e,t){e.value=t??""}function Q(e,t,l){for(let n=0;ne.indexOf(n)===-1?t.push(n):l.push(n)),l.forEach(n=>n()),L=t}const q=new Set;let Te;function fe(e,t){e&&e.i&&(q.delete(e),e.i(t))}function Ae(e,t,l,n){if(e&&e.o){if(q.has(e))return;q.add(e),Te.c.push(()=>{q.delete(e)}),e.o(t)}}function te(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function Ne(e){e&&e.c()}function we(e,t,l){const{fragment:n,after_update:o}=e.$$;n&&n.m(t,l),D(()=>{const r=e.$$.on_mount.map(de).filter(ce);e.$$.on_destroy?e.$$.on_destroy.push(...r):A(r),e.$$.on_mount=[]}),o.forEach(D)}function pe(e,t){const l=e.$$;l.fragment!==null&&(Le(l.after_update),A(l.on_destroy),l.fragment&&l.fragment.d(t),l.on_destroy=l.fragment=null,l.ctx=[])}function Be(e,t){e.$$.dirty[0]===-1&&($.push(e),Ie(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<{const f=_.length?_[0]:c;return d.ctx&&o(d.ctx[u],d.ctx[u]=f)&&(!d.skip_bound&&d.bound[u]&&d.bound[u](f),g&&Be(e,u)),c}):[],d.update(),g=!0,A(d.before_update),d.fragment=n?n(d.ctx):!1,t.target){if(t.hydrate){const u=Se(t.target);d.fragment&&d.fragment.l(u),u.forEach(O)}else d.fragment&&d.fragment.c();t.intro&&fe(e.$$.fragment),we(e,t.target,t.anchor),ue()}N(m)}class he{constructor(){W(this,"$$");W(this,"$$set")}$destroy(){pe(this,1),this.$destroy=T}$on(t,l){if(!ce(l))return T;const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(l),()=>{const o=n.indexOf(l);o!==-1&&n.splice(o,1)}}$set(t){this.$$set&&!be(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Pe="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Pe);const le=async(e="",t="")=>{let l=null;const n=await fetch(`${t}/models`,{method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",...e&&{authorization:`Bearer ${e}`}}}).then(async r=>{if(!r.ok)throw await r.json();return r.json()}).catch(r=>{var s;return l=`OpenAI: ${((s=r==null?void 0:r.error)==null?void 0:s.message)??"Network Problem"}`,[]});if(l)throw l;const o=Array.isArray(n)?n:(n==null?void 0:n.data)??null;return o&&o.map(r=>({id:r.id,name:r.name??r.id,url:t,custom_info:r.custom_info})).sort((r,s)=>r.name.localeCompare(s.name))},ne=async(e,t)=>{let l=await Promise.all([le(e,`${t}/ollama/v1`).catch(n=>(console.log(n),null)),le(e,`${t}/openai/api`).catch(n=>(console.log(n),null))]);return l=l.filter(n=>n).reduce((n,o,r,s)=>n.concat(o),[]),console.log(l),l},He=async(e="",t={},l="http://localhost:8080")=>{const n=new AbortController;let o=null;const r=await fetch(`${l}/chat/completions`,{signal:n.signal,method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(t)}).catch(s=>(console.log(s),o=s,null));if(o)throw o;return[r,n]},ze=e=>{let t="";return new TransformStream({transform(l,n){t+=l;const o=t.split(e);o.slice(0,-1).forEach(r=>n.enqueue(r)),t=o[o.length-1]},flush(l){t&&l.enqueue(t)}})};function oe(e,t,l){const n=e.slice();return n[6]=t[l],n}function re(e){let t,l,n;function o(i,m){return i[1]?qe:Ke}let r=o(e),s=r(e);return{c(){t=p("div"),s.c(),a(t,"class","tlwd-fixed tlwd-top-0 tlwd-right-0 tlwd-left-0 tlwd-bottom-0 tlwd-w-full tlwd-min-h-screen tlwd-h-screen tlwd-flex tlwd-justify-center tlwd-z-[9999999999] tlwd-overflow-hidden tlwd-overscroll-contain")},m(i,m){j(i,t,m),s.m(t,null),l||(n=S(t,"mousedown",e[15]),l=!0)},p(i,m){r===(r=o(i))&&s?s.p(i,m):(s.d(1),s=r(i),s&&(s.c(),s.m(t,null)))},d(i){i&&O(t),s.d(),l=!1,n()}}}function Ke(e){let t,l,n,o,r,s,i,m,d,g,u,c,_,f;return{c(){t=p("div"),l=p("div"),n=p("form"),o=p("div"),r=p("div"),r.innerHTML=``,s=C(),i=p("input"),m=C(),d=p("div"),g=p("div"),g.textContent="Press ⌘Space+Shift to toggle",u=C(),c=p("button"),c.innerHTML=``,a(r,"class","tlwd-flex tlwd-items-center"),a(i,"id","open-webui-search-input"),a(i,"placeholder","Search Open WebUI"),a(i,"class","tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"),a(i,"autocomplete","one-time-code"),a(o,"class","tlwd-flex tlwd-items-center tlwd-gap-2 tlwd-w-full"),a(g,"class","tlwd-text-right tlwd-text-[0.7rem] tlwd-p-0 tlwd-m-0 tlwd-text-neutral-300 tlwd-h-fit"),a(c,"class","tlwd-h-fit tlwd-flex tlwd-items-center tlwd-bg-transparent tlwd-text-neutral-100 tlwd-cursor-pointer tlwd-p-0 tlwd-m-0 tlwd-outline-none tlwd-border-none"),a(c,"type","button"),a(d,"class","tlwd-flex tlwd-justify-end tlwd-gap-1 tlwd-items-center"),a(n,"class","tlwd-text-gray-200 tlwd-w-full tlwd-p-0 tlwd-m-0"),a(n,"autocomplete","off"),a(l,"class","tlwd-w-full tlwd-flex tlwd-flex-col tlwd-justify-between tlwd-py-2.5 tlwd-px-3.5 tlwd-rounded-2xl tlwd-outline tlwd-outline-1 tlwd-outline-gray-850 tlwd-backdrop-blur-3xl tlwd-bg-gray-850/70 shadow-4xl modal-animation"),a(t,"class","tlwd-m-auto tlwd-max-w-xl tlwd-w-full tlwd-pb-32")},m(k,E){j(k,t,E),w(t,l),w(l,n),w(n,o),w(o,r),w(o,s),w(o,i),M(i,e[4]),w(n,m),w(n,d),w(d,g),w(d,u),w(d,c),_||(f=[S(i,"input",e[13]),S(c,"click",e[14]),S(n,"submit",e[7]),S(n,"mousedown",Ve)],_=!0)},p(k,E){E&16&&i.value!==k[4]&&M(i,k[4])},d(k){k&&O(t),_=!1,A(f)}}}function qe(e){let t,l,n,o,r,s,i,m,d,g,u,c,_,f,k,E,P,b=e[5]&&e[5].length>0&&se(e);return{c(){t=p("div"),l=p("div"),n=p("form"),o=p("div"),r=p("div"),r.innerHTML=``,s=C(),i=p("input"),m=C(),d=p("div"),g=p("div"),g.innerHTML=``,u=C(),c=p("input"),_=C(),f=p("button"),f.innerHTML=``,k=C(),b&&b.c(),a(r,"class","tlwd-flex tlwd-items-center"),a(i,"id","open-webui-url-input"),a(i,"placeholder","Open WebUI URL"),a(i,"class","tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"),a(i,"autocomplete","one-time-code"),i.required=!0,a(o,"class","tlwd-flex tlwd-items-center tlwd-gap-2 tlwd-w-full"),a(g,"class","tlwd-flex tlwd-items-center"),a(c,"placeholder","Open WebUI API Key"),a(c,"class","tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"),a(c,"autocomplete","one-time-code"),c.required=!0,a(f,"class","tlwd-flex tlwd-items-center tlwd-bg-transparent tlwd-text-neutral-100 tlwd-cursor-pointer tlwd-p-0 tlwd-m-0 tlwd-outline-none tlwd-border-none"),a(f,"type","button"),a(d,"class","tlwd-flex tlwd-items-center tlwd-gap-2 tlwd-w-full tlwd-mt-2"),a(n,"class","tlwd-text-gray-200 tlwd-w-full tlwd-p-0 tlwd-m-0"),a(n,"autocomplete","off"),a(l,"class","tlwd-w-full tlwd-flex tlwd-flex-col tlwd-justify-between tlwd-py-2.5 tlwd-px-3.5 tlwd-rounded-2xl tlwd-outline tlwd-outline-1 tlwd-outline-gray-850 tlwd-backdrop-blur-3xl tlwd-bg-gray-850/70 shadow-4xl modal-animation"),a(t,"class","tlwd-m-auto tlwd-max-w-sm tlwd-w-full tlwd-pb-32")},m(x,h){j(x,t,h),w(t,l),w(l,n),w(n,o),w(o,r),w(o,s),w(o,i),M(i,e[2]),w(n,m),w(n,d),w(d,g),w(d,u),w(d,c),M(c,e[3]),w(d,_),w(d,f),w(n,k),b&&b.m(n,null),E||(P=[S(i,"input",e[9]),S(c,"input",e[10]),S(f,"click",e[11]),S(n,"submit",e[8]),S(n,"mousedown",Ue)],E=!0)},p(x,h){h&4&&i.value!==x[2]&&M(i,x[2]),h&8&&c.value!==x[3]&&M(c,x[3]),x[5]&&x[5].length>0?b?b.p(x,h):(b=se(x),b.c(),b.m(n,null)):b&&(b.d(1),b=null)},d(x){x&&O(t),b&&b.d(),E=!1,A(P)}}}function se(e){let t,l,n,o,r,s,i,m,d,g=te(e[5]),u=[];for(let c=0;c`,n=C(),o=p("select"),r=p("option"),r.textContent="Select a model";for(let c=0;c`,a(l,"class","tlwd-flex tlwd-items-center"),r.__value="",M(r,r.__value),a(o,"id","open-webui-model-input"),a(o,"class","tlwd-p-0 tlwd-m-0 tlwd-text-xl tlwd-w-full tlwd-font-medium tlwd-bg-transparent tlwd-border-none placeholder:tlwd-text-gray-500 tlwd-text-neutral-100 tlwd-outline-none"),a(o,"autocomplete","off"),o.required=!0,e[6]===void 0&&D(()=>e[12].call(o)),a(i,"class","tlwd-flex tlwd-items-center tlwd-bg-transparent tlwd-text-neutral-100 tlwd-cursor-pointer tlwd-p-0 tlwd-m-0 tlwd-outline-none tlwd-border-none"),a(i,"type","submit"),a(t,"class","tlwd-flex tlwd-items-center tlwd-gap-2 tlwd-w-full tlwd-mt-2")},m(c,_){j(c,t,_),w(t,l),w(t,n),w(t,o),w(o,r);for(let f=0;f{e.stopPropagation()},Ve=e=>{e.stopPropagation()};function Re(e,t,l){let n=!1,o=!0,r="",s="",i="",m="",d=[];const g=()=>{console.log("resetConfig");try{chrome.storage.local.clear().then(()=>{console.log("Value is cleared")})}catch(h){console.log(h),localStorage.setItem("url",""),localStorage.setItem("key",""),localStorage.setItem("model","")}l(2,r=""),l(3,s=""),l(6,i=""),l(1,o=!0)},u=h=>{h.preventDefault(),window.open(`${r}/?q=${encodeURIComponent(m)}&models=${i}`,"_blank"),l(4,m=""),l(0,n=!1)},c=h=>{h.preventDefault();try{chrome.storage.local.set({url:r,key:s,model:i}).then(()=>{console.log("Value is set")})}catch(H){console.log(H),localStorage.setItem("url",r),localStorage.setItem("key",s),localStorage.setItem("model",i)}l(1,o=!1)};Oe(async()=>{let h=null;try{h=await chrome.storage.local.get()}catch(y){console.log(y)}h&&(l(2,r=h.url??""),l(3,s=h.key??""),l(6,i=h.model??""),h.url&&h.key&&h.model&&(l(5,d=await ne(h.key,h.url)),l(1,o=!1)));const H=async y=>{var G;if(n&&y.shiftKey&&y.key==="Escape"?g():y.key==="Escape"&&l(0,n=!1),y.key===" "&&(y.metaKey||y.ctrlKey)&&(y.shiftKey||y.altKey)){y.preventDefault();try{const v=await chrome.runtime.sendMessage({action:"getSelection"});((v==null?void 0:v.data)??!1)&&l(4,m=v.data)}catch(v){console.log("catch",v)}l(0,n=!n),setTimeout(()=>{const v=document.getElementById("open-webui-search-input");v&&v.focus()},0)}if(s!==""&&r!==""&&y.key==="Enter"&&(y.metaKey||y.ctrlKey)&&(y.shiftKey||y.altKey)){y.preventDefault();try{const v=await chrome.runtime.sendMessage({action:"getSelection"});if((v==null?void 0:v.data)??!1){await chrome.runtime.sendMessage({action:"writeText",text:` `});const[U,Je]=await He(s,{model:i,messages:[{role:"system",content:"You are a helpful assistant."},{role:"user",content:v.data}],stream:!0},(G=d.find(V=>V.id===i))==null?void 0:G.url);if(U&&U.ok){const V=U.body.pipeThrough(new TextDecoderStream).pipeThrough(ze(` `)).getReader();for(;;){const{value:ge,done:_e}=await V.read();if(_e)break;try{let R=ge.split(` `);for(const z of R)if(z!=="")if(console.log(z),z==="data: [DONE]")console.log("DONE");else{let K=JSON.parse(z.replace(/^data: /,""));console.log(K),"request_id"in K?console.log(K.request_id):await chrome.runtime.sendMessage({action:"writeText",text:K.choices[0].delta.content??""})}}catch(R){console.log(R)}}}}}catch(v){console.log(v)}}};return document.addEventListener("keydown",H,{capture:!0}),()=>document.removeEventListener("keydown",H)});function _(){r=this.value,l(2,r)}function f(){s=this.value,l(3,s)}const k=async()=>{r.endsWith("/")&&l(2,r=r.slice(0,-1)),l(5,d=await ne(s,r))};function E(){i=Ee(this),l(6,i),l(5,d)}function P(){m=this.value,l(4,m)}return[n,o,r,s,m,d,i,u,c,_,f,k,E,P,()=>{l(1,o=!0)},()=>{l(0,n=!1)}]}class We extends he{constructor(t){super(),me(this,t,Re,De,ae,{})}}function Ze(e){let t,l,n;return l=new We({}),{c(){t=p("div"),Ne(l.$$.fragment),a(t,"class","extension-container")},m(o,r){j(o,t,r),we(l,t,null),n=!0},p:T,i(o){n||(fe(l.$$.fragment,o),n=!0)},o(o){Ae(l.$$.fragment,o),n=!1},d(o){o&&O(t),pe(l)}}}class Fe extends he{constructor(t){super(),me(this,t,null,Ze,ae,{})}}new Fe({target:document.getElementById("extension-app")}); diff --git a/extension/src/lib/components/SpotlightSearch.svelte b/extension/src/lib/components/SpotlightSearch.svelte index 1e40ea8..806d1c3 100644 --- a/extension/src/lib/components/SpotlightSearch.svelte +++ b/extension/src/lib/components/SpotlightSearch.svelte @@ -4,7 +4,7 @@ import { splitStream } from "../utils"; let show = false; - let showConfig = false; + let showConfig = true; let url = ""; let key = "";