@urun-sh/openai 0.6.31 → 0.6.32
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-5473ZAQ4.js +17 -0
- package/dist/chunk-7OH7UJ2H.js +60 -0
- package/dist/chunk-CAR4AEQJ.js +1 -0
- package/dist/{chunk-76BZLCGT.js → chunk-GL7EWL3V.js} +1 -1
- package/dist/chunk-KTMDSM7F.js +2 -0
- package/dist/chunk-L6HTHDVV.js +1 -0
- package/dist/chunk-LM4E5YM2.js +19 -0
- package/dist/chunk-M3YMNU5P.js +6 -0
- package/dist/chunk-NN6TQQUG.js +1 -0
- package/dist/chunk-OOCRI7ZM.js +6 -0
- package/dist/chunk-PAYCMH5F.js +1 -0
- package/dist/{responses-turn-BGb_XPOa.d.ts → composite-DMawda97.d.ts} +125 -83
- package/dist/{responses-turn-DXrwiPJh.d.cts → composite-DtBebn0Y.d.cts} +545 -309
- package/dist/gemini-live.cjs +2 -2
- package/dist/gemini-live.d.cts +85 -105
- package/dist/gemini-live.d.ts +48 -48
- package/dist/gemini-live.js +1 -1
- package/dist/hosted/bin.cjs +56 -42
- package/dist/hosted/bin.js +4 -22
- package/dist/hosted/index.cjs +52 -38
- package/dist/hosted/index.d.cts +230 -7
- package/dist/hosted/index.d.ts +114 -3
- package/dist/hosted/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{models-DUdx_Y6X.d.cts → models-D7F0bLJ3.d.cts} +14 -0
- package/dist/{models-DUdx_Y6X.d.ts → models-D7F0bLJ3.d.ts} +6 -0
- package/dist/pi-extension/index.cjs +6 -6
- package/dist/pi-extension/index.js +1 -1
- package/dist/pi-extension/standalone.cjs +33 -33
- package/dist/pooler/bin.cjs +335 -0
- package/dist/pooler/bin.js +316 -0
- package/dist/proxy/cli.cjs +58 -53
- package/dist/proxy/cli.js +1 -1
- package/dist/proxy/conformance-probe.cjs +1 -0
- package/dist/proxy/conformance-probe.js +1 -0
- package/dist/proxy/index.cjs +31 -28
- package/dist/proxy/index.d.cts +315 -167
- package/dist/proxy/index.d.ts +85 -53
- package/dist/proxy/index.js +1 -1
- package/package.json +14 -4
- package/dist/chunk-4MI2TNQS.js +0 -62
- package/dist/chunk-7SAW4IL4.js +0 -2
- package/dist/chunk-7V2JKPIG.js +0 -1
- package/dist/chunk-CUDFHFNX.js +0 -4
- package/dist/chunk-HZC2SKKI.js +0 -8
- package/dist/chunk-K23AZPI4.js +0 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import{a as De,c as fe}from"./chunk-YSFSRI3D.js";var Ge=De(()=>{"use strict";fe();var ue;(function(z){(function(_){var p=typeof globalThis=="object"?globalThis:typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:x(),O=m(z);typeof p.Reflect<"u"&&(O=m(p.Reflect,O)),_(O,p),typeof p.Reflect>"u"&&(p.Reflect=z);function m(T,I){return function(b,j){Object.defineProperty(T,b,{configurable:!0,writable:!0,value:j}),I&&I(b,j)}}function G(){try{return Function("return this;")()}catch{}}function k(){try{return(0,eval)("(function() { return this; })()")}catch{}}function x(){return G()||k()}})(function(_,p){var O=Object.prototype.hasOwnProperty,m=typeof Symbol=="function",G=m&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",k=m&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",x=typeof Object.create=="function",T={__proto__:[]}instanceof Array,I=!x&&!T,b={create:x?function(){return V(Object.create(null))}:T?function(){return V({__proto__:null})}:function(){return V({})},has:I?function(e,t){return O.call(e,t)}:function(e,t){return t in e},get:I?function(e,t){return O.call(e,t)?e[t]:void 0}:function(e,t){return e[t]}},j=Object.getPrototypeOf(Function),R=typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:Ie(),A=typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:je(),F=typeof WeakMap=="function"?WeakMap:Re(),E=m?Symbol.for("@reflect-metadata:registry"):void 0,D=Ee(),B=Pe(D);function oe(e,t,r,n){if(s(r)){if(!$(e))throw new TypeError;if(!K(t))throw new TypeError;return _e(e,t)}else{if(!$(e))throw new TypeError;if(!h(t))throw new TypeError;if(!h(n)&&!s(n)&&!P(n))throw new TypeError;return P(n)&&(n=void 0),r=g(r),Me(e,t,r,n)}}_("decorate",oe);function se(e,t){function r(n,o){if(!h(n))throw new TypeError;if(!s(o)&&!ke(o))throw new TypeError;q(e,t,n,o)}return r}_("metadata",se);function ce(e,t,r,n){if(!h(r))throw new TypeError;return s(n)||(n=g(n)),q(e,t,r,n)}_("defineMetadata",ce);function de(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=g(r)),L(e,t,r)}_("hasMetadata",de);function le(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=g(r)),U(e,t,r)}_("hasOwnMetadata",le);function he(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=g(r)),N(e,t,r)}_("getMetadata",he);function ve(e,t,r){if(!h(t))throw new TypeError;return s(r)||(r=g(r)),Z(e,t,r)}_("getOwnMetadata",ve);function ye(e,t){if(!h(e))throw new TypeError;return s(t)||(t=g(t)),J(e,t)}_("getMetadataKeys",ye);function we(e,t){if(!h(e))throw new TypeError;return s(t)||(t=g(t)),Q(e,t)}_("getOwnMetadataKeys",we);function pe(e,t,r){if(!h(t))throw new TypeError;if(s(r)||(r=g(r)),!h(t))throw new TypeError;s(r)||(r=g(r));var n=C(t,r,!1);return s(n)?!1:n.OrdinaryDeleteMetadata(e,t,r)}_("deleteMetadata",pe);function _e(e,t){for(var r=e.length-1;r>=0;--r){var n=e[r],o=n(t);if(!s(o)&&!P(o)){if(!K(o))throw new TypeError;t=o}}return t}function Me(e,t,r,n){for(var o=e.length-1;o>=0;--o){var v=e[o],w=v(t,r,n);if(!s(w)&&!P(w)){if(!h(w))throw new TypeError;n=w}}return n}function L(e,t,r){var n=U(e,t,r);if(n)return!0;var o=H(t);return P(o)?!1:L(e,o,r)}function U(e,t,r){var n=C(t,r,!1);return s(n)?!1:Y(n.OrdinaryHasOwnMetadata(e,t,r))}function N(e,t,r){var n=U(e,t,r);if(n)return Z(e,t,r);var o=H(t);if(!P(o))return N(e,o,r)}function Z(e,t,r){var n=C(t,r,!1);if(!s(n))return n.OrdinaryGetOwnMetadata(e,t,r)}function q(e,t,r,n){var o=C(r,n,!0);o.OrdinaryDefineOwnMetadata(e,t,r,n)}function J(e,t){var r=Q(e,t),n=H(e);if(n===null)return r;var o=J(n,t);if(o.length<=0)return r;if(r.length<=0)return o;for(var v=new A,w=[],c=0,a=r;c<a.length;c++){var i=a[c],f=v.has(i);f||(v.add(i),w.push(i))}for(var u=0,d=o;u<d.length;u++){var i=d[u],f=v.has(i);f||(v.add(i),w.push(i))}return w}function Q(e,t){var r=C(e,t,!1);return r?r.OrdinaryOwnMetadataKeys(e,t):[]}function X(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 P(e){return e===null}function ge(e){return typeof e=="symbol"}function h(e){return typeof e=="object"?e!==null:typeof e=="function"}function be(e,t){switch(X(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=ee(e,G);if(n!==void 0){var o=n.call(e,r);if(h(o))throw new TypeError;return o}return Oe(e,r==="default"?"number":r)}function Oe(e,t){if(t==="string"){var r=e.toString;if(S(r)){var n=r.call(e);if(!h(n))return n}var o=e.valueOf;if(S(o)){var n=o.call(e);if(!h(n))return n}}else{var o=e.valueOf;if(S(o)){var n=o.call(e);if(!h(n))return n}var v=e.toString;if(S(v)){var n=v.call(e);if(!h(n))return n}}throw new TypeError}function Y(e){return!!e}function me(e){return""+e}function g(e){var t=be(e,3);return ge(t)?t:me(t)}function $(e){return Array.isArray?Array.isArray(e):e instanceof Object?e instanceof Array:Object.prototype.toString.call(e)==="[object Array]"}function S(e){return typeof e=="function"}function K(e){return typeof e=="function"}function ke(e){switch(X(e)){case 3:return!0;case 4:return!0;default:return!1}}function W(e,t){return e===t||e!==e&&t!==t}function ee(e,t){var r=e[t];if(r!=null){if(!S(r))throw new TypeError;return r}}function te(e){var t=ee(e,k);if(!S(t))throw new TypeError;var r=t.call(e);if(!h(r))throw new TypeError;return r}function re(e){return e.value}function ne(e){var t=e.next();return t.done?!1:t}function ae(e){var t=e.return;t&&t.call(e)}function H(e){var t=Object.getPrototypeOf(e);if(typeof e!="function"||e===j||t!==j)return t;var r=e.prototype,n=r&&Object.getPrototypeOf(r);if(n==null||n===Object.prototype)return t;var o=n.constructor;return typeof o!="function"||o===e?t:o}function Te(){var e;!s(E)&&typeof p.Reflect<"u"&&!(E in p.Reflect)&&typeof p.Reflect.defineMetadata=="function"&&(e=Se(p.Reflect));var t,r,n,o=new F,v={registerProvider:w,getProvider:a,setProvider:f};return v;function w(u){if(!Object.isExtensible(v))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case e===u:break;case s(t):t=u;break;case t===u:break;case s(r):r=u;break;case r===u:break;default:n===void 0&&(n=new A),n.add(u);break}}function c(u,d){if(!s(t)){if(t.isProviderFor(u,d))return t;if(!s(r)){if(r.isProviderFor(u,d))return t;if(!s(n))for(var l=te(n);;){var y=ne(l);if(!y)return;var M=re(y);if(M.isProviderFor(u,d))return ae(l),M}}}if(!s(e)&&e.isProviderFor(u,d))return e}function a(u,d){var l=o.get(u),y;return s(l)||(y=l.get(d)),s(y)&&(y=c(u,d),s(y)||(s(l)&&(l=new R,o.set(u,l)),l.set(d,y))),y}function i(u){if(s(u))throw new TypeError;return t===u||r===u||!s(n)&&n.has(u)}function f(u,d,l){if(!i(l))throw new Error("Metadata provider not registered.");var y=a(u,d);if(y!==l){if(!s(y))return!1;var M=o.get(u);s(M)&&(M=new R,o.set(u,M)),M.set(d,l)}return!0}}function Ee(){var e;return!s(E)&&h(p.Reflect)&&Object.isExtensible(p.Reflect)&&(e=p.Reflect[E]),s(e)&&(e=Te()),!s(E)&&h(p.Reflect)&&Object.isExtensible(p.Reflect)&&Object.defineProperty(p.Reflect,E,{enumerable:!1,configurable:!1,writable:!1,value:e}),e}function Pe(e){var t=new F,r={isProviderFor:function(i,f){var u=t.get(i);return s(u)?!1:u.has(f)},OrdinaryDefineOwnMetadata:w,OrdinaryHasOwnMetadata:o,OrdinaryGetOwnMetadata:v,OrdinaryOwnMetadataKeys:c,OrdinaryDeleteMetadata:a};return D.registerProvider(r),r;function n(i,f,u){var d=t.get(i),l=!1;if(s(d)){if(!u)return;d=new R,t.set(i,d),l=!0}var y=d.get(f);if(s(y)){if(!u)return;if(y=new R,d.set(f,y),!e.setProvider(i,f,r))throw d.delete(f),l&&t.delete(i),new Error("Wrong provider for target.")}return y}function o(i,f,u){var d=n(f,u,!1);return s(d)?!1:Y(d.has(i))}function v(i,f,u){var d=n(f,u,!1);if(!s(d))return d.get(i)}function w(i,f,u,d){var l=n(u,d,!0);l.set(i,f)}function c(i,f){var u=[],d=n(i,f,!1);if(s(d))return u;for(var l=d.keys(),y=te(l),M=0;;){var ie=ne(y);if(!ie)return u.length=M,u;var Ce=re(ie);try{u[M]=Ce}catch(xe){try{ae(y)}finally{throw xe}}M++}}function a(i,f,u){var d=n(f,u,!1);if(s(d)||!d.delete(i))return!1;if(d.size===0){var l=t.get(f);s(l)||(l.delete(u),l.size===0&&t.delete(l))}return!0}}function Se(e){var t=e.defineMetadata,r=e.hasOwnMetadata,n=e.getOwnMetadata,o=e.getOwnMetadataKeys,v=e.deleteMetadata,w=new F,c={isProviderFor:function(a,i){var f=w.get(a);return!s(f)&&f.has(i)?!0:o(a,i).length?(s(f)&&(f=new A,w.set(a,f)),f.add(i),!0):!1},OrdinaryDefineOwnMetadata:t,OrdinaryHasOwnMetadata:r,OrdinaryGetOwnMetadata:n,OrdinaryOwnMetadataKeys:o,OrdinaryDeleteMetadata:v};return c}function C(e,t,r){var n=D.getProvider(e,t);if(!s(n))return n;if(r){if(D.setProvider(e,t,B))return B;throw new Error("Illegal state.")}}function Ie(){var e={},t=[],r=(function(){function c(a,i,f){this._index=0,this._keys=a,this._values=i,this._selector=f}return c.prototype["@@iterator"]=function(){return this},c.prototype[k]=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 f=this._find(a,!0);return this._values[f]=i,this},c.prototype.delete=function(a){var i=this._find(a,!1);if(i>=0){for(var f=this._keys.length,u=i+1;u<f;u++)this._keys[u-1]=this._keys[u],this._values[u-1]=this._values[u];return this._keys.length--,this._values.length--,W(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,o)},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[k]=function(){return this.entries()},c.prototype._find=function(a,i){if(!W(this._cacheKey,a)){this._cacheIndex=-1;for(var f=0;f<this._keys.length;f++)if(W(this._keys[f],a)){this._cacheIndex=f;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 o(c,a){return c}function v(c,a){return a}function w(c,a){return[c,a]}}function je(){var e=(function(){function t(){this._map=new R}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[k]=function(){return this.keys()},t})();return e}function Re(){var e=16,t=b.create(),r=n();return(function(){function a(){this._key=n()}return a.prototype.has=function(i){var f=o(i,!1);return f!==void 0?b.has(f,this._key):!1},a.prototype.get=function(i){var f=o(i,!1);return f!==void 0?b.get(f,this._key):void 0},a.prototype.set=function(i,f){var u=o(i,!0);return u[this._key]=f,this},a.prototype.delete=function(i){var f=o(i,!1);return f!==void 0?delete f[this._key]:!1},a.prototype.clear=function(){this._key=n()},a})();function n(){var a;do a="@@WeakMap@@"+c();while(b.has(t,a));return t[a]=!0,a}function o(a,i){if(!O.call(a,r)){if(!i)return;Object.defineProperty(a,r,{value:b.create()})}return a[r]}function v(a,i){for(var f=0;f<i;++f)a[f]=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="",f=0;f<e;++f){var u=a[f];(f===4||f===6||f===8)&&(i+="-"),u<16&&(i+="0"),i+=u.toString(16).toLowerCase()}return i}}function V(e){return e.__=void 0,delete e.__,e}})})(ue||(ue={}))});export{Ge as a};
|
|
2
|
+
/*! Bundled license information:
|
|
3
|
+
|
|
4
|
+
reflect-metadata/Reflect.js:
|
|
5
|
+
(*! *****************************************************************************
|
|
6
|
+
Copyright (C) Microsoft. All rights reserved.
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
8
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
9
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
12
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
13
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
14
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
15
|
+
|
|
16
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
17
|
+
and limitations under the License.
|
|
18
|
+
***************************************************************************** *)
|
|
19
|
+
*/
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{g as m}from"./chunk-OOCRI7ZM.js";import{c as h}from"./chunk-YSFSRI3D.js";h();import w from"os";import U from"path";import{fileURLToPath as _}from"url";import{format as S}from"util";var f="0.6.32";var y=4141,R=f,J={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 P(e,t="openai"){if(t==="anthropic")return{ANTHROPIC_BASE_URL:`http://127.0.0.1:${e}`,ANTHROPIC_API_KEY:"urun-local"};let n=`http://127.0.0.1:${e}/v1`;return{OPENAI_BASE_URL:n,OPENAI_API_BASE:n,OPENAI_API_KEY:"urun-local"}}function B(e,t,n){let r={...e,...P(t,n)};return delete r.URUN_API_KEY,delete r.URUN_JWT,r}function K(e,t,n){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"'],o=n.indexOf("--"),s=o===-1?n:n.slice(0,o),a=s.some(p=>p==="-m"||p==="--model"||p.startsWith("--model=")),i=n[0]==="exec",d=s.includes("--skip-git-repo-check"),u=i&&!d?["exec","--skip-git-repo-check",...n.slice(1)]:n;return[...r,...a?[]:["-m",t],...u]}function M(e,t){return t.some(r=>r==="--model"||r==="--provider"||r.startsWith("--model=")||r.startsWith("--provider="))?t:["--provider","urun","--model",e,...t]}function F(e,t){return t.some(r=>r==="--model"||r==="--provider"||r.startsWith("--model=")||r.startsWith("--provider="))?t:["--model",`urun/${e}`,...t]}function H(e,t,n){let r=(e.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=_(new URL("../pi-extension/standalone.cjs",t));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 x(e){let t=Number(e);if(!Number.isInteger(t)||t<0)throw new Error(`--port needs a non-negative integer (0 = OS-assigned ephemeral), got ${e}`);return t}function V(e){if(e[0]!=="--port")return null;let t=x(e[1]);return e.splice(0,2),t}function X(e){let t=e.indexOf("--port");if(t===-1)return y;let n=x(e[t+1]);return e.splice(t,2),n}function z(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 c(e,t){let n=(e[t]??"").trim();if(!n)throw new Error(`${t} 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 Q(e){let t=N(c(e,"URUN_BASE_URL")),n=c(e,"URUN_ORG_ID"),r=c(e,"URUN_APP"),o=(e.URUN_FUNCTION??"serve").trim()||"serve",s=(e.URUN_API_URL??"").trim(),a=s?g(s,"URUN_API_URL"):m,i=(e.URUN_JWT??"").trim();if(i)return{baseUrl:t,orgId:n,appId:r,fnName:o,apiUrl:a,auth:{lane:"jwt",jwt:i}};let d=(e.URUN_API_KEY??"").trim();if(d){let u=(e.URUN_GATEWAY_URL??"").trim(),p=u?g(u):void 0;return{baseUrl:t,orgId:n,appId:r,fnName:o,apiUrl: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 N(e,t="URUN_BASE_URL"){if(/\/v1\/*$/.test(new URL(e).pathname))throw new Error(`${t} 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 g(e,t="URUN_GATEWAY_URL"){let n=new URL(e),r=n.hostname==="localhost"||n.hostname==="127.0.0.1"||n.hostname==="[::1]";if(n.protocol!=="https:"&&!r)throw new Error(`${t} must be https (got ${e}) \u2014 the org API key rides the request's Authorization header`);return e}function Z(e){return{app:e.appId,org:e.orgId,fn:e.fnName,base_url:e.baseUrl,proxy_version:R}}function I(e,t){return e.app===t.app&&e.org===t.org&&e.fn===t.fn&&e.base_url===t.base_url&&e.proxy_version===t.proxy_version}var k=250;async function A(e,t=k){try{let n=await fetch(`http://127.0.0.1:${e}/stats`,{signal:AbortSignal.timeout(t)});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:a,base_url:i,proxy_version:d}=r;return typeof o!="string"||typeof s!="string"||typeof a!="string"||typeof i!="string"||typeof d!="string"?null:{app:o,org:s,fn:a,base_url:i,proxy_version:d}}catch{return null}}var v=2e3;async function O(e,t=v){try{let n=await fetch(`http://127.0.0.1:${e}/v1/models`,{signal:AbortSignal.timeout(t)});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 ee(e,t,n=y,r=v){if(e!=null)return{mode:"spawn",port:e};let o=await A(n);if(o!==null&&I(o,t)){let s=await O(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 te(e,t=w.homedir()){return U.join(t,".urun","logs",`compat-proxy-${e}.log`)}var l=["log","info","warn","error","debug","trace"];function ne(e,t=process,n=console){let r=t.stdout.write,o=t.stderr.write,s=(i,...d)=>e.write(i,...d);t.stdout.write=s,t.stderr.write=s;let a=Object.fromEntries(l.map(i=>[i,n[i]]));for(let i of l)n[i]=(...d)=>{e.write(`${S(...d)}
|
|
2
|
+
`)};return()=>{t.stdout.write=r,t.stderr.write=o;for(let i of l)n[i]=a[i]}}var j=new Set(["EPIPE","EIO","EBADF","ENXIO"]);function E(e){let t=e?.code;return typeof t=="string"&&j.has(t)}function re(e,t){try{return e.write(t),!0}catch(n){if(E(n))return!1;throw n}}function oe(e){let t={stdout:!1,stderr:!1},n=[];for(let r of["stdout","stderr"]){let o=e.streams[r],s=a=>{E(a)&&(t[r]=!0);let i=a?.code;try{e.note(`${new Date().toISOString()} urun compat: process.${r} died (${String(i??(a instanceof Error?a.message:a))}) \u2014 the terminal is gone; launcher output continues in this log only
|
|
3
|
+
`)}catch{}};o.on("error",s),n.push([o,s])}return{isDead:r=>t[r],uninstall:()=>{for(let[r,o]of n)r.off("error",o)}}}function ie(e){let t=n=>{let r=n instanceof Error?`${n.stack??`${n.name}: ${n.message}`}`:String(n);try{e.appendSync(e.logPath,`${new Date().toISOString()} launcher crashed (in-process proxy): ${r}
|
|
4
|
+
`)}catch{}e.restore();try{e.writeStderr(`urun compat: the in-process proxy crashed (${n instanceof Error?n.message:String(n)}) \u2014 terminating the harness (its backend is gone); details: ${e.logPath}
|
|
5
|
+
`)}catch(o){try{e.appendSync(e.logPath,`${new Date().toISOString()} urun compat: the crash line could not reach stderr (${String(o?.code??o)}) \u2014 the terminal is gone
|
|
6
|
+
`)}catch{}}e.killChild(),e.exit(1)};return e.proc.on("uncaughtException",t),e.proc.on("unhandledRejection",t),()=>{e.proc.off("uncaughtException",t),e.proc.off("unhandledRejection",t)}}function se(e,t){let n="pass --port 0 for an OS-assigned ephemeral port";return t?`port ${e} is held by another urun-openai proxy serving app ${t.app} (org ${t.org}, fn ${t.fn}, version ${t.proxy_version}) \u2014 reuse it by pointing your agent at http://127.0.0.1:${e}, or ${n}`:`port ${e} is already in use and does not answer the urun-openai /stats identity probe \u2014 ${n}`}export{J as a,P as b,B as c,K as d,M as e,F as f,H as g,V as h,X as i,z as j,Q as k,N as l,g as m,Z as n,A as o,ee as p,te as q,ne as r,re as s,oe as t,ie as u,se as v};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as i}from"./chunk-YSFSRI3D.js";i();function m(e,t,o,n){let s=e.response??{},r={request_id:o,consumer_id:n,stream:!0,kind:"chat",messages:t};return typeof s.instructions=="string"&&(r.instructions=s.instructions),Array.isArray(s.modalities)&&(r.modalities=s.modalities),typeof s.temperature=="number"&&(r.temperature=s.temperature),typeof s.max_output_tokens=="number"&&(r.max_output_tokens=s.max_output_tokens),s.tools!==void 0&&(r.tools=s.tools),r}function y(e,t,o){let n={request_id:t,consumer_id:o,stream:!!e.stream,kind:"responses",input:e.input};return e.model&&(n.model=e.model),e.tools!==void 0&&(n.tools=e.tools),e.tool_choice!==void 0&&(n.tool_choice=e.tool_choice),typeof e.temperature=="number"&&(n.temperature=e.temperature),typeof e.max_output_tokens=="number"&&(n.max_output_tokens=e.max_output_tokens),typeof e.top_p=="number"&&(n.top_p=e.top_p),Array.isArray(e.stop)&&e.stop.length>0&&(n.stop=e.stop),typeof e.reasoning_effort=="string"&&(n.reasoning_effort=e.reasoning_effort),typeof e.instructions=="string"&&(n.instructions=e.instructions),e.chat_template_kwargs!==void 0&&(n.chat_template_kwargs=e.chat_template_kwargs),e.response_format!==void 0&&(n.response_format=e.response_format),typeof e.voice=="string"&&(n.voice=e.voice),typeof e.language=="string"&&(n.language=e.language),n}i();function _(e){if(e instanceof Error)return{type:"error",error:{type:"urun_error",code:e.name||null,message:e.message}};if(e&&typeof e=="object"&&e.t==="error"){let t=e,o=t.body??{},n=o.error,s=n?.message??o.message??`unreadable serve error body: ${JSON.stringify(t.body??null)}`;return{type:"error",error:{type:n?.type??"urun_error",code:t.code??n?.code??null,message:s}}}return{type:"error",error:{type:"urun_error",code:null,message:String(e)}}}i();i();var k="llm-resp";async function*w(e,t){let o=`resp_${e}`,n=new Map;for await(let s of t){let r=s;if(r.t==="delta"){if(typeof r.delta=="string"&&(yield{type:"response.output_text.delta",item_id:o,delta:r.delta}),typeof r.reasoning=="string"&&(yield{type:"response.reasoning_text.delta",item_id:o,delta:r.reasoning}),Array.isArray(r.tool_calls))for(let a of r.tool_calls){let c=typeof a.index=="number"?a.index:0,u=n.get(c)??{};a.id&&(u.id=a.id),a.function?.name&&(u.name=a.function.name),n.set(c,u),yield{type:"response.function_call_arguments.delta",item_id:`fc_${e}_${c}`,tool_index:c,call_id:u.id,name:u.name,delta:a.function?.arguments??""}}}else if(r.t==="response"){yield{type:"response.completed",response:{id:o,status:"completed",...r.body}};return}else if(r.t==="error"){yield _(r);return}}}async function*g(e,t){let o=`${k}:${t}`;yield{type:"response.created",response:{id:`resp_${t}`,status:"in_progress"}};try{yield*w(t,e.stream(o).messages())}finally{try{e.doc("llm").set({requests:{[t]:null}})}catch{}}}i();var f=class e{constructor(t,o=e.DEFAULT_DOC_SYNC_GATE_TIMEOUT_MS){this.session=t;this.docSyncTimeoutMs=o;this.sessionTag=t.sessionId??globalThis.crypto.randomUUID()}session;docSyncTimeoutMs;sessionTag;static DEFAULT_DOC_SYNC_GATE_TIMEOUT_MS=15e3;get consumerId(){return this.session.consumerId}async ensureDocSynced(){let t=this.session.doc("llm");if(t.synced===!0||typeof t.onSynced!="function")return;let o;await new Promise((s,r)=>{let a=t.onSynced(()=>{clearTimeout(o),s()});o=setTimeout(()=>{a(),r(new Error(`[urun] llm doc plane never synced within ${this.docSyncTimeoutMs}ms \u2014 the request envelope write is withheld rather than raced into a possibly-lost pre-sync write (resumed-attach first-write-lost, prod-usw2 2026-09-23)`))},this.docSyncTimeoutMs)})}write(t){t.session_tag=this.sessionTag,this.session.doc("llm").set({requests:{[t.request_id]:{payload:t,consumer_id:t.consumer_id,stream:t.stream}}})}sendResponses(t,o){return this.writeGated(o,()=>{let n=y(t,o,this.consumerId);return this.write(n),g(this.session,o)})}sendResponseCreate(t,o,n){return this.writeGated(n,()=>{let s=m(t,o,n,this.consumerId);return this.write(s),g(this.session,n)})}async writeGated(t,o){try{await this.ensureDocSynced()}catch(n){throw new Error(`[urun] responses dial ${t} aborted before its envelope write: ${n instanceof Error?n.message:String(n)}`)}return o()}};export{m as a,y as b,_ as c,w as d,g as e,f};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{c as w}from"./chunk-YSFSRI3D.js";w();w();var p=class extends Error{},_e=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;function ve(n){if(typeof n!="string")return!1;let e=_e.exec(n);if(!e)return!1;let[,t,r,o,i,l,d]=e.map(Number);if(!Number.isFinite(Date.parse(n)))return!1;let a=new Date(Date.UTC(t,r-1,o,i,l,d));return a.getUTCFullYear()===t&&a.getUTCMonth()===r-1&&a.getUTCDate()===o&&a.getUTCHours()===i&&a.getUTCMinutes()===l&&a.getUTCSeconds()===d}function Re(n){if(n===null||typeof n!="object")return null;let e=n.shared;if(e==null)return null;if(typeof e!="object")throw new p(`catalog "shared" block is ${typeof e}, expected an object`);let{shared_org_id:t,endpoints:r,regions:o,compliance:i}=e;if(typeof t!="string"||t==="")throw new p(`catalog "shared" block has no shared_org_id: ${JSON.stringify(e)}`);if(!Array.isArray(r))throw new p(`catalog "shared" block endpoints is not an array: ${JSON.stringify(e)}`);let l=r.map((d,a)=>{if(d===null||typeof d!="object")throw new p(`catalog shared endpoints[${a}] is not an object: ${JSON.stringify(d)}`);let s=d;for(let c of["model_id","variant","app_slug","function"])if(typeof s[c]!="string"||s[c].length===0)throw new p(`catalog shared endpoints[${a}] (${JSON.stringify(s)}) has no valid "${c}"`);if(s.app_id!==void 0&&s.app_id!==null&&(typeof s.app_id!="string"||s.app_id===""))throw new p(`catalog shared endpoints[${a}] (${s.model_id}:${s.variant}) carries a malformed "app_id": ${JSON.stringify(s.app_id)}`);let u=(c,g)=>{if(s[c]!==void 0&&s[c]!==null&&!g)throw new p(`catalog shared endpoints[${a}] (${s.model_id}:${s.variant}) carries a malformed "${c}": ${JSON.stringify(s[c])}`)};u("ready",typeof s.ready=="boolean"),u("ready_runtimes",typeof s.ready_runtimes=="number"&&Number.isInteger(s.ready_runtimes)&&s.ready_runtimes>=0),u("ready_since",ve(s.ready_since));for(let c of["model_id","variant"]){let g=s[c];if(g.includes(":"))throw new p(`catalog shared endpoints[${a}] has "${c}" containing ":" (${JSON.stringify(g)}) \u2014 the external identity <model_id>:<variant> would be unparseable (resolveSharedModel splits at the LAST colon); platform catalog defect`)}return u("output_free",typeof s.output_free=="boolean"),s});if(o!=null&&(!Array.isArray(o)||!o.every(d=>typeof d=="string"&&d.length>0)))throw new p(`catalog "shared" block regions is malformed: ${JSON.stringify(o)}`);if(i!=null){let d=i;if(typeof i!="object"||typeof d.zdr!="boolean"||typeof d.hipaa!="boolean")throw new p(`catalog "shared" block compliance is malformed (operator-declared zdr + hipaa booleans required): ${JSON.stringify(i)}`);for(let a of Object.keys(d))if(a!=="zdr"&&a!=="hipaa")throw new p(`catalog "shared" block compliance carries "${a}" beyond the declared zdr/hipaa contract: ${JSON.stringify(i)}`)}return l.length===0?null:{shared_org_id:t,endpoints:l,...o!=null?{regions:o}:{},...i!=null?{compliance:i}:{}}}function S(n){return[...n.endpoints].sort((e,t)=>e.model_id.localeCompare(t.model_id)||e.variant.localeCompare(t.variant))}function D(n,e,t){let r=(e??"").trim();if(r==="")return null;let o=r,i=t,l=r.lastIndexOf(":");l>0&&(o=r.slice(0,l),i=r.slice(l+1));let d=n.endpoints.filter(s=>s.model_id===o);if(d.length===0)return null;if(i!==void 0){let s=d.find(u=>u.variant===i);return s?{shared_org_id:n.shared_org_id,endpoint:s}:null}if(d.length===1)return{shared_org_id:n.shared_org_id,endpoint:d[0]};let a=d.filter(s=>s.compat_default===!0);if(a.length!==1)throw new p(`shared model "${o}" has ${a.length} compat_default rows (exactly one required) among variants ${d.map(s=>s.variant).join(", ")}`);return{shared_org_id:n.shared_org_id,endpoint:a[0]}}async function We(n){let e=n.fetchImpl??fetch,t=`${n.apiUrl.replace(/\/+$/,"")}/catalog`,r=await e(t,{headers:{Authorization:`Bearer ${n.apiKey}`,Accept:"application/json"}});if(!r.ok)throw new p(`catalog read failed: GET ${t} \u2192 ${r.status}`);return Re(await r.json())}w();function h(n){return n.toLowerCase().replace(/[^\p{L}\p{N}-]/gu,"-").replace(/^-+|-+$/g,"")}w();var _=class extends Error{name="ModelPriceError"},j="per_million_input_tokens",U="per_million_output_tokens",Q="model_id,variant,unit,price_usd,effective_at,expires_at",Y={per_request:!0,per_minute:!0,per_output_unit:!0},be=5e3;function Se(n,e){let t=typeof n=="number"?n:typeof n=="string"&&n.trim()!==""?Number(n):NaN;if(!Number.isFinite(t)||t<0)throw new _(`${e}: price_usd is not a non-negative number (${JSON.stringify(n)})`);return t}function X(n,e,t){let r=typeof n=="string"?Date.parse(n):NaN;if(!Number.isFinite(r))throw new _(`${e}: ${t} is not a parseable timestamp (${JSON.stringify(n)})`);return r}function Te(n,e,t){return n===null?null:X(n,e,t)}function $e(n,e){if(n===j)return"input";if(n===U)return"output";if(typeof n=="string"&&Object.hasOwn(Y,n))return null;throw new _(`${e}: unit ${JSON.stringify(n)} is neither a per-token rate (${j} | ${U}) nor a known GPU-time unit (${Object.keys(Y).join(" | ")}). Skipping it would publish no prices forever with no signal \u2014 if ENG-317 named the per-token units differently, teach this module the new names instead`)}function ke(n,e){let t=n.reduce((o,i)=>i.effective_at>o.effective_at?i:o,n[0]),r=n.find(o=>o.effective_at===t.effective_at&&o.usd!==t.usd);return r?{reason:`two ${e} rates are effective at the same instant (${t.usd} and ${r.usd} USD/Mtok), so the winner would be read order \u2014 this model is served UNPRICED until one of them is expired; expire one of them`}:{rate:t}}function K(n,e){return`${n}\0${e}`}function Pe(n){if(!Array.isArray(n))throw new _(`model_prices read is not an array: ${JSON.stringify(n)}`);let e=[];for(let t=0;t<n.length;t++){let r=n[t],o=`model_prices[${t}]`;if(r===null||typeof r!="object"||Array.isArray(r))throw new _(`${o} is not an object: ${JSON.stringify(r)}`);let i=r;for(let s of Q.split(","))if(!Object.hasOwn(i,s))throw new _(`${o} has no "${s}" column: ${JSON.stringify(i)}`);let l=$e(i.unit,o);if(l===null)continue;let d=i.model_id;if(typeof d!="string"||d==="")throw new _(`${o} has no model_id (${JSON.stringify(i)})`);let a=i.variant;if(!(a===null||typeof a=="string"&&a!==""))throw new _(`${o} has a non-string variant (${JSON.stringify(a)})`);e.push({model_id:d,variant:a,side:l,usd:Se(i.price_usd,o),effective_at:X(i.effective_at,o,"effective_at"),expires_at:Te(i.expires_at,o,"expires_at")})}return e}function Z(n,e=Date.now(),t){let r=new Map,o=new Map;for(let a of n){if(a.effective_at>e||a.expires_at!==null&&a.expires_at<=e)continue;let s=r.get(a.model_id);s||(s=new Map,r.set(a.model_id,s),o.set(a.model_id,new Map));let u=a.variant??"",c=s.get(u);c||(c={input:[],output:[]},s.set(u,c),o.get(a.model_id).set(u,a.variant)),c[a.side].push({effective_at:a.effective_at,usd:a.usd})}let i=[],l=[];for(let[a,s]of r){let u=s.get(""),c=(g,f,v)=>{let m=g&&g.length>0?g:u?.[f];if(!m||m.length===0)return null;let y=ke(m,f);return"reason"in y?y:y.rate.usd===0?f==="output"&&v!==null&&t?.has(K(a,v))?y.rate:{reason:`the ${f} rate in force is zero, which publishes as "free" and would top :cheapest routing \u2014 this model is served UNPRICED; delete the row if the model is not token-priced, or set a real rate`}:y.rate};for(let[g,f]of o.get(a)){let v=s.get(g),m=c(v?.input,"input",f),y=c(v?.output,"output",f);if(m!==null&&"reason"in m){l.push({model_id:a,variant:f,reason:m.reason});continue}if(y!==null&&"reason"in y){l.push({model_id:a,variant:f,reason:y.reason});continue}m===null||y===null||i.push({model_id:a,variant:f,pricing:{input:m.usd,output:y.usd}})}}let d=(a,s)=>a.model_id.localeCompare(s.model_id)||(a.variant===null?1:0)-(s.variant===null?1:0)||(a.variant??"").localeCompare(s.variant??"");return{prices:i.sort(d),refusals:l.sort(d)}}function A(n,e,t){if(t.refusals.some(i=>i.model_id===n&&i.variant===e))return null;let r=t.prices.find(i=>i.model_id===n&&i.variant===e);if(r)return r.pricing;if(t.refusals.some(i=>i.model_id===n&&i.variant===null))return null;let o=t.prices.find(i=>i.model_id===n&&i.variant===null);return o?o.pricing:null}var E={prices:[],refusals:[]};async function et(n){let e=n.fetchImpl??fetch,t=`${j},${U}`,r=await e(`${n.catalogUrl}/model_prices?select=${Q}&unit=in.(${t})`,{headers:{apikey:n.anonKey,Authorization:`Bearer ${n.anonKey}`},signal:AbortSignal.timeout(be)});if(!r.ok)throw new Error(`model_prices fetch failed: ${r.status}`);return Pe(await r.json())}w();var st="/partners/openrouter/models",xe={chat:!0,code:!0,agent:!0,vl:!0},ee={int4:"int4",int8:"int8",fp4:"fp4",mxfp4:"mxfp4",nvfp4:"nvfp4",fp6:"fp6",fp8:"fp8",mxfp8:"mxfp8",fp16:"fp16",bf16:"bf16",fp32:"fp32"};function Ce(n){let e=n.toLowerCase();return Object.hasOwn(ee,e)?ee[e]:null}var te={"us-east-1":"US","us-east-2":"US","us-west-1":"US","us-west-2":"US","ca-central-1":"CA","ca-west-1":"CA","sa-east-1":"BR","eu-central-1":"DE","eu-central-2":"CH","eu-west-1":"IE","eu-west-2":"GB","eu-west-3":"FR","eu-north-1":"SE","eu-south-1":"IT","eu-south-2":"ES","af-south-1":"ZA","ap-east-1":"HK","ap-south-1":"IN","ap-south-2":"IN","ap-northeast-1":"JP","ap-northeast-2":"KR","ap-northeast-3":"JP","ap-southeast-1":"SG","ap-southeast-2":"AU","ap-southeast-3":"ID","ap-southeast-4":"AU","ap-southeast-5":"MY","ap-southeast-7":"TH","il-central-1":"IL","me-central-1":"AE","me-south-1":"BH"};function Ae(n,e){if(!n||n.length===0)return[];let t=[],r=[];for(let o of n){let i=Object.hasOwn(te,o)?te[o]:null;if(i===null){r.push(o);continue}t.some(d=>d.region===o)||t.push({country_code:i,region:o})}return r.length>0&&e(`urun openrouter doc: shared block region(s) ${r.join(", ")} have no country mapping \u2014 omitted from datacenters, never guessed`),t}var ne={qwen:"Qwen",qwen1:"Qwen",qwen2:"Qwen",qwen3:"Qwen",gemma:"Gemma",diffusiongemma:"Gemma",gpt:"GPT",glm:"GLM",deepseek:"DeepSeek",mistral:"Mistral"},re={2:"Llama2",3:"Llama3"};function Ee(n){if(!n)return null;let e=n.split("@")[0],t=e.indexOf("/"),r=(t===-1?e:e.slice(t+1)).toLowerCase().split(/[^a-z0-9]+/).filter(o=>o.length>0);for(let o=0;o<r.length;o+=1){let i=r[o];if(Object.hasOwn(ne,i))return ne[i];let l=r[o+1];if(i==="llama"&&l!==void 0&&Object.hasOwn(re,l))return re[l];if(i==="phi"&&l!==void 0&&/^\d/.test(l))return"Phi"}return null}var Me=["context_length","max_model_len"];function Oe(n){let e=Me.map(t=>n.engine_args?.[t]).filter(t=>typeof t=="number"&&Number.isFinite(t)&&t>0);return e.length===0?null:e.every(t=>t===e[0])?e[0]:null}function N(n){let e=n.map(Oe),t=e[0];return t==null?null:e.every(r=>r===t)?t:null}function Ie(n){let e=n.engine_args?.reasoning_parser;return e==null||e===""?!1:typeof e=="string"?!0:null}function J(n){if(n.length===0)return null;let e=n.map(Ie),t=e[0];return t==null?null:e.every(r=>r===t)?t:null}function B(n,e){let t=e.filter(o=>o.serve_app_slug===n);return new Set(t.map(o=>o.model_id)).size===1?t:[]}function Ne(n,e){let t=e.filter(i=>h(`${i.model_id}-${i.variant}`)===n);if(t.length>0)return M(t);let r=e.filter(i=>h(i.model_id)===n);if(r.length>0)return M(r);let o=B(n,e);return o.length>0?M(o):null}function M(n){let e=n[0];return n.every(r=>r.model_id===e.model_id&&r.variant===e.variant)?{row:n.length===1?e:Le(n),matches:n}:null}function Le(n){let e=n[0],t=r=>n.every(o=>(o[r]??void 0)===(e[r]??void 0))?e[r]:void 0;return{model_id:e.model_id,variant:e.variant,gpu_spec:t("gpu_spec"),engine:t("engine"),task:t("task"),description:t("description"),size_gb:t("size_gb"),hf_repo:t("hf_repo"),updated_at:t("updated_at")}}var T=class extends Error{name="ModelCreatedError"};function $(n){if(n.length===0)return 0;let e=`${n[0].model_id}:${n[0].variant}`,t=n.map(u=>u.created_at??void 0);if(t.some(u=>u===void 0))throw new T(`model "${e}" is catalog-joined but not every model_catalog row carries created_at \u2014 the catalog generator stamps every authored row (urun-infra#2951); the listing refuses to publish a created: 0 that lies about the model's appearance date`);let r=t[0];if(!t.every(u=>u===r))throw new T(`model "${e}" has model_catalog rows that disagree on created_at ("${[...new Set(t)].join('", "')}") \u2014 created is per model id and never changes; disagreement is catalog drift`);let o=/^(\d{4})-(\d{2})-(\d{2})$/.exec(r);if(o===null)throw new T(`model "${e}" carries a malformed created_at ("${r}") \u2014 expected an ISO calendar date (YYYY-MM-DD), the model_catalog column's own shape`);let i=Number(o[1]),l=Number(o[2]),d=Number(o[3]),a=Date.UTC(i,l-1,d),s=new Date(a);if(s.getUTCFullYear()!==i||s.getUTCMonth()!==l-1||s.getUTCDate()!==d)throw new T(`model "${e}" carries a malformed created_at ("${r}") \u2014 not a real calendar date`);return a/1e3}function b(n){let e={id:n.id,object:n.object,created:n.created,owned_by:n.owned_by,...n.context_length!==void 0?{context_length:n.context_length}:{},...n.pricing!==void 0?{pricing:n.pricing}:{},...n.voices!==void 0?{voices:n.voices}:{},...n.capabilities!==void 0?{capabilities:n.capabilities}:{}};return"image_modes"in n?{...e,image_modes:n.image_modes}:e}function L(n,e,t){let r=Ne(n,e);if(!r)return b({id:n,object:"model",created:0,owned_by:"urun"});let{row:o,matches:i}=r,l=N(i),d=$(i),a=A(o.model_id,o.variant,t),s=se(o,i),u=J(i);return b({id:n,object:"model",created:d,owned_by:"urun",...l!==null?{context_length:l}:{},...a!==null?{pricing:a}:{},...s.published.length>0?{voices:[...s.published]}:{},...u!==null?{capabilities:{reasoning:u}}:{}})}var Fe=["Vivian","Serena","Uncle_Fu","Dylan","Eric","Ryan","Aiden","Ono_Anna","Sohee"];function se(n,e){if((n.task??void 0)!=="tts")return{published:[],defect:null};let t=e.map(i=>i.engine_args?.voices),r=t[0];if(Array.isArray(r)&&r.length>0&&r.every(i=>typeof i=="string")&&t.every(i=>Array.isArray(i)&&i.length===r.length&&i.every((l,d)=>l===r[d])))return{published:[...r],defect:null};let o=t.some(i=>i!=null)?`the catalog's engine_args.voices for ${n.model_id}:${n.variant} could not be vouched (empty, malformed, or not an identical non-empty string array on every GPU placement)`:null;return n.model_id==="qwen3-tts-customvoice"?{published:[...Fe],defect:o}:{published:[],defect:o}}function z(n){let e=n.length>0?M(n):null;return e===null?{published:[],defect:null}:se(e.row,e.matches)}function oe(n){let e=/^(\d+)(?:\.(\d+))?(?:e([+-]?\d+))?$/.exec(String(n));if(!e)throw new Error(`unrenderable per-token price: ${String(n)}`);let[,t="",r="",o=""]=e,i=t+r,l=t.length-6+(o===""?0:Number(o));return(l<=0?`0.${"0".repeat(-l)}${i}`:`${i.slice(0,l)}.${i.slice(l).padEnd(1,"0")}`).replace(/(\.\d*?)0+$/,"$1").replace(/\.$/,"")}function ie(n){return{input:[{type:"prompt",unit:"token",cost_usd:oe(n.input)}],output:[{type:"completion",unit:"token",cost_usd:oe(n.output)}]}}function De(n,e,t,r){if(e.length===0)return null;let o=M(e);if(!o)return null;let{row:i,matches:l}=o;if(!i.task||xe[i.task]!==!0)return null;let d=N(l),a=A(i.model_id,i.variant,t),s=Ee(i.hf_repo),u={temperature:{type:"range",min:0,max:2},top_p:{type:"range",min:0,max:1},stop:{type:"array",max_items:4}};return d!==null&&(u.max_tokens={type:"integer",min:1,max:d,unit:"token"}),{schema_version:"2.4",id:`${i.model_id}:${i.variant}`,name:`${i.model_id}:${i.variant}`,created:$(l),quantization:Ce(i.variant),...s!==null?{tokenizer:s}:{},description:i.description??"",hugging_face_id:i.hf_repo?i.hf_repo.split("@")[0]??i.hf_repo:"",is_ready:n.ready===!0&&a!==null,is_free:!1,input_modalities:[{type:"text",...d!==null?{supported_inputs:{max_context_length:{value:d,unit:"token"}}}:{},...a?{pricing:ie(a).input}:{}},...i.task==="vl"?[{type:"image"}]:[]],output_modalities:[{type:"text",streaming:!0,supported_parameters:u,...a?{pricing:ie(a).output}:{}}],...r.datacenters.length>0?{datacenters:r.datacenters}:{},...r.compliance?{compliance:r.compliance}:{}}}function ae(n,e,t,r){let o=r??(s=>console.warn(s.trimEnd())),i=n?S(n):[];if(i.length>0){let s=i.filter(u=>u.ready===void 0);if(s.length===i.length)o("urun openrouter doc: readiness seam absent from shared block; declaring every endpoint not ready");else if(s.length>0){let u=s.map(c=>`${c.model_id}:${c.variant}`).join(", ");o(`urun openrouter doc: readiness seam partially deployed \u2014 endpoints ${u} carry no ready field and are declared not ready`)}}let l={datacenters:Ae(n?.regions,o),compliance:n?.compliance??null},d=[],a=new Set;for(let s of i){let u=`${s.model_id}:${s.variant}`;if(a.has(u))continue;a.add(u);let c=De(s,e.filter(g=>g.model_id===s.model_id&&g.variant===s.variant),t,l);c&&d.push(c)}return{data:d}}w();var le={delta:!0,final:!0,turn_start:!0,turn_end:!0,turn_eager_end:!0,turn_resumed:!0},k=class extends Error{constructor(e){super(e),this.name="TurnLaneDecodeError"}};function de(n){let e=n.t;if(typeof e!="string"||!(e in le))throw new k(`the "stt" transcript lane delivered an unknown turn kind ${JSON.stringify(e??null)} \u2014 known kinds: ${Object.keys(le).join(", ")}`);let t={kind:e};return typeof n.delta=="string"&&(t.text=n.delta),typeof n.start_ms=="number"&&Number.isFinite(n.start_ms)&&(t.startMs=n.start_ms),t}function je(n){if(typeof n=="string"){let e;try{e=JSON.parse(n)}catch(t){throw new k(`the "stt" transcript lane delivered a string payload that is not valid JSON (${t instanceof Error?t.message:String(t)})`)}if(e===null||typeof e!="object"||Array.isArray(e))throw new k(`the "stt" transcript lane delivered a JSON string that is not an object (${JSON.stringify(e)})`);return de(e)}if(n===null||typeof n!="object"||Array.isArray(n))throw new k(`the "stt" transcript lane delivered a non-object payload (${Array.isArray(n)?"array":typeof n}) \u2014 transcript events are {"t":\u2026,"delta":\u2026,"start_ms":\u2026} objects (or their JSON serialization)`);return de(n)}function ue(n){return n.reason instanceof Error?n.reason:new Error("the turn-lane consumer aborted")}async function Ue(n,e){return e.aborted?"aborted":await new Promise(t=>{let r=!1,o=l=>{r||(r=!0,e.removeEventListener("abort",i),t(l))},i=()=>o("aborted");e.addEventListener("abort",i,{once:!0}),n.then(()=>o("pulled"),()=>o("pulled"))})}function dt(n,e){let t=n.stream("stt");if(typeof t.messages!="function")throw new Error("openSessionTurnLane: session.stream('stt') has no messages() \u2014 the named-DATA stream consume seam (@urun-sh/core SessionStream.messages, contract \xA75) is required for the engine's own turn/transcript lane");async function*r(){let o=t.messages()[Symbol.asyncIterator]();try{for(;;){if(e!==void 0&&e.aborted)throw ue(e);let i=o.next();if(e!==void 0&&await Ue(i,e)==="aborted")throw i.catch(()=>{}),ue(e);let l=await i;if(l.done)return;yield je(l.value)}}finally{let i=o.return?.();i&&i.catch(()=>{})}}return r()}var wt="https://api.urun.sh/v1",P=class extends Error{},I=class extends Error{},G="urs1.";function ce(n,e){return G+Buffer.from(JSON.stringify([n,e]),"utf8").toString("base64url")}function Je(n){if(!n.startsWith(G))return null;try{let e=JSON.parse(Buffer.from(n.slice(G.length),"base64url").toString("utf8"));if(Array.isArray(e)&&typeof e[0]=="string"&&typeof e[1]=="string")return{app:e[0],key:e[1]}}catch{}return null}async function _t(n){let e=n.fetchImpl??fetch,t=`${n.apiUrl.replace(/\/+$/,"")}/apps`,r=await e(t,{headers:{Authorization:`Bearer ${n.apiKey}`,Accept:"application/json"}});if(!r.ok)throw new Error(`org apps listing failed: GET ${t} \u2192 ${r.status}`);let o=await r.json();if(!Array.isArray(o.apps))throw new Error(`org apps listing returned no "apps" array (GET ${t})`);if(o.truncated===!0)throw new Error(`org apps listing was truncated (GET ${t} returned ${o.apps.length} of more) \u2014 model discovery would silently omit deployed apps`);return o.apps}function pe(n){if(n.length===0)return[];if(!n.every(t=>(t.task??void 0)==="image"))return[];let e=qe(n);return e===null?[]:[e]}function Be(n){if(n==null)return null;if(typeof n!="object"||Array.isArray(n))return process.stderr.write(`[serving-pool] skipping malformed engine_args.pool (not an object): ${JSON.stringify(n)}
|
|
2
|
+
`),null;let e={},t=[["min",0],["max",1],["in_flight_cap",1],["idle_grace_s",0],["warm_wait_s",1]],r=!1;for(let[o,i]of t){let l=n[o];if(l==null)continue;let d=typeof l=="number"?l:typeof l=="string"?Number.parseInt(l,10):NaN;if(!Number.isInteger(d)||d<i){process.stderr.write(`[serving-pool] skipping engine_args.pool (malformed ${String(o)}=${JSON.stringify(l)})
|
|
3
|
+
`),r=!0;break}e[o]=d}return r||Object.keys(e).length===0?null:e}function ze(n,e){if(n.length===0)return null;let t;return e.modelId&&(t=n.find(r=>r.model_id===e.modelId&&(!e.variant||r.variant===e.variant))),t||(t=n.find(r=>r.serve_app_slug===e.appSlug||h(`${r.model_id}-${r.variant}`)===e.appSlug||h(r.model_id)===e.appSlug)),t?Be(t.engine_args?.pool):null}function H(n,e,t,r,o){if(!o)throw new p(`shared model "${n}" cannot be gated: no catalog oracle is configured, and a shared endpoint's modality must come from the model's OWN model_catalog row \u2014 never a default`);if(e===void 0||t===void 0)throw new p(`shared model "${n}" resolved without a catalog id + variant to join on`);let i=r.filter(l=>l.model_id===e&&l.variant===t);if(i.length===0)throw new p(`shared model "${n}" names endpoint ${e}:${t} but the catalog has no model_catalog row for it \u2014 the shared block cannot vouch a modality from nothing`);return i}function ge(n,e){if(!e.every(o=>(o.task??void 0)==="image"))return[];let t=e.map(o=>o.engine_args?.expects_image),r=t[0];if(typeof r!="boolean"||!t.every(o=>o===r))throw new p(`shared image model "${n}" does not vouch an explicit image mode: its ${e.length} model_catalog row(s) carry engine_args.expects_image ${JSON.stringify(t)} \u2014 the shared lane requires a boolean (false = pure text-to-image generation, true = edit) and refuses to silently default to edit`);return[r===!1?"generation":"edit"]}var ye="shared:",fe="speech:";function q(n){return n.sharedApp?ye+n.appSlug:n.appSlug}function he(n){return typeof n.modelId=="string"&&typeof n.variant=="string"?{kind:"catalog",model_id:n.modelId,variant:n.variant}:{kind:"not-a-catalog-model",model:n.appSlug}}function V(n,e){let t=e.filter(i=>h(`${i.model_id}-${i.variant}`)===n);if(t.length>0)return t;let r=e.filter(i=>h(i.model_id)===n);return new Set(r.map(i=>i.variant)).size===1?r:[]}function He(n){let e=n.engine_args?.expects_image;return e==null?"edit":e===!1?"generation":e===!0?"edit":null}function qe(n){let e=n.map(He),t=e[0];return t!=null&&e.every(r=>r===t)?t:null}var Ge={stt:"stt",tts:"tts"};function R(n){if(n.length===0)return null;let e=n[0].task??void 0,t=n.every(o=>(o.task??void 0)===e),r=e===void 0?void 0:Ge[e];return r!==void 0?t?r:null:t&&n.every(o=>o.engine_args?.realtime===!0)?"decision":null}function we(n,e){let t=V(n,e);return t.length>0?t:B(n,e)}function O(n,e){return we(n.appSlug,e)}function Ve(n){let e=n.map(r=>r.engine_args?.transcript_stream).filter(r=>r!=null);if(e.length===0)return"stt";let t=e[0];if(typeof t!="string"||t.length===0||!e.every(r=>r===t))throw new p(`the model's model_catalog rows cannot vow one engine_args.transcript_stream (found ${JSON.stringify(e)}) \u2014 the field must be a non-empty string agreeing across placements; the realtime transcription lane refuses to guess the stream the engine writes`);return t}var F=6e4,me=class{constructor(e){this.opts=e}opts;pool=new Map;apps={current:null};rows={current:null};shared={current:null};async swr(e,t,r){let o=e.current;return o&&Date.now()-o.at<r?o.value:o?(o.refreshing||(o.refreshing=(async()=>{try{e.current={at:Date.now(),value:await t()}}catch{}finally{o.refreshing=void 0}})()),o.value):(e.current={at:Date.now(),value:await t()},e.current.value)}seed(e,t){this.pool.set(e,Promise.resolve(t))}async deployedApps(){return this.opts.listApps?this.swr(this.apps,()=>this.opts.listApps(),this.opts.appsTtlMs??F):[]}async sharedBlock(){return this.opts.shared?this.swr(this.shared,()=>this.opts.shared(),this.opts.appsTtlMs??F):null}async catalogRows(){return this.opts.listCatalog?this.swr(this.rows,()=>this.opts.listCatalog(),this.opts.appsTtlMs??F):[]}pricesCache=null;async priceRows(){if(!this.opts.listPrices)return[];let e=this.opts.appsTtlMs??F;if(this.pricesCache&&Date.now()-this.pricesCache.at<e)return this.pricesCache.rows;let t=await this.opts.listPrices();return this.pricesCache={at:Date.now(),rows:t},t}async pricesForListing(e){let t;try{t=await this.priceRows()}catch(o){if(o instanceof _)throw o;return this.warn(`urun /v1/models: the per-token price surface could not be read (${String(o instanceof Error?o.message:o)}) \u2014 every model is listed UNPRICED for now; Hugging Face will show no price until the read succeeds
|
|
4
|
+
`),E}let r=Z(t,Date.now(),e);for(let o of r.refusals)this.warn(`urun /v1/models: refusing to price ${o.model_id}:${o.variant??"*"} \u2014 ${o.reason}
|
|
5
|
+
`);return r}outputFreeKeys(e){let t=new Set;if(!e)return t;for(let r of e.endpoints)r.output_free===!0&&t.add(K(r.model_id,r.variant));return t}warn(e){(this.opts.warn??(r=>console.warn(r.trimEnd())))(e)}servable(e){return e.filter(t=>t.serves==="openai"&&t.deployment_status==="active").map(t=>t.app_slug)}async availableIds(){let e=this.opts.defaultApp,t=new Set(e===null?[]:[e]);if(this.opts.listApps)for(let o of this.servable(await this.deployedApps()))t.add(o);for(let o of this.pool.keys())o.startsWith(ye)||o.startsWith(fe)||t.add(o);let r=[...t].filter(o=>o!==e).sort();return e===null?r:[e,...r]}async noDefaultApp(e){let t=await this.availableIds(),r=t.length>0?t.join(", "):"(none deployed)";throw new P(e===""?`no "model" was given and this endpoint has no default model \u2014 name one of your org's deployed apps that declare serves="openai"; available models: ${r}`:`model "${e}" does not name a deployed app in your org that declares serves="openai", and this endpoint has no default model to fall back to; available models: ${r}`)}async sharedLane(e){if(!this.opts.shared)return null;let t=await this.sharedBlock();if(!t)return null;let r=D(t,e);if(r)return r;let o=e.lastIndexOf(":"),i=o>0?e.slice(0,o):e,l=o>0?e.slice(o+1):void 0,d=h(i),a=t.endpoints.filter(c=>h(c.model_id)===d&&(l===void 0||c.variant===l)),s=new Set(a.map(c=>c.model_id)),u=[...s][0];return u===void 0||s.size!==1?null:D(t,u,l)}async resolveTarget(e){let t=(e??"").trim(),r=this.opts.defaultApp;if(!t||t==="urun")return r===null?this.noDefaultApp(t):{appSlug:r};let o=h(t);if(o===r)return{appSlug:r};let i=await this.sharedLane(t);if(i)return{appSlug:i.endpoint.app_slug,fnName:i.endpoint.function,sharedApp:!0,modelId:i.endpoint.model_id,variant:i.endpoint.variant,sharedOrgId:i.shared_org_id,gpuSpec:i.endpoint.gpu_spec??void 0,appId:i.endpoint.app_id??void 0};if(this.pool.has(o))return{appSlug:o};if(this.opts.listApps){let l=await this.deployedApps(),d=this.servable(l);if(d.includes(o))return{appSlug:o};let a=d.filter(u=>u.startsWith(`${o}-`));if(a.length===1)return{appSlug:a[0]};if(a.length>1)throw new P(`model "${t}" is ambiguous across deployed apps ${a.join(", ")} \u2014 name the exact app slug (or catalog id:variant)`);let s=l.find(u=>u.app_slug===o||u.app_slug.startsWith(`${o}-`));if(s)throw new P(`model "${t}" maps to app "${s.app_slug}", which has no function declaring serves="openai" \u2014 add serves="openai" to its @app.function or deploy it with \`urun serve ${t}\`; available models: ${(await this.availableIds()).join(", ")}`)}if(this.opts.listCatalog){let d=(await this.opts.listCatalog()).find(a=>t===a.model_id||t===`${a.model_id}:${a.variant}`||o===h(a.model_id)||o===h(`${a.model_id}-${a.variant}`));if(d)throw new P(`model "${t}" is in the uRun catalog but not deployed \u2014 deploy it with \`urun serve ${d.model_id}\`; available models: ${(await this.availableIds()).join(", ")}`)}return r===null?this.noDefaultApp(t):{appSlug:r}}async catalogIdentityFor(e){let t=he(await this.resolveTarget(e));return t.kind==="catalog"?{model_id:t.model_id,variant:t.variant}:null}async poolTuningFor(e){return ze(await this.catalogRows(),e)}async servingAppSlugFor(e){return(await this.resolveTarget(e)).appSlug}async resolveApp(e){return q(await this.resolveTarget(e))}async sessionFor(e){let t=await this.resolveTarget(e);return this.acquire(t,q(t))}async resolveTargetFor(e){return this.resolveTarget(e)}async speechSessionFor(e){let t=await this.resolveTarget(e);return this.acquire(t,fe+q(t))}async acquire(e,t){let r=this.pool.get(t);return r||(r=Promise.resolve(this.opts.openSession(e,t)),this.pool.set(t,r),r.catch(()=>this.pool.delete(t))),{app:t,entry:await r,identity:he(e)}}keyOf(e){let t=this.opts.sessionKey;if(!t)throw new Error("ModelRouter: sessionKey is not configured \u2014 the session-identity seam (handleFor/sessionForHandle) is unavailable on this router");let r=t(e);if(typeof r!="string"||r.length===0)throw new Error("ModelRouter: sessionKey returned an empty identity for a pooled session");return r}async handleFor(e){let{app:t,entry:r}=await this.sessionFor(e);return{app:t,handle:ce(t,this.keyOf(r))}}async speechHandleFor(e){let{app:t,entry:r}=await this.speechSessionFor(e);return{app:t,handle:ce(t,this.keyOf(r))}}async sessionForHandle(e){let t=Je(e);if(!t)throw new I(`malformed session handle ${JSON.stringify(e)} \u2014 not issued by this proxy`);let{app:r,key:o}=t,i=this.pool.get(r),l=i?await i.then(d=>d,()=>null):null;if(l===null)throw new I(`the session behind this handle (app "${r}") is gone \u2014 closed, evicted after its pod died, or the proxy restarted; it cannot be reattached. Reconnect without a handle to start a new session.`);if(this.keyOf(l)!==o)throw new I(`the session behind this handle (app "${r}") was replaced \u2014 the original backhaul died and a new session serves this app now; the handle's session cannot be reattached. Reconnect without a handle to start a new session.`);return{app:r,entry:l}}async evict(e,t){let r=this.pool.get(e);!r||await r.then(i=>i,()=>null)!==t||this.pool.get(e)!==r||(this.pool.delete(e),await this.opts.closeSession(t).catch(()=>{}))}async modelList(){let e=this.opts.sharedOnlyListing?[]:await this.availableIds(),t=await this.sharedBlock(),[r,o]=await Promise.all([this.catalogRows().then(s=>({ok:!0,rows:s}),()=>({ok:!1,rows:[]})),this.pricesForListing(this.outputFreeKeys(t))]),i=r.rows,l=r.ok?o:E;r.ok||this.warn(`urun /v1/models: the model catalog could not be read \u2014 entries fall back to the bare OpenAI fields AND no model is priced on either lane (pricing follows catalog identity, so a half-priced listing would flicker on Hugging Face)
|
|
6
|
+
`);let a=(t?S(t):[]).map(s=>{let u=i.filter(W=>W.model_id===s.model_id&&W.variant===s.variant),c=N(u),g=$(u),f=J(u),v=A(s.model_id,s.variant,l),m=z(u);return b({id:`${s.model_id}:${s.variant}`,object:"model",created:g,owned_by:"urun",...c!==null?{context_length:c}:{},...v!==null?{pricing:v}:{},...m.published.length>0?{voices:[...m.published]}:{},...f!==null?{capabilities:{reasoning:f}}:{}})});return{object:"list",data:this.opts.sharedOnlyListing?a:[...e.map(s=>L(s,i,l)),...a]}}async openRouterModels(){let e=await this.sharedBlock(),[t,r]=await Promise.all([this.catalogRows(),this.pricesForListing(this.outputFreeKeys(e))]);return ae(e,t,r,o=>this.warn(o))}async supportsImages(e,t){let r=await this.resolveTarget(e),o=await this.catalogRows();if(r.sharedApp){let i=H(String(e),r.modelId,r.variant,o,this.opts.listCatalog!==null);return ge(`${r.modelId}:${r.variant}`,i).includes(t)}return pe(V(r.appSlug,o)).includes(t)}async supportsAudio(e){let t=await this.resolveTarget(e),r=await this.catalogRows();return t.sharedApp?R(r.filter(o=>o.model_id===t.modelId&&o.variant===t.variant))!==null:R(O(t,r))!==null}async supportsSpeech(e){let t=await this.resolveTarget(e),r=await this.catalogRows();return t.sharedApp?R(r.filter(o=>o.model_id===t.modelId&&o.variant===t.variant))==="tts":R(O(t,r))==="tts"}async supportsTranscription(e){let t=await this.resolveTarget(e),r=await this.catalogRows();return t.sharedApp?R(r.filter(o=>o.model_id===t.modelId&&o.variant===t.variant))==="stt":R(O(t,r))==="stt"}async transcriptStreamFor(e){let t=await this.resolveTarget(e),r=await this.catalogRows(),o=t.sharedApp?r.filter(i=>i.model_id===t.modelId&&i.variant===t.variant):O(t,r);return Ve(o)}async speechVoices(e){let t=await this.resolveTarget(e),r=await this.catalogRows(),o=t.sharedApp?r.filter(i=>i.model_id===t.modelId&&i.variant===t.variant):O(t,r);return z(o)}async imageModelList(){let e=await this.catalogRows(),t=E,r=[];for(let i of await this.availableIds()){let l=pe(V(i,e));l.length!==0&&r.push(b({...L(i,e,t),image_modes:l}))}let o=await this.sharedBlock();if(o)for(let i of S(o)){let l=H(`${i.model_id}:${i.variant}`,i.model_id,i.variant,e,this.opts.listCatalog!==null),d=ge(`${i.model_id}:${i.variant}`,l);if(d.length===0)continue;let a=b({id:`${i.model_id}:${i.variant}`,object:"model",created:$(l),owned_by:"urun",image_modes:d});r.push(a)}return{object:"list",data:r}}async speechToTextModelList(){let e=await this.catalogRows(),t=E,r=[];for(let i of await this.availableIds())R(we(i,e))==="stt"&&r.push(L(i,e,t));let o=await this.sharedBlock();if(o)for(let i of S(o)){let l=H(`${i.model_id}:${i.variant}`,i.model_id,i.variant,e,this.opts.listCatalog!==null);if(R(l)!=="stt")continue;let d=b({id:`${i.model_id}:${i.variant}`,object:"model",created:$(l),owned_by:"urun"});r.push(d)}return{object:"list",data:r}}async closeAll(){let e=[...this.pool.values()],t=[];if(await Promise.all(e.map(async r=>{try{await this.opts.closeSession(await r)}catch(o){t.push(String(o instanceof Error?o.message:o))}})),t.length>0)throw new Error(`failed to close ${t.length} pooled session(s): ${t.join("; ")}`)}};export{p as a,We as b,et as c,st as d,T as e,dt as f,wt as g,P as h,I as i,ce as j,Je as k,_t as l,ze as m,fe as n,q as o,he as p,me as q};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as x}from"./chunk-YSFSRI3D.js";x();import{createHmac as m,randomUUID as _,timingSafeEqual as T}from"crypto";var A=["sfu","urun-doc"],I="runtime:lease",L="lane:join",S="urun-runtime-key-v1";function y(r,t){if(!r)throw new Error("deriveOrgRuntimeKey requires a master secret");if(!t)throw new Error("deriveOrgRuntimeKey requires an orgId");return m("sha256",r).update(`${S}|${t}`).digest("base64url")}var $=120;function N(r){return Buffer.from(r).toString("base64url")}function k(r,t,i){let o=N(JSON.stringify(r)),e=N(JSON.stringify(t)),s=m("sha256",i).update(`${o}.${e}`).digest("base64url");return`${o}.${e}.${s}`}function K(r,t,i=$,o=L,e){let s=Math.floor(Date.now()/1e3),f=e?y(t,e):t;return k({alg:"HS256",typ:"JWT"},{session_id:r,aud:"sfu",sub:r,scope:o,...e?{tenant:e}:{},iat:s,exp:s+i,jti:_()},f)}function J(r,t,i,o=Math.floor(Date.now()/1e3),e){let s=r.split(".");if(s.length!==3)return null;let[f,E,O]=s,h,n;try{h=JSON.parse(Buffer.from(f,"base64url").toString()),n=JSON.parse(Buffer.from(E,"base64url").toString())}catch{return null}if(h.alg!=="HS256")return null;let l;try{l=Buffer.from(O,"base64url")}catch{return null}let d=typeof n.tenant=="string"&&n.tenant!==""?n.tenant:void 0,u=[];if(d!==void 0?(u.push(y(i,d)),e&&u.push(y(e,d))):(u.push(i),e&&u.push(e)),!u.some(g=>{let b=m("sha256",g).update(`${f}.${E}`).digest();return l.length===b.length&&T(l,b)}))return null;let p=n.exp;if(typeof p!="number"||p<=o)return null;let a=typeof n.aud=="string"||Array.isArray(n.aud)?n.aud:void 0;if(!(a!==void 0&&A.some(g=>g===a||Array.isArray(a)&&a.includes(g))))return null;let c=n.session_id??n.sub;return typeof c!="string"||c!==t?null:{sessionId:c,aud:a,scope:typeof n.scope=="string"?n.scope:void 0,tenant:d,app:typeof n.app=="string"?n.app:void 0,fn:typeof n.fn=="string"?n.fn:void 0,exp:p}}export{I as a,K as b,J as c};
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import { C as CatalogRow } from './models-
|
|
1
|
+
import { C as CatalogRow } from './models-D7F0bLJ3.js';
|
|
2
2
|
import { IncomingMessage } from 'node:http';
|
|
3
3
|
import { a as AudioBridge, h as VideoFrameLane, j as VideoOutLane } from './video-out-Cawtm7SF.js';
|
|
4
4
|
|
|
5
|
-
interface ProxyIdentity {
|
|
6
|
-
app: string;
|
|
7
|
-
org: string;
|
|
8
|
-
fn: string;
|
|
9
|
-
|
|
10
|
-
base_url: string;
|
|
11
|
-
proxy_version: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
5
|
type TurnCatalogIdentity = {
|
|
15
6
|
kind: 'catalog';
|
|
16
7
|
model_id: string;
|
|
@@ -72,39 +63,21 @@ interface InferenceRecord {
|
|
|
72
63
|
readonly catalog: TurnCatalogIdentity;
|
|
73
64
|
}
|
|
74
65
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
function: string;
|
|
82
|
-
|
|
83
|
-
gpu_spec?: string | null;
|
|
84
|
-
|
|
85
|
-
warm?: number | null;
|
|
86
|
-
|
|
87
|
-
compat_default?: boolean | null;
|
|
88
|
-
|
|
89
|
-
output_free?: boolean | null;
|
|
90
|
-
|
|
91
|
-
ready?: boolean | null;
|
|
92
|
-
|
|
93
|
-
ready_runtimes?: number | null;
|
|
94
|
-
|
|
95
|
-
ready_since?: string | null;
|
|
66
|
+
type SessionTurnKind = 'delta' | 'final' | 'turn_start' | 'turn_end' | 'turn_eager_end' | 'turn_resumed';
|
|
67
|
+
|
|
68
|
+
interface SessionTurnLaneEvent {
|
|
69
|
+
kind: SessionTurnKind;
|
|
70
|
+
text?: string;
|
|
71
|
+
startMs?: number;
|
|
96
72
|
}
|
|
97
73
|
|
|
98
|
-
interface
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
regions?: string[] | null;
|
|
74
|
+
interface ProxyIdentity {
|
|
75
|
+
app: string;
|
|
76
|
+
org: string;
|
|
77
|
+
fn: string;
|
|
103
78
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
hipaa: boolean;
|
|
107
|
-
} | null;
|
|
79
|
+
base_url: string;
|
|
80
|
+
proxy_version: string;
|
|
108
81
|
}
|
|
109
82
|
|
|
110
83
|
interface TokenPricing {
|
|
@@ -127,48 +100,41 @@ interface ModelPriceRow {
|
|
|
127
100
|
expires_at: number | null;
|
|
128
101
|
}
|
|
129
102
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
interface OpenRouterDatacenter {
|
|
135
|
-
country_code: string;
|
|
136
|
-
region?: string;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
interface OpenRouterCompliance {
|
|
140
|
-
zdr: boolean;
|
|
141
|
-
hipaa: boolean;
|
|
142
|
-
}
|
|
143
|
-
interface OpenRouterProviderModel {
|
|
144
|
-
schema_version: '2.4';
|
|
103
|
+
interface SharedEndpointRow {
|
|
104
|
+
model_id: string;
|
|
105
|
+
variant: string;
|
|
145
106
|
|
|
146
|
-
|
|
147
|
-
name: string;
|
|
148
|
-
created: number;
|
|
107
|
+
app_slug: string;
|
|
149
108
|
|
|
150
|
-
|
|
109
|
+
app_id?: string | null;
|
|
151
110
|
|
|
152
|
-
|
|
153
|
-
description: string;
|
|
154
|
-
hugging_face_id: string;
|
|
111
|
+
function: string;
|
|
155
112
|
|
|
156
|
-
|
|
113
|
+
gpu_spec?: string | null;
|
|
157
114
|
|
|
158
|
-
|
|
159
|
-
input_modalities: Array<Record<string, unknown>>;
|
|
160
|
-
output_modalities: Array<Record<string, unknown>>;
|
|
115
|
+
warm?: number | null;
|
|
161
116
|
|
|
162
|
-
|
|
117
|
+
compat_default?: boolean | null;
|
|
163
118
|
|
|
164
|
-
|
|
119
|
+
output_free?: boolean | null;
|
|
120
|
+
|
|
121
|
+
ready?: boolean | null;
|
|
122
|
+
|
|
123
|
+
ready_runtimes?: number | null;
|
|
124
|
+
|
|
125
|
+
ready_since?: string | null;
|
|
165
126
|
}
|
|
166
127
|
|
|
167
|
-
interface
|
|
128
|
+
interface SharedCatalogBlock {
|
|
129
|
+
shared_org_id: string;
|
|
130
|
+
endpoints: SharedEndpointRow[];
|
|
168
131
|
|
|
169
|
-
|
|
132
|
+
regions?: string[] | null;
|
|
170
133
|
|
|
171
|
-
|
|
134
|
+
compliance?: {
|
|
135
|
+
zdr: boolean;
|
|
136
|
+
hipaa: boolean;
|
|
137
|
+
} | null;
|
|
172
138
|
}
|
|
173
139
|
|
|
174
140
|
interface DeployedApp {
|
|
@@ -219,6 +185,19 @@ interface RouterImageModelList {
|
|
|
219
185
|
data: RouterImageModelEntry[];
|
|
220
186
|
}
|
|
221
187
|
|
|
188
|
+
interface PoolTuning {
|
|
189
|
+
|
|
190
|
+
min?: number;
|
|
191
|
+
|
|
192
|
+
max?: number;
|
|
193
|
+
|
|
194
|
+
in_flight_cap?: number;
|
|
195
|
+
|
|
196
|
+
idle_grace_s?: number;
|
|
197
|
+
|
|
198
|
+
warm_wait_s?: number;
|
|
199
|
+
}
|
|
200
|
+
|
|
222
201
|
interface RouteTarget {
|
|
223
202
|
appSlug: string;
|
|
224
203
|
|
|
@@ -231,6 +210,10 @@ interface RouteTarget {
|
|
|
231
210
|
variant?: string;
|
|
232
211
|
|
|
233
212
|
sharedOrgId?: string;
|
|
213
|
+
|
|
214
|
+
gpuSpec?: string;
|
|
215
|
+
|
|
216
|
+
appId?: string;
|
|
234
217
|
}
|
|
235
218
|
|
|
236
219
|
declare function billingIdentityOf(target: RouteTarget): TurnCatalogIdentity;
|
|
@@ -262,19 +245,21 @@ interface ModelRouterOptions<S> {
|
|
|
262
245
|
}
|
|
263
246
|
|
|
264
247
|
type ImageCapabilityMode = 'generation' | 'edit';
|
|
265
|
-
|
|
266
248
|
declare class ModelRouter<S> {
|
|
267
249
|
private readonly opts;
|
|
268
250
|
private readonly pool;
|
|
269
|
-
|
|
270
|
-
private
|
|
251
|
+
|
|
252
|
+
private apps;
|
|
253
|
+
private rows;
|
|
254
|
+
private shared;
|
|
271
255
|
constructor(opts: ModelRouterOptions<S>);
|
|
272
256
|
|
|
257
|
+
private swr;
|
|
258
|
+
|
|
273
259
|
seed(appSlug: string, entry: S): void;
|
|
274
260
|
private deployedApps;
|
|
275
261
|
|
|
276
262
|
private sharedBlock;
|
|
277
|
-
private sharedCache;
|
|
278
263
|
|
|
279
264
|
private catalogRows;
|
|
280
265
|
private pricesCache;
|
|
@@ -292,6 +277,8 @@ declare class ModelRouter<S> {
|
|
|
292
277
|
|
|
293
278
|
private noDefaultApp;
|
|
294
279
|
|
|
280
|
+
private sharedLane;
|
|
281
|
+
|
|
295
282
|
private resolveTarget;
|
|
296
283
|
|
|
297
284
|
catalogIdentityFor(model: string | undefined): Promise<{
|
|
@@ -299,6 +286,8 @@ declare class ModelRouter<S> {
|
|
|
299
286
|
variant: string;
|
|
300
287
|
} | null>;
|
|
301
288
|
|
|
289
|
+
poolTuningFor(target: RouteTarget): Promise<PoolTuning | null>;
|
|
290
|
+
|
|
302
291
|
servingAppSlugFor(model: string | undefined): Promise<string>;
|
|
303
292
|
|
|
304
293
|
resolveApp(model: string | undefined): Promise<string>;
|
|
@@ -360,12 +349,48 @@ declare class ModelRouter<S> {
|
|
|
360
349
|
closeAll(): Promise<void>;
|
|
361
350
|
}
|
|
362
351
|
|
|
363
|
-
type
|
|
352
|
+
type OpenRouterProviderDoc = {
|
|
353
|
+
data: OpenRouterProviderModel[];
|
|
354
|
+
};
|
|
364
355
|
|
|
365
|
-
interface
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
356
|
+
interface OpenRouterDatacenter {
|
|
357
|
+
country_code: string;
|
|
358
|
+
region?: string;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
interface OpenRouterCompliance {
|
|
362
|
+
zdr: boolean;
|
|
363
|
+
hipaa: boolean;
|
|
364
|
+
}
|
|
365
|
+
interface OpenRouterProviderModel {
|
|
366
|
+
schema_version: '2.4';
|
|
367
|
+
|
|
368
|
+
id: string;
|
|
369
|
+
name: string;
|
|
370
|
+
created: number;
|
|
371
|
+
|
|
372
|
+
quantization: string | null;
|
|
373
|
+
|
|
374
|
+
tokenizer?: string;
|
|
375
|
+
description: string;
|
|
376
|
+
hugging_face_id: string;
|
|
377
|
+
|
|
378
|
+
is_ready: boolean;
|
|
379
|
+
|
|
380
|
+
is_free: boolean;
|
|
381
|
+
input_modalities: Array<Record<string, unknown>>;
|
|
382
|
+
output_modalities: Array<Record<string, unknown>>;
|
|
383
|
+
|
|
384
|
+
datacenters?: OpenRouterDatacenter[];
|
|
385
|
+
|
|
386
|
+
compliance?: OpenRouterCompliance;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
interface SpeechVoicesResolution {
|
|
390
|
+
|
|
391
|
+
readonly published: readonly string[];
|
|
392
|
+
|
|
393
|
+
readonly defect: string | null;
|
|
369
394
|
}
|
|
370
395
|
|
|
371
396
|
interface InferenceUsageRecord {
|
|
@@ -546,6 +571,8 @@ interface ProxyClients {
|
|
|
546
571
|
|
|
547
572
|
supportsTranscription?(model: string | undefined): Promise<boolean>;
|
|
548
573
|
|
|
574
|
+
realtimeCompanionsFor?(model: string | undefined): Promise<RealtimeCompanions | null>;
|
|
575
|
+
|
|
549
576
|
speechVoices?(model: string | undefined): Promise<SpeechVoicesResolution>;
|
|
550
577
|
|
|
551
578
|
listImageModels?(): Promise<unknown>;
|
|
@@ -561,7 +588,7 @@ interface ProxyClients {
|
|
|
561
588
|
|
|
562
589
|
openAudio?(model: string | undefined, signal?: AbortSignal): Promise<ProxyAudioLane>;
|
|
563
590
|
|
|
564
|
-
openAudioOn?(handle: string, signal?: AbortSignal): Promise<PinnedAudioLane>;
|
|
591
|
+
openAudioOn?(handle: string, signal?: AbortSignal, connectionTag?: string): Promise<PinnedAudioLane>;
|
|
565
592
|
|
|
566
593
|
openTurnsOn?(handle: string, signal?: AbortSignal): AsyncIterable<SessionTurnLaneEvent>;
|
|
567
594
|
|
|
@@ -573,11 +600,15 @@ interface ProxyClients {
|
|
|
573
600
|
|
|
574
601
|
sessionHandle(model: string | undefined): Promise<string>;
|
|
575
602
|
|
|
603
|
+
releaseSessionHandle?(handle: string): void;
|
|
604
|
+
|
|
576
605
|
speechSessionHandle?(model: string | undefined): Promise<string>;
|
|
577
606
|
|
|
578
607
|
evictSpeechSession?(handle: string): Promise<void>;
|
|
579
608
|
|
|
580
|
-
createResponseOn(handle: string, params: ResponsesCreateParams
|
|
609
|
+
createResponseOn(handle: string, params: ResponsesCreateParams,
|
|
610
|
+
|
|
611
|
+
connectionTag?: string): Promise<AsyncIterable<unknown>> | AsyncIterable<unknown>;
|
|
581
612
|
|
|
582
613
|
onSessionEnd(handle: string, cb: (end: SessionEndInfo) => void): Promise<() => void>;
|
|
583
614
|
}
|
|
@@ -608,10 +639,13 @@ interface ProxyHandlerOptions {
|
|
|
608
639
|
status: number;
|
|
609
640
|
openaiType: string;
|
|
610
641
|
anthropicType: string;
|
|
642
|
+
operatorDetail?: string;
|
|
611
643
|
} | null;
|
|
612
644
|
|
|
613
645
|
requestLog?: (line: string) => void;
|
|
614
646
|
|
|
647
|
+
operatorLog?: (line: string) => void;
|
|
648
|
+
|
|
615
649
|
usage?: UsageLane;
|
|
616
650
|
|
|
617
651
|
ledger?: LedgerLane;
|
|
@@ -619,4 +653,12 @@ interface ProxyHandlerOptions {
|
|
|
619
653
|
observe?: (record: InferenceRecord) => void;
|
|
620
654
|
}
|
|
621
655
|
|
|
622
|
-
|
|
656
|
+
interface RealtimeCompanions {
|
|
657
|
+
readonly stt: string;
|
|
658
|
+
readonly tts: string;
|
|
659
|
+
readonly voice?: string;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
type RealtimeCompanionsFor = (model: string | undefined) => Promise<RealtimeCompanions | null>;
|
|
663
|
+
|
|
664
|
+
export { type DialObserver as D, type InferenceRecord as I, type LedgerFailure as L, ModelRouter as M, type ProxyClients as P, type RealtimeCompanionsFor as R, SessionGoneError as S, UnknownModelError as U, type DialReport as a, type InferenceUsageRecord as b, type LedgerOutcome as c, type LedgerRecorded as d, type LedgerWrite as e, type ProxyHandlerOptions as f, type ProxyIdentity as g, type ProxyVideoOutLane as h, type RouteTarget as i, type UsageRowReporter as j, billingIdentityOf as k };
|