@urun-sh/openai 0.6.20 → 0.6.21
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-TF2IMK3T.js → chunk-5SBYFTBD.js} +1 -1
- package/dist/{chunk-64WZRHYB.js → chunk-CL3LVMNL.js} +1 -1
- package/dist/hosted/bin.js +1 -1
- package/dist/hosted/index.js +1 -1
- package/dist/pi-extension/standalone.cjs +39 -39
- package/dist/proxy/cli.cjs +1 -1
- package/dist/proxy/cli.js +1 -1
- package/dist/proxy/index.js +1 -1
- package/package.json +1 -1
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 Co(t,e){let n=new ke.WebSocketServer({noServer:!0,maxPayload:$a}),r=new Ie,o=new Set,s=new Set,i=new Set,a=typeof e.clients=="function"?e.clients:()=>e.clients,d=!1,u=(l,c,f)=>{let p;try{p=new URL(l.url??"/","http://localhost")}catch{Mt(c,400,"malformed upgrade URL");return}if(c.on("error",()=>c.destroy()),c.on("close",()=>i.delete(c)),p.pathname!==Ca){i.add(c);return}s.add(c);let m=!1;(async()=>{if(e.apiKey&&(l.headers.authorization??"")!==`Bearer ${e.apiKey}`){Mt(c,401,"invalid local proxy api key");return}let k;try{k=await a(l)}catch(v){let y=e.statusOf?.(v)??null;Mt(c,y?.status??500,"upstream resolver rejected the connection");return}d||c.destroyed||(m=!0,n.handleUpgrade(l,c,f,v=>{s.delete(c),o.add(v),v.on("close",()=>o.delete(v));try{new En(v,k,r,e.statusOf)}catch{o.delete(v),v.close(1011,"responses websocket setup failed")}}))})().catch(()=>{!m&&!c.destroyed&&Mt(c,500,"responses websocket upgrade failed")}).finally(()=>s.delete(c))};return t.on("upgrade",u),{stats:r,close:()=>{let{promise:l,resolve:c}=An();if(d)return c(),l;d=!0,t.off("upgrade",u);for(let p of s)p.destroy();s.clear();for(let p of i)p.destroy();i.clear();for(let p of o)p.close(1001,"server shutting down");let f=setTimeout(()=>{for(let p of o)p.readyState!==ke.WebSocket.CLOSED&&p.terminate()},2e3);return f.unref?.(),n.close(()=>{clearTimeout(f),c()}),l}}}var is=require("@urun-sh/core");var $o=require("@urun-sh/core"),Fa={no_capacity:429,queue_timeout:429,cold_start_exceeded:429,queue_full:429,admission_busy:503,admission_unavailable:503,backend_error:502},Ba={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 On(t,e){let n=Ba[t.code];return e?`${n} (${e})`:n}function Ut(t){if(t==null)return null;let e=Fa[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 Nt(t){if(t.kind==="create-failed")return Ut(t.status.error?.code??null);if(t.kind!=="never-live")return null;let e=(t.status.elapsedMs??0)>=$o.COLD_BOOT_WHEN_LIVE_TIMEOUT_MS;return Ut(e?"cold_start_exceeded":"queue_timeout")}var Mo=Ne(require("os"),1),Uo=Ne(require("path"),1),No=require("url"),Do=require("util");var Lo="0.6.
|
|
17
|
+
${o}`)}function Co(t,e){let n=new ke.WebSocketServer({noServer:!0,maxPayload:$a}),r=new Ie,o=new Set,s=new Set,i=new Set,a=typeof e.clients=="function"?e.clients:()=>e.clients,d=!1,u=(l,c,f)=>{let p;try{p=new URL(l.url??"/","http://localhost")}catch{Mt(c,400,"malformed upgrade URL");return}if(c.on("error",()=>c.destroy()),c.on("close",()=>i.delete(c)),p.pathname!==Ca){i.add(c);return}s.add(c);let m=!1;(async()=>{if(e.apiKey&&(l.headers.authorization??"")!==`Bearer ${e.apiKey}`){Mt(c,401,"invalid local proxy api key");return}let k;try{k=await a(l)}catch(v){let y=e.statusOf?.(v)??null;Mt(c,y?.status??500,"upstream resolver rejected the connection");return}d||c.destroyed||(m=!0,n.handleUpgrade(l,c,f,v=>{s.delete(c),o.add(v),v.on("close",()=>o.delete(v));try{new En(v,k,r,e.statusOf)}catch{o.delete(v),v.close(1011,"responses websocket setup failed")}}))})().catch(()=>{!m&&!c.destroyed&&Mt(c,500,"responses websocket upgrade failed")}).finally(()=>s.delete(c))};return t.on("upgrade",u),{stats:r,close:()=>{let{promise:l,resolve:c}=An();if(d)return c(),l;d=!0,t.off("upgrade",u);for(let p of s)p.destroy();s.clear();for(let p of i)p.destroy();i.clear();for(let p of o)p.close(1001,"server shutting down");let f=setTimeout(()=>{for(let p of o)p.readyState!==ke.WebSocket.CLOSED&&p.terminate()},2e3);return f.unref?.(),n.close(()=>{clearTimeout(f),c()}),l}}}var is=require("@urun-sh/core");var $o=require("@urun-sh/core"),Fa={no_capacity:429,queue_timeout:429,cold_start_exceeded:429,queue_full:429,admission_busy:503,admission_unavailable:503,backend_error:502},Ba={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 On(t,e){let n=Ba[t.code];return e?`${n} (${e})`:n}function Ut(t){if(t==null)return null;let e=Fa[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 Nt(t){if(t.kind==="create-failed")return Ut(t.status.error?.code??null);if(t.kind!=="never-live")return null;let e=(t.status.elapsedMs??0)>=$o.COLD_BOOT_WHEN_LIVE_TIMEOUT_MS;return Ut(e?"cold_start_exceeded":"queue_timeout")}var Mo=Ne(require("os"),1),Uo=Ne(require("path"),1),No=require("url"),Do=require("util");var Lo="0.6.21";var Fo=4141,qa=Lo,Ft={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 Pn(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 Bo(t,e,n){let r={...t,...Pn(e,n)};return delete r.URUN_API_KEY,delete r.URUN_JWT,r}function jo(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",d=s.includes("--skip-git-repo-check"),u=a&&!d?["exec","--skip-git-repo-check",...n.slice(1)]:n;return[...r,...i?[]:["-m",e],...u]}function qo(t,e){return e.some(r=>r==="--model"||r==="--provider"||r.startsWith("--model=")||r.startsWith("--provider="))?e:["--provider","urun","--model",t,...e]}function Ho(t,e){return e.some(r=>r==="--model"||r==="--provider"||r.startsWith("--model=")||r.startsWith("--provider="))?e:["--model",`urun/${t}`,...e]}function Go(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,No.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 Vo(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 Jo(t){if(t[0]!=="--port")return null;let e=Vo(t[1]);return t.splice(0,2),e}function Cn(t){let e=t.indexOf("--port");if(e===-1)return Fo;let n=Vo(t[e+1]);return t.splice(e,2),n}function Wo(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 In(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 Ve(t){let e=Ha(In(t,"URUN_BASE_URL")),n=In(t,"URUN_ORG_ID"),r=In(t,"URUN_APP"),o=(t.URUN_FUNCTION??"serve").trim()||"serve",s=(t.URUN_API_URL??"").trim(),i=s?Dt(s,"URUN_API_URL"):Vr,a=(t.URUN_JWT??"").trim();if(a)return{baseUrl:e,orgId:n,appId:r,fnName:o,apiUrl:i,auth:{lane:"jwt",jwt:a}};let d=(t.URUN_API_KEY??"").trim();if(d){let u=(t.URUN_GATEWAY_URL??"").trim(),l=u?Dt(u):void 0;return{baseUrl:e,orgId:n,appId:r,fnName:o,apiUrl:i,auth:{lane:"api-key",apiKey:d,gatewayUrl:l}}}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 Ha(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 Dt(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 $n(t){return{app:t.appId,org:t.orgId,fn:t.fnName,base_url:t.baseUrl,proxy_version:qa}}function Ga(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 Va=250;async function Ln(t,e=Va){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:d}=r;return typeof o!="string"||typeof s!="string"||typeof i!="string"||typeof a!="string"||typeof d!="string"?null:{app:o,org:s,fn:i,base_url:a,proxy_version:d}}catch{return null}}var Ko=2e3;async function Ja(t,e=Ko){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 zo(t,e,n=Fo,r=Ko){if(t!=null)return{mode:"spawn",port:t};let o=await Ln(n);if(o!==null&&Ga(o,e)){let s=await Ja(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 Mn(t,e=Mo.default.homedir()){return Uo.default.join(e,".urun","logs",`compat-proxy-${t}.log`)}var Tn=["log","info","warn","error","debug","trace"];function Yo(t,e=process,n=console){let r=e.stdout.write,o=e.stderr.write,s=(a,...d)=>t.write(a,...d);e.stdout.write=s,e.stderr.write=s;let i=Object.fromEntries(Tn.map(a=>[a,n[a]]));for(let a of Tn)n[a]=(...d)=>{t.write(`${(0,Do.format)(...d)}
|
|
18
18
|
`)};return()=>{e.stdout.write=r,e.stderr.write=o;for(let a of Tn)n[a]=i[a]}}var Wa=new Set(["EPIPE","EIO","EBADF","ENXIO"]);function Xo(t){let e=t?.code;return typeof e=="string"&&Wa.has(e)}function de(t,e){try{return t.write(e),!0}catch(n){if(Xo(n))return!1;throw n}}function Qo(t){let e={stdout:!1,stderr:!1},n=[];for(let r of["stdout","stderr"]){let o=t.streams[r],s=i=>{Xo(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 Zo(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 F}from"../chunk-7ZH2UHK6.js";import"../chunk-K23AZPI4.js";import{A as M,S as J,f as h,g as $,h as C,i as U,j as L,k as N,l as I,m as O,n as E,o as G,p as m,r as _,s as A,t as W,u as B,v as P,w as j,x as v,y as D,z as K}from"../chunk-
|
|
2
|
+
import{a as q,b as F}from"../chunk-7ZH2UHK6.js";import"../chunk-K23AZPI4.js";import{A as M,S as J,f as h,g as $,h as C,i as U,j as L,k as N,l as I,m as O,n as E,o as G,p as m,r as _,s as A,t as W,u as B,v as P,w as j,x as v,y as D,z as K}from"../chunk-5SBYFTBD.js";import"../chunk-76BZLCGT.js";import"../chunk-BAKPG5S3.js";import"../chunk-3JWYIKHM.js";import{g as k}from"../chunk-6M5JK4YC.js";import"../chunk-7V2JKPIG.js";import{c as w}from"../chunk-YSFSRI3D.js";w();import{spawn as Q}from"child_process";import{appendFileSync as R,createWriteStream as ae,existsSync as le,mkdirSync as X}from"fs";import Z from"path";import r from"process";w();import{ensureNodeWebRTC as oe,nodeWebRTCUnavailableReason as ie}from"@urun-sh/core/internal";var se={ensureWebRTC:oe,webrtcUnavailableReason:ie,audioBackend:k};async function Y(e=se){try{await e.ensureWebRTC()}catch(n){return{ok:!1,reason:`the WebRTC bootstrap threw: ${String(n)}`}}let i=e.webrtcUnavailableReason();if(i)return{ok:!1,reason:`${i} \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(n){return{ok:!1,reason:`the werift/opus audio backend could not be constructed: ${String(n)}`}}return{ok:!0,reason:null}}function ue(e,i){let n=(e.URUN_CATALOG_URL??"").trim(),u=n?_(n,"URUN_CATALOG_URL"):"",o=(e.URUN_CATALOG_ANON_KEY??"").trim();return!u||!o?(i(`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:o}}function ce(e){return q({baseUrl:e.baseUrl,orgId:e.orgId,defaultApp:e.appId,fnName:e.fnName,apiUrl:e.apiUrl,auth:e.auth,catalog:ue(r.env,i=>r.stderr.write(i))})}async function H(e,i,n){let u=Q(e,i,{stdio:"inherit",env:n});return new Promise(o=>{u.once("exit",s=>o(s??1)),u.once("error",s=>{r.stderr.write(`failed to launch ${e}: ${String(s)}
|
|
4
4
|
`),o(127)})})}function V(){return I(r.env,import.meta.url,le)}function ee(e){for(let[i,n]of Object.entries($(e)))r.stdout.write(`export ${i}=${n}
|
|
5
5
|
`)}async function z(e,i){let n=m(r.env),u=i?A(n):void 0,o=ce(n),s=null,f=c=>{if(s===null){let l=a.address();if(l===null)throw new Error("urun compat: a /v1 request was recorded before the proxy socket was listening");s=P(l.port),X(Z.dirname(s),{recursive:!0})}R(s,c)},a=J({clients:F(o),identity:u,...i?{requestLog:f}:{}});try{await new Promise((c,l)=>{a.once("error",l),a.listen(e,"127.0.0.1",c)})}catch(c){throw await o.closeAll().catch(()=>{}),c.code==="EADDRINUSE"?new Error(M(e,await W(e))):c}let d=a.address().port;return i&&(r.stdout.write(`urun openai proxy listening on http://127.0.0.1:${d}/v1
|
package/dist/proxy/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{B as l,C as a,D as x,E as s,G as O,H 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,G as O,H as f,S as I,a as n,b as p,c as m}from"../chunk-5SBYFTBD.js";import{f as r,g as i}from"../chunk-BAKPG5S3.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};
|