@urun-sh/openai 0.6.6 → 0.6.8
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-ABV527TZ.js → chunk-3ES5EIDJ.js} +1 -1
- package/dist/{chunk-ZG2D2OAL.js → chunk-CSI2JEWL.js} +1 -1
- package/dist/chunk-VRCCLQ5P.js +1 -0
- package/dist/hosted/bin.cjs +19 -19
- package/dist/hosted/bin.js +1 -1
- package/dist/hosted/index.cjs +18 -18
- package/dist/hosted/index.js +1 -1
- package/dist/pi-extension/standalone.cjs +71 -74
- package/dist/proxy/cli.cjs +23 -23
- package/dist/proxy/cli.js +1 -1
- package/dist/proxy/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-X3GLH2HQ.js +0 -1
package/dist/proxy/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as q,b as Y}from"../chunk-
|
|
2
|
+
import{a as q,b as Y}from"../chunk-VRCCLQ5P.js";import"../chunk-K23AZPI4.js";import{A as M,Q as F,S as J,f as h,g as U,h as $,i as C,j as N,k as L,l as I,m as O,n as x,o as G,p as m,r as _,s as P,t as D,u as W,v as A,w as B,x as v,y as K,z as j}from"../chunk-CSI2JEWL.js";import"../chunk-76BZLCGT.js";import"../chunk-TMQJY56F.js";import"../chunk-3JWYIKHM.js";import{g as T}from"../chunk-6M5JK4YC.js";import"../chunk-7V2JKPIG.js";import{c as w}from"../chunk-YSFSRI3D.js";w();import{spawn as X}from"child_process";import{appendFileSync as k,createWriteStream as ue,existsSync as ce,mkdirSync as Z}from"fs";import ee from"path";import t from"process";w();import{ensureNodeWebRTC as se,nodeWebRTCUnavailableReason as ae}from"@urun-sh/core/internal";var le={ensureWebRTC:se,webrtcUnavailableReason:ae,audioBackend:T};async function H(e=le){try{await e.ensureWebRTC()}catch(r){return{ok:!1,reason:`the WebRTC bootstrap threw: ${String(r)}`}}let o=e.webrtcUnavailableReason();if(o)return{ok:!1,reason:`${o} \u2014 this artifact would join every session doc/KV-only and every token stream would error. Either "werift" is missing from the deployment directory (npm lane), or it was marked --external in a single-file build, where nothing can ever resolve it (bunfs: "Cannot find package 'werift' from '/$bunfs/root/\u2026'").`};try{(await e.audioBackend()).createSource()}catch(r){return{ok:!1,reason:`the werift/opus audio backend could not be constructed: ${String(r)}`}}return{ok:!0,reason:null}}function de(e,o){let r=(e.URUN_CATALOG_URL??"").trim(),u=r?_(r,"URUN_CATALOG_URL"):"",i=(e.URUN_CATALOG_ANON_KEY??"").trim();return!u||!i?(o(`urun compat: catalog oracle off (URUN_CATALOG_URL/URUN_CATALOG_ANON_KEY unset) \u2014 an undeployed uRun CATALOG model name falls through to the default app instead of a loud 404; deployed apps still resolve exactly, and /stats.models records every mapping
|
|
3
3
|
`),null):{catalogUrl:u,anonKey:i}}function pe(e){return q({baseUrl:e.baseUrl,orgId:e.orgId,defaultApp:e.appId,fnName:e.fnName,apiUrl:e.apiUrl,auth:e.auth,catalog:de(t.env,o=>t.stderr.write(o)),statelessDirect:te(e)})}function te(e){return e.decisionSecret!==""&&e.auth.lane==="api-key"}function fe(e,o){if(te(e))return t.stderr.write(`urun compat: stateless direct path ENABLED (POST /v1/decision answered by the serving pods)
|
|
4
4
|
`),new F({targetFor:r=>o.targetFor(r),apiUrl:e.apiUrl,fnName:e.fnName,apiKey:e.auth.apiKey,orgId:e.orgId,secret:e.decisionSecret})}async function V(e,o,r){let u=X(e,o,{stdio:"inherit",env:r});return new Promise(i=>{u.once("exit",s=>i(s??1)),u.once("error",s=>{t.stderr.write(`failed to launch ${e}: ${String(s)}
|
|
5
5
|
`),i(127)})})}function z(){return I(t.env,import.meta.url,ce)}function re(e){for(let[o,r]of Object.entries(U(e)))t.stdout.write(`export ${o}=${r}
|
package/dist/proxy/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{B as l,C as a,D as x,E as s,F as O,G as f,S as I,a as n,b as p,c as m}from"../chunk-
|
|
1
|
+
import{B as l,C as a,D as x,E as s,F as O,G as f,S as I,a as n,b as p,c as m}from"../chunk-CSI2JEWL.js";import{d as r,e as i}from"../chunk-TMQJY56F.js";import{a as o,h as t}from"../chunk-3JWYIKHM.js";import"../chunk-6M5JK4YC.js";import{c as e}from"../chunk-YSFSRI3D.js";e();export{o as GEMINI_LIVE_PATH,a as OPENAI_REALTIME_PATH,l as OpenAIRealtimeConnection,n as ResumptionRegistry,i as SessionGoneError,r as UnknownModelError,t as VIDEO_OUT_SETUP_KEY,p as attachGeminiLive,x as attachOpenAIRealtime,I as createOpenAIProxy,f as fixedClientsResolver,O as realtimeBindingFor,s as realtimeModelOf,m as serveGeminiLiveSocket};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@urun-sh/openai",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"description": "OpenAI-compatible Realtime + Responses SDK over uRun session primitives (not websockets).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"build:bin": "bun build --compile --external @roamhq/wrtc src/proxy/bin.ts --outfile dist/bin/urun-openai && node scripts/assert-bin-transport.mjs"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
|
-
"@urun-sh/core": "^0.6.
|
|
73
|
+
"@urun-sh/core": "^0.6.8"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@prometheus-io/client": "^0.16.1",
|
package/dist/chunk-X3GLH2HQ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as T}from"./chunk-K23AZPI4.js";import{a as I}from"./chunk-76BZLCGT.js";import{a as D,b as M,e as A,f as U,g as _,h as $,j}from"./chunk-TMQJY56F.js";import{c as C,f as x,g as F,p as G}from"./chunk-6M5JK4YC.js";import{c as y}from"./chunk-YSFSRI3D.js";y();import{App as B,createClientToken as ee}from"@urun-sh/core";y();import{SessionFailedError as J}from"@urun-sh/core";var P=2;function Q(e){let t=e?.type;return t==="response.created"||t==="response.in_progress"}function X(e){let t=e?.type;return t==="response.completed"||t==="error"}function W(e){return async function(i,p){return(async function*(){for(let d=1;d<=P;d++){let{app:c,entry:l,identity:r}=await e.sessionFor(i.model);p?.({sessionId:e.sessionIdOf?.(l)??null,identity:r});let w=!1,a=!1;try{let f=await e.createStream(l,i);for await(let g of f){if(X(g)&&(w=!0),Q(g)){if(d>1)continue}else a=!0;yield g}}catch(f){if(f instanceof J&&(f.kind==="never-live"||f.kind==="create-failed")){try{e.onAdmissionVerdict?.(c,l,f)}catch{}throw f}if(d<P&&!a){await e.evict(c,l);continue}throw f}if(w)return;if(d<P&&!a){await e.evict(c,l);continue}return}})()}}y();var Y=3,z="llm",Z=new Set(["paused","error"]);function N(e,t){let i=e.doc(z),p=typeof i.onConnectionState=="function",u=typeof e.onPhase=="function";if(!p&&!u)throw new Error(`session for app "${t}" exposes neither a doc connection-state surface nor onPhase \u2014 session-gone detection requires @urun-sh/core Session (SessionDocument.onConnectionState / Session.onPhase); pooling a session with no native lifecycle signal would silently swallow requests dispatched after the platform closes it`);let d=null,c=!1,l=new Set,r=[],w=a=>{if(!d){d=a;for(let f of[...l])f(a);l.clear()}};return p&&r.push(i.onConnectionState(a=>{c&&(a.consecutiveFailures<Y||w(new A(`the pooled session for app "${t}" is gone: its doc backhaul failed ${a.consecutiveFailures} consecutive times (last close ${a.lastCloseCode===null?"by provider liveness reap":`code ${a.lastCloseCode}`}${a.lastCloseReason?`, reason ${JSON.stringify(a.lastCloseReason)}`:""}) \u2014 the platform closed the session (idle timeout or a serve-side crash). The entry is evicted; retry to get a fresh session.`)))})),u&&r.push(e.onPhase(a=>{if(a.name==="live"){c=!0;return}c&&Z.has(a.name)&&w(new A(`the pooled session for app "${t}" lost its compute binding (phase "${a.name}"). The entry is evicted; retry to get a fresh session. The named session itself is not over \u2014 it stays attachable by name.`))})),{gone:()=>d,onGone(a){return d?(a(d),()=>{}):(l.add(a),()=>l.delete(a))},dispose(){l.clear();for(let a of r.splice(0))a()}}}async function*O(e,t){let i=t.gone();if(i)throw i;let p=e[Symbol.asyncIterator](),u,d=new Promise((c,l)=>{u=t.onGone(r=>l(r))});d.catch(()=>{});try{for(;;){let c=await Promise.race([p.next(),d]);if(c.done)return;yield c.value}}finally{u?.(),p.return?.(void 0)}}function q(e,t,i,p){let u=e[i];if(typeof u!="function")throw new Error(`app "${t}" has no function "${i}" (set URUN_FUNCTION)`);let d=p?u(void 0,p):u();if(typeof d.end!="function")throw new Error(`app "${t}" function "${i}" returned a session without end()`);return d}function ne(e,t,i){let{baseUrl:p,orgId:u,auth:d}=e,c=typeof e.subject=="function"?e.subject():e.subject,l=i.startsWith(_)&&c!==void 0?`${c}:speech`:c,r=t.fnName??e.fnName,w=e.sessionStartOptions?.(i),a=t.sharedApp?{sharedApp:!0,...w}:w,f=o=>({session:o,responses:new I(o),gone:N(o,i)});if(d.lane==="jwt"){let o=B(t.appSlug,{baseUrl:p,orgId:u,jwt:d.jwt});return f(q(o,t.appSlug,r,a))}let{apiKey:g,gatewayUrl:n}=d,s=B(t.appSlug,{baseUrl:p,orgId:u,getAccessToken:async()=>(await ee(g,{baseUrl:n,expiresIn:300,allowedFunctions:[`${t.appSlug}/${r}`],...l===void 0?{}:{subject:l},...t.sharedApp?{sharedApp:!0}:{}})).token});return f(q(s,t.appSlug,r,a))}function oe(e){let t=e.session.id;if(typeof t!="string"||t.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 t}function se(e){if(e.kind==="never-live")return!0;if(e.kind!=="create-failed")return!1;let t=e.status.error?.httpStatus,i=e.status.error?.code;return t===410||t===409&&(i==="cancelled"||i==="expired")?!0:i==="client_ended"}var te=new Set(["error","paused"]);function Ae(e){let{auth:t,catalog:i}=e,p=null,u=(c,l)=>{let r=ne(e,c,l);return e.onSessionOpen&&typeof r.session.id=="string"&&r.session.id!==""&&e.onSessionOpen(l,r.session.id),r.gone.onGone(()=>{p?.evict(l,r)}),r},d=new j({sharedOnlyListing:e.sharedOnlyListing===!0,defaultApp:e.defaultApp,fnName:e.fnName,openSession:u,closeSession:async c=>{if(c.gone.dispose(),e.release==="detach"){if(typeof c.session.detach!="function")throw new Error('pooled session exposes no native detach() \u2014 the release:"detach" lane requires @urun-sh/core Session.detach');c.session.detach();return}await c.session.end()},listApps:t.lane==="api-key"?()=>U({apiUrl:e.apiUrl,apiKey:t.apiKey}):null,listCatalog:i?()=>T(i):null,listPrices:i?()=>M(i):null,shared:t.lane==="api-key"?()=>D({apiUrl:e.apiUrl,apiKey:t.apiKey}):null,sessionKey:oe});return p=d,e.defaultApp!==null&&e.statelessDirect!==!0&&d.seed(e.defaultApp,u({appSlug:e.defaultApp},$({appSlug:e.defaultApp}))),d}async function E(e,t){let i=e.whenLive;if(typeof i!="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 i.call(e,t===void 0?void 0:{signal:t})}async function K(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()}function k(e){return e.reason instanceof Error?e.reason:new Error("the client socket closed")}function Pe(e,t=F,i,p){let u=new WeakMap,d=new WeakMap,c=new WeakMap,l=new WeakMap,r=new WeakMap,w=n=>{let s=n.session.id;return typeof s=="string"&&s.length>0?s:null},a=n=>{let s=u.get(n);if(!s){let o={waiting:0,gone:new AbortController};r.set(n,o),s=(async()=>{if(await E(n.session,o.gone.signal),o.gone.signal.aborted)throw k(o.gone.signal);r.get(n)===o&&r.delete(n);let h=await C(n.session,await t());return Object.assign(h,{sessionId:n.session.id})})(),u.set(n,s),s.catch(()=>{u.get(n)===s&&u.delete(n)}),s.then(()=>{r.get(n)===o&&r.delete(n)},()=>{r.get(n)===o&&r.delete(n)})}return s},f=n=>{let s=l.get(n);return s||(s=(async()=>{let o=await a(n);return{appendInputAudio:h=>o.appendInputAudio(h),onOutputAudio:h=>o.onOutputAudio(h),sessionId:w(n)}})(),l.set(n,s),s.catch(()=>{l.get(n)===s&&l.delete(n)})),s},g=async(n,s,o)=>{if(o?.aborted){let S=r.get(n);throw(u.get(n)===void 0||S!==void 0&&S.waiting===0)&&await K(n.session),k(o)}let h=s(n),m=r.get(n);return m!==void 0&&m.waiting++,o===void 0?h:new Promise((S,v)=>{let R=()=>{m!==void 0&&--m.waiting===0&&r.get(n)===m&&(m.gone.abort(),r.delete(n),u.delete(n),l.delete(n),K(n.session).catch(()=>{})),v(k(o))};o.addEventListener("abort",R,{once:!0});let L=()=>o.removeEventListener("abort",R);h.then(b=>{L(),S(b)},b=>{L(),v(b)})})};return{createResponse:W({sessionFor:n=>e.sessionFor(n),sessionIdOf:n=>w(n),evict:(n,s)=>e.evict(n,s),onAdmissionVerdict:(n,s,o)=>{se(o)&&(e.evict(n,s),i?.(n,o.kind==="never-live"?"never-live":"create-failed"))},createStream:async(n,s)=>(await E(n.session),O(await n.responses.responses.create(s),n.gone))}),listModels:()=>e.modelList(),openRouterModels:()=>e.openRouterModels(),supportsImages:(n,s)=>e.supportsImages(n,s),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),listSpeechToTextModels:()=>e.speechToTextModelList(),openAudio:async(n,s)=>{let{entry:o}=await e.sessionFor(n);return await g(o,a,s)},openAudioOn:async(n,s)=>{let{entry:o}=await e.sessionForHandle(n);return await g(o,f,s)},openVideo:async n=>{let{entry:s}=await e.sessionFor(n),o=d.get(s);return o||(o=x(s.session),d.set(s,o)),o},openVideoOut:async n=>{let{entry:s}=await e.sessionFor(n),o=c.get(s);return o||(o=G(s.session),c.set(s,o)),o},sessionHandle:async n=>(await e.handleFor(n)).handle,speechSessionHandle:async n=>(await e.speechHandleFor(n)).handle,evictSpeechSession:async n=>{let{app:s,entry:o}=await e.sessionForHandle(n);await e.evict(s,o)},createResponseOn:async(n,s)=>{let{entry:o}=await e.sessionForHandle(n);return await E(o.session),O(await o.responses.responses.create(s),o.gone)},onSessionEnd:async(n,s)=>{let{entry:o}=await e.sessionForHandle(n),h=o.session;if(typeof h.onPhase!="function")throw new Error("pooled session exposes no onPhase \u2014 session-end (goAway) wiring requires @urun-sh/core Session");let m=!1;return h.onPhase(S=>{if(m||!te.has(S.name))return;m=!0;let v=h.endsAt??null;s({timeLeftMs:v?Math.max(0,v.getTime()-Date.now()):null,reason:S.reason??`session ${S.name}`})})},...p?{stateless:p}:{}}}export{Ae as a,Pe as b};
|