@urun-sh/openai 0.6.45 → 0.6.47
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-NUPHEB3L.js → chunk-2KN45E7P.js} +6 -6
- package/dist/{chunk-5JTIJPFV.js → chunk-5D7TVOAX.js} +1 -1
- package/dist/{chunk-3QZYIRAL.js → chunk-C452ZIU5.js} +5 -5
- package/dist/{chunk-ZXQXOEVN.js → chunk-LROCLDDN.js} +2 -2
- package/dist/chunk-P2YVKUSQ.js +66 -0
- package/dist/{chunk-GCQR62TJ.js → chunk-VRNM6ZKU.js} +1 -1
- package/dist/{chunk-BMSZZYSZ.js → chunk-XGAF2NDT.js} +1 -1
- package/dist/{composite-BXbbnmL2.d.ts → composite-D0ivH65M.d.ts} +7 -2
- package/dist/{composite-n3axzdCh.d.cts → composite-QilJ-Faj.d.cts} +25 -2
- package/dist/hosted/bin.cjs +48 -48
- package/dist/hosted/bin.js +1 -1
- package/dist/hosted/index.cjs +45 -45
- package/dist/hosted/index.d.cts +1 -1
- package/dist/hosted/index.d.ts +1 -1
- package/dist/hosted/index.js +1 -1
- package/dist/pi-extension/index.js +1 -1
- package/dist/pooler/bin.cjs +5 -5
- package/dist/pooler/bin.js +1 -1
- package/dist/proxy/cli.cjs +54 -54
- package/dist/proxy/cli.js +1 -1
- package/dist/proxy/index.cjs +33 -33
- package/dist/proxy/index.d.cts +57 -8
- package/dist/proxy/index.d.ts +16 -3
- package/dist/proxy/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-LNQW3VFC.js +0 -66
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as D}from"./chunk-
|
|
1
|
+
import{c as D}from"./chunk-5D7TVOAX.js";import{c as C}from"./chunk-YSFSRI3D.js";C();import{createClientToken as U}from"@urun-sh/core";import{Queue as H}from"bullmq";import{randomUUID as I}from"crypto";var M=3e4;var V=1e3,G=12e4;function v(n){let s;try{s=JSON.parse(n)}catch{return null}if(typeof s!="object"||s===null||!("proxy_url"in s))return null;let t=s;return typeof t.proxy_url!="string"||t.proxy_url===""?null:{proxy_url:t.proxy_url,occupant_id:typeof t.occupant_id=="string"?t.occupant_id:"",capacity:typeof t.capacity=="number"?t.capacity:0,heartbeat_ms:typeof t.heartbeat_ms=="number"?t.heartbeat_ms:0,...typeof t.region=="string"&&t.region!==""?{region:t.region}:{}}}var P=class extends Error{};async function O(n,s){let t;try{await Promise.race([n,new Promise(c=>{t=setTimeout(c,Math.max(0,s))})])}finally{clearTimeout(t)}}function X(n){let s=n.now??Date.now,t=new Map,c=new Map,h=new Map,u=new Map,_=new Map,y=new Map,b=new Map,f=new Set,w=e=>{let a=t.get(e);return a||(a=n.queueFor?.(e)??S(e),t.set(e,a)),a},S=e=>{let a=n.redis,m=new H(e,{prefix:"bull:dispatch",connection:a});return{reassertWaiting:async p=>{let l=(await m.getJobs(["waiting"])).filter(r=>r.data?.session_kind==="lane").sort((r,d)=>r.timestamp-d.timestamp);if(l.length===0)return{found:0};for(let r of l)try{await r.updateData({...r.data,demand_reaffirmed_at_ms:p})}catch{}for(let r of l.slice(1))try{await r.remove()}catch{}return{found:l.length}},close:()=>m.close()}},k=async e=>{let a=await n.redis.hgetall(`lanes:${e}`),m=[],p=new Map;for(let[r,d]of Object.entries(a)){let o=v(d);o&&o.proxy_url===n.docHostUrl&&(m.push(r),p.set(r,o.region))}if(m.length===0)return[];let g=await n.redis.mget(...m.map(r=>`lane_hosts:${r}`)),l=[];return m.forEach((r,d)=>{let o=g[d];o&&l.push({laneId:r,host:o,region:p.get(r)})}),l},T=async(e,a,m,p,g)=>{let l=m,r=p,d=g;if(typeof l!="string"||l===""||typeof r!="string"||r===""){let A=n.catalogIdentity?await n.catalogIdentity(a).catch(()=>null):null;if(A)l=A.app,r=A.fn,d=A.sharedApp??d;else{let $=h.get(e)??0;if(s()-$<M)return;throw h.set(e,s()),new P("lane demand refused: the pick carried no app/fn identity and no catalog row names the pick's model \u2014 a new lane can only be admitted through session-api with the app and function (roll out the proxy's identity wire, or publish the model's catalog row)")}}let o=c.get(e)??0,L=s();if(L-o<M)return;if(c.set(e,L),(await w(e).reassertWaiting(s()).catch(A=>{throw c.delete(e),A})).found>0){_.set(a??"",(_.get(a??"")??0)+1),n.onEvent?.({kind:"lane_demand_reaffirmed",pool:e,model:a});return}let x=`lane-${I().replaceAll("-","")}`,E=await n.admission.createLaneSession({pool:e,app:l,fn:r,...d?{sharedApp:!0}:{},laneId:x,laneHostUrl:n.docHostUrl});if(E.sessionId!==x)throw new Error(`session-api lane admission returned session_id "${E.sessionId}" for requested logical_id "${x}" \u2014 refusing to fork the lane identity`);u.set(a??"",(u.get(a??"")??0)+1),b.delete(e),n.onEvent?.({kind:"lane_demand_enqueued",pool:e,model:a})};return{async pick({pool:e,app:a,fn:m,sharedApp:p,model:g,holdMs:l=0}){if(f.add(e),n.targets!==void 0&&g!==void 0&&!n.targets.some(i=>i.model===g)){let i=`no pooler target for ${g} \u2014 refusing to mint a lane demand`;throw y.set("untargeted",(y.get("untargeted")??0)+1),b.set(e,i),n.onEvent?.({kind:"lane_demand_failed",pool:e,model:g,reason:i}),new D(e,g)}let r=async()=>{try{await T(e,g,a,m,p)}catch(i){let R=i instanceof Error?i.message:String(i),x=i instanceof P?"identity":"admission";y.set(x,(y.get(x)??0)+1),b.set(e,R),n.onEvent?.({kind:"lane_demand_failed",pool:e,model:g,reason:R})}},d=async()=>{try{return await k(e)}catch{return[]}},o=await d();if(o.length>0){let i=n.laneMinFor?.(e)??0;return i>o.length&&(async()=>{for(let R=o.length;R<i;R++)await r()})(),o}let L=s()+l;for(await O(r(),l);s()<L;){if(await new Promise(i=>setTimeout(i,V)),o=await d(),o.length>0)return o;await O(r(),L-s())}return[]},async status(){let e=[...f].sort();return Promise.all(e.map(async a=>{let m=[];try{let p=await n.redis.hgetall(`lanes:${a}`),g=Object.keys(p),l=g.length===0?[]:await n.redis.mget(...g.map(d=>`lane_hosts:${d}`)),r=s();m=g.map((d,o)=>{let L=p[d],i=L===void 0?null:v(L);return{laneId:d,occupantId:i?.occupant_id??"",capacity:i?.capacity??0,heartbeatAgeMs:i===null?null:r-i.heartbeat_ms,advertisedHere:i?.proxy_url===n.docHostUrl,hosted:!!l[o]}})}catch{}return{pool:a,lanes:m,lastDemandAt:c.get(a)??null}}))},demandCounters(){return[...new Set([...u.keys(),..._.keys()])].sort().map(a=>({model:a,enqueued:u.get(a)??0,reaffirmed:_.get(a)??0}))},demandRefusals(){return[...y.entries()].sort(([e],[a])=>e.localeCompare(a)).map(([e,a])=>({reason:e,count:a}))},demandFailure(e){return b.get(e)??null},async close(){await Promise.all([...t.values()].map(e=>e.close().catch(()=>{}))),t.clear()}}}var q=4e3,j=5e3;function Q(n){return(s,t)=>n(s,{...t,signal:AbortSignal.timeout(q)})}function Y(n){return{createLaneSession:async({pool:s,app:t,fn:c,sharedApp:h,laneId:u,laneHostUrl:_})=>{let y=await U(n.apiKey,{baseUrl:n.baseUrl,expiresIn:300,allowedFunctions:[`${t}/${c}`],bindPrincipal:!0,...h?{sharedApp:!0}:{},fetch:Q(n.fetch??globalThis.fetch)}),b=n.fetch??globalThis.fetch,f;try{f=await b(`${n.baseUrl}/api/sessions/create`,{method:"POST",signal:AbortSignal.timeout(j),headers:{"content-type":"application/json",authorization:`Bearer ${y.token}`,"x-tenant-id":y.orgId},body:JSON.stringify({app:t,function:c,...h?{shared_app:!0}:{},logical_id:u,idempotency_key:u,concurrency_key:u,lane_host_url:_})})}catch(k){throw new Error(`session-api lane admission for ${u} (app ${t}/${c}) failed: ${k instanceof Error?k.message:String(k)}`)}let w={};try{w=await f.json()}catch{}let S=w.session_id;if(f.status!==200||w.status!=="allocated"||typeof S!="string"){let k=typeof w.message=="string"?w.message:`HTTP ${f.status}`;throw new Error(`session-api lane admission refused for ${u} (app ${t}/${c}): ${k}`)}return{sessionId:S}}}}C();var J="urun:catalog:v1";function ne(n){let s=n.refreshMs??5e3,t=n.now??Date.now,c=null,h=0,u=null,_=async()=>{let b=await n.redis.hgetall(J),f=[];for(let w of Object.values(b))try{f.push(JSON.parse(w))}catch{process.stderr.write(`[lane-catalog] dropping malformed catalog row (bad JSON)
|
|
2
2
|
`)}return c=f,h=t(),f},y=()=>c===null||t()-h>=s;return{rows(){return y()?(u||(u=_().finally(()=>{u=null})),u):Promise.resolve(c)},close(){c=null,u=null}}}export{G as a,X as b,Y as c,J as d,ne as e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as d}from"./chunk-
|
|
1
|
+
import{j as d}from"./chunk-C452ZIU5.js";import{c as h}from"./chunk-YSFSRI3D.js";h();var p=3,v="llm",y=new Set(["paused","error"]);function w(i,t,l){let o=i.doc(v),a=typeof o.onConnectionState=="function",c=typeof i.onPhase=="function";if(!a&&!c)throw new Error(`session for app "${t}" exposes neither a doc connection-state surface nor onPhase \u2014 session-gone detection requires @urun-sh/core Session (SessionDocument.onConnectionState / Session.onPhase); pooling a session with no native lifecycle signal would silently swallow requests dispatched after the platform closes it`);let n=null,r=!1,s=new Set,u=[],f=e=>{if(!n){n=e;for(let S of[...s])S(e);s.clear()}};return a&&u.push(o.onConnectionState(e=>{r&&(e.consecutiveFailures<p||f(new d(`the pooled session for app "${t}" is gone: its doc backhaul failed ${e.consecutiveFailures} consecutive times (last close ${e.lastCloseCode===null?"by provider liveness reap":`code ${e.lastCloseCode}`}${e.lastCloseReason?`, reason ${JSON.stringify(e.lastCloseReason)}`:""}) \u2014 the platform closed the session (idle timeout or a serve-side crash). The entry is evicted; retry to get a fresh session.`)))})),l?.armOnFirstSync===!0&&typeof o.onSynced=="function"?u.push(o.onSynced(()=>{r=!0})):c&&u.push(i.onPhase(e=>{if(e.name==="live"){r=!0;return}r&&y.has(e.name)&&f(new d(`the pooled session for app "${t}" lost its compute binding (phase "${e.name}"). The entry is evicted; retry to get a fresh session. The named session itself is not over \u2014 it stays attachable by name.`,{bindingLost:!0,reason:e.reason??null}))})),{gone:()=>n,onGone(e){return n?(e(n),()=>{}):(s.add(e),()=>s.delete(e))},dispose(){s.clear();for(let e of u.splice(0))e()}}}async function*E(i,t){let l=t.gone();if(l)throw l;let o=i[Symbol.asyncIterator](),a,c=new Promise((n,r)=>{a=t.onGone(s=>r(s))});c.catch(()=>{});try{for(;;){let n=await Promise.race([o.next(),c]);if(n.done)return;yield n.value}}finally{a?.(),o.return?.(void 0)}}export{w as a,E as b};
|
|
@@ -131,7 +131,9 @@ interface RealtimeBinding<S = unknown> {
|
|
|
131
131
|
|
|
132
132
|
release?: () => Promise<void> | void;
|
|
133
133
|
|
|
134
|
-
endSession?: () => Promise<
|
|
134
|
+
endSession?: () => Promise<unknown> | unknown;
|
|
135
|
+
|
|
136
|
+
onSessionEnd?: (cb: (end: SessionEndInfo) => void) => Promise<() => void>;
|
|
135
137
|
}
|
|
136
138
|
interface OpenAIRealtimeOptions<S = unknown> {
|
|
137
139
|
resolver: OpenAIRealtimeResolver<S>;
|
|
@@ -235,8 +237,11 @@ declare class UnknownModelError extends Error {
|
|
|
235
237
|
declare class SessionGoneError extends Error {
|
|
236
238
|
|
|
237
239
|
readonly bindingLost: boolean;
|
|
240
|
+
|
|
241
|
+
readonly reason: string | null;
|
|
238
242
|
constructor(message: string, options?: {
|
|
239
243
|
bindingLost?: boolean;
|
|
244
|
+
reason?: string | null;
|
|
240
245
|
});
|
|
241
246
|
}
|
|
242
247
|
|
|
@@ -710,7 +715,7 @@ interface ProxyClients {
|
|
|
710
715
|
|
|
711
716
|
dedicatedSessionHandle?(model: string | undefined): Promise<string>;
|
|
712
717
|
|
|
713
|
-
endDedicatedSession?(handle: string): Promise<
|
|
718
|
+
endDedicatedSession?(handle: string): Promise<unknown> | unknown;
|
|
714
719
|
|
|
715
720
|
realtimeBillingIdentityFor?(model: string | undefined): Promise<TurnCatalogIdentity>;
|
|
716
721
|
|
|
@@ -436,7 +436,20 @@ interface RealtimeBinding<S = unknown> {
|
|
|
436
436
|
* dedicated/pooled handles only; absent ⇒ the caller's frame is answered
|
|
437
437
|
* `unknown_event` (the shared-lane bindings have no session to end).
|
|
438
438
|
*/
|
|
439
|
-
endSession?: () => Promise<
|
|
439
|
+
endSession?: () => Promise<unknown> | unknown;
|
|
440
|
+
/**
|
|
441
|
+
* THE PINNED SESSION'S END SIGNAL (the credits cutoff, 2026-11): the
|
|
442
|
+
* pinned handle's native end, wired through backhaul `onSessionEnd` —
|
|
443
|
+
* core Session.onPhase's paused/error WITH the park cause (`end.reason`:
|
|
444
|
+
* credits_exhausted, max_session_age, …), or a lane's own gone-watch. The
|
|
445
|
+
* connection arms it at construction so a PARKED session names its cause
|
|
446
|
+
* to the client the moment the platform cuts it — the terminal
|
|
447
|
+
* `insufficient_credits` error event + 1011 close — instead of the death
|
|
448
|
+
* surfacing at the next turn as a generic `session_gone` the sense SDKs
|
|
449
|
+
* redial into. Absent = the embedder wired no end seam: the death
|
|
450
|
+
* surfaces only at the next turn, exactly as before.
|
|
451
|
+
*/
|
|
452
|
+
onSessionEnd?: (cb: (end: SessionEndInfo) => void) => Promise<() => void>;
|
|
440
453
|
}
|
|
441
454
|
interface OpenAIRealtimeOptions<S = unknown> {
|
|
442
455
|
resolver: OpenAIRealtimeResolver<S>;
|
|
@@ -757,8 +770,18 @@ declare class SessionGoneError extends Error {
|
|
|
757
770
|
* session (doc-backhaul failure class) — a corpse; rotation applies.
|
|
758
771
|
*/
|
|
759
772
|
readonly bindingLost: boolean;
|
|
773
|
+
/**
|
|
774
|
+
* THE PARK CAUSE (the credits cutoff, 2026-11): the platform's own
|
|
775
|
+
* `phase.reason` (core Session.onPhase — max_session_age,
|
|
776
|
+
* credits_exhausted, idle_timeout, …), threaded from the phase path of the
|
|
777
|
+
* gone-watch. Structured, never message-sniffed. Null on the doc-backhaul
|
|
778
|
+
* failure path (a corpse has no park reason) and on lane handles whose
|
|
779
|
+
* remote session exposes no onPhase.
|
|
780
|
+
*/
|
|
781
|
+
readonly reason: string | null;
|
|
760
782
|
constructor(message: string, options?: {
|
|
761
783
|
bindingLost?: boolean;
|
|
784
|
+
reason?: string | null;
|
|
762
785
|
});
|
|
763
786
|
}
|
|
764
787
|
/**
|
|
@@ -2873,7 +2896,7 @@ interface ProxyClients {
|
|
|
2873
2896
|
* SEAT FULL. Optional at the seam: a composition that wires none answers
|
|
2874
2897
|
* the caller's frame with the standard `unknown_event` error.
|
|
2875
2898
|
*/
|
|
2876
|
-
endDedicatedSession?(handle: string): Promise<
|
|
2899
|
+
endDedicatedSession?(handle: string): Promise<unknown> | unknown;
|
|
2877
2900
|
/**
|
|
2878
2901
|
* THE REALTIME LANE'S BILLING IDENTITY (session-time billing, DDR
|
|
2879
2902
|
* addendum): the {@link TurnCatalogIdentity} the model's dial resolves,
|