@urun-sh/openai 0.6.46 → 0.6.48
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.
- package/dist/{chunk-NCKEKCTI.js → chunk-25PW2MQZ.js} +1 -1
- package/dist/{chunk-CUO2JOW4.js → chunk-C452ZIU5.js} +1 -1
- package/dist/chunk-HZNYGJGF.js +66 -0
- package/dist/{chunk-UOQP3DBT.js → chunk-O53WI5BK.js} +1 -1
- package/dist/{chunk-2AFSBZLN.js → chunk-RX37QTWI.js} +1 -1
- package/dist/{chunk-WWFK27D2.js → chunk-XGAF2NDT.js} +1 -1
- package/dist/{chunk-MJGUEL2U.js → chunk-YC6TNAKY.js} +1 -1
- package/dist/hosted/bin.cjs +47 -47
- package/dist/hosted/bin.js +1 -1
- package/dist/hosted/index.cjs +45 -45
- package/dist/hosted/index.js +1 -1
- package/dist/pi-extension/index.js +1 -1
- package/dist/pi-extension/standalone.cjs +22 -22
- package/dist/pooler/bin.js +1 -1
- package/dist/proxy/cli.cjs +54 -54
- package/dist/proxy/cli.js +1 -1
- package/dist/proxy/index.cjs +33 -33
- package/dist/proxy/index.d.cts +36 -5
- package/dist/proxy/index.d.ts +11 -0
- package/dist/proxy/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-U6TUJPC3.js +0 -66
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as ne}from"./chunk-CAR4AEQJ.js";import{e as ue,f as B,g as pe,h as fe}from"./chunk-
|
|
1
|
+
import{a as ne}from"./chunk-CAR4AEQJ.js";import{e as ue,f as B,g as pe,h as fe}from"./chunk-HZNYGJGF.js";import{c as Z,f as j,g as ee,p as oe}from"./chunk-64VO62LW.js";import{a as me,b as W}from"./chunk-XGAF2NDT.js";import{c as le}from"./chunk-RX37QTWI.js";import{a as V}from"./chunk-Q3AIBMET.js";import{b as Y,d as $}from"./chunk-PXV7QBSD.js";import{b as te,c as se,d as re,g as ie,j as R,m as H,n as _,o as ae,r as N,s as L,t as ce,u as de}from"./chunk-C452ZIU5.js";import{c as v}from"./chunk-YSFSRI3D.js";v();import{App as q,createClientToken as Ee,COLD_BOOT_WHEN_LIVE_TIMEOUT_MS as He,DEFAULT_WHEN_LIVE_TIMEOUT_MS as be,isWakingPhase as Be,SessionFailedError as K}from"@urun-sh/core";v();import{SessionFailedError as Ie}from"@urun-sh/core";var G=2;function _e(e){let o=e?.type;return o==="response.created"||o==="response.in_progress"}function Le(e){let o=e?.type;return o==="response.completed"||o==="error"}function ge(e){return async function(s,i){let a=await e.sessionFor(s.model);return(async function*(){for(let l=1;l<=G;l++){let{app:g,entry:y,identity:h}=l===1?a:await e.sessionFor(s.model);i?.({sessionId:e.sessionIdOf?.(y)??null,identity:h});let d=!1,p=!1;try{let m=await e.createStream(y,s);for await(let f of m){if(Le(f)&&(d=!0),_e(f)){if(l>1)continue}else p=!0;yield f}}catch(m){if(m instanceof Ie&&(m.kind==="never-live"||m.kind==="create-failed")){try{e.onAdmissionVerdict?.(g,y,m)}catch{}throw m}if(l<G&&!p){await e.evict(g,y);continue}throw m}if(d)return;if(l<G&&!p){await e.evict(g,y);continue}return}})()}}import{randomUUID as ve}from"crypto";v();import{request as Te}from"http";var Fe="/pooler/v1/inference",k=class extends Error{constructor(s,i,a,c){super(a);this.status=s;this.code=i;this.retryAfterSeconds=c;this.name="PoolerTransportError"}status;code;retryAfterSeconds},Re=e=>{if(typeof e.instructions=="string"&&e.instructions!=="")return e.instructions;let o=e.messages?.find(s=>s.role==="system"||s.role==="developer");if(o!==void 0)return typeof o.content=="string"?o.content:JSON.stringify(o.content)},Ne=e=>{let o=e.messages?.find(s=>s.role!=="system"&&s.role!=="developer");if(o!==void 0)return typeof o.content=="string"?o.content:JSON.stringify(o.content);if(typeof e.input=="string")return e.input;if(Array.isArray(e.input)){let s=e.input.find(i=>{if(i===null||typeof i!="object"||!("role"in i))return!0;let a=i.role;return a!=="system"&&a!=="developer"});if(s===void 0)return;if(typeof s=="string")return s;if(s!==null&&typeof s=="object"&&"content"in s){let i=s.content;return typeof i=="string"?i:JSON.stringify(i)}return JSON.stringify(s)}},we=e=>new Promise((o,s)=>{let i=[];e.on("data",a=>i.push(a)),e.on("end",()=>o(Buffer.concat(i).toString("utf8"))),e.on("error",s)}),Me=async e=>{let o="pooler_error",s=`the pooler refused the request (HTTP ${e.status})`;try{let i=JSON.parse(await we(e.body));if(i!==null&&typeof i=="object"&&"error"in i){let a=i.error;a!==null&&typeof a=="object"&&"code"in a&&typeof a.code=="string"&&(o=a.code),a!==null&&typeof a=="object"&&"message"in a&&typeof a.message=="string"&&(s=a.message)}}catch{}return new k(e.status,o,s,e.retryAfterSeconds)};async function De(e,o,s,i,a){let c=new URL(`${e.baseUrl.replace(/\/+$/,"")}${Fe}`),l=JSON.stringify({region:e.region,model:i,request_id:s,streaming:a,payload:o,affinity:{systemPrompt:Re(o),firstMessage:Ne(o)}});return new Promise((g,y)=>{let h=Te({hostname:c.hostname,port:c.port===""?void 0:Number(c.port),path:`${c.pathname}${c.search}`,method:"POST",headers:{authorization:`Bearer ${e.token}`,"content-type":"application/json",accept:a?"text/event-stream":"application/json","content-length":String(Buffer.byteLength(l))}},d=>{let p=Number(d.headers["retry-after"]??"");g({status:d.statusCode??0,retryAfterSeconds:Number.isFinite(p)?p:void 0,body:d})});h.on("error",d=>y(new k(502,"pooler_unreachable",`the pooler channel failed: ${d.message}`))),h.end(l)})}var ye=e=>{if(!e.startsWith("data: "))return null;let o=e.slice(6).trim();if(o===""||o==="[DONE]")return null;let s;try{s=JSON.parse(o)}catch{return null}if(s===null||typeof s!="object")return null;let i=s;if(i.t===void 0&&i.error!==null&&typeof i.error=="object"){let a=i.error.code;return{t:"error",code:typeof a=="string"?a:null,body:i}}return i};async function*xe(e){let o="";for await(let i of e.body)for(o+=String(i);;){let a=o.indexOf(`
|
|
2
2
|
|
|
3
3
|
`);if(a===-1)break;let c=o.slice(0,a);o=o.slice(a+2);let l=ye(c);l!==null&&(yield l)}let s=ye(o);s!==null&&(yield s)}async function on(e,o,s,i){let a=Y(o,s,i),c=a.model??"";if(c==="")throw new k(400,"missing_model","the pooler submit requires a model");let l=await De(e,a,s,c,o.stream===!0);if(l.status>=400)throw await Me(l);let g=o.stream===!0?$(s,xe(l)):await Ce(l,s);return(async function*(){yield{type:"response.created",response:{id:`resp_${s}`,status:"in_progress"}},yield*g})()}async function Ce(e,o){let s=await we(e.body),i=null;try{let c=JSON.parse(s);c!==null&&typeof c=="object"&&(i=c)}catch{i=null}if(i===null)throw new k(502,"pooler_bad_body","the pooler answered a non-object body");let a=i;return $(o,(async function*(){yield a})())}v();import{encodeStreamEnvelope as he}from"@urun-sh/core";var Ue="audio";function Se(e){let o=e.streamEndpoint(Ue);return{sessionId:e.id,appendInputAudio(s,i){let a=Buffer.from(s,"base64");if(a.byteLength!==0){if(i===void 0){o.send(he(new Uint8Array(a)));return}o.send(he({pcm16:s,capture_wall_ms:i}))}},onOutputAudio(){return()=>{}}}}v();import{encodeStreamEnvelope as $e}from"@urun-sh/core";var je="rt-video-in";function Pe(e){let o=e.streamEndpoint(je);return{sendInputFrame:async s=>{o.send($e(s))}}}var We=0,Ge=4,qe=4;function Tn(e,o){let s=(l,g)=>{let y=(e[l]??"").trim();if(!y)return g;let h=Number.parseInt(y,10);if(!Number.isInteger(h)||h<1)throw new Error(`${l} must be a positive integer (got ${JSON.stringify(e[l])})`);return h},i=(e.URUN_DECISION_POOL_MIN??"").trim();if(i==="0")return null;let a=i?Number.parseInt(i,10):We;if(!Number.isInteger(a)||a<0)throw new Error(`URUN_DECISION_POOL_MIN must be a non-negative integer (got ${JSON.stringify(e.URUN_DECISION_POOL_MIN)})`);let c=s("URUN_DECISION_POOL_MAX",Math.max(a,Ge));return{min:a,max:c,idleGraceMs:3e4,inFlightCap:s("URUN_DECISION_POOL_INFLIGHT_CAP",qe),replicaId:(e.URUN_REPLICA_ID??"").trim()||o||"proxy"}}function Fn(e){let o=(e.URUN_DECISION_STREAM_IDLE_TIMEOUT_S??"").trim();if(!o)return B;let s=Number.parseInt(o,10);if(!Number.isInteger(s)||s<=0)throw new Error(`URUN_DECISION_STREAM_IDLE_TIMEOUT_S must be a positive integer (got ${JSON.stringify(e.URUN_DECISION_STREAM_IDLE_TIMEOUT_S)})`);return s*1e3}function J(e,o,s,i){let a=e[s];if(typeof a!="function")throw new Error(`app "${o}" has no function "${s}" (set URUN_FUNCTION)`);let c=i?a(void 0,i):a();if(typeof c.end!="function")throw new Error(`app "${o}" function "${s}" returned a session without end()`);return c}function Ae(e,o,s,i){let{baseUrl:a,orgId:c,auth:l}=e,g=o.fnName??e.fnName,y=e.sessionStartOptions?.(s),h=i||y||o.sharedApp?{...o.sharedApp?{sharedApp:!0}:{},...y,...i}:void 0,d=w=>({session:w,responses:new V(w),gone:me(w,s)});if(l.lane==="jwt"){let w=q(o.appSlug,{baseUrl:a,orgId:c,jwt:l.jwt});return d(J(w,o.appSlug,g,h))}if(l.lane==="machine"||l.lane==="user"){let w=l.lane==="machine"?l.machineToken:l.userToken,{gatewayUrl:I}=l,T=(typeof e.subject=="function"?e.subject():e.subject)??ve(),F=q(o.appSlug,{baseUrl:a,orgId:c,getAccessToken:async()=>(await Ee(w,{baseUrl:I,expiresIn:300,allowedFunctions:[`${o.appSlug}/${g}`],subject:T,...o.sharedApp?{sharedApp:!0}:{}})).token});return d(J(F,o.appSlug,g,h))}let{apiKey:p,gatewayUrl:m}=l,f=(typeof e.subject=="function"?e.subject():e.subject)??ve(),S=q(o.appSlug,{baseUrl:a,orgId:c,getAccessToken:async()=>(await Ee(p,{baseUrl:m,expiresIn:300,allowedFunctions:[`${o.appSlug}/${g}`],subject:f,...o.sharedApp?{sharedApp:!0}:{}})).token});return d(J(S,o.appSlug,g,h))}function ke(e){let o=e.session.id;if(typeof o!="string"||o.length===0)throw new Error("pooled session exposes no stable session id \u2014 the session-identity seam requires @urun-sh/core Session (session.id)");return o}function X(e){if(e.kind==="never-live")return!0;if(e.kind!=="create-failed")return!1;let o=e.status.error?.httpStatus,s=e.status.error?.code;return o===410||o===409&&(s==="cancelled"||s==="expired")?!0:s==="client_ended"}var Je=new Set(["error","paused"]);function Rn(e){let{auth:o,catalog:s}=e,i=null,a=(l,g)=>{let y=Ae(e,l,g);return e.onSessionOpen&&typeof y.session.id=="string"&&y.session.id!==""&&e.onSessionOpen(g,y.session.id),y.gone.onGone(()=>{i?.evict(g,y)}),y},c=new de({sharedOnlyListing:e.sharedOnlyListing===!0,defaultApp:e.defaultApp,fnName:e.fnName,openSession:a,closeSession:async l=>{if(l.gone.dispose(),l.audioDispose?.(),e.release==="detach"){if(typeof l.session.detach!="function")throw new Error('pooled session exposes no native detach() \u2014 the release:"detach" lane requires @urun-sh/core Session.detach');l.session.detach();return}await l.session.end()},listApps:o.lane==="api-key"?()=>ae({apiUrl:e.apiUrl,apiKey:o.apiKey}):null,listCatalog:e.catalogRows??(s?()=>ne(s):null),listPrices:s?()=>re(s):null,shared:e.catalogRows?async()=>{let l=await e.catalogRows();return te(l)}:o.lane==="api-key"?()=>se({apiUrl:e.apiUrl,apiKey:o.apiKey}):null,sessionKey:ke});return i=c,e.defaultApp!==null&&c.seed(e.defaultApp,a({appSlug:e.defaultApp},L({appSlug:e.defaultApp}))),c}function Nn(e,o){let s=e.decisionPool;if(!s)throw new Error("wireDecisionPool called without BackhaulConfig.decisionPool");let i=s.replicaId??"proxy",a=new Map,c=new Map,l=new Map,g=d=>{process.stderr.write(`[decision-pool] ${d}
|
|
4
4
|
`)},y=(d,p)=>{let m=a.get(p);if(m)return m;let f=new ue({min:s.min,max:s.max,idleGraceMs:s.idleGraceMs,inFlightCap:s.inFlightCap,replicaId:i,openSlot:async S=>{let w=Ae(e,d,p,{concurrencyKey:S.concurrencyKey});return w.gone.onGone(I=>I.bindingLost?f.evict(w):f.markSessionDead(w)),await C(w.session),g(`slot attached pool=${p} slot=${S.concurrencyKey} session=${w.session.id??"(no id)"}`),w},closeSlot:async S=>{S.gone.dispose(),S.audioDispose?.(),await S.session.end()},onDetach:(S,w)=>g(`slot detached pool=${p} slot=${S.concurrencyKey} reason=${w}`),terminalOpenFailure:S=>S instanceof K&&X(S)});return c.set(p,{target:d,env:s}),a.set(p,f),f},h=async(d,p)=>{let m=c.get(p);if(m)try{let f=await o.poolTuningFor(d);y(d,p).retune({min:f?.min??m.env.min,max:f?.max??m.env.max,inFlightCap:f?.in_flight_cap??m.env.inFlightCap,idleGraceMs:f?.idle_grace_s!==void 0?f.idle_grace_s*1e3:m.env.idleGraceMs,warmWaitMs:f?.warm_wait_s!==void 0?f.warm_wait_s*1e3:void 0})}catch(f){g(`pool tuning refresh failed pool=${p} reason=${f instanceof Error?f.message:String(f)}`)}};return{async boot(){if(e.defaultApp===null)return;let d={appSlug:e.defaultApp};await y(d,L(d)).boot()},async sessionFor(d){let p=await o.resolveTargetFor(d),m=L(p),f=y(p,m);await h(p,m);let S=await f.acquire({timeoutMs:f.requestWaitMs}),w=l.get(S.entry)??[];return w.push(S),l.set(S.entry,w),{app:m,entry:S.entry,identity:ce(p)}},async warmFor(d){let p=await o.resolveTargetFor(d);await y(p,L(p)).boot()},end(d){let p=l.get(d)?.shift();p&&(l.get(d)?.length===0&&l.delete(d),p.release())},evict(d){for(let p of a.values())p.evict(d)},markSessionDead(d){for(let p of a.values())p.markSessionDead(d)},reap(){for(let[d,{target:p}]of c)h(p,d).then(()=>{let m=a.get(d);m&&m.reap()})},async pingReady(d){for(let p of a.values())if(await p.pingReady(d))return!0;return!1},stats(){return[...a.entries()].map(([d,p])=>({poolKey:d,...p.stats()}))},async drain(d){await Promise.all([...a.values()].map(p=>p.drain({timeoutMs:d})))},async close(){await Promise.all([...a.values()].map(d=>d.close()))}}}function Ke(e){return Be(e?.name)?e?.runtime?.wake?.expectedWakePath==="portable-golden-restore"?be:He:be}async function C(e,o){let s=e.whenLive;if(typeof s!="function")throw new Error("pooled session exposes no native whenLive() \u2014 the audio lane must wait for the session's own admission (cold wake: queued \u2192 demand \u2192 promote) before wiring media; a session without the core Session.whenLive surface cannot be served audio");await s.call(e,{timeout:Ke(e.phase),signal:o})}async function Xe(e){if(typeof e.cancel=="function")try{await e.cancel();return}catch{}if(typeof e.detach!="function")throw new Error("pooled session exposes neither cancel() nor detach() \u2014 the client-gone abandon path requires the @urun-sh/core Session native lifecycle surface");e.detach()}async function Oe(e){let o=e.phase?.name;if(o==="live"||o==="paused"){if(typeof e.detach!="function")throw new Error("the dedicated dial session reads live but exposes no native detach() \u2014 the client-gone release refuses to park a serving lane");e.detach();return}if(typeof e.end!="function")throw new Error("the dedicated dial session exposes no end() \u2014 the client-gone release requires the @urun-sh/core Session terminal surface");await e.end()}function x(e){return e.reason instanceof Error?e.reason:new Error("the client socket closed")}function Mn(e,o=ee,s,i,a=B,c){let l=new WeakMap,g=new WeakMap,y=new WeakMap,h=new WeakMap,d=new WeakMap,p=n=>{let t=n.session.id;return typeof t=="string"&&t.length>0?t:null},m="lane",f=n=>{let t=_(n);if(!c||!t||t.app!==m)return null;let r=c.entryFor(t.key);if(!r)throw new R(`the lane behind this handle (${t.key}) is gone \u2014 its runtime released it or the host lost it; it cannot be reattached. Reconnect without a handle to pick a lane again.`);return{laneId:t.key,entry:r}},S=async n=>f(n)?.entry??(await e.sessionForHandle(n)).entry,w=n=>{let t=l.get(n);if(!t){let r={waiting:0,gone:new AbortController};d.set(n,r),t=(async()=>{if(await C(n.session,r.gone.signal),r.gone.signal.aborted)throw x(r.gone.signal);d.get(n)===r&&d.delete(n);let u=await Z(n.session,await o());return Object.assign(u,{sessionId:n.session.id})})(),l.set(n,t),t.then(u=>{l.get(n)===t&&(n.audioDispose=()=>u.dispose())},()=>{}),t.catch(()=>{l.get(n)===t&&l.delete(n)}),t.then(()=>{d.get(n)===r&&d.delete(n)},()=>{d.get(n)===r&&d.delete(n)})}return t},I=n=>{let t=h.get(n);return t||(t=(async()=>{let r=await w(n);return{appendInputAudio:(u,E)=>r.appendInputAudio(u,E),onOutputAudio:u=>r.onOutputAudio(u),sessionId:p(n)}})(),h.set(n,t),t.catch(()=>{h.get(n)===t&&h.delete(n)})),t},T=async(n,t,r,u=!1)=>{let E=()=>u?Oe(n.session):Xe(n.session);if(r?.aborted){let O=d.get(n);throw(l.get(n)===void 0||O!==void 0&&O.waiting===0)&&await E().catch(()=>{}),x(r)}let b=t(n),P=d.get(n);return P!==void 0&&P.waiting++,r===void 0?b:new Promise((O,A)=>{let z=()=>{P!==void 0&&--P.waiting===0&&d.get(n)===P&&(P.gone.abort(),d.delete(n),l.delete(n),h.delete(n),E().catch(()=>{})),A(x(r))};r.addEventListener("abort",z,{once:!0});let Q=()=>r.removeEventListener("abort",z);b.then(U=>{Q(),O(U)},U=>{Q(),A(U)})})},F=async(n,t,r)=>{try{return await r}catch(u){throw(u instanceof R||u instanceof K&&X(u))&&(e.evict(n,t),u instanceof K&&s?.(n,u.kind==="never-live"?"never-live":"create-failed")),u}};return{createResponse:ge({sessionFor:c?async n=>{let t=await e.resolveTargetFor(n);if(t.sharedApp)try{let r=await c.sessionFor(n,t);return{app:r.app,entry:r.entry,identity:r.identity}}catch(r){if(r instanceof le)return i?i.sessionFor(n):e.sessionFor(n);if(r instanceof k)return console.error(`[pooler-fallback] pooler channel failed for ${n} (${r.name} ${r.code}: ${r.message}) \u2014 serving via the per-request path`),i?i.sessionFor(n):e.sessionFor(n);throw r}return i?i.sessionFor(n):e.sessionFor(n)}:i?n=>i.sessionFor(n):n=>e.sessionFor(n),sessionIdOf:n=>p(n),evict:(n,t)=>{c&&c.owns(t)?c.evict(t):i?i.evict(t):e.evict(n,t)},onAdmissionVerdict:(n,t,r)=>{X(r)&&(c&&c.owns(t)?c.evict(t):i?i.markSessionDead(t):e.evict(n,t),s?.(n,r.kind==="never-live"?"never-live":"create-failed"))},createStream:async(n,t)=>{try{await C(n.session);let r=pe(W(await n.responses.responses.create(t),n.gone),a);if(!i&&!c)return r;let u=n;return(async function*(){try{yield*r}catch(b){throw fe(b)&&(c&&c.owns(u)?c.evict(u):i&&(b instanceof R&&!b.bindingLost?i.markSessionDead(u):i.evict(u))),b}finally{c&&c.owns(u)?c.release(u):i?.end(u)}})()}catch(r){throw c&&c.owns(n)?c.release(n):i&&i.end(n),r}}}),listModels:()=>e.modelList(),openRouterModels:()=>e.openRouterModels(),supportsImages:(n,t)=>e.supportsImages(n,t),listImageModels:()=>e.imageModelList(),catalogIdentity:n=>e.catalogIdentityFor(n),servingAppSlug:async n=>await e.servingAppSlugFor(n),supportsAudio:n=>e.supportsAudio(n),supportsSpeech:n=>e.supportsSpeech(n),speechVoices:n=>e.speechVoices(n),supportsTranscription:n=>e.supportsTranscription(n),transcriptStreamFor:n=>e.transcriptStreamFor(n),listSpeechToTextModels:()=>e.speechToTextModelList(),openAudio:async(n,t)=>{let{app:r,entry:u}=await e.sessionFor(n);return await F(r,u,T(u,w,t))},openAudioOn:async(n,t,r,u)=>{let E=f(n);if(E){let A=E.entry.session;return Se(A)}let{app:b,entry:P}=await e.sessionForHandle(n);if(u&&P.session.phase?.name!=="live"){let A=P.session.phase?.name;u({status:A==="queued"||A==="waiting_for_capacity"?A:"pending",reason:`the dial's session is ${A??"not yet admitted"} \u2014 the connection waits for admission`})}let O=_(n)?.app.startsWith(N)??!1;return await F(b,P,T(P,I,t,O))},openTurnsOn:async function*(n,t){if(t?.aborted)throw x(t);let r=await S(n);yield*ie(r.session,t)},openVideoOn:async n=>{let t=f(n);if(t)return Pe(t.entry.session);let{entry:r}=await e.sessionForHandle(n),u=g.get(r);return u||(u=j(r.session),g.set(r,u)),u},openVideo:async n=>{let{entry:t}=await e.sessionFor(n),r=g.get(t);return r||(r=j(t.session),g.set(t,r)),r},openVideoOut:async n=>{let{entry:t}=await e.sessionFor(n),r=y.get(t);return r||(r=oe(t.session),y.set(t,r)),r},sessionHandle:async n=>{if(c){let t=await e.resolveTargetFor(n);if(t.sharedApp){let r=await c.sessionFor(n,t),u=p(r.entry);if(u===null)throw new Error("lane pick returned an entry with no lane id \u2014 the lane session must carry its laneId as `id`");return H(m,u)}}return(await e.handleFor(n)).handle},dedicatedSessionHandle:async n=>{if(!(await e.resolveTargetFor(n)).sharedApp)return(await e.handleFor(n)).handle;let{app:r,entry:u}=await e.dedicatedSessionFor(n);return H(r,ke(u))},releaseSessionHandle:n=>{let t=_(n);if(!t)return;if(t.app.startsWith(N)){(async()=>{let u=null;try{u=(await e.sessionForHandle(n)).entry}catch{return}await Oe(u.session).catch(()=>{}),await e.evict(t.app,u)})();return}if(!c||t.app!==m)return;let r=c.entryFor(t.key);r&&c.release(r)},endDedicatedSession:async n=>{let t=_(n);if(!t||!t.app.startsWith(N))return;let r=null;try{r=(await e.sessionForHandle(n)).entry}catch{return}if(typeof r.session.end!="function")throw new Error("the dedicated dial session exposes no end() \u2014 the app-close verb requires the @urun-sh/core Session terminal surface");let u=await r.session.end();return await e.evict(t.app,r),u},speechSessionHandle:async n=>(await e.speechHandleFor(n)).handle,evictSpeechSession:async n=>{let{app:t,entry:r}=await e.sessionForHandle(n);await e.evict(t,r)},createResponseOn:async(n,t,r)=>{let u=await S(n);await C(u.session);let E=r!==void 0&&f(n)?new V({...u.session,consumerId:r},{sessionTag:r}):u.responses;return W(await E.responses.create(t),u.gone)},onSessionEnd:async(n,t)=>{let r=f(n);if(r)return r.entry.gone.onGone(P=>t({timeLeftMs:null,reason:P.message}));let{entry:u}=await e.sessionForHandle(n),E=u.session;if(typeof E.onPhase!="function")throw new Error("pooled session exposes no onPhase \u2014 session-end (goAway) wiring requires @urun-sh/core Session");let b=!1;return E.onPhase(P=>{if(b||!Je.has(P.name))return;b=!0;let O=E.endsAt??null;t({timeLeftMs:O?Math.max(0,O.getTime()-Date.now()):null,reason:P.reason??`session ${P.name}`})})}}}export{k as a,on as b,Tn as c,Fn as d,Rn as e,Nn as f,Mn as g};
|
|
@@ -2,5 +2,5 @@ import{c as w}from"./chunk-YSFSRI3D.js";w();import{randomUUID as Ke}from"crypto"
|
|
|
2
2
|
`),null;let e={},t=[["min",0],["max",1],["in_flight_cap",1],["idle_grace_s",0],["warm_wait_s",1]],o=!1;for(let[r,i]of t){let s=n[r];if(s==null)continue;let d=typeof s=="number"?s:typeof s=="string"?Number.parseInt(s,10):NaN;if(!Number.isInteger(d)||d<i){process.stderr.write(`[serving-pool] skipping engine_args.pool (malformed ${String(r)}=${JSON.stringify(s)})
|
|
3
3
|
`),o=!0;break}e[r]=d}return o||Object.keys(e).length===0?null:e}function He(n,e){if(n.length===0)return null;let t;return e.modelId&&(t=n.find(o=>o.model_id===e.modelId&&(!e.variant||o.variant===e.variant))),t||(t=n.find(o=>o.serve_app_slug===e.appSlug||h(`${o.model_id}-${o.variant}`)===e.appSlug||h(o.model_id)===e.appSlug)),t?ze(t.engine_args?.pool):null}function H(n,e,t,o,r){if(!r)throw new p(`shared model "${n}" cannot be gated: no catalog oracle is configured, and a shared endpoint's modality must come from the model's OWN model_catalog row \u2014 never a default`);if(e===void 0||t===void 0)throw new p(`shared model "${n}" resolved without a catalog id + variant to join on`);let i=o.filter(s=>s.model_id===e&&s.variant===t);if(i.length===0)throw new p(`shared model "${n}" names endpoint ${e}:${t} but the catalog has no model_catalog row for it \u2014 the shared block cannot vouch a modality from nothing`);return i}function he(n,e){if(!e.every(r=>(r.task??void 0)==="image"))return[];let t=e.map(r=>r.engine_args?.expects_image),o=t[0];if(typeof o!="boolean"||!t.every(r=>r===o))throw new p(`shared image model "${n}" does not vouch an explicit image mode: its ${e.length} model_catalog row(s) carry engine_args.expects_image ${JSON.stringify(t)} \u2014 the shared lane requires a boolean (false = pure text-to-image generation, true = edit) and refuses to silently default to edit`);return[o===!1?"generation":"edit"]}var we="shared:",me="speech:",qe="realtime:";function q(n){return n.sharedApp?we+n.appSlug:n.appSlug}function G(n){return typeof n.modelId=="string"&&typeof n.variant=="string"?{kind:"catalog",model_id:n.modelId,variant:n.variant}:{kind:"not-a-catalog-model",model:n.appSlug}}function W(n,e){let t=e.filter(i=>h(`${i.model_id}-${i.variant}`)===n);if(t.length>0)return t;let o=e.filter(i=>h(i.model_id)===n);return new Set(o.map(i=>i.variant)).size===1?o:[]}function Ge(n){let e=n.engine_args?.expects_image;return e==null?"edit":e===!1?"generation":e===!0?"edit":null}function Ve(n){let e=n.map(Ge),t=e[0];return t!=null&&e.every(o=>o===t)?t:null}var We={stt:"stt",tts:"tts"};function R(n){if(n.length===0)return null;let e=n[0].task??void 0,t=n.every(r=>(r.task??void 0)===e),o=e===void 0?void 0:We[e];return o!==void 0?t?o:null:t&&n.every(r=>r.engine_args?.realtime===!0)?"decision":null}function _e(n,e){let t=W(n,e);return t.length>0?t:K(n,e)}function A(n,e){return _e(n.appSlug,e)}function Ye(n){let e=n.map(o=>o.engine_args?.transcript_stream).filter(o=>o!=null);if(e.length===0)return"stt";let t=e[0];if(typeof t!="string"||t.length===0||!e.every(o=>o===t))throw new p(`the model's model_catalog rows cannot vow one engine_args.transcript_stream (found ${JSON.stringify(e)}) \u2014 the field must be a non-empty string agreeing across placements; the realtime transcription lane refuses to guess the stream the engine writes`);return t}var F=6e4,ye=class{constructor(e){this.opts=e}opts;pool=new Map;mintedIds=new WeakMap;apps={current:null};rows={current:null};shared={current:null};async swr(e,t,o){let r=e.current;return r&&Date.now()-r.at<o?r.value:r?(r.refreshing||(r.refreshing=(async()=>{try{e.current={at:Date.now(),value:await t()}}catch{}finally{r.refreshing=void 0}})()),r.value):(e.current={at:Date.now(),value:await t()},e.current.value)}seed(e,t){this.snapshotMintId(t),this.pool.set(e,Promise.resolve(t))}snapshotMintId(e){try{let t=this.keyOf(e),o=e;this.mintedIds.has(o)||this.mintedIds.set(o,t)}catch{}}async deployedApps(){return this.opts.listApps?this.swr(this.apps,()=>this.opts.listApps(),this.opts.appsTtlMs??F):[]}async sharedBlock(){return this.opts.shared?this.swr(this.shared,()=>this.opts.shared(),this.opts.appsTtlMs??F):null}async catalogRows(){return this.opts.listCatalog?this.swr(this.rows,()=>this.opts.listCatalog(),this.opts.appsTtlMs??F):[]}pricesCache=null;async priceRows(){if(!this.opts.listPrices)return[];let e=this.opts.appsTtlMs??F;if(this.pricesCache&&Date.now()-this.pricesCache.at<e)return this.pricesCache.rows;let t=await this.opts.listPrices();return this.pricesCache={at:Date.now(),rows:t},t}async pricesForListing(e){let t;try{t=await this.priceRows()}catch(r){if(r instanceof _)throw r;return this.warn(`urun /v1/models: the per-token price surface could not be read (${String(r instanceof Error?r.message:r)}) \u2014 every model is listed UNPRICED for now; Hugging Face will show no price until the read succeeds
|
|
4
4
|
`),I}let o=ee(t,Date.now(),e);for(let r of o.refusals)this.warn(`urun /v1/models: refusing to price ${r.model_id}:${r.variant??"*"} \u2014 ${r.reason}
|
|
5
|
-
`);return o}outputFreeKeys(e){let t=new Set;if(!e)return t;for(let o of e.endpoints)o.output_free===!0&&t.add(J(o.model_id,o.variant));return t}warn(e){(this.opts.warn??(o=>console.warn(o.trimEnd())))(e)}servable(e){return e.filter(t=>t.serves==="openai"&&t.deployment_status==="active").map(t=>t.app_slug)}async availableIds(){let e=this.opts.defaultApp,t=new Set(e===null?[]:[e]);if(this.opts.listApps)for(let r of this.servable(await this.deployedApps()))t.add(r);for(let r of this.pool.keys())r.startsWith(we)||r.startsWith(me)||t.add(r);let o=[...t].filter(r=>r!==e).sort();return e===null?o:[e,...o]}async noDefaultApp(e){let t=await this.availableIds(),o=t.length>0?t.join(", "):"(none deployed)";throw new P(e===""?`no "model" was given and this endpoint has no default model \u2014 name one of your org's deployed apps that declare serves="openai"; available models: ${o}`:`model "${e}" does not name a deployed app in your org that declares serves="openai", and this endpoint has no default model to fall back to; available models: ${o}`)}async sharedLane(e){if(!this.opts.shared)return null;let t=await this.sharedBlock();if(!t)return null;let o=D(t,e);if(o)return o;let r=e.lastIndexOf(":"),i=r>0?e.slice(0,r):e,s=r>0?e.slice(r+1):void 0,d=h(i),a=t.endpoints.filter(c=>h(c.model_id)===d&&(s===void 0||c.variant===s)),l=new Set(a.map(c=>c.model_id)),u=[...l][0];return u===void 0||l.size!==1?null:D(t,u,s)}async resolveTarget(e){let t=(e??"").trim(),o=this.opts.defaultApp;if(!t||t==="urun")return o===null?this.noDefaultApp(t):{appSlug:o};let r=h(t);if(r===o)return{appSlug:o};let i=await this.sharedLane(t);if(i)return{appSlug:i.endpoint.app_slug,fnName:i.endpoint.function,sharedApp:!0,modelId:i.endpoint.model_id,variant:i.endpoint.variant,sharedOrgId:i.shared_org_id,gpuSpec:i.endpoint.gpu_spec??void 0,appId:i.endpoint.app_id??void 0};if(this.pool.has(r))return{appSlug:r};if(this.opts.listApps){let s=await this.deployedApps(),d=this.servable(s);if(d.includes(r))return{appSlug:r};let a=d.filter(u=>u.startsWith(`${r}-`));if(a.length===1)return{appSlug:a[0]};if(a.length>1)throw new P(`model "${t}" is ambiguous across deployed apps ${a.join(", ")} \u2014 name the exact app slug (or catalog id:variant)`);let l=s.find(u=>u.app_slug===r||u.app_slug.startsWith(`${r}-`));if(l)throw new P(`model "${t}" maps to app "${l.app_slug}", which has no function declaring serves="openai" \u2014 add serves="openai" to its @app.function or deploy it with \`urun serve ${t}\`; available models: ${(await this.availableIds()).join(", ")}`)}if(this.opts.listCatalog){let d=(await this.opts.listCatalog()).find(a=>t===a.model_id||t===`${a.model_id}:${a.variant}`||r===h(a.model_id)||r===h(`${a.model_id}-${a.variant}`));if(d)throw new P(`model "${t}" is in the uRun catalog but not deployed \u2014 deploy it with \`urun serve ${d.model_id}\`; available models: ${(await this.availableIds()).join(", ")}`)}return o===null?this.noDefaultApp(t):{appSlug:o}}async catalogIdentityFor(e){let t=G(await this.resolveTarget(e));return t.kind==="catalog"?{model_id:t.model_id,variant:t.variant}:null}async poolTuningFor(e){return He(await this.catalogRows(),e)}async servingAppSlugFor(e){return(await this.resolveTarget(e)).appSlug}async resolveApp(e){return q(await this.resolveTarget(e))}async sessionFor(e){let t=await this.resolveTarget(e);return this.acquire(t,q(t))}async resolveTargetFor(e){return this.resolveTarget(e)}async realtimeBillingIdentityFor(e){return G(await this.resolveTarget(e))}async speechSessionFor(e){let t=await this.resolveTarget(e);return this.acquire(t,me+q(t))}async dedicatedSessionFor(e){let t=await this.resolveTarget(e);return this.acquire(t,qe+Ke())}async evictHandle(e){let t=ge(e);if(!t)return;let o=this.pool.get(t.app);if(!o)return;let r=await o.then(i=>i,()=>null);r!==null&&await this.evict(t.app,r)}async acquire(e,t){let o=this.pool.get(t);return o||(o=Promise.resolve(this.opts.openSession(e,t)),this.pool.set(t,o),o.then(r=>this.snapshotMintId(r),()=>{}),o.catch(()=>this.pool.delete(t))),{app:t,entry:await o,identity:G(e)}}keyOf(e){let t=this.opts.sessionKey;if(!t)throw new Error("ModelRouter: sessionKey is not configured \u2014 the session-identity seam (handleFor/sessionForHandle) is unavailable on this router");let o=t(e);if(typeof o!="string"||o.length===0)throw new Error("ModelRouter: sessionKey returned an empty identity for a pooled session");return o}async handleFor(e){let{app:t,entry:o}=await this.sessionFor(e);return{app:t,handle:pe(t,this.keyOf(o))}}async speechHandleFor(e){let{app:t,entry:o}=await this.speechSessionFor(e);return{app:t,handle:pe(t,this.keyOf(o))}}async sessionForHandle(e){let t=ge(e);if(!t)throw new M(`malformed session handle ${JSON.stringify(e)} \u2014 not issued by this proxy`);let{app:o,key:r}=t,i=this.pool.get(o),s=i?await i.then(d=>d,()=>null):null;if(s===null)throw new M(`the session behind this handle (app "${o}") is gone \u2014 closed, evicted after its pod died, or the proxy restarted; it cannot be reattached. Reconnect without a handle to start a new session.`);if(this.keyOf(s)!==r&&this.mintedIds.get(s)!==r)throw new M(`the session behind this handle (app "${o}") was replaced \u2014 the original backhaul died and a new session serves this app now; the handle's session cannot be reattached. Reconnect without a handle to start a new session.`);return{app:o,entry:s}}async evict(e,t){let o=this.pool.get(e);!o||await o.then(i=>i,()=>null)!==t||this.pool.get(e)!==o||(this.pool.delete(e),await this.opts.closeSession(t).catch(()=>{}))}async modelList(){let e=this.opts.sharedOnlyListing?[]:await this.availableIds(),t=await this.sharedBlock(),[o,r]=await Promise.all([this.catalogRows().then(l=>({ok:!0,rows:l}),()=>({ok:!1,rows:[]})),this.pricesForListing(this.outputFreeKeys(t))]),i=o.rows,s=o.ok?r:I;o.ok||this.warn(`urun /v1/models: the model catalog could not be read \u2014 entries fall back to the bare OpenAI fields AND no model is priced on either lane (pricing follows catalog identity, so a half-priced listing would flicker on Hugging Face)
|
|
5
|
+
`);return o}outputFreeKeys(e){let t=new Set;if(!e)return t;for(let o of e.endpoints)o.output_free===!0&&t.add(J(o.model_id,o.variant));return t}warn(e){(this.opts.warn??(o=>console.warn(o.trimEnd())))(e)}servable(e){return e.filter(t=>t.serves==="openai"&&t.deployment_status==="active").map(t=>t.app_slug)}async availableIds(){let e=this.opts.defaultApp,t=new Set(e===null?[]:[e]);if(this.opts.listApps)for(let r of this.servable(await this.deployedApps()))t.add(r);for(let r of this.pool.keys())r.startsWith(we)||r.startsWith(me)||t.add(r);let o=[...t].filter(r=>r!==e).sort();return e===null?o:[e,...o]}async noDefaultApp(e){let t=await this.availableIds(),o=t.length>0?t.join(", "):"(none deployed)";throw new P(e===""?`no "model" was given and this endpoint has no default model \u2014 name one of your org's deployed apps that declare serves="openai"; available models: ${o}`:`model "${e}" does not name a deployed app in your org that declares serves="openai", and this endpoint has no default model to fall back to; available models: ${o}`)}async sharedLane(e){if(!this.opts.shared)return null;let t=await this.sharedBlock();if(!t)return null;let o=D(t,e);if(o)return o;let r=e.lastIndexOf(":"),i=r>0?e.slice(0,r):e,s=r>0?e.slice(r+1):void 0,d=h(i),a=t.endpoints.filter(c=>h(c.model_id)===d&&(s===void 0||c.variant===s)),l=new Set(a.map(c=>c.model_id)),u=[...l][0];return u===void 0||l.size!==1?null:D(t,u,s)}async resolveTarget(e){let t=(e??"").trim(),o=this.opts.defaultApp;if(!t||t==="urun")return o===null?this.noDefaultApp(t):{appSlug:o};t=t.replace(/^urun\//i,"");let r=h(t);if(r===o)return{appSlug:o};let i=await this.sharedLane(t);if(i)return{appSlug:i.endpoint.app_slug,fnName:i.endpoint.function,sharedApp:!0,modelId:i.endpoint.model_id,variant:i.endpoint.variant,sharedOrgId:i.shared_org_id,gpuSpec:i.endpoint.gpu_spec??void 0,appId:i.endpoint.app_id??void 0};if(this.pool.has(r))return{appSlug:r};if(this.opts.listApps){let s=await this.deployedApps(),d=this.servable(s);if(d.includes(r))return{appSlug:r};let a=d.filter(u=>u.startsWith(`${r}-`));if(a.length===1)return{appSlug:a[0]};if(a.length>1)throw new P(`model "${t}" is ambiguous across deployed apps ${a.join(", ")} \u2014 name the exact app slug (or catalog id:variant)`);let l=s.find(u=>u.app_slug===r||u.app_slug.startsWith(`${r}-`));if(l)throw new P(`model "${t}" maps to app "${l.app_slug}", which has no function declaring serves="openai" \u2014 add serves="openai" to its @app.function or deploy it with \`urun serve ${t}\`; available models: ${(await this.availableIds()).join(", ")}`)}if(this.opts.listCatalog){let d=(await this.opts.listCatalog()).find(a=>t===a.model_id||t===`${a.model_id}:${a.variant}`||r===h(a.model_id)||r===h(`${a.model_id}-${a.variant}`));if(d)throw new P(`model "${t}" is in the uRun catalog but not deployed \u2014 deploy it with \`urun serve ${d.model_id}\`; available models: ${(await this.availableIds()).join(", ")}`)}return o===null?this.noDefaultApp(t):{appSlug:o}}async catalogIdentityFor(e){let t=G(await this.resolveTarget(e));return t.kind==="catalog"?{model_id:t.model_id,variant:t.variant}:null}async poolTuningFor(e){return He(await this.catalogRows(),e)}async servingAppSlugFor(e){return(await this.resolveTarget(e)).appSlug}async resolveApp(e){return q(await this.resolveTarget(e))}async sessionFor(e){let t=await this.resolveTarget(e);return this.acquire(t,q(t))}async resolveTargetFor(e){return this.resolveTarget(e)}async realtimeBillingIdentityFor(e){return G(await this.resolveTarget(e))}async speechSessionFor(e){let t=await this.resolveTarget(e);return this.acquire(t,me+q(t))}async dedicatedSessionFor(e){let t=await this.resolveTarget(e);return this.acquire(t,qe+Ke())}async evictHandle(e){let t=ge(e);if(!t)return;let o=this.pool.get(t.app);if(!o)return;let r=await o.then(i=>i,()=>null);r!==null&&await this.evict(t.app,r)}async acquire(e,t){let o=this.pool.get(t);return o||(o=Promise.resolve(this.opts.openSession(e,t)),this.pool.set(t,o),o.then(r=>this.snapshotMintId(r),()=>{}),o.catch(()=>this.pool.delete(t))),{app:t,entry:await o,identity:G(e)}}keyOf(e){let t=this.opts.sessionKey;if(!t)throw new Error("ModelRouter: sessionKey is not configured \u2014 the session-identity seam (handleFor/sessionForHandle) is unavailable on this router");let o=t(e);if(typeof o!="string"||o.length===0)throw new Error("ModelRouter: sessionKey returned an empty identity for a pooled session");return o}async handleFor(e){let{app:t,entry:o}=await this.sessionFor(e);return{app:t,handle:pe(t,this.keyOf(o))}}async speechHandleFor(e){let{app:t,entry:o}=await this.speechSessionFor(e);return{app:t,handle:pe(t,this.keyOf(o))}}async sessionForHandle(e){let t=ge(e);if(!t)throw new M(`malformed session handle ${JSON.stringify(e)} \u2014 not issued by this proxy`);let{app:o,key:r}=t,i=this.pool.get(o),s=i?await i.then(d=>d,()=>null):null;if(s===null)throw new M(`the session behind this handle (app "${o}") is gone \u2014 closed, evicted after its pod died, or the proxy restarted; it cannot be reattached. Reconnect without a handle to start a new session.`);if(this.keyOf(s)!==r&&this.mintedIds.get(s)!==r)throw new M(`the session behind this handle (app "${o}") was replaced \u2014 the original backhaul died and a new session serves this app now; the handle's session cannot be reattached. Reconnect without a handle to start a new session.`);return{app:o,entry:s}}async evict(e,t){let o=this.pool.get(e);!o||await o.then(i=>i,()=>null)!==t||this.pool.get(e)!==o||(this.pool.delete(e),await this.opts.closeSession(t).catch(()=>{}))}async modelList(){let e=this.opts.sharedOnlyListing?[]:await this.availableIds(),t=await this.sharedBlock(),[o,r]=await Promise.all([this.catalogRows().then(l=>({ok:!0,rows:l}),()=>({ok:!1,rows:[]})),this.pricesForListing(this.outputFreeKeys(t))]),i=o.rows,s=o.ok?r:I;o.ok||this.warn(`urun /v1/models: the model catalog could not be read \u2014 entries fall back to the bare OpenAI fields AND no model is priced on either lane (pricing follows catalog identity, so a half-priced listing would flicker on Hugging Face)
|
|
6
6
|
`);let a=(t?S(t):[]).map(l=>{let u=i.filter(Y=>Y.model_id===l.model_id&&Y.variant===l.variant),c=N(u),g=$(u),f=B(u),v=E(l.model_id,l.variant,s),m=z(u);return b({id:`${l.model_id}:${l.variant}`,object:"model",created:g,owned_by:"urun",...c!==null?{context_length:c}:{},...v!==null?{pricing:v}:{},...m.published.length>0?{voices:[...m.published]}:{},...f!==null?{capabilities:{reasoning:f}}:{}})});return{object:"list",data:this.opts.sharedOnlyListing?a:[...e.map(l=>L(l,i,s)),...a]}}async openRouterModels(){let e=await this.sharedBlock(),[t,o]=await Promise.all([this.catalogRows(),this.pricesForListing(this.outputFreeKeys(e))]);return le(e,t,o,r=>this.warn(r))}async supportsImages(e,t){let o=await this.resolveTarget(e),r=await this.catalogRows();if(o.sharedApp){let i=H(String(e),o.modelId,o.variant,r,this.opts.listCatalog!==null);return he(`${o.modelId}:${o.variant}`,i).includes(t)}return fe(W(o.appSlug,r)).includes(t)}async supportsAudio(e){let t=await this.resolveTarget(e),o=await this.catalogRows();return t.sharedApp?R(o.filter(r=>r.model_id===t.modelId&&r.variant===t.variant))!==null:R(A(t,o))!==null}async supportsSpeech(e){let t=await this.resolveTarget(e),o=await this.catalogRows();return t.sharedApp?R(o.filter(r=>r.model_id===t.modelId&&r.variant===t.variant))==="tts":R(A(t,o))==="tts"}async supportsTranscription(e){let t=await this.resolveTarget(e),o=await this.catalogRows();return t.sharedApp?R(o.filter(r=>r.model_id===t.modelId&&r.variant===t.variant))==="stt":R(A(t,o))==="stt"}async transcriptStreamFor(e){let t=await this.resolveTarget(e),o=await this.catalogRows(),r=t.sharedApp?o.filter(i=>i.model_id===t.modelId&&i.variant===t.variant):A(t,o);return Ye(r)}async speechVoices(e){let t=await this.resolveTarget(e),o=await this.catalogRows(),r=t.sharedApp?o.filter(i=>i.model_id===t.modelId&&i.variant===t.variant):A(t,o);return z(r)}async imageModelList(){let e=await this.catalogRows(),t=I,o=[];for(let i of await this.availableIds()){let s=fe(W(i,e));s.length!==0&&o.push(b({...L(i,e,t),image_modes:s}))}let r=await this.sharedBlock();if(r)for(let i of S(r)){let s=H(`${i.model_id}:${i.variant}`,i.model_id,i.variant,e,this.opts.listCatalog!==null),d=he(`${i.model_id}:${i.variant}`,s);if(d.length===0)continue;let a=b({id:`${i.model_id}:${i.variant}`,object:"model",created:$(s),owned_by:"urun",image_modes:d});o.push(a)}return{object:"list",data:o}}async speechToTextModelList(){let e=await this.catalogRows(),t=I,o=[];for(let i of await this.availableIds())R(_e(i,e))==="stt"&&o.push(L(i,e,t));let r=await this.sharedBlock();if(r)for(let i of S(r)){let s=H(`${i.model_id}:${i.variant}`,i.model_id,i.variant,e,this.opts.listCatalog!==null);if(R(s)!=="stt")continue;let d=b({id:`${i.model_id}:${i.variant}`,object:"model",created:$(s),owned_by:"urun"});o.push(d)}return{object:"list",data:o}}async closeAll(){let e=[...this.pool.values()],t=[];if(await Promise.all(e.map(async o=>{try{await this.opts.closeSession(await o)}catch(r){t.push(String(r instanceof Error?r.message:r))}})),t.length>0)throw new Error(`failed to close ${t.length} pooled session(s): ${t.join("; ")}`)}};export{p as a,Qe as b,Xe as c,rt as d,dt as e,T as f,pt as g,bt as h,P as i,M as j,St as k,Tt as l,pe as m,ge as n,$t as o,He as p,me as q,qe as r,q as s,G as t,ye as u};
|