1import{_ as J}from"./C1FmrZbK.js";import{d as h,x as L,y as q}from"./B9lJIPPW.js";import{g as M}from"./T90MGdFx.js";const D=a=>{if(typeof a=="string")return a;if(typeof a=="object"&&a!==null&&"name"in a)return a.name},W=a=>(Array.isArray(a)?a:[]).map(D).filter(t=>typeof t=="string"&&t.trim()!=="").map(t=>({name:t.trim()})),_=1e4,G=new Set(["get","put","post","delete","options","head","patch","trace"]),Y=async(a="",t=null,e=!1,o=!1)=>{const n=new URLSearchParams;o&&n.append("refresh","true");let i=null;const s=await fetch(`${h}/api/models${e?"/base":""}?${n.toString()}`,{method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}}}).then(async r=>{if(!r.ok)throw await r.json();return r.json()}).catch(r=>(i=r,null));if(i)throw i;let l=(s==null?void 0:s.data)??[];if(t&&!e){let r=[];if(t){const c=t.OPENAI_API_BASE_URLS,j=t.OPENAI_API_KEYS,u=t.OPENAI_API_CONFIGS,w=[];for(const d in c){const $=c[d];if(d.toString()in u){const m=u[d.toString()]??{},A=(m==null?void 0:m.enable)??!0,P=(m==null?void 0:m.model_ids)??[];if(A)if(P.length>0){const O={object:"list",data:P.map(g=>({id:g,name:g,owned_by:"openai",openai:{id:g},urlIdx:d}))};w.push((async()=>O)())}else w.push((async()=>await M($,j[d]).then(O=>O).catch(O=>({object:"list",data:[],urlIdx:d})))());else w.push((async()=>({object:"list",data:[],urlIdx:d}))())}}const S=await Promise.all(w);for(const d in S){const $=S[d],m=u[d.toString()]??{};let A=Array.isArray($)?$:($==null?void 0:$.data)??[];A=A.map(g=>({...g,openai:{id:g.id},urlIdx:d}));const P=m.prefix_id;if(P)for(const g of A)g.id=`${P}.${g.id}`;const O=W(m.tags);if(O.length>0)for(const g of A)g.tags=O;r=r.concat(A)}}l=l.concat(r.map(c=>({...c,name:(c==null?void 0:c.name)??(c==null?void 0:c.id),direct:!0})));const f={};for(const c of l){const j=f[c.id];f[c.id]=j?{...j,...c,info:j.info??c.info}:c}l=Object.values(f)}return l},X=async(a,t)=>{let e=null;const o=await fetch(`${h}/api/models/unload`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}},body:JSON.stringify({model:t})}).then(async n=>{if(!n.ok)throw await n.json();return n.json()}).catch(n=>("detail"in n?e=n.detail:e=n,null));if(e)throw e;return o},Q=async(a,t,e)=>{let o=null;const n=await fetch(`${h}/api/chat/actions/${t}`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}},body:JSON.stringify(e)}).then(async i=>{if(!i.ok)throw await i.json();return i.json()}).catch(i=>("detail"in i?o=i.detail:o=i,null));if(o)throw o;return n},Z=async(a,t)=>{let e=null;const o=await fetch(`${h}/api/tasks/stop/${t}`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}}}).then(async n=>{if(!n.ok)throw await n.json();return n.json()}).catch(n=>("detail"in n?e=n.detail:e=n,null));if(e)throw e;return o},v=async(a,t)=>{let e=null;const o=await fetch(`${h}/api/tasks/chat/${encodeURIComponent(t)}/stop`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}}}).then(async n=>{if(!n.ok)throw await n.json();return n.json()}).catch(n=>("detail"in n?e=n.detail:e=n,null));if(e)throw e;return o},tt=async(a,t)=>{let e=null;const o=await fetch(`${h}/api/tasks/chat/${encodeURIComponent(t)}`,{method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}}}).then(async n=>{if(!n.ok)throw await n.json();return n.json()}).catch(n=>("detail"in n?e=n.detail:e=n,null));if(e)throw e;return o},V=async(a,t)=>{let e=null;const o=await fetch(`${t}`,{signal:AbortSignal.timeout(_),method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}}}).then(async n=>{if(t.toLowerCase().endsWith(".yaml")||t.toLowerCase().endsWith(".yml")){if(!n.ok)throw await n.text();const[i,{parse:s}]=await Promise.all([n.text(),J(()=>import("./B09doO8H.js"),[],import.meta.url)]);return s(i)}else{if(!n.ok)throw await n.json();return n.json()}}).catch(n=>((n==null?void 0:n.name)==="TimeoutError"?e=`Connection to ${t} timed out`:"detail"in n?e=n.detail:e=n,null));if(e)throw e;return o},nt=async a=>(await Promise.all(a.filter(t=>{var e;return(e=t==null?void 0:t.config)==null?void 0:e.enable}).map(async t=>{var l;let e=null,o=null;const n=(t==null?void 0:t.auth_type)??"bearer";n==="bearer"?o=t==null?void 0:t.key:n==="none"||n==="session"&&(o=localStorage.token);let i=null;const s=(t==null?void 0:t.spec_type)??"url";if(s==="url")i=await V(o,((t==null?void 0:t.path)??"").includes("://")?t==null?void 0:t.path:`${t==null?void 0:t.url}${((t==null?void 0:t.path)??"").startsWith("/")?"":"/"}${t==null?void 0:t.path}`).catch(r=>(e=r,null));else if((s==="json"&&(t==null?void 0:t.spec))??null)try{i=JSON.parse(t==null?void 0:t.spec)}catch{e="Failed to parse JSON spec"}if(i){if(!i.paths)return{error:"Invalid OpenAPI spec",url:t==null?void 0:t.url};
1const{openapi:r,info:f,specs:c}={openapi:i,info:i.info,specs:q(i)},j={url:t==null?void 0:t.url,openapi:r,info:f,specs:c};try{const u=((t==null?void 0:t.url)??"").replace(/\/$/,""),w=await fetch(`${u}/api/config`,{signal:AbortSignal.timeout(_)});if(w.ok){const S=await w.json();if((l=S==null?void 0:S.features)!=null&&l.system){const d={};o&&(d.Authorization=`Bearer ${o}`);const $=await fetch(`${u}/system`,{signal:AbortSignal.timeout(_),headers:d});if($.ok){const m=await $.json();m!=null&&m.prompt&&(j.system_prompt=m.prompt)}}}}catch{}return j}else return e?{error:e,url:t==null?void 0:t.url}:null}))).filter(t=>t),et=async(a,t,e,o,n,i)=>{var l,r,f;let s=null;try{const c=Object.entries(n.openapi.paths).find(([p,y])=>Object.entries(y).some(([T,E])=>G.has(T)&&E&&typeof E=="object"&&E.operationId===e));if(!c)throw new Error(`No matching route found for operationId: ${e}`);const[j,u]=c,w=Object.entries(u).find(([p,y])=>G.has(p)&&y&&typeof y=="object"&&y.operationId===e);if(!w)throw new Error(`No matching method found for operationId: ${e}`);const[S,d]=w,$=Array.isArray(u.parameters)?u.parameters:[],m=Array.isArray(d.parameters)?d.parameters:[],A=new Map;for(const p of $)p!=null&&p.name&&A.set(`${p.name}:${p.in??""}`,p);for(const p of m)p!=null&&p.name&&A.set(`${p.name}:${p.in??""}`,p);const P={},O={};let g={};const z=new Set;for(const p of A.values()){const y=p==null?void 0:p.name;if(!y)continue;z.add(y);const T=p==null?void 0:p.in;o.hasOwnProperty(y)&&(T==="path"?P[y]=o[y]:T==="query"&&(O[y]=o[y]))}let B=`${t}${j}`;if(Object.entries(P).forEach(([p,y])=>{B=B.replace(new RegExp(`{${p}}`,"g"),encodeURIComponent(y))}),Object.keys(O).length>0){const p=new URLSearchParams(Object.entries(O).map(([y,T])=>[y,String(T)])).toString();B+=`?${p}`}if(d.requestBody&&d.requestBody.content){const p=Object.keys(d.requestBody.content)[0];if(o!==void 0){const y=(l=d.requestBody.content["application/json"])==null?void 0:l.schema,T=L(y,n.openapi.components),C=["allOf","anyOf","oneOf"].some(k=>k in T)?{}:T.properties??{};Object.keys(C).length>0?g=Object.fromEntries(Object.entries(o).filter(([k])=>Object.prototype.hasOwnProperty.call(C,k)||!z.has(k))):g=o}else throw new Error(`Request body expected for operation '${e}' but none found.`)}const N={"Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}};i&&(N["X-Session-Id"]=i);const R={method:S.toUpperCase(),headers:N};["post","put","patch","delete"].includes(S.toLowerCase())&&d.requestBody&&(R.body=JSON.stringify(g));const b=await fetch(B,R);if(!b.ok){const p=await b.text();throw new Error(`HTTP error! Status: ${b.status}. Message: ${p}`)}const U={};b.headers.forEach((p,y)=>{U[y]=p});let I;const x=((f=(r=b.headers.get("Content-Type"))==null?void 0:r.split(";")[0])==null?void 0:f.trim())??"";try{I=await b.clone().json()}catch{if(x.startsWith("text/")||!x)I=await b.text();else{const p=await b.arrayBuffer(),y=new Uint8Array(p);let T="";for(let C=0;C<y.length;C++)T+=String.fromCharCode(y[C]);const E=btoa(T);I=`data:${x};base64,${E}`}}return[I,U]}catch(c){return s=c.message,[{error:s},null]}},ot=async(a="")=>{let t=null;const e=await fetch(`${h}/api/v1/tasks/config`,{method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}}}).then(async o=>{if(!o.ok)throw await o.json();return o.json()}).catch(o=>(t=o,null));if(t)throw t;return e},at=async(a,t)=>{let e=null;const o=await fetch(`${h}/api/v1/tasks/config/update`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}},body:JSON.stringify(t)}).then(async n=>{if(!n.ok)throw await n.json();return n.json()}).catch(n=>("detail"in n?e=n.detail:e=n,null));if(e)throw e;return o},it=async(a="",t,e,o)=>{var s,l;let n=null;const i=await fetch(`${h}/api/v1/tasks/title/completions`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({model:t,messages:e,...o})}).then(async r=>{if(!r.ok)throw await r.json();return r.json()}).catch(r=>("detail"in r&&(n=r.detail),null));if(n)throw n;try{const f=(((l=(s=i==null?void 0:i.choices[0])==null?void 0:s.message)==null?void 0:l.content)??"").replace(/['ââ`]/g,'"'),c=f.indexOf("{"),j=f.lastIndexOf("}");if(c!==-1&&j!==-1){const u=f.substring(c,j+1),w=JSON.parse(u);return w&&w.title?w.title:null}return null}catch{return null}},st=async(a="",t,e,o)=>{var s,l;let n=null;const i=await fetch(`${h}/api/v1/tasks/tags/completions`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({model:t,messages:e,...o&&{chat_id:o}})}).then(async r=>{if(!r.ok)throw await r.json();return r.json()}).catch(r=>("detail"in r&&(n=r.detail),null));if(n)throw n;try{const f=(((l=(s=i==null?void 0:i.choices[0])==null?void 0:s.message)==null?void 0:l.content)??"").replace(/['ââ`]/g,'"'),c=f.indexOf("{"),j=f.lastIndexOf("}");if(c!==-1&&j!==-1){const u=f.substring(c,j+1),w=JSON.parse(u);return w&&w.tags?Array.isArray(w.tags)?w.tags:[]:[]}return[]}catch{return[]}},rt=async(a="",t,e,o)=>{var l,r,f;let n=null;const i=await fetch(`${h}/api/v1/tasks/emoji/completions`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({model:t,prompt:e,...o&&{chat_id:o}})}).then(async c=>{if(!c.ok)throw await c.json();return c.json()}).catch(c=>("detail"in c&&(n=c.detail),null));if(n)throw n;const s=((f=(r=(l=i==null?void 0:i.choices[0])==null?void 0:l.message)==null?void 0:r.content)==null?void 0:f.replace(/["']/g,""))??null;return s&&new RegExp("\\p{Extended_Pictographic}","u").test(s)?s.match(new RegExp("\\p{Extended_Pictographic}","gu"))[0]:null},ct=async(a="",t,e,o,n="search query",i)=>{var c,j;const s=new AbortController;let l=null;const r=await fetch(`${h}/api/v1/tasks/auto/completions`,{signal:s.signal,method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({model:t,prompt:e,...o&&{messages:o},type:n,stream:!1,...i})}).then(async u=>
1{if(!u.ok)throw await u.json();return u.json()}).catch(u=>("detail"in u&&(l=u.detail),null));if(l)throw l;const f=((j=(c=r==null?void 0:r.choices[0])==null?void 0:c.message)==null?void 0:j.content)??"";try{const u=f.indexOf("{"),w=f.lastIndexOf("}");if(u!==-1&&w!==-1){const S=f.substring(u,w+1),d=JSON.parse(S);return d&&d.text?d.text:""}return f}catch{return f}},lt=async(a="",t,e,o)=>{const n=new AbortController;let i=null;const s=await fetch(`${h}/api/v1/tasks/moa/completions`,{signal:n.signal,method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({model:t,prompt:e,responses:o,stream:!0})}).catch(l=>(i=l,null));if(i)throw i;return[s,n]},pt=async(a="")=>{let t=null;const e=await fetch(`${h}/api/v1/pipelines/list`,{method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}}}).then(async n=>{if(!n.ok)throw await n.json();return n.json()}).catch(n=>(t=n,null));if(t)throw t;return(e==null?void 0:e.data)??[]},ht=async(a,t,e)=>{let o=null;const n=new FormData;n.append("file",t),n.append("urlIdx",e);const i=await fetch(`${h}/api/v1/pipelines/upload`,{method:"POST",headers:{...a&&{authorization:`Bearer ${a}`}},body:n}).then(async s=>{if(!s.ok)throw await s.json();return s.json()}).catch(s=>("detail"in s?o=s.detail:o=s,null));if(o)throw o;return i},ut=async(a,t,e)=>{let o=null;const n=await fetch(`${h}/api/v1/pipelines/add`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}},body:JSON.stringify({url:t,urlIdx:e})}).then(async i=>{if(!i.ok)throw await i.json();return i.json()}).catch(i=>("detail"in i?o=i.detail:o=i,null));if(o)throw o;return n},dt=async(a,t,e)=>{let o=null;const n=await fetch(`${h}/api/v1/pipelines/delete`,{method:"DELETE",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}},body:JSON.stringify({id:t,urlIdx:e})}).then(async i=>{if(!i.ok)throw await i.json();return i.json()}).catch(i=>("detail"in i?o=i.detail:o=i,null));if(o)throw o;return n},ft=async(a,t)=>{let e=null;const o=new URLSearchParams;t!==void 0&&o.append("urlIdx",t);const n=await fetch(`${h}/api/v1/pipelines/?${o.toString()}`,{method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}}}).then(async s=>{if(!s.ok)throw await s.json();return s.json()}).catch(s=>(e=s,null));if(e)throw e;return(n==null?void 0:n.data)??[]},yt=async(a,t,e)=>{let o=null;const n=new URLSearchParams;e!==void 0&&n.append("urlIdx",e);const i=await fetch(`${h}/api/v1/pipelines/${t}/valves?${n.toString()}`,{method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}}}).then(async s=>{if(!s.ok)throw await s.json();return s.json()}).catch(s=>(o=s,null));if(o)throw o;return i},wt=async(a,t,e)=>{let o=null;const n=new URLSearchParams;e!==void 0&&n.append("urlIdx",e);const i=await fetch(`${h}/api/v1/pipelines/${t}/valves/spec?${n.toString()}`,{method:"GET",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}}}).then(async s=>{if(!s.ok)throw await s.json();return s.json()}).catch(s=>(o=s,null));if(o)throw o;return i},jt=async(a="",t,e,o)=>{let n=null;const i=new URLSearchParams;o!==void 0&&i.append("urlIdx",o);const s=await fetch(`${h}/api/v1/pipelines/${t}/valves/update?${i.toString()}`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...a&&{authorization:`Bearer ${a}`}},body:JSON.stringify(e)}).then(async l=>{if(!l.ok)throw await l.json();return l.json()}).catch(l=>("detail"in l?n=l.detail:n=l,null));if(n)throw n;return s},mt=async(a="")=>{let t=null;const e=await fetch(`${h}/api/usage`,{method:"GET",headers:{"Content-Type":"application/json",...a&&{Authorization:`Bearer ${a}`}}}).then(async o=>{if(!o.ok)throw await o.json();return o.json()}).catch(o=>(t=o,null));if(t)throw t;return e},gt=async()=>{let a=null;const t=await fetch(`${h}/api/config`,{method:"GET",credentials:"include",headers:{"Content-Type":"application/json"}}).then(async e=>{if(!e.ok)throw await e.json();return e.json()}).catch(e=>(a=e,null));if(a){if(a instanceof TypeError)try{const e=await fetch(`${h}/api/config`,{method:"GET",credentials:"include",redirect:"manual",headers:{"Content-Type":"application/json"}});if(e.type==="opaqueredirect"||e.status>=300&&e.status<400)throw{authRedirect:!0}}catch(e){if(e!=null&&e.authRedirect)throw e}throw a}return t},$t=async()=>{let a=null;const t=await fetch(`${h}/api/changelog`,{method:"GET",headers:{"Content-Type":"application/json"}}).then(async e=>{if(!e.ok)throw await e.json();return e.json()}).catch(e=>(a=e,null));if(a)throw a;return t},Tt=async a=>{let t=null;const e=await fetch(`${h}/api/version`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`}}).then(async o=>{if(!o.ok)throw await o.json();return o.json()}).catch(o=>(t=o,null));if(t)throw t;return e},St=async a=>{let t=null;const e=await fetch(`${h}/api/version/updates`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`}}).then(async o=>{if(!o.ok)throw await o.json();return o.json()}).catch(o=>(t=o,null));if(t)throw t;return e},At=async a=>{let t=null;const e=await fetch(`${h}/api/events`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`}}).then(async o=>{if(!o.ok)throw await o.json();return o.json()}).catch(o=>(t=o,null));if(t)throw t;return e},Ot=async a=>{let t=null;const e=await fetch(`${h}/api/events/webhooks`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`}}).then(async o=>{if(!o.ok)throw await o.json();return o.json()}).catch(o=>(t=o,null));if(t)throw t;return e},Pt=async(a,t)=>{let e=null;const o=await fetch(`${h}/api/events/webhooks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify(t)}).then(async n=>{if(!n.ok)throw await n.json();return n.json()}).catch(n=>
1(e=n,null));if(e)throw e;return o},bt=async(a,t,e)=>{let o=null;const n=await fetch(`${h}/api/events/webhooks/${t}`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify(e)}).then(async i=>{if(!i.ok)throw await i.json();return i.json()}).catch(i=>(o=i,null));if(o)throw o;return n},Et=async(a,t)=>{let e=null;const o=await fetch(`${h}/api/events/webhooks/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`}}).then(async n=>{if(!n.ok)throw await n.json();return n.json()}).catch(n=>(e=n,null));if(e)throw e;return o};export{dt as A,$t as B,ct as C,rt as D,v as E,Z as F,tt as G,Q as H,lt as I,gt as a,Tt as b,st as c,mt as d,et as e,it as f,Y as g,St as h,V as i,nt as j,At as k,Ot as l,bt as m,W as n,Pt as o,Et as p,ot as q,at as r,pt as s,jt as t,X as u,ft as v,wt as w,yt as x,ht as y,ut as z}; 2//# sourceMappingURL=C2m0p6Eu.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.