@urun-sh/core 0.6.43 → 0.6.44
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/internal.browser.js +2 -2
- package/dist/internal.browser.mjs +1 -1
- package/dist/internal.js +5 -5
- package/dist/internal.mjs +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$ as
|
|
1
|
+
import{$ as I,A as j,B as L,F as B,N as H,Y as E,a as $,aa as T,b as q,ba as G,ca as Q,da as Y,ia as F,ja as z,ka as v,la as R,ma as J,na as w,oa as K,y as P,z as N}from"./chunk-NZQI3Y33.mjs";var A=["inflight","progress","responses","tokens"],V=6e4;function O(n,e){if(n===null||typeof n!="object"||!(e in n))return!1;let t=Reflect.get(n,e);return t===null||typeof t!="object"||!("status"in t)?!1:t.status==="done"||t.status==="error"}function p(n,e,t=6e4){n.delete(["requests",e]);let r=()=>{for(let i of A)n.delete([i,e])};if(O(n.get("inflight"),e)){r();return}let s=()=>{},o=n.on("change",i=>{O(i.inflight,e)&&(o(),s(),r())}),l=setTimeout(o,t);s=()=>clearTimeout(l),typeof l=="object"&&"unref"in l&&l.unref()}var X="llm",Z="llm-resp",k=class{items=[];waiters=[];closed=!1;push(e){this.items.push(e),e===null&&(this.closed=!0);for(let t of this.waiters.splice(0))t()}async*drain(){for(;;){for(;this.items.length>0;){let e=this.items.shift();if(e==null)return;yield e}if(this.closed)return;await new Promise(e=>this.waiters.push(e))}}};function U(n,e){if(n){let t=n.message;if(typeof t=="string"&&t.length>0)return t;let r=n.code??n.type??n.error;if(typeof r=="string"&&r.length>0)return`serve error: ${r}`;let s=JSON.stringify(n);if(s&&s!=="{}")return`serve error: ${s.slice(0,300)}`}return e??"serve error"}var C=class{constructor(e){this.opts=e;if(this.wsCtor=e.WebSocketPolyfill??globalThis.WebSocket,!this.wsCtor)throw new Error("[hub-serve] no WebSocket implementation (pass ws in Node)");this.consumerId=e.consumerId??`serve-client-${Math.random().toString(36).slice(2,10)}`,this.grantQuery=`token=${encodeURIComponent(e.attach.token)}&gen=${e.attach.gen}`;let t=R({serverUrl:v(this.sfuWsUrl()),sessionId:e.sessionId,attach:{url:e.sfuUrl,token:e.attach.token,gen:e.attach.gen},WebSocketPolyfill:this.wsCtor}),r=(s,o,l)=>(this.docConnection=t(s,o,l),this.docConnection);this.doc=new w(X,e.sessionId,r)}opts;doc;docConnection;wsCtor;grantQuery;consumerId;streamSockets=new Set;async ready(e=3e4){this.doc.synced||await new Promise((t,r)=>{let s=setTimeout(()=>r(new Error("[hub-serve] doc sync timeout")),e);this.doc.onSynced(()=>{clearTimeout(s),t()})})}request(e){let t=`req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`,r=`${Z}:${t}`,s=e.stream!==!1,o={request_id:t,consumer_id:this.consumerId,respond_on:r,stream:s};e.model&&(o.model=e.model),e.messages!==void 0?(o.kind="chat",o.messages=e.messages):(o.kind="responses",o.input=e.input),e.instructions!==void 0&&(o.instructions=e.instructions),e.temperature!==void 0&&(o.temperature=e.temperature),e.max_output_tokens!==void 0&&(o.max_output_tokens=e.max_output_tokens);let l=`${this.sfuWsUrl()}/stream/${encodeURIComponent(this.opts.sessionId)}/${encodeURIComponent(r)}?${this.grantQuery}`,i=new this.wsCtor(l);this.streamSockets.add(i),i.addEventListener?.("close",()=>this.streamSockets.delete(i));let h=new k,b,f,_=new Promise((S,c)=>{b=S,f=c});_.catch(()=>{});let W=new T,g,m,d,D=!1,M=()=>{try{p(this.doc,t)}catch{}},y=()=>{D||(D=!0,h.push(null),M(),g!==void 0?b(g):f(m!==void 0?new Error(U(m,d)):d!==void 0?new Error(d):new Error("[hub-serve] the response lane ended without a terminal response")))};return this.doc.set({requests:{[t]:{payload:o,consumer_id:this.consumerId,stream:s}}}),i.onmessage=S=>{let c=S.data,x=c instanceof ArrayBuffer?new Uint8Array(c):c instanceof Uint8Array?c:new Uint8Array(c.buffer,c.byteOffset,c.byteLength),u;try{u=I(x)}catch{if(u=W.feed(x),u===void 0)return}if(u===E){y();return}let a=u;a&&typeof a=="object"&&typeof a.t=="string"&&(a.t==="delta"&&typeof a.delta=="string"?h.push(a.delta):a.t==="response"?g=a.body??{}:a.t==="error"&&(m=a,d=U(m,void 0)))},i.onerror=()=>{d??="response lane socket error",y()},i.onclose=()=>{d??="response lane closed before the terminal",y()},{requestId:t,lane:r,deltas:h.drain(),result:_,cancel:()=>{p(this.doc,t)}}}async destroy(){for(let e of this.streamSockets)try{e.close()}catch{}this.streamSockets.clear();try{this.doc.disconnect()}catch{}this.docConnection?.destroy()}sfuWsUrl(){return this.opts.sfuUrl.replace(/^http/,"ws").replace(/\/+$/,"")}};export{$ as ChannelMultiplexer,z as DOC_SYNC_WIRE_CONTRACT_VERSION,q as DeferredChannelMultiplexer,J as DeferredDocConnector,C as HubServeClient,G as LoopbackStreamData,V as RECORD_GC_WAIT_MS,A as REQUEST_RECORD_ROOTS,w as SessionDocumentImpl,F as TransportSession,H as allocateSession,B as computeBackoffDelay,K as createPresence,R as createWebsocketDocConnector,v as deriveYjsServerUrl,L as ensureNodeWebRTC,p as gcRequest,P as isNodeRuntime,N as nodeMediasoupHandlerName,j as nodeWebRTCUnavailableReason,Y as streamDataLabel,Q as transportStreamData};
|