@urun-sh/openai 0.3.1 → 0.3.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-ZW6ENXZY.js → chunk-AJYWEXQZ.js} +1 -1
- package/dist/{chunk-54VWZJU7.js → chunk-FVFF5EWK.js} +1 -1
- package/dist/hosted/bin.js +1 -1
- package/dist/hosted/index.js +1 -1
- package/dist/pi-extension/standalone.cjs +43 -43
- package/dist/proxy/cli.cjs +1 -1
- package/dist/proxy/cli.js +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as _,b as x,m as A,n as g}from"./chunk-
|
|
1
|
+
import{a as _,b as x,m as A,n as g}from"./chunk-FVFF5EWK.js";import{a as v}from"./chunk-M6ICU4F5.js";import{c as i}from"./chunk-YSFSRI3D.js";i();import{createClientToken as E,ClientTokenError as I}from"@urun-sh/core";var l=class extends Error{constructor(t,n=401){super(t);this.status=n;this.name="ProxyAuthError"}status},p=class extends Error{constructor(e){super(e),this.name="ControlPlaneUnavailableError"}};function C(r){let e=(r??"").trim();if(e==="")throw new l("missing Authorization header \u2014 send your uRun org API key as `Authorization: Bearer <key>`");let t=/^Bearer[ \t]+(\S.*)$/i.exec(e);if(!t)throw new l("malformed Authorization header \u2014 expected `Authorization: Bearer <urun org api key>`");return t[1].trim()}var S=60,N=6e4,O=4096;function k(r){return r===401||r===403}var y=class{constructor(e){this.opts=e;this.mint=e.mint??E,this.now=e.now??Date.now}opts;cache=new Map;mint;now;async resolve(e){if(e==="")throw new l("empty Authorization bearer token");let t=this.cache.get(e);if(t&&this.now()-t.at<N)return{apiKey:e,orgId:t.orgId};let n;try{n=(await this.mint(e,{baseUrl:this.opts.gatewayUrl,expiresIn:S})).orgId}catch(o){throw o instanceof I&&k(o.status)?(this.cache.delete(e),new l("the uRun org API key was rejected by the control plane \u2014 check the key and that it is not revoked")):new p(`could not verify the API key against the uRun control plane at ${this.opts.gatewayUrl}: ${o instanceof Error?o.message:String(o)}`)}if(!n)throw new p("the control plane verified the API key but returned no org_id \u2014 refusing to route a request with no tenancy (control-plane contract violation)");if(this.cache.size>=O){let o=this.cache.keys().next();o.done||this.cache.delete(o.value)}return this.cache.set(e,{orgId:n,at:this.now()}),{apiKey:e,orgId:n}}clear(){this.cache.clear()}};i();var $=8080,T="serve",X="0.0.0.0";function L(r,e,t){let n=(r[e]??"").trim();if(!n)throw new Error(`${e} is not set \u2014 ${t}`);return n}function W(r=process.env){let e=(r.PORT??"").trim(),t=e===""?$:Number(e);if(!Number.isInteger(t)||t<0||t>65535)throw new Error(`PORT must be an integer in 0..65535, got ${JSON.stringify(e)}`);let n=A(g(L(r,"URUN_BASE_URL","the hosted proxy needs the uRun session-gateway base it opens sessions and verifies API keys against (e.g. https://api.urun.sh)"),"URUN_BASE_URL")),o=(r.URUN_API_URL??"").trim(),d=o?g(o,"URUN_API_URL"):`${n.replace(/\/+$/,"")}/v1`,a=(r.URUN_CATALOG_URL??"").trim(),m=(r.URUN_CATALOG_ANON_KEY??"").trim();if(!!a!=!!m)throw new Error("URUN_CATALOG_URL and URUN_CATALOG_ANON_KEY must be set together (or both left unset) \u2014 exactly one of them is set, which would silently disable the model-catalog oracle");let s=a?{catalogUrl:g(a,"URUN_CATALOG_URL"),anonKey:m}:null;return{port:t,baseUrl:n,apiUrl:d,catalog:s}}i();import{createHash as H}from"crypto";var z=512;function M(r){return`urun-inference-proxy-${H("sha256").update(r).digest("hex").slice(0,32)}`}var f=class{constructor(e){this.opts=e}opts;tenants=new Map;build(e){if(this.opts.build)return this.opts.build(e);let t=_({baseUrl:this.opts.baseUrl,orgId:e.orgId,defaultApp:null,fnName:T,apiUrl:this.opts.apiUrl,auth:{lane:"api-key",apiKey:e.apiKey,gatewayUrl:this.opts.baseUrl},catalog:this.opts.catalog,subject:M(e.apiKey)});return{router:t,clients:x(t)}}clientsFor(e){let t=this.tenants.get(e.apiKey);if(t)return this.tenants.delete(e.apiKey),this.tenants.set(e.apiKey,t),t.clients;for(;this.tenants.size>=z;){let o=this.tenants.entries().next();if(o.done)break;let[d,a]=o.value;this.tenants.delete(d),a.router.closeAll().catch(()=>{})}let n=this.build(e);return this.tenants.set(e.apiKey,n),n.clients}get size(){return this.tenants.size}async closeAll(){let e=[...this.tenants.values()].map(n=>n.router);this.tenants.clear();let t=[];if(await Promise.all(e.map(async n=>{try{await n.closeAll()}catch(o){t.push(String(o instanceof Error?o.message:o))}})),t.length>0)throw new Error(`failed to close ${t.length} tenant backhaul(s): ${t.join("; ")}`)}};i();import{createServer as G}from"http";var B=5e3,F=3e3,K="/api/client-tokens";function U(r,e,t){r.writeHead(e,{"content-type":"application/json"}),r.end(JSON.stringify(t))}function R(r,e,t,n){U(r,e,{error:{message:t,type:n}})}async function D(r,e=fetch){let t=`${r.replace(/\/+$/,"")}${K}`;try{let n=await e(t,{method:"POST",headers:{"content-type":"application/json"},body:"{}",signal:AbortSignal.timeout(F)});return n.status===404?{ready:!1,detail:`${t} answered 404 \u2014 this is not a uRun control plane`}:n.status>=500?{ready:!1,detail:`${t} answered HTTP ${n.status}`}:{ready:!0,detail:`${t} answered HTTP ${n.status}`}}catch(n){return{ready:!1,detail:`${t} unreachable: ${n instanceof Error?n.message:String(n)}`}}}function le(r){let e=r.resolver??new y({gatewayUrl:r.baseUrl}),t=r.registry??new f({baseUrl:r.baseUrl,apiUrl:r.apiUrl,catalog:r.catalog}),n=r.probeControlPlane??(()=>D(r.baseUrl)),o=async s=>e.resolve(C(s.headers.authorization)),d=v({clients:async s=>t.clientsFor(await o(s)),statusOf:s=>s instanceof l?{status:s.status,openaiType:"authentication_error",anthropicType:"authentication_error"}:s instanceof p?{status:502,openaiType:"upstream_error",anthropicType:"api_error"}:null}),a=null;return{server:G((s,c)=>{let h=new URL(s.url??"/","http://localhost");(async()=>{if(s.method==="GET"&&h.pathname==="/healthz"){U(c,200,{ok:!0});return}if(s.method==="GET"&&h.pathname==="/readyz"){let u=Date.now();if(!a||u-a.at>=B){let P=await n();a={at:u,...P}}U(c,a.ready?200:503,{ok:a.ready,control_plane:a.detail});return}if(h.pathname!=="/v1"&&!h.pathname.startsWith("/v1/")){R(c,404,`no route for ${s.method} ${h.pathname} \u2014 this endpoint serves the OpenAI-compatible /v1 surface plus /healthz and /readyz`,"invalid_request_error");return}d(s,c)})().catch(u=>{if(!c.headersSent){R(c,500,String(u instanceof Error?u.message:u),"proxy_error");return}c.end()})}),closeAll:()=>t.closeAll()}}async function ce(r,e){let t=new Promise(n=>r.close(()=>n()));r.closeAllConnections(),await t,await e()}export{l as a,p as b,C as c,N as d,O as e,y as f,$ as g,T as h,X as i,W as j,z as k,M as l,f as m,B as n,F as o,le as p,ce as q};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as b}from"./chunk-F2TEK34X.js";import{a as v}from"./chunk-G3NMGP4N.js";import{a as P,c as h,d as U,e as _}from"./chunk-XHIIEA6Z.js";import{c as x,f as S,g as E,p as R}from"./chunk-CWJRDBDC.js";import{c as l}from"./chunk-YSFSRI3D.js";l();import{App as I,createClientToken as H}from"@urun-sh/core";l();function j(e){let n=e?.type;return n==="response.created"||n==="response.in_progress"}function D(e){let n=e?.type;return n==="response.completed"||n==="error"}function k(e){return async function(t){return(async function*(){for(let a=1;a<=2;a++){let{app:s,entry:o}=await e.sessionFor(t.model),i=!1,u=!1;try{let c=await e.createStream(o,t);for await(let d of c){if(D(d)&&(i=!0),j(d)){if(a>1)continue}else u=!0;yield d}}catch(c){if(a<2&&!u){await e.evict(s,o);continue}throw c}if(i)return;if(a<2&&!u){await e.evict(s,o);continue}return}})()}}l();var M=3,F="llm",W=new Set(["ended","expired","error"]);function A(e,n){let t=e.doc(F),r=typeof t.onConnectionState=="function",a=typeof e.onPhase=="function";if(!r&&!a)throw new Error(`session for app "${n}" 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 s=null,o=new Set,i=[],u=c=>{if(!s){s=c;for(let d of[...o])d(c);o.clear()}};return r&&i.push(t.onConnectionState(c=>{c.consecutiveFailures<M||u(new h(`the pooled session for app "${n}" is gone: its doc backhaul failed ${c.consecutiveFailures} consecutive times (last close ${c.lastCloseCode===null?"by provider liveness reap":`code ${c.lastCloseCode}`}${c.lastCloseReason?`, reason ${JSON.stringify(c.lastCloseReason)}`:""}) \u2014 the platform closed the session (idle timeout or a serve-side crash). The entry is evicted; retry to get a fresh session.`))})),a&&i.push(e.onPhase(c=>{W.has(c.name)&&u(new h(`the pooled session for app "${n}" is gone: it reached terminal phase "${c.name}". The entry is evicted; retry to get a fresh session.`))})),{gone:()=>s,onGone(c){return s?(c(s),()=>{}):(o.add(c),()=>o.delete(c))},dispose(){o.clear();for(let c of i.splice(0))c()}}}async function*g(e,n){let t=n.gone();if(t)throw t;let r=e[Symbol.asyncIterator](),a,s=new Promise((o,i)=>{a=n.onGone(u=>i(u))});s.catch(()=>{});try{for(;;){let o=await Promise.race([r.next(),s]);if(o.done)return;yield o.value}}finally{a?.(),r.return?.(void 0)}}function O(e,n,t){let r=e[t];if(typeof r!="function")throw new Error(`app "${n}" has no function "${t}" (set URUN_FUNCTION)`);let a=r();if(typeof a.end!="function")throw new Error(`app "${n}" function "${t}" returned a session without end()`);return a}function B(e,n){let{baseUrl:t,orgId:r,fnName:a,auth:s,subject:o}=e,i=p=>({session:p,responses:new v(p),gone:A(p,n)});if(s.lane==="jwt"){let p=I(n,{baseUrl:t,orgId:r,jwt:s.jwt});return i(O(p,n,a))}let{apiKey:u,gatewayUrl:c}=s,d=I(n,{baseUrl:t,orgId:r,getAccessToken:async()=>(await H(u,{baseUrl:c,expiresIn:300,allowedFunctions:[`${n}/${a}`],...o===void 0?{}:{subject:o}})).token});return i(O(d,n,a))}function K(e){let n=e.session.id;if(typeof n!="string"||n.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 n}var q=new Set(["error","ended","expired"]);function xe(e){let{auth:n,catalog:t}=e,r=null,a=o=>{let i=B(e,o);return i.gone.onGone(()=>{r?.evict(o,i)}),i},s=new _({defaultApp:e.defaultApp,fnName:e.fnName,openSession:a,closeSession:async o=>{o.gone.dispose(),await o.session.end()},listApps:n.lane==="api-key"?()=>U({apiUrl:e.apiUrl,apiKey:n.apiKey}):null,listCatalog:t?()=>b(t):null,sessionKey:K});return r=s,e.defaultApp!==null&&s.seed(e.defaultApp,a(e.defaultApp)),s}function Se(e,n=E){let t=new WeakMap,r=new WeakMap,a=new WeakMap;return{createResponse:k({sessionFor:s=>e.sessionFor(s),evict:(s,o)=>e.evict(s,o),createStream:async(s,o)=>g(await s.responses.responses.create(o),s.gone)}),listModels:()=>e.modelList(),openAudio:async s=>{let{entry:o}=await e.sessionFor(s),i=t.get(o);return i||(i=(async()=>x(o.session,await n()))(),t.set(o,i),i.catch(()=>t.delete(o))),i},openVideo:async s=>{let{entry:o}=await e.sessionFor(s),i=r.get(o);return i||(i=S(o.session),r.set(o,i)),i},openVideoOut:async s=>{let{entry:o}=await e.sessionFor(s),i=a.get(o);return i||(i=R(o.session),a.set(o,i)),i},sessionHandle:async s=>(await e.handleFor(s)).handle,createResponseOn:async(s,o)=>{let{entry:i}=await e.sessionForHandle(s);return g(await i.responses.responses.create(o),i.gone)},onSessionEnd:async(s,o)=>{let{entry:i}=await e.sessionForHandle(s),u=i.session;if(typeof u.onPhase!="function")throw new Error("pooled session exposes no onPhase \u2014 session-end (goAway) wiring requires @urun-sh/core Session");let c=!1;return u.onPhase(d=>{if(c||!q.has(d.name))return;c=!0;let p=u.endsAt??null;o({timeLeftMs:p?Math.max(0,p.getTime()-Date.now()):null,reason:d.name==="expired"?"session reached its maximum length":`session ${d.name}`})})}}}l();import V from"os";import J from"path";import{fileURLToPath as X}from"url";import{format as z}from"util";var N="0.3.1";var T=4141,Q=N,Ie={claude:{bin:"claude",env:"anthropic"},codex:{bin:"codex",env:"openai"},pi:{bin:"pi",env:"openai"},aider:{bin:"aider",env:"openai"},opencode:{bin:"opencode",env:"openai"},crush:{bin:"crush",env:"openai"}};function Z(e,n="openai"){if(n==="anthropic")return{ANTHROPIC_BASE_URL:`http://127.0.0.1:${e}`,ANTHROPIC_API_KEY:"urun-local"};let t=`http://127.0.0.1:${e}/v1`;return{OPENAI_BASE_URL:t,OPENAI_API_BASE:t,OPENAI_API_KEY:"urun-local"}}function Oe(e,n,t){let r={...e,...Z(n,t)};return delete r.URUN_API_KEY,delete r.URUN_JWT,r}function Ne(e,n,t){let r=["-c","model_providers.urun.name=urun","-c",`model_providers.urun.base_url="http://127.0.0.1:${e}/v1"`,"-c",'model_providers.urun.wire_api="responses"',"-c",'model_provider="urun"'],a=t.indexOf("--"),s=a===-1?t:t.slice(0,a),o=s.some(d=>d==="-m"||d==="--model"||d.startsWith("--model=")),i=t[0]==="exec",u=s.includes("--skip-git-repo-check"),c=i&&!u?["exec","--skip-git-repo-check",...t.slice(1)]:t;return[...r,...o?[]:["-m",n],...c]}function $e(e,n){return n.some(r=>r==="--model"||r==="--provider"||r.startsWith("--model=")||r.startsWith("--provider="))?n:["--provider","urun","--model",e,...n]}function Te(e,n,t){let r=(e.URUN_PI_EXTENSION_ENTRY??"").trim();if(r){if(!t(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 a=X(new URL("../pi-extension/standalone.cjs",n));if(!t(a))throw new Error(`pi extension entry not found at ${a} \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 a}function C(e){let n=Number(e);if(!Number.isInteger(n)||n<0)throw new Error(`--port needs a non-negative integer (0 = OS-assigned ephemeral), got ${e}`);return n}function Ce(e){if(e[0]!=="--port")return null;let n=C(e[1]);return e.splice(0,2),n}function Ge(e){let n=e.indexOf("--port");if(n===-1)return T;let t=C(e[n+1]);return e.splice(n,2),t}function Le(e){if(e===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 e}function y(e,n){let t=(e[n]??"").trim();if(!t)throw new Error(`${n} 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 t}function je(e){let n=ee(y(e,"URUN_BASE_URL")),t=y(e,"URUN_ORG_ID"),r=y(e,"URUN_APP"),a=(e.URUN_FUNCTION??"serve").trim()||"serve",s=(e.URUN_API_URL??"").trim(),o=s?$(s,"URUN_API_URL"):P,i=(e.URUN_JWT??"").trim();if(i)return{baseUrl:n,orgId:t,appId:r,fnName:a,apiUrl:o,auth:{lane:"jwt",jwt:i}};let u=(e.URUN_API_KEY??"").trim();if(u){let c=(e.URUN_GATEWAY_URL??"").trim(),d=c?$(c):void 0;return{baseUrl:n,orgId:t,appId:r,fnName:a,apiUrl:o,auth:{lane:"api-key",apiKey:u,gatewayUrl:d}}}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 ee(e,n="URUN_BASE_URL"){if(/\/v1\/*$/.test(new URL(e).pathname))throw new Error(`${n} must be the session-gateway base (e.g. https://api.urun.sh), got ${e} \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 e}function $(e,n="URUN_GATEWAY_URL"){let t=new URL(e),r=t.hostname==="localhost"||t.hostname==="127.0.0.1"||t.hostname==="[::1]";if(t.protocol!=="https:"&&!r)throw new Error(`${n} must be https (got ${e}) \u2014 the org API key rides the request's Authorization header`);return e}function De(e){return{app:e.appId,org:e.orgId,fn:e.fnName,base_url:e.baseUrl,proxy_version:Q}}function ne(e,n){return e.app===n.app&&e.org===n.org&&e.fn===n.fn&&e.base_url===n.base_url&&e.proxy_version===n.proxy_version}var te=250;async function oe(e,n=te){try{let t=await fetch(`http://127.0.0.1:${e}/stats`,{signal:AbortSignal.timeout(n)});if(!t.ok)return null;let r=(await t.json()).identity;if(r==null||typeof r!="object")return null;let{app:a,org:s,fn:o,base_url:i,proxy_version:u}=r;return typeof a!="string"||typeof s!="string"||typeof o!="string"||typeof i!="string"||typeof u!="string"?null:{app:a,org:s,fn:o,base_url:i,proxy_version:u}}catch{return null}}var G=2e3;async function re(e,n=G){try{let t=await fetch(`http://127.0.0.1:${e}/v1/models`,{signal:AbortSignal.timeout(n)});return t.ok?null:`GET /v1/models answered HTTP ${t.status}`}catch(t){return`GET /v1/models failed (${String(t instanceof Error?t.message:t)})`}}async function Me(e,n,t=T,r=G){if(e!=null)return{mode:"spawn",port:e};let a=await oe(t);if(a!==null&&ne(a,n)){let s=await re(t,r);return s===null?{mode:"reuse",port:t,identity:a}:{mode:"spawn",port:0,reason:`a urun-openai proxy on port ${t} 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 Fe(e,n=V.homedir()){return J.join(n,".urun","logs",`compat-proxy-${e}.log`)}var w=["log","info","warn","error","debug","trace"];function We(e,n=process,t=console){let r=n.stdout.write,a=n.stderr.write,s=(i,...u)=>e.write(i,...u);n.stdout.write=s,n.stderr.write=s;let o=Object.fromEntries(w.map(i=>[i,t[i]]));for(let i of w)t[i]=(...u)=>{e.write(`${z(...u)}
|
|
1
|
+
import{a as b}from"./chunk-F2TEK34X.js";import{a as v}from"./chunk-G3NMGP4N.js";import{a as P,c as h,d as U,e as _}from"./chunk-XHIIEA6Z.js";import{c as x,f as S,g as E,p as R}from"./chunk-CWJRDBDC.js";import{c as l}from"./chunk-YSFSRI3D.js";l();import{App as I,createClientToken as H}from"@urun-sh/core";l();function j(e){let n=e?.type;return n==="response.created"||n==="response.in_progress"}function D(e){let n=e?.type;return n==="response.completed"||n==="error"}function k(e){return async function(t){return(async function*(){for(let a=1;a<=2;a++){let{app:s,entry:o}=await e.sessionFor(t.model),i=!1,u=!1;try{let c=await e.createStream(o,t);for await(let d of c){if(D(d)&&(i=!0),j(d)){if(a>1)continue}else u=!0;yield d}}catch(c){if(a<2&&!u){await e.evict(s,o);continue}throw c}if(i)return;if(a<2&&!u){await e.evict(s,o);continue}return}})()}}l();var M=3,F="llm",W=new Set(["ended","expired","error"]);function A(e,n){let t=e.doc(F),r=typeof t.onConnectionState=="function",a=typeof e.onPhase=="function";if(!r&&!a)throw new Error(`session for app "${n}" 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 s=null,o=new Set,i=[],u=c=>{if(!s){s=c;for(let d of[...o])d(c);o.clear()}};return r&&i.push(t.onConnectionState(c=>{c.consecutiveFailures<M||u(new h(`the pooled session for app "${n}" is gone: its doc backhaul failed ${c.consecutiveFailures} consecutive times (last close ${c.lastCloseCode===null?"by provider liveness reap":`code ${c.lastCloseCode}`}${c.lastCloseReason?`, reason ${JSON.stringify(c.lastCloseReason)}`:""}) \u2014 the platform closed the session (idle timeout or a serve-side crash). The entry is evicted; retry to get a fresh session.`))})),a&&i.push(e.onPhase(c=>{W.has(c.name)&&u(new h(`the pooled session for app "${n}" is gone: it reached terminal phase "${c.name}". The entry is evicted; retry to get a fresh session.`))})),{gone:()=>s,onGone(c){return s?(c(s),()=>{}):(o.add(c),()=>o.delete(c))},dispose(){o.clear();for(let c of i.splice(0))c()}}}async function*g(e,n){let t=n.gone();if(t)throw t;let r=e[Symbol.asyncIterator](),a,s=new Promise((o,i)=>{a=n.onGone(u=>i(u))});s.catch(()=>{});try{for(;;){let o=await Promise.race([r.next(),s]);if(o.done)return;yield o.value}}finally{a?.(),r.return?.(void 0)}}function O(e,n,t){let r=e[t];if(typeof r!="function")throw new Error(`app "${n}" has no function "${t}" (set URUN_FUNCTION)`);let a=r();if(typeof a.end!="function")throw new Error(`app "${n}" function "${t}" returned a session without end()`);return a}function B(e,n){let{baseUrl:t,orgId:r,fnName:a,auth:s,subject:o}=e,i=p=>({session:p,responses:new v(p),gone:A(p,n)});if(s.lane==="jwt"){let p=I(n,{baseUrl:t,orgId:r,jwt:s.jwt});return i(O(p,n,a))}let{apiKey:u,gatewayUrl:c}=s,d=I(n,{baseUrl:t,orgId:r,getAccessToken:async()=>(await H(u,{baseUrl:c,expiresIn:300,allowedFunctions:[`${n}/${a}`],...o===void 0?{}:{subject:o}})).token});return i(O(d,n,a))}function K(e){let n=e.session.id;if(typeof n!="string"||n.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 n}var q=new Set(["error","ended","expired"]);function xe(e){let{auth:n,catalog:t}=e,r=null,a=o=>{let i=B(e,o);return i.gone.onGone(()=>{r?.evict(o,i)}),i},s=new _({defaultApp:e.defaultApp,fnName:e.fnName,openSession:a,closeSession:async o=>{o.gone.dispose(),await o.session.end()},listApps:n.lane==="api-key"?()=>U({apiUrl:e.apiUrl,apiKey:n.apiKey}):null,listCatalog:t?()=>b(t):null,sessionKey:K});return r=s,e.defaultApp!==null&&s.seed(e.defaultApp,a(e.defaultApp)),s}function Se(e,n=E){let t=new WeakMap,r=new WeakMap,a=new WeakMap;return{createResponse:k({sessionFor:s=>e.sessionFor(s),evict:(s,o)=>e.evict(s,o),createStream:async(s,o)=>g(await s.responses.responses.create(o),s.gone)}),listModels:()=>e.modelList(),openAudio:async s=>{let{entry:o}=await e.sessionFor(s),i=t.get(o);return i||(i=(async()=>x(o.session,await n()))(),t.set(o,i),i.catch(()=>t.delete(o))),i},openVideo:async s=>{let{entry:o}=await e.sessionFor(s),i=r.get(o);return i||(i=S(o.session),r.set(o,i)),i},openVideoOut:async s=>{let{entry:o}=await e.sessionFor(s),i=a.get(o);return i||(i=R(o.session),a.set(o,i)),i},sessionHandle:async s=>(await e.handleFor(s)).handle,createResponseOn:async(s,o)=>{let{entry:i}=await e.sessionForHandle(s);return g(await i.responses.responses.create(o),i.gone)},onSessionEnd:async(s,o)=>{let{entry:i}=await e.sessionForHandle(s),u=i.session;if(typeof u.onPhase!="function")throw new Error("pooled session exposes no onPhase \u2014 session-end (goAway) wiring requires @urun-sh/core Session");let c=!1;return u.onPhase(d=>{if(c||!q.has(d.name))return;c=!0;let p=u.endsAt??null;o({timeLeftMs:p?Math.max(0,p.getTime()-Date.now()):null,reason:d.name==="expired"?"session reached its maximum length":`session ${d.name}`})})}}}l();import V from"os";import J from"path";import{fileURLToPath as X}from"url";import{format as z}from"util";var N="0.3.2";var T=4141,Q=N,Ie={claude:{bin:"claude",env:"anthropic"},codex:{bin:"codex",env:"openai"},pi:{bin:"pi",env:"openai"},aider:{bin:"aider",env:"openai"},opencode:{bin:"opencode",env:"openai"},crush:{bin:"crush",env:"openai"}};function Z(e,n="openai"){if(n==="anthropic")return{ANTHROPIC_BASE_URL:`http://127.0.0.1:${e}`,ANTHROPIC_API_KEY:"urun-local"};let t=`http://127.0.0.1:${e}/v1`;return{OPENAI_BASE_URL:t,OPENAI_API_BASE:t,OPENAI_API_KEY:"urun-local"}}function Oe(e,n,t){let r={...e,...Z(n,t)};return delete r.URUN_API_KEY,delete r.URUN_JWT,r}function Ne(e,n,t){let r=["-c","model_providers.urun.name=urun","-c",`model_providers.urun.base_url="http://127.0.0.1:${e}/v1"`,"-c",'model_providers.urun.wire_api="responses"',"-c",'model_provider="urun"'],a=t.indexOf("--"),s=a===-1?t:t.slice(0,a),o=s.some(d=>d==="-m"||d==="--model"||d.startsWith("--model=")),i=t[0]==="exec",u=s.includes("--skip-git-repo-check"),c=i&&!u?["exec","--skip-git-repo-check",...t.slice(1)]:t;return[...r,...o?[]:["-m",n],...c]}function $e(e,n){return n.some(r=>r==="--model"||r==="--provider"||r.startsWith("--model=")||r.startsWith("--provider="))?n:["--provider","urun","--model",e,...n]}function Te(e,n,t){let r=(e.URUN_PI_EXTENSION_ENTRY??"").trim();if(r){if(!t(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 a=X(new URL("../pi-extension/standalone.cjs",n));if(!t(a))throw new Error(`pi extension entry not found at ${a} \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 a}function C(e){let n=Number(e);if(!Number.isInteger(n)||n<0)throw new Error(`--port needs a non-negative integer (0 = OS-assigned ephemeral), got ${e}`);return n}function Ce(e){if(e[0]!=="--port")return null;let n=C(e[1]);return e.splice(0,2),n}function Ge(e){let n=e.indexOf("--port");if(n===-1)return T;let t=C(e[n+1]);return e.splice(n,2),t}function Le(e){if(e===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 e}function y(e,n){let t=(e[n]??"").trim();if(!t)throw new Error(`${n} 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 t}function je(e){let n=ee(y(e,"URUN_BASE_URL")),t=y(e,"URUN_ORG_ID"),r=y(e,"URUN_APP"),a=(e.URUN_FUNCTION??"serve").trim()||"serve",s=(e.URUN_API_URL??"").trim(),o=s?$(s,"URUN_API_URL"):P,i=(e.URUN_JWT??"").trim();if(i)return{baseUrl:n,orgId:t,appId:r,fnName:a,apiUrl:o,auth:{lane:"jwt",jwt:i}};let u=(e.URUN_API_KEY??"").trim();if(u){let c=(e.URUN_GATEWAY_URL??"").trim(),d=c?$(c):void 0;return{baseUrl:n,orgId:t,appId:r,fnName:a,apiUrl:o,auth:{lane:"api-key",apiKey:u,gatewayUrl:d}}}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 ee(e,n="URUN_BASE_URL"){if(/\/v1\/*$/.test(new URL(e).pathname))throw new Error(`${n} must be the session-gateway base (e.g. https://api.urun.sh), got ${e} \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 e}function $(e,n="URUN_GATEWAY_URL"){let t=new URL(e),r=t.hostname==="localhost"||t.hostname==="127.0.0.1"||t.hostname==="[::1]";if(t.protocol!=="https:"&&!r)throw new Error(`${n} must be https (got ${e}) \u2014 the org API key rides the request's Authorization header`);return e}function De(e){return{app:e.appId,org:e.orgId,fn:e.fnName,base_url:e.baseUrl,proxy_version:Q}}function ne(e,n){return e.app===n.app&&e.org===n.org&&e.fn===n.fn&&e.base_url===n.base_url&&e.proxy_version===n.proxy_version}var te=250;async function oe(e,n=te){try{let t=await fetch(`http://127.0.0.1:${e}/stats`,{signal:AbortSignal.timeout(n)});if(!t.ok)return null;let r=(await t.json()).identity;if(r==null||typeof r!="object")return null;let{app:a,org:s,fn:o,base_url:i,proxy_version:u}=r;return typeof a!="string"||typeof s!="string"||typeof o!="string"||typeof i!="string"||typeof u!="string"?null:{app:a,org:s,fn:o,base_url:i,proxy_version:u}}catch{return null}}var G=2e3;async function re(e,n=G){try{let t=await fetch(`http://127.0.0.1:${e}/v1/models`,{signal:AbortSignal.timeout(n)});return t.ok?null:`GET /v1/models answered HTTP ${t.status}`}catch(t){return`GET /v1/models failed (${String(t instanceof Error?t.message:t)})`}}async function Me(e,n,t=T,r=G){if(e!=null)return{mode:"spawn",port:e};let a=await oe(t);if(a!==null&&ne(a,n)){let s=await re(t,r);return s===null?{mode:"reuse",port:t,identity:a}:{mode:"spawn",port:0,reason:`a urun-openai proxy on port ${t} 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 Fe(e,n=V.homedir()){return J.join(n,".urun","logs",`compat-proxy-${e}.log`)}var w=["log","info","warn","error","debug","trace"];function We(e,n=process,t=console){let r=n.stdout.write,a=n.stderr.write,s=(i,...u)=>e.write(i,...u);n.stdout.write=s,n.stderr.write=s;let o=Object.fromEntries(w.map(i=>[i,t[i]]));for(let i of w)t[i]=(...u)=>{e.write(`${z(...u)}
|
|
2
2
|
`)};return()=>{n.stdout.write=r,n.stderr.write=a;for(let i of w)t[i]=o[i]}}var se=new Set(["EPIPE","EIO","EBADF","ENXIO"]);function L(e){let n=e?.code;return typeof n=="string"&&se.has(n)}function He(e,n){try{return e.write(n),!0}catch(t){if(L(t))return!1;throw t}}function Be(e){let n={stdout:!1,stderr:!1},t=[];for(let r of["stdout","stderr"]){let a=e.streams[r],s=o=>{L(o)&&(n[r]=!0);let i=o?.code;try{e.note(`${new Date().toISOString()} urun compat: process.${r} died (${String(i??(o instanceof Error?o.message:o))}) \u2014 the terminal is gone; launcher output continues in this log only
|
|
3
3
|
`)}catch{}};a.on("error",s),t.push([a,s])}return{isDead:r=>n[r],uninstall:()=>{for(let[r,a]of t)r.off("error",a)}}}function Ke(e){let n=t=>{let r=t instanceof Error?`${t.stack??`${t.name}: ${t.message}`}`:String(t);try{e.appendSync(e.logPath,`${new Date().toISOString()} launcher crashed (in-process proxy): ${r}
|
|
4
4
|
`)}catch{}e.restore();try{e.writeStderr(`urun compat: the in-process proxy crashed (${t instanceof Error?t.message:String(t)}) \u2014 terminating the harness (its backend is gone); details: ${e.logPath}
|
package/dist/hosted/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{i as z,j as se,p as ce,q as de}from"../chunk-ZW6ENXZY.js";import"../chunk-54VWZJU7.js";import"../chunk-F2TEK34X.js";import"../chunk-M6ICU4F5.js";import"../chunk-G3NMGP4N.js";import"../chunk-XHIIEA6Z.js";import"../chunk-5NXM4IO3.js";import"../chunk-CWJRDBDC.js";import"../chunk-UVAY7Q7Z.js";import{a as We,b as $e,c as H}from"../chunk-YSFSRI3D.js";var he=We(()=>{"use strict";H();var le;(function(M){(function(_){var p=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:A(),b=g(M);typeof p.Reflect<"u"&&(b=g(p.Reflect,b)),_(b,p),typeof p.Reflect>"u"&&(p.Reflect=M);function g(P,x){return function(k,C){Object.defineProperty(P,k,{configurable:!0,writable:!0,value:C}),x&&x(k,C)}}function j(){try{return Function("return this;")()}catch{}}function E(){try{return(0,eval)("(function() { return this; })()")}catch{}}function A(){return j()||E()}})(function(_,p){var b=Object.prototype.hasOwnProperty,g=typeof Symbol=="function",j=g&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",E=g&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",A=typeof Object.create=="function",P={__proto__:[]}instanceof Array,x=!A&&!P,k={create:A?function(){return B(Object.create(null))}:P?function(){return B({__proto__:null})}:function(){return B({})},has:x?function(e,t){return b.call(e,t)}:function(e,t){return t in e},get:x?function(e,t){return b.call(e,t)?e[t]:void 0}:function(e,t){return e[t]}},C=Object.getPrototypeOf(Function),G=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:De(),U=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Ae(),W=typeof WeakMap=="function"?WeakMap:Fe(),I=g?Symbol.for("@reflect-metadata:registry"):void 0,F=xe(),L=Ce(F);function ve(e,t,r,n){if(s(r)){if(!te(e))throw new TypeError;if(!re(t))throw new TypeError;return ke(e,t)}else{if(!te(e))throw new TypeError;if(!h(t))throw new TypeError;if(!h(n)&&!s(n)&&!S(n))throw new TypeError;return S(n)&&(n=void 0),r=O(r),Te(e,t,r,n)}}_("decorate",ve);function ye(e,t){function r(n,u){if(!h(n))throw new TypeError;if(!s(u)&&!Re(u))throw new TypeError;Q(e,t,n,u)}return r}_("metadata",ye);function we(e,t,r,n){if(!h(r))throw new TypeError;return s(n)||(n=O(n)),Q(e,t,r,n)}_("defineMetadata",we);function pe(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=O(r)),Z(e,t,r)}_("hasMetadata",pe);function _e(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=O(r)),$(e,t,r)}_("hasOwnMetadata",_e);function Me(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=O(r)),q(e,t,r)}_("getMetadata",Me);function ge(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=O(r)),J(e,t,r)}_("getOwnMetadata",ge);function me(e,t){if(!h(e))throw new TypeError;return s(t)||(t=O(t)),X(e,t)}_("getMetadataKeys",me);function be(e,t){if(!h(e))throw new TypeError;return s(t)||(t=O(t)),Y(e,t)}_("getOwnMetadataKeys",be);function Oe(e,t,r){if(!h(t))throw new TypeError;if(s(r)||(r=O(r)),!h(t))throw new TypeError;s(r)||(r=O(r));var n=D(t,r,!1);return s(n)?!1:n.OrdinaryDeleteMetadata(e,t,r)}_("deleteMetadata",Oe);function ke(e,t){for(var r=e.length-1;r>=0;--r){var n=e[r],u=n(t);if(!s(u)&&!S(u)){if(!re(u))throw new TypeError;t=u}}return t}function Te(e,t,r,n){for(var u=e.length-1;u>=0;--u){var v=e[u],w=v(t,r,n);if(!s(w)&&!S(w)){if(!h(w))throw new TypeError;n=w}}return n}function Z(e,t,r){var n=$(e,t,r);if(n)return!0;var u=V(t);return S(u)?!1:Z(e,u,r)}function $(e,t,r){var n=D(t,r,!1);return s(n)?!1:ee(n.OrdinaryHasOwnMetadata(e,t,r))}function q(e,t,r){var n=$(e,t,r);if(n)return J(e,t,r);var u=V(t);if(!S(u))return q(e,u,r)}function J(e,t,r){var n=D(t,r,!1);if(!s(n))return n.OrdinaryGetOwnMetadata(e,t,r)}function Q(e,t,r,n){var u=D(r,n,!0);u.OrdinaryDefineOwnMetadata(e,t,r,n)}function X(e,t){var r=Y(e,t),n=V(e);if(n===null)return r;var u=X(n,t);if(u.length<=0)return r;if(r.length<=0)return u;for(var v=new U,w=[],c=0,a=r;c<a.length;c++){var i=a[c],o=v.has(i);o||(v.add(i),w.push(i))}for(var f=0,d=u;f<d.length;f++){var i=d[f],o=v.has(i);o||(v.add(i),w.push(i))}return w}function Y(e,t){var r=D(e,t,!1);return r?r.OrdinaryOwnMetadataKeys(e,t):[]}function K(e){if(e===null)return 1;switch(typeof e){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return e===null?1:6;default:return 6}}function s(e){return e===void 0}function S(e){return e===null}function Ee(e){return typeof e=="symbol"}function h(e){return typeof e=="object"?e!==null:typeof e=="function"}function Pe(e,t){switch(K(e)){case 0:return e;case 1:return e;case 2:return e;case 3:return e;case 4:return e;case 5:return e}var r=t===3?"string":t===5?"number":"default",n=ne(e,j);if(n!==void 0){var u=n.call(e,r);if(h(u))throw new TypeError;return u}return Ie(e,r==="default"?"number":r)}function Ie(e,t){if(t==="string"){var r=e.toString;if(R(r)){var n=r.call(e);if(!h(n))return n}var u=e.valueOf;if(R(u)){var n=u.call(e);if(!h(n))return n}}else{var u=e.valueOf;if(R(u)){var n=u.call(e);if(!h(n))return n}var v=e.toString;if(R(v)){var n=v.call(e);if(!h(n))return n}}throw new TypeError}function ee(e){return!!e}function Se(e){return""+e}function O(e){var t=Pe(e,3);return Ee(t)?t:Se(t)}function te(e){return Array.isArray?Array.isArray(e):e instanceof Object?e instanceof Array:Object.prototype.toString.call(e)==="[object Array]"}function R(e){return typeof e=="function"}function re(e){return typeof e=="function"}function Re(e){switch(K(e)){case 3:return!0;case 4:return!0;default:return!1}}function N(e,t){return e===t||e!==e&&t!==t}function ne(e,t){var r=e[t];if(r!=null){if(!R(r))throw new TypeError;return r}}function ae(e){var t=ne(e,E);if(!R(t))throw new TypeError;var r=t.call(e);if(!h(r))throw new TypeError;return r}function ie(e){return e.value}function oe(e){var t=e.next();return t.done?!1:t}function fe(e){var t=e.return;t&&t.call(e)}function V(e){var t=Object.getPrototypeOf(e);if(typeof e!="function"||e===C||t!==C)return t;var r=e.prototype,n=r&&Object.getPrototypeOf(r);if(n==null||n===Object.prototype)return t;var u=n.constructor;return typeof u!="function"||u===e?t:u}function je(){var e;!s(I)&&typeof p.Reflect<"u"&&!(I in p.Reflect)&&typeof p.Reflect.defineMetadata=="function"&&(e=Ge(p.Reflect));var t,r,n,u=new W,v={registerProvider:w,getProvider:a,setProvider:o};return v;function w(f){if(!Object.isExtensible(v))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case e===f:break;case s(t):t=f;break;case t===f:break;case s(r):r=f;break;case r===f:break;default:n===void 0&&(n=new U),n.add(f);break}}function c(f,d){if(!s(t)){if(t.isProviderFor(f,d))return t;if(!s(r)){if(r.isProviderFor(f,d))return t;if(!s(n))for(var l=ae(n);;){var y=oe(l);if(!y)return;var m=ie(y);if(m.isProviderFor(f,d))return fe(l),m}}}if(!s(e)&&e.isProviderFor(f,d))return e}function a(f,d){var l=u.get(f),y;return s(l)||(y=l.get(d)),s(y)&&(y=c(f,d),s(y)||(s(l)&&(l=new G,u.set(f,l)),l.set(d,y))),y}function i(f){if(s(f))throw new TypeError;return t===f||r===f||!s(n)&&n.has(f)}function o(f,d,l){if(!i(l))throw new Error("Metadata provider not registered.");var y=a(f,d);if(y!==l){if(!s(y))return!1;var m=u.get(f);s(m)&&(m=new G,u.set(f,m)),m.set(d,l)}return!0}}function xe(){var e;return!s(I)&&h(p.Reflect)&&Object.isExtensible(p.Reflect)&&(e=p.Reflect[I]),s(e)&&(e=je()),!s(I)&&h(p.Reflect)&&Object.isExtensible(p.Reflect)&&Object.defineProperty(p.Reflect,I,{enumerable:!1,configurable:!1,writable:!1,value:e}),e}function Ce(e){var t=new W,r={isProviderFor:function(i,o){var f=t.get(i);return s(f)?!1:f.has(o)},OrdinaryDefineOwnMetadata:w,OrdinaryHasOwnMetadata:u,OrdinaryGetOwnMetadata:v,OrdinaryOwnMetadataKeys:c,OrdinaryDeleteMetadata:a};return F.registerProvider(r),r;function n(i,o,f){var d=t.get(i),l=!1;if(s(d)){if(!f)return;d=new G,t.set(i,d),l=!0}var y=d.get(o);if(s(y)){if(!f)return;if(y=new G,d.set(o,y),!e.setProvider(i,o,r))throw d.delete(o),l&&t.delete(i),new Error("Wrong provider for target.")}return y}function u(i,o,f){var d=n(o,f,!1);return s(d)?!1:ee(d.has(i))}function v(i,o,f){var d=n(o,f,!1);if(!s(d))return d.get(i)}function w(i,o,f,d){var l=n(f,d,!0);l.set(i,o)}function c(i,o){var f=[],d=n(i,o,!1);if(s(d))return f;for(var l=d.keys(),y=ae(l),m=0;;){var ue=oe(y);if(!ue)return f.length=m,f;var He=ie(ue);try{f[m]=He}catch(Ue){try{fe(y)}finally{throw Ue}}m++}}function a(i,o,f){var d=n(o,f,!1);if(s(d)||!d.delete(i))return!1;if(d.size===0){var l=t.get(o);s(l)||(l.delete(f),l.size===0&&t.delete(l))}return!0}}function Ge(e){var t=e.defineMetadata,r=e.hasOwnMetadata,n=e.getOwnMetadata,u=e.getOwnMetadataKeys,v=e.deleteMetadata,w=new W,c={isProviderFor:function(a,i){var o=w.get(a);return!s(o)&&o.has(i)?!0:u(a,i).length?(s(o)&&(o=new U,w.set(a,o)),o.add(i),!0):!1},OrdinaryDefineOwnMetadata:t,OrdinaryHasOwnMetadata:r,OrdinaryGetOwnMetadata:n,OrdinaryOwnMetadataKeys:u,OrdinaryDeleteMetadata:v};return c}function D(e,t,r){var n=F.getProvider(e,t);if(!s(n))return n;if(r){if(F.setProvider(e,t,L))return L;throw new Error("Illegal state.")}}function De(){var e={},t=[],r=(function(){function c(a,i,o){this._index=0,this._keys=a,this._values=i,this._selector=o}return c.prototype["@@iterator"]=function(){return this},c.prototype[E]=function(){return this},c.prototype.next=function(){var a=this._index;if(a>=0&&a<this._keys.length){var i=this._selector(this._keys[a],this._values[a]);return a+1>=this._keys.length?(this._index=-1,this._keys=t,this._values=t):this._index++,{value:i,done:!1}}return{value:void 0,done:!0}},c.prototype.throw=function(a){throw this._index>=0&&(this._index=-1,this._keys=t,this._values=t),a},c.prototype.return=function(a){return this._index>=0&&(this._index=-1,this._keys=t,this._values=t),{value:a,done:!0}},c})(),n=(function(){function c(){this._keys=[],this._values=[],this._cacheKey=e,this._cacheIndex=-2}return Object.defineProperty(c.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),c.prototype.has=function(a){return this._find(a,!1)>=0},c.prototype.get=function(a){var i=this._find(a,!1);return i>=0?this._values[i]:void 0},c.prototype.set=function(a,i){var o=this._find(a,!0);return this._values[o]=i,this},c.prototype.delete=function(a){var i=this._find(a,!1);if(i>=0){for(var o=this._keys.length,f=i+1;f<o;f++)this._keys[f-1]=this._keys[f],this._values[f-1]=this._values[f];return this._keys.length--,this._values.length--,N(a,this._cacheKey)&&(this._cacheKey=e,this._cacheIndex=-2),!0}return!1},c.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=e,this._cacheIndex=-2},c.prototype.keys=function(){return new r(this._keys,this._values,u)},c.prototype.values=function(){return new r(this._keys,this._values,v)},c.prototype.entries=function(){return new r(this._keys,this._values,w)},c.prototype["@@iterator"]=function(){return this.entries()},c.prototype[E]=function(){return this.entries()},c.prototype._find=function(a,i){if(!N(this._cacheKey,a)){this._cacheIndex=-1;for(var o=0;o<this._keys.length;o++)if(N(this._keys[o],a)){this._cacheIndex=o;break}}return this._cacheIndex<0&&i&&(this._cacheIndex=this._keys.length,this._keys.push(a),this._values.push(void 0)),this._cacheIndex},c})();return n;function u(c,a){return c}function v(c,a){return a}function w(c,a){return[c,a]}}function Ae(){var e=(function(){function t(){this._map=new G}return Object.defineProperty(t.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),t.prototype.has=function(r){return this._map.has(r)},t.prototype.add=function(r){return this._map.set(r,r),this},t.prototype.delete=function(r){return this._map.delete(r)},t.prototype.clear=function(){this._map.clear()},t.prototype.keys=function(){return this._map.keys()},t.prototype.values=function(){return this._map.keys()},t.prototype.entries=function(){return this._map.entries()},t.prototype["@@iterator"]=function(){return this.keys()},t.prototype[E]=function(){return this.keys()},t})();return e}function Fe(){var e=16,t=k.create(),r=n();return(function(){function a(){this._key=n()}return a.prototype.has=function(i){var o=u(i,!1);return o!==void 0?k.has(o,this._key):!1},a.prototype.get=function(i){var o=u(i,!1);return o!==void 0?k.get(o,this._key):void 0},a.prototype.set=function(i,o){var f=u(i,!0);return f[this._key]=o,this},a.prototype.delete=function(i){var o=u(i,!1);return o!==void 0?delete o[this._key]:!1},a.prototype.clear=function(){this._key=n()},a})();function n(){var a;do a="@@WeakMap@@"+c();while(k.has(t,a));return t[a]=!0,a}function u(a,i){if(!b.call(a,r)){if(!i)return;Object.defineProperty(a,r,{value:k.create()})}return a[r]}function v(a,i){for(var o=0;o<i;++o)a[o]=Math.random()*255|0;return a}function w(a){if(typeof Uint8Array=="function"){var i=new Uint8Array(a);return typeof crypto<"u"?crypto.getRandomValues(i):typeof msCrypto<"u"?msCrypto.getRandomValues(i):v(i,a),i}return v(new Array(a),a)}function c(){var a=w(e);a[6]=a[6]&79|64,a[8]=a[8]&191|128;for(var i="",o=0;o<e;++o){var f=a[o];(o===4||o===6||o===8)&&(i+="-"),f<16&&(i+="0"),i+=f.toString(16).toLowerCase()}return i}}function B(e){return e.__=void 0,delete e.__,e}})})(le||(le={}))});H();var qe=$e(he(),1);import T from"process";async function Be(){let M=se(T.env),{server:_,closeAll:p}=ce(M);await new Promise((g,j)=>{_.once("error",j),_.listen(M.port,z,g)}),T.stdout.write(`inference-proxy listening on http://${z}:${M.port}/v1 (control plane ${M.baseUrl}, org API ${M.apiUrl}, catalog oracle ${M.catalog?"on":"off"})
|
|
2
|
+
import{i as z,j as se,p as ce,q as de}from"../chunk-AJYWEXQZ.js";import"../chunk-FVFF5EWK.js";import"../chunk-F2TEK34X.js";import"../chunk-M6ICU4F5.js";import"../chunk-G3NMGP4N.js";import"../chunk-XHIIEA6Z.js";import"../chunk-5NXM4IO3.js";import"../chunk-CWJRDBDC.js";import"../chunk-UVAY7Q7Z.js";import{a as We,b as $e,c as H}from"../chunk-YSFSRI3D.js";var he=We(()=>{"use strict";H();var le;(function(M){(function(_){var p=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:A(),b=g(M);typeof p.Reflect<"u"&&(b=g(p.Reflect,b)),_(b,p),typeof p.Reflect>"u"&&(p.Reflect=M);function g(P,x){return function(k,C){Object.defineProperty(P,k,{configurable:!0,writable:!0,value:C}),x&&x(k,C)}}function j(){try{return Function("return this;")()}catch{}}function E(){try{return(0,eval)("(function() { return this; })()")}catch{}}function A(){return j()||E()}})(function(_,p){var b=Object.prototype.hasOwnProperty,g=typeof Symbol=="function",j=g&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",E=g&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",A=typeof Object.create=="function",P={__proto__:[]}instanceof Array,x=!A&&!P,k={create:A?function(){return B(Object.create(null))}:P?function(){return B({__proto__:null})}:function(){return B({})},has:x?function(e,t){return b.call(e,t)}:function(e,t){return t in e},get:x?function(e,t){return b.call(e,t)?e[t]:void 0}:function(e,t){return e[t]}},C=Object.getPrototypeOf(Function),G=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:De(),U=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:Ae(),W=typeof WeakMap=="function"?WeakMap:Fe(),I=g?Symbol.for("@reflect-metadata:registry"):void 0,F=xe(),L=Ce(F);function ve(e,t,r,n){if(s(r)){if(!te(e))throw new TypeError;if(!re(t))throw new TypeError;return ke(e,t)}else{if(!te(e))throw new TypeError;if(!h(t))throw new TypeError;if(!h(n)&&!s(n)&&!S(n))throw new TypeError;return S(n)&&(n=void 0),r=O(r),Te(e,t,r,n)}}_("decorate",ve);function ye(e,t){function r(n,u){if(!h(n))throw new TypeError;if(!s(u)&&!Re(u))throw new TypeError;Q(e,t,n,u)}return r}_("metadata",ye);function we(e,t,r,n){if(!h(r))throw new TypeError;return s(n)||(n=O(n)),Q(e,t,r,n)}_("defineMetadata",we);function pe(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=O(r)),Z(e,t,r)}_("hasMetadata",pe);function _e(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=O(r)),$(e,t,r)}_("hasOwnMetadata",_e);function Me(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=O(r)),q(e,t,r)}_("getMetadata",Me);function ge(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=O(r)),J(e,t,r)}_("getOwnMetadata",ge);function me(e,t){if(!h(e))throw new TypeError;return s(t)||(t=O(t)),X(e,t)}_("getMetadataKeys",me);function be(e,t){if(!h(e))throw new TypeError;return s(t)||(t=O(t)),Y(e,t)}_("getOwnMetadataKeys",be);function Oe(e,t,r){if(!h(t))throw new TypeError;if(s(r)||(r=O(r)),!h(t))throw new TypeError;s(r)||(r=O(r));var n=D(t,r,!1);return s(n)?!1:n.OrdinaryDeleteMetadata(e,t,r)}_("deleteMetadata",Oe);function ke(e,t){for(var r=e.length-1;r>=0;--r){var n=e[r],u=n(t);if(!s(u)&&!S(u)){if(!re(u))throw new TypeError;t=u}}return t}function Te(e,t,r,n){for(var u=e.length-1;u>=0;--u){var v=e[u],w=v(t,r,n);if(!s(w)&&!S(w)){if(!h(w))throw new TypeError;n=w}}return n}function Z(e,t,r){var n=$(e,t,r);if(n)return!0;var u=V(t);return S(u)?!1:Z(e,u,r)}function $(e,t,r){var n=D(t,r,!1);return s(n)?!1:ee(n.OrdinaryHasOwnMetadata(e,t,r))}function q(e,t,r){var n=$(e,t,r);if(n)return J(e,t,r);var u=V(t);if(!S(u))return q(e,u,r)}function J(e,t,r){var n=D(t,r,!1);if(!s(n))return n.OrdinaryGetOwnMetadata(e,t,r)}function Q(e,t,r,n){var u=D(r,n,!0);u.OrdinaryDefineOwnMetadata(e,t,r,n)}function X(e,t){var r=Y(e,t),n=V(e);if(n===null)return r;var u=X(n,t);if(u.length<=0)return r;if(r.length<=0)return u;for(var v=new U,w=[],c=0,a=r;c<a.length;c++){var i=a[c],o=v.has(i);o||(v.add(i),w.push(i))}for(var f=0,d=u;f<d.length;f++){var i=d[f],o=v.has(i);o||(v.add(i),w.push(i))}return w}function Y(e,t){var r=D(e,t,!1);return r?r.OrdinaryOwnMetadataKeys(e,t):[]}function K(e){if(e===null)return 1;switch(typeof e){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return e===null?1:6;default:return 6}}function s(e){return e===void 0}function S(e){return e===null}function Ee(e){return typeof e=="symbol"}function h(e){return typeof e=="object"?e!==null:typeof e=="function"}function Pe(e,t){switch(K(e)){case 0:return e;case 1:return e;case 2:return e;case 3:return e;case 4:return e;case 5:return e}var r=t===3?"string":t===5?"number":"default",n=ne(e,j);if(n!==void 0){var u=n.call(e,r);if(h(u))throw new TypeError;return u}return Ie(e,r==="default"?"number":r)}function Ie(e,t){if(t==="string"){var r=e.toString;if(R(r)){var n=r.call(e);if(!h(n))return n}var u=e.valueOf;if(R(u)){var n=u.call(e);if(!h(n))return n}}else{var u=e.valueOf;if(R(u)){var n=u.call(e);if(!h(n))return n}var v=e.toString;if(R(v)){var n=v.call(e);if(!h(n))return n}}throw new TypeError}function ee(e){return!!e}function Se(e){return""+e}function O(e){var t=Pe(e,3);return Ee(t)?t:Se(t)}function te(e){return Array.isArray?Array.isArray(e):e instanceof Object?e instanceof Array:Object.prototype.toString.call(e)==="[object Array]"}function R(e){return typeof e=="function"}function re(e){return typeof e=="function"}function Re(e){switch(K(e)){case 3:return!0;case 4:return!0;default:return!1}}function N(e,t){return e===t||e!==e&&t!==t}function ne(e,t){var r=e[t];if(r!=null){if(!R(r))throw new TypeError;return r}}function ae(e){var t=ne(e,E);if(!R(t))throw new TypeError;var r=t.call(e);if(!h(r))throw new TypeError;return r}function ie(e){return e.value}function oe(e){var t=e.next();return t.done?!1:t}function fe(e){var t=e.return;t&&t.call(e)}function V(e){var t=Object.getPrototypeOf(e);if(typeof e!="function"||e===C||t!==C)return t;var r=e.prototype,n=r&&Object.getPrototypeOf(r);if(n==null||n===Object.prototype)return t;var u=n.constructor;return typeof u!="function"||u===e?t:u}function je(){var e;!s(I)&&typeof p.Reflect<"u"&&!(I in p.Reflect)&&typeof p.Reflect.defineMetadata=="function"&&(e=Ge(p.Reflect));var t,r,n,u=new W,v={registerProvider:w,getProvider:a,setProvider:o};return v;function w(f){if(!Object.isExtensible(v))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case e===f:break;case s(t):t=f;break;case t===f:break;case s(r):r=f;break;case r===f:break;default:n===void 0&&(n=new U),n.add(f);break}}function c(f,d){if(!s(t)){if(t.isProviderFor(f,d))return t;if(!s(r)){if(r.isProviderFor(f,d))return t;if(!s(n))for(var l=ae(n);;){var y=oe(l);if(!y)return;var m=ie(y);if(m.isProviderFor(f,d))return fe(l),m}}}if(!s(e)&&e.isProviderFor(f,d))return e}function a(f,d){var l=u.get(f),y;return s(l)||(y=l.get(d)),s(y)&&(y=c(f,d),s(y)||(s(l)&&(l=new G,u.set(f,l)),l.set(d,y))),y}function i(f){if(s(f))throw new TypeError;return t===f||r===f||!s(n)&&n.has(f)}function o(f,d,l){if(!i(l))throw new Error("Metadata provider not registered.");var y=a(f,d);if(y!==l){if(!s(y))return!1;var m=u.get(f);s(m)&&(m=new G,u.set(f,m)),m.set(d,l)}return!0}}function xe(){var e;return!s(I)&&h(p.Reflect)&&Object.isExtensible(p.Reflect)&&(e=p.Reflect[I]),s(e)&&(e=je()),!s(I)&&h(p.Reflect)&&Object.isExtensible(p.Reflect)&&Object.defineProperty(p.Reflect,I,{enumerable:!1,configurable:!1,writable:!1,value:e}),e}function Ce(e){var t=new W,r={isProviderFor:function(i,o){var f=t.get(i);return s(f)?!1:f.has(o)},OrdinaryDefineOwnMetadata:w,OrdinaryHasOwnMetadata:u,OrdinaryGetOwnMetadata:v,OrdinaryOwnMetadataKeys:c,OrdinaryDeleteMetadata:a};return F.registerProvider(r),r;function n(i,o,f){var d=t.get(i),l=!1;if(s(d)){if(!f)return;d=new G,t.set(i,d),l=!0}var y=d.get(o);if(s(y)){if(!f)return;if(y=new G,d.set(o,y),!e.setProvider(i,o,r))throw d.delete(o),l&&t.delete(i),new Error("Wrong provider for target.")}return y}function u(i,o,f){var d=n(o,f,!1);return s(d)?!1:ee(d.has(i))}function v(i,o,f){var d=n(o,f,!1);if(!s(d))return d.get(i)}function w(i,o,f,d){var l=n(f,d,!0);l.set(i,o)}function c(i,o){var f=[],d=n(i,o,!1);if(s(d))return f;for(var l=d.keys(),y=ae(l),m=0;;){var ue=oe(y);if(!ue)return f.length=m,f;var He=ie(ue);try{f[m]=He}catch(Ue){try{fe(y)}finally{throw Ue}}m++}}function a(i,o,f){var d=n(o,f,!1);if(s(d)||!d.delete(i))return!1;if(d.size===0){var l=t.get(o);s(l)||(l.delete(f),l.size===0&&t.delete(l))}return!0}}function Ge(e){var t=e.defineMetadata,r=e.hasOwnMetadata,n=e.getOwnMetadata,u=e.getOwnMetadataKeys,v=e.deleteMetadata,w=new W,c={isProviderFor:function(a,i){var o=w.get(a);return!s(o)&&o.has(i)?!0:u(a,i).length?(s(o)&&(o=new U,w.set(a,o)),o.add(i),!0):!1},OrdinaryDefineOwnMetadata:t,OrdinaryHasOwnMetadata:r,OrdinaryGetOwnMetadata:n,OrdinaryOwnMetadataKeys:u,OrdinaryDeleteMetadata:v};return c}function D(e,t,r){var n=F.getProvider(e,t);if(!s(n))return n;if(r){if(F.setProvider(e,t,L))return L;throw new Error("Illegal state.")}}function De(){var e={},t=[],r=(function(){function c(a,i,o){this._index=0,this._keys=a,this._values=i,this._selector=o}return c.prototype["@@iterator"]=function(){return this},c.prototype[E]=function(){return this},c.prototype.next=function(){var a=this._index;if(a>=0&&a<this._keys.length){var i=this._selector(this._keys[a],this._values[a]);return a+1>=this._keys.length?(this._index=-1,this._keys=t,this._values=t):this._index++,{value:i,done:!1}}return{value:void 0,done:!0}},c.prototype.throw=function(a){throw this._index>=0&&(this._index=-1,this._keys=t,this._values=t),a},c.prototype.return=function(a){return this._index>=0&&(this._index=-1,this._keys=t,this._values=t),{value:a,done:!0}},c})(),n=(function(){function c(){this._keys=[],this._values=[],this._cacheKey=e,this._cacheIndex=-2}return Object.defineProperty(c.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),c.prototype.has=function(a){return this._find(a,!1)>=0},c.prototype.get=function(a){var i=this._find(a,!1);return i>=0?this._values[i]:void 0},c.prototype.set=function(a,i){var o=this._find(a,!0);return this._values[o]=i,this},c.prototype.delete=function(a){var i=this._find(a,!1);if(i>=0){for(var o=this._keys.length,f=i+1;f<o;f++)this._keys[f-1]=this._keys[f],this._values[f-1]=this._values[f];return this._keys.length--,this._values.length--,N(a,this._cacheKey)&&(this._cacheKey=e,this._cacheIndex=-2),!0}return!1},c.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=e,this._cacheIndex=-2},c.prototype.keys=function(){return new r(this._keys,this._values,u)},c.prototype.values=function(){return new r(this._keys,this._values,v)},c.prototype.entries=function(){return new r(this._keys,this._values,w)},c.prototype["@@iterator"]=function(){return this.entries()},c.prototype[E]=function(){return this.entries()},c.prototype._find=function(a,i){if(!N(this._cacheKey,a)){this._cacheIndex=-1;for(var o=0;o<this._keys.length;o++)if(N(this._keys[o],a)){this._cacheIndex=o;break}}return this._cacheIndex<0&&i&&(this._cacheIndex=this._keys.length,this._keys.push(a),this._values.push(void 0)),this._cacheIndex},c})();return n;function u(c,a){return c}function v(c,a){return a}function w(c,a){return[c,a]}}function Ae(){var e=(function(){function t(){this._map=new G}return Object.defineProperty(t.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),t.prototype.has=function(r){return this._map.has(r)},t.prototype.add=function(r){return this._map.set(r,r),this},t.prototype.delete=function(r){return this._map.delete(r)},t.prototype.clear=function(){this._map.clear()},t.prototype.keys=function(){return this._map.keys()},t.prototype.values=function(){return this._map.keys()},t.prototype.entries=function(){return this._map.entries()},t.prototype["@@iterator"]=function(){return this.keys()},t.prototype[E]=function(){return this.keys()},t})();return e}function Fe(){var e=16,t=k.create(),r=n();return(function(){function a(){this._key=n()}return a.prototype.has=function(i){var o=u(i,!1);return o!==void 0?k.has(o,this._key):!1},a.prototype.get=function(i){var o=u(i,!1);return o!==void 0?k.get(o,this._key):void 0},a.prototype.set=function(i,o){var f=u(i,!0);return f[this._key]=o,this},a.prototype.delete=function(i){var o=u(i,!1);return o!==void 0?delete o[this._key]:!1},a.prototype.clear=function(){this._key=n()},a})();function n(){var a;do a="@@WeakMap@@"+c();while(k.has(t,a));return t[a]=!0,a}function u(a,i){if(!b.call(a,r)){if(!i)return;Object.defineProperty(a,r,{value:k.create()})}return a[r]}function v(a,i){for(var o=0;o<i;++o)a[o]=Math.random()*255|0;return a}function w(a){if(typeof Uint8Array=="function"){var i=new Uint8Array(a);return typeof crypto<"u"?crypto.getRandomValues(i):typeof msCrypto<"u"?msCrypto.getRandomValues(i):v(i,a),i}return v(new Array(a),a)}function c(){var a=w(e);a[6]=a[6]&79|64,a[8]=a[8]&191|128;for(var i="",o=0;o<e;++o){var f=a[o];(o===4||o===6||o===8)&&(i+="-"),f<16&&(i+="0"),i+=f.toString(16).toLowerCase()}return i}}function B(e){return e.__=void 0,delete e.__,e}})})(le||(le={}))});H();var qe=$e(he(),1);import T from"process";async function Be(){let M=se(T.env),{server:_,closeAll:p}=ce(M);await new Promise((g,j)=>{_.once("error",j),_.listen(M.port,z,g)}),T.stdout.write(`inference-proxy listening on http://${z}:${M.port}/v1 (control plane ${M.baseUrl}, org API ${M.apiUrl}, catalog oracle ${M.catalog?"on":"off"})
|
|
3
3
|
`);let b=async g=>{T.stdout.write(`inference-proxy: ${g} \u2014 draining
|
|
4
4
|
`),await de(_,p)};await new Promise(g=>{T.once("SIGINT",()=>{b("SIGINT").finally(g)}),T.once("SIGTERM",()=>{b("SIGTERM").finally(g)})})}Be().then(()=>T.exit(0),M=>{T.stderr.write(`inference-proxy: ${String(M instanceof Error?M.stack??M.message:M)}
|
|
5
5
|
`),T.exit(1)});
|
package/dist/hosted/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,b as o,c as t,d as n,e as p,f as s,g as T,h as E,i as _,j as a,k as S,l as f,m as x,n as i,o as y,p as O}from"../chunk-
|
|
1
|
+
import{a as e,b as o,c as t,d as n,e as p,f as s,g as T,h as E,i as _,j as a,k as S,l as f,m as x,n as i,o as y,p as O}from"../chunk-AJYWEXQZ.js";import"../chunk-FVFF5EWK.js";import"../chunk-F2TEK34X.js";import"../chunk-M6ICU4F5.js";import"../chunk-G3NMGP4N.js";import"../chunk-XHIIEA6Z.js";import"../chunk-5NXM4IO3.js";import"../chunk-CWJRDBDC.js";import"../chunk-UVAY7Q7Z.js";import{c as r}from"../chunk-YSFSRI3D.js";r();export{_ as BIND_HOST,o as ControlPlaneUnavailableError,T as DEFAULT_PORT,p as MAX_CACHED_KEYS,S as MAX_TENANTS,n as ORG_BINDING_TTL_MS,s as OrgResolver,e as ProxyAuthError,y as READINESS_TIMEOUT_MS,i as READINESS_TTL_MS,E as SERVE_FUNCTION,x as TenantRegistry,t as bearerFrom,O as createHostedProxy,a as resolveHostedConfig,f as tenantSubject};
|