@urun-sh/openai 0.6.1 → 0.6.2
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-T2LNHDPS.js → chunk-CT2GQG5R.js} +1 -1
- package/dist/{chunk-WEBOBE7Z.js → chunk-URMOBMSP.js} +1 -1
- package/dist/hosted/bin.js +1 -1
- package/dist/hosted/index.js +1 -1
- package/dist/pi-extension/standalone.cjs +10 -10
- package/dist/proxy/cli.cjs +1 -1
- package/dist/proxy/cli.js +1 -1
- package/dist/proxy/index.js +1 -1
- package/package.json +2 -2
package/dist/proxy/cli.cjs
CHANGED
|
@@ -14,7 +14,7 @@ Connection: close\r
|
|
|
14
14
|
Content-Type: text/plain; charset=utf-8\r
|
|
15
15
|
Content-Length: ${Buffer.byteLength(o)}\r
|
|
16
16
|
\r
|
|
17
|
-
${o}`)}function xo(t,e){let n=new ke.WebSocketServer({noServer:!0,maxPayload:ga}),r=new Oe,o=new Set,s=new Set,i=new Set,a=typeof e.clients=="function"?e.clients:()=>e.clients,u=!1,d=(l,p,m)=>{let c;try{c=new URL(l.url??"/","http://localhost")}catch{Pt(p,400,"malformed upgrade URL");return}if(p.on("error",()=>p.destroy()),p.on("close",()=>i.delete(p)),c.pathname!==ma){i.add(p);return}s.add(p);let f=!1;(async()=>{if(e.apiKey&&(l.headers.authorization??"")!==`Bearer ${e.apiKey}`){Pt(p,401,"invalid local proxy api key");return}let g;try{g=await a(l)}catch(_){let y=e.statusOf?.(_)??null;Pt(p,y?.status??500,"upstream resolver rejected the connection");return}u||p.destroyed||(f=!0,n.handleUpgrade(l,p,m,_=>{s.delete(p),o.add(_),_.on("close",()=>o.delete(_));try{new xn(_,g,r,e.statusOf)}catch{o.delete(_),_.close(1011,"responses websocket setup failed")}}))})().catch(()=>{!f&&!p.destroyed&&Pt(p,500,"responses websocket upgrade failed")}).finally(()=>s.delete(p))};return t.on("upgrade",d),{stats:r,close:()=>{let{promise:l,resolve:p}=Rn();if(u)return p(),l;u=!0,t.off("upgrade",d);for(let c of s)c.destroy();s.clear();for(let c of i)c.destroy();i.clear();for(let c of o)c.close(1001,"server shutting down");let m=setTimeout(()=>{for(let c of o)c.readyState!==ke.WebSocket.CLOSED&&c.terminate()},2e3);return m.unref?.(),n.close(()=>{clearTimeout(m),p()}),l}}}var Qo=require("@urun-sh/core");var Ro=require("@urun-sh/core"),ba={no_capacity:429,queue_timeout:429,cold_start_exceeded:429,queue_full:429,admission_busy:503,admission_unavailable:503,backend_error:502},ka={no_capacity:"no ready GPU capacity for this model right now \u2014 the platform will cold-wake it on request; retry",queue_timeout:"the session was admitted but never became live within the cold-wake fence \u2014 the backend is busy or wedged; retry",cold_start_exceeded:"the cold boot exceeded its budget without serving \u2014 the platform keeps pursuing the wake; retry with a longer client timeout",queue_full:"the admission queue for this model is full \u2014 retry after the Retry-After period",admission_busy:"admission is momentarily contended (lock convoy) \u2014 retry shortly",admission_unavailable:"session admission is temporarily unavailable \u2014 retry",backend_error:"the control plane failed while admitting the session"};function En(t,e){let n=ka[t.code];return e?`${n} (${e})`:n}function Ct(t){if(t==null)return null;let e=ba[t];return e===void 0?null:{status:e,code:t,retryable:e!==502,openaiType:e===429?"capacity_error":"upstream_error",anthropicType:e===429?"rate_limit_error":e===503?"overloaded_error":"api_error"}}function $t(t){if(t.kind==="create-failed")return Ct(t.status.error?.code??null);if(t.kind!=="never-live")return null;let e=(t.status.elapsedMs??0)>=Ro.COLD_BOOT_WHEN_LIVE_TIMEOUT_MS;return Ct(e?"cold_start_exceeded":"queue_timeout")}var Ao=xe(require("os"),1),Oo=xe(require("path"),1),Io=require("url"),To=require("util");var Eo="0.6.
|
|
17
|
+
${o}`)}function xo(t,e){let n=new ke.WebSocketServer({noServer:!0,maxPayload:ga}),r=new Oe,o=new Set,s=new Set,i=new Set,a=typeof e.clients=="function"?e.clients:()=>e.clients,u=!1,d=(l,p,m)=>{let c;try{c=new URL(l.url??"/","http://localhost")}catch{Pt(p,400,"malformed upgrade URL");return}if(p.on("error",()=>p.destroy()),p.on("close",()=>i.delete(p)),c.pathname!==ma){i.add(p);return}s.add(p);let f=!1;(async()=>{if(e.apiKey&&(l.headers.authorization??"")!==`Bearer ${e.apiKey}`){Pt(p,401,"invalid local proxy api key");return}let g;try{g=await a(l)}catch(_){let y=e.statusOf?.(_)??null;Pt(p,y?.status??500,"upstream resolver rejected the connection");return}u||p.destroyed||(f=!0,n.handleUpgrade(l,p,m,_=>{s.delete(p),o.add(_),_.on("close",()=>o.delete(_));try{new xn(_,g,r,e.statusOf)}catch{o.delete(_),_.close(1011,"responses websocket setup failed")}}))})().catch(()=>{!f&&!p.destroyed&&Pt(p,500,"responses websocket upgrade failed")}).finally(()=>s.delete(p))};return t.on("upgrade",d),{stats:r,close:()=>{let{promise:l,resolve:p}=Rn();if(u)return p(),l;u=!0,t.off("upgrade",d);for(let c of s)c.destroy();s.clear();for(let c of i)c.destroy();i.clear();for(let c of o)c.close(1001,"server shutting down");let m=setTimeout(()=>{for(let c of o)c.readyState!==ke.WebSocket.CLOSED&&c.terminate()},2e3);return m.unref?.(),n.close(()=>{clearTimeout(m),p()}),l}}}var Qo=require("@urun-sh/core");var Ro=require("@urun-sh/core"),ba={no_capacity:429,queue_timeout:429,cold_start_exceeded:429,queue_full:429,admission_busy:503,admission_unavailable:503,backend_error:502},ka={no_capacity:"no ready GPU capacity for this model right now \u2014 the platform will cold-wake it on request; retry",queue_timeout:"the session was admitted but never became live within the cold-wake fence \u2014 the backend is busy or wedged; retry",cold_start_exceeded:"the cold boot exceeded its budget without serving \u2014 the platform keeps pursuing the wake; retry with a longer client timeout",queue_full:"the admission queue for this model is full \u2014 retry after the Retry-After period",admission_busy:"admission is momentarily contended (lock convoy) \u2014 retry shortly",admission_unavailable:"session admission is temporarily unavailable \u2014 retry",backend_error:"the control plane failed while admitting the session"};function En(t,e){let n=ka[t.code];return e?`${n} (${e})`:n}function Ct(t){if(t==null)return null;let e=ba[t];return e===void 0?null:{status:e,code:t,retryable:e!==502,openaiType:e===429?"capacity_error":"upstream_error",anthropicType:e===429?"rate_limit_error":e===503?"overloaded_error":"api_error"}}function $t(t){if(t.kind==="create-failed")return Ct(t.status.error?.code??null);if(t.kind!=="never-live")return null;let e=(t.status.elapsedMs??0)>=Ro.COLD_BOOT_WHEN_LIVE_TIMEOUT_MS;return Ct(e?"cold_start_exceeded":"queue_timeout")}var Ao=xe(require("os"),1),Oo=xe(require("path"),1),Io=require("url"),To=require("util");var Eo="0.6.2";var Po=4141,xa=Eo,Mt={claude:{bin:"claude",env:"anthropic"},codex:{bin:"codex",env:"openai"},pi:{bin:"pi",env:"openai"},omp:{bin:"omp",env:"openai"},aider:{bin:"aider",env:"openai"},opencode:{bin:"opencode",env:"openai"},crush:{bin:"crush",env:"openai"}};function In(t,e="openai"){if(e==="anthropic")return{ANTHROPIC_BASE_URL:`http://127.0.0.1:${t}`,ANTHROPIC_API_KEY:"urun-local"};let n=`http://127.0.0.1:${t}/v1`;return{OPENAI_BASE_URL:n,OPENAI_API_BASE:n,OPENAI_API_KEY:"urun-local"}}function Co(t,e,n){let r={...t,...In(e,n)};return delete r.URUN_API_KEY,delete r.URUN_JWT,delete r.URUN_SESSION_TOKEN_SECRET,r}function $o(t,e,n){let r=["-c","model_providers.urun.name=urun","-c",`model_providers.urun.base_url="http://127.0.0.1:${t}/v1"`,"-c",'model_providers.urun.wire_api="responses"',"-c",'model_provider="urun"'],o=n.indexOf("--"),s=o===-1?n:n.slice(0,o),i=s.some(l=>l==="-m"||l==="--model"||l.startsWith("--model=")),a=n[0]==="exec",u=s.includes("--skip-git-repo-check"),d=a&&!u?["exec","--skip-git-repo-check",...n.slice(1)]:n;return[...r,...i?[]:["-m",e],...d]}function Lo(t,e){return e.some(r=>r==="--model"||r==="--provider"||r.startsWith("--model=")||r.startsWith("--provider="))?e:["--provider","urun","--model",t,...e]}function Mo(t,e){return e.some(r=>r==="--model"||r==="--provider"||r.startsWith("--model=")||r.startsWith("--provider="))?e:["--model",`urun/${t}`,...e]}function Uo(t,e,n){let r=(t.URUN_PI_EXTENSION_ENTRY??"").trim();if(r){if(!n(r))throw new Error(`URUN_PI_EXTENSION_ENTRY points at ${r}, which does not exist \u2014 the launcher that injected it (the vendored urun CLI shim) must materialize the pi extension bundle before spawning pi`);return r}let o=(0,Io.fileURLToPath)(new URL("../pi-extension/standalone.cjs",e));if(!n(o))throw new Error(`pi extension entry not found at ${o} \u2014 the pi lane loads the self-contained @urun-sh/openai dist/pi-extension/standalone.cjs from the installed package (run \`urun compat pi\` via the npm-installed CLI, e.g. \`npx @urun-sh/openai\`), or pass an entry to pi yourself: \`pi -e <path-to-@urun-sh/openai>/dist/pi-extension/standalone.cjs\``);return o}function No(t){let e=Number(t);if(!Number.isInteger(e)||e<0)throw new Error(`--port needs a non-negative integer (0 = OS-assigned ephemeral), got ${t}`);return e}function Do(t){if(t[0]!=="--port")return null;let e=No(t[1]);return t.splice(0,2),e}function Tn(t){let e=t.indexOf("--port");if(e===-1)return Po;let n=No(t[e+1]);return t.splice(e,2),n}function Bo(t){if(t===0)throw new Error("`env` cannot use --port 0: it starts no proxy, so the OS never assigns the ephemeral port \u2014 pass the actual port of the running proxy");return t}function An(t,e){let n=(t[e]??"").trim();if(!n)throw new Error(`${e} is not set. The proxy needs URUN_BASE_URL, URUN_ORG_ID, URUN_APP and either URUN_API_KEY (the org key; the proxy vends short-lived function-scoped client tokens from it via the SDK) or URUN_JWT (an explicit pre-vended token override) \u2014 plus optional URUN_FUNCTION, default "serve" \u2014 to open the backhaul session.`);return n}function Fe(t){let e=Ra(An(t,"URUN_BASE_URL")),n=An(t,"URUN_ORG_ID"),r=An(t,"URUN_APP"),o=(t.URUN_FUNCTION??"serve").trim()||"serve",s=(t.URUN_API_URL??"").trim(),i=s?Lt(s,"URUN_API_URL"):Nr,a=(t.URUN_SESSION_TOKEN_SECRET??"").trim(),u=(t.URUN_JWT??"").trim();if(u)return{baseUrl:e,orgId:n,appId:r,fnName:o,apiUrl:i,decisionSecret:a,auth:{lane:"jwt",jwt:u}};let d=(t.URUN_API_KEY??"").trim();if(d){let l=(t.URUN_GATEWAY_URL??"").trim(),p=l?Lt(l):void 0;return{baseUrl:e,orgId:n,appId:r,fnName:o,apiUrl:i,decisionSecret:a,auth:{lane:"api-key",apiKey:d,gatewayUrl:p}}}throw new Error("neither URUN_API_KEY nor URUN_JWT is set. Set URUN_API_KEY (the org API key \u2014 the proxy vends short-lived, function-scoped client tokens from it via the SDK, so the key never reaches the agent process) or URUN_JWT (an explicit pre-vended token; when set it always wins). URUN_BASE_URL, URUN_ORG_ID and URUN_APP are also required.")}function Ra(t,e="URUN_BASE_URL"){if(/\/v1\/*$/.test(new URL(t).pathname))throw new Error(`${e} must be the session-gateway base (e.g. https://api.urun.sh), got ${t} \u2014 a trailing /v1 is the org control-plane API form (that belongs in URUN_API_URL); session allocation 404s against it. Drop the /v1.`);return t}function Lt(t,e="URUN_GATEWAY_URL"){let n=new URL(t),r=n.hostname==="localhost"||n.hostname==="127.0.0.1"||n.hostname==="[::1]";if(n.protocol!=="https:"&&!r)throw new Error(`${e} must be https (got ${t}) \u2014 the org API key rides the request's Authorization header`);return t}function Pn(t){return{app:t.appId,org:t.orgId,fn:t.fnName,base_url:t.baseUrl,proxy_version:xa}}function Ea(t,e){return t.app===e.app&&t.org===e.org&&t.fn===e.fn&&t.base_url===e.base_url&&t.proxy_version===e.proxy_version}var Aa=250;async function Cn(t,e=Aa){try{let n=await fetch(`http://127.0.0.1:${t}/stats`,{signal:AbortSignal.timeout(e)});if(!n.ok)return null;let r=(await n.json()).identity;if(r==null||typeof r!="object")return null;let{app:o,org:s,fn:i,base_url:a,proxy_version:u}=r;return typeof o!="string"||typeof s!="string"||typeof i!="string"||typeof a!="string"||typeof u!="string"?null:{app:o,org:s,fn:i,base_url:a,proxy_version:u}}catch{return null}}var Fo=2e3;async function Oa(t,e=Fo){try{let n=await fetch(`http://127.0.0.1:${t}/v1/models`,{signal:AbortSignal.timeout(e)});return n.ok?null:`GET /v1/models answered HTTP ${n.status}`}catch(n){return`GET /v1/models failed (${String(n instanceof Error?n.message:n)})`}}async function jo(t,e,n=Po,r=Fo){if(t!=null)return{mode:"spawn",port:t};let o=await Cn(n);if(o!==null&&Ea(o,e)){let s=await Oa(n,r);return s===null?{mode:"reuse",port:n,identity:o}:{mode:"spawn",port:0,reason:`a urun-openai proxy on port ${n} matches this invocation's identity but failed the serving-surface liveness check (${s}) \u2014 starting a fresh proxy on an ephemeral port instead of pointing the harness at it`}}return{mode:"spawn",port:0}}function $n(t,e=Ao.default.homedir()){return Oo.default.join(e,".urun","logs",`compat-proxy-${t}.log`)}var On=["log","info","warn","error","debug","trace"];function qo(t,e=process,n=console){let r=e.stdout.write,o=e.stderr.write,s=(a,...u)=>t.write(a,...u);e.stdout.write=s,e.stderr.write=s;let i=Object.fromEntries(On.map(a=>[a,n[a]]));for(let a of On)n[a]=(...u)=>{t.write(`${(0,To.format)(...u)}
|
|
18
18
|
`)};return()=>{e.stdout.write=r,e.stderr.write=o;for(let a of On)n[a]=i[a]}}var Ia=new Set(["EPIPE","EIO","EBADF","ENXIO"]);function Go(t){let e=t?.code;return typeof e=="string"&&Ia.has(e)}function ie(t,e){try{return t.write(e),!0}catch(n){if(Go(n))return!1;throw n}}function Ho(t){let e={stdout:!1,stderr:!1},n=[];for(let r of["stdout","stderr"]){let o=t.streams[r],s=i=>{Go(i)&&(e[r]=!0);let a=i?.code;try{t.note(`${new Date().toISOString()} urun compat: process.${r} died (${String(a??(i instanceof Error?i.message:i))}) \u2014 the terminal is gone; launcher output continues in this log only
|
|
19
19
|
`)}catch{}};o.on("error",s),n.push([o,s])}return{isDead:r=>e[r],uninstall:()=>{for(let[r,o]of n)r.off("error",o)}}}function Vo(t){let e=n=>{let r=n instanceof Error?`${n.stack??`${n.name}: ${n.message}`}`:String(n);try{t.appendSync(t.logPath,`${new Date().toISOString()} launcher crashed (in-process proxy): ${r}
|
|
20
20
|
`)}catch{}t.restore();try{t.writeStderr(`urun compat: the in-process proxy crashed (${n instanceof Error?n.message:String(n)}) \u2014 terminating the harness (its backend is gone); details: ${t.logPath}
|
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-X3GLH2HQ.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-
|
|
2
|
+
import{a as q,b as Y}from"../chunk-X3GLH2HQ.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-URMOBMSP.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-URMOBMSP.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.2",
|
|
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.2"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@prometheus-io/client": "^0.16.1",
|