@lunora/angular 1.0.0-alpha.26 → 1.0.0-alpha.260

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.
Files changed (51) hide show
  1. package/README.md +71 -0
  2. package/dist/index.d.mts +345 -47
  3. package/dist/index.d.ts +345 -47
  4. package/dist/index.mjs +1 -1
  5. package/dist/packem_shared/LUNORA_CLIENT-B0toApHY.mjs +1 -0
  6. package/dist/packem_shared/agent-DjMQf-yE.mjs +1 -0
  7. package/dist/packem_shared/agentChat-CQ3TWlc5.mjs +1 -0
  8. package/dist/packem_shared/agentState-Bjqf9q2f.mjs +1 -0
  9. package/dist/packem_shared/agentToolEvents-CFnjzw3X.mjs +1 -0
  10. package/dist/packem_shared/auth-C3dB8sYS.mjs +1 -0
  11. package/dist/packem_shared/connectionStatus-UhmuwzMa.mjs +1 -0
  12. package/dist/packem_shared/flag-BDKBQGos.mjs +1 -0
  13. package/dist/packem_shared/hydratePreloaded-QPAo50Am.mjs +1 -0
  14. package/dist/packem_shared/infiniteQuery-CnLj_eFx.mjs +1 -0
  15. package/dist/packem_shared/liveQuery-eE9zMaxo.mjs +1 -0
  16. package/dist/packem_shared/liveTopic-Cz1BDkMP.mjs +1 -0
  17. package/dist/packem_shared/mutate-Dg5AiM8y.mjs +1 -0
  18. package/dist/packem_shared/mutator-DjG1yGk8.mjs +1 -0
  19. package/dist/packem_shared/platform-DGTu4Ucl.mjs +1 -0
  20. package/dist/packem_shared/presence-NK13Gvdk.mjs +1 -0
  21. package/dist/packem_shared/rateLimit-B3h9qzh-.mjs +1 -0
  22. package/dist/packem_shared/runAction-BfiPq4Xz.mjs +1 -0
  23. package/dist/packem_shared/stream-BuhiwhIH.mjs +1 -0
  24. package/dist/packem_shared/subscription-zJv48q6C.mjs +1 -0
  25. package/dist/packem_shared/voiceAgent-DppK8OxH.mjs +1 -0
  26. package/dist/server.d.mts +1 -0
  27. package/dist/server.d.ts +1 -0
  28. package/dist/server.mjs +1 -0
  29. package/dist/upload.d.mts +20 -0
  30. package/dist/upload.d.ts +20 -0
  31. package/dist/upload.mjs +1 -1
  32. package/package.json +9 -4
  33. package/dist/packem_shared/LUNORA_CLIENT-B0pGE0Tv.mjs +0 -1
  34. package/dist/packem_shared/agent-C-GavfBl.mjs +0 -1
  35. package/dist/packem_shared/agentChat-DVHf7gsd.mjs +0 -1
  36. package/dist/packem_shared/agentState-BAfa0QuC.mjs +0 -1
  37. package/dist/packem_shared/agentToolEvents-CBTZ_DsO.mjs +0 -1
  38. package/dist/packem_shared/auth-BTEtMnGG.mjs +0 -1
  39. package/dist/packem_shared/connectionStatus-C53UhkPi.mjs +0 -1
  40. package/dist/packem_shared/flag-BYFWoQTg.mjs +0 -1
  41. package/dist/packem_shared/hydratePreloaded-BKHgpXzQ.mjs +0 -1
  42. package/dist/packem_shared/infiniteQuery-DyWJIpUr.mjs +0 -1
  43. package/dist/packem_shared/liveQuery-DEIqmTPj.mjs +0 -1
  44. package/dist/packem_shared/mutate-DR8Uo8Hs.mjs +0 -1
  45. package/dist/packem_shared/mutator-Cw6jpG06.mjs +0 -1
  46. package/dist/packem_shared/platform-BGZypnc9.mjs +0 -1
  47. package/dist/packem_shared/presence-BMrTlOCF.mjs +0 -1
  48. package/dist/packem_shared/rateLimit-CQazDrPJ.mjs +0 -1
  49. package/dist/packem_shared/stream-CcvHiJf2.mjs +0 -1
  50. package/dist/packem_shared/subscription-DJeoGEDR.mjs +0 -1
  51. package/dist/packem_shared/voiceAgent-DUFVwTWi.mjs +0 -1
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{agent as e}from"./packem_shared/agent-C-GavfBl.mjs";import{agentChat as m}from"./packem_shared/agentChat-DVHf7gsd.mjs";import{agentState as a}from"./packem_shared/agentState-BAfa0QuC.mjs";import{agentToolEvents as x}from"./packem_shared/agentToolEvents-CBTZ_DsO.mjs";import{auth as i,authGate as u}from"./packem_shared/auth-BTEtMnGG.mjs";import{LUNORA_CLIENT as s,injectLunoraClient as c,provideLunora as l}from"./packem_shared/LUNORA_CLIENT-B0pGE0Tv.mjs";import{connectionStatus as L}from"./packem_shared/connectionStatus-C53UhkPi.mjs";import{flag as v,flags as y}from"./packem_shared/flag-BYFWoQTg.mjs";import{hydratePreloaded as Q}from"./packem_shared/hydratePreloaded-BKHgpXzQ.mjs";import{liveQuery as A}from"./packem_shared/liveQuery-DEIqmTPj.mjs";import{mutate as I}from"./packem_shared/mutate-DR8Uo8Hs.mjs";import{mutator as P}from"./packem_shared/mutator-Cw6jpG06.mjs";import{infiniteQuery as b,paginatedQuery as j}from"./packem_shared/infiniteQuery-DyWJIpUr.mjs";import{presence as K}from"./packem_shared/presence-BMrTlOCF.mjs";import{rateLimit as R}from"./packem_shared/rateLimit-CQazDrPJ.mjs";import{stream as _}from"./packem_shared/stream-CcvHiJf2.mjs";import{subscription as q}from"./packem_shared/subscription-DJeoGEDR.mjs";import{voiceAgent as z}from"./packem_shared/voiceAgent-DUFVwTWi.mjs";import{SKIP as D}from"@lunora/client/query";export{s as LUNORA_CLIENT,D as SKIP,e as agent,m as agentChat,a as agentState,x as agentToolEvents,i as auth,u as authGate,L as connectionStatus,v as flag,y as flags,Q as hydratePreloaded,b as infiniteQuery,c as injectLunoraClient,A as liveQuery,I as mutate,P as mutator,j as paginatedQuery,K as presence,l as provideLunora,R as rateLimit,_ as stream,q as subscription,z as voiceAgent};
1
+ import{agent as e}from"./packem_shared/agent-DjMQf-yE.mjs";import{agentChat as p}from"./packem_shared/agentChat-CQ3TWlc5.mjs";import{agentState as f}from"./packem_shared/agentState-Bjqf9q2f.mjs";import{agentToolEvents as x}from"./packem_shared/agentToolEvents-CFnjzw3X.mjs";import{auth as i,authGate as u}from"./packem_shared/auth-C3dB8sYS.mjs";import{LUNORA_CLIENT as g,injectLunoraClient as l,provideLunora as s}from"./packem_shared/LUNORA_CLIENT-B0toApHY.mjs";import{connectionStatus as v}from"./packem_shared/connectionStatus-UhmuwzMa.mjs";import{flag as h,flags as y}from"./packem_shared/flag-BDKBQGos.mjs";import{hydratePreloaded as C}from"./packem_shared/hydratePreloaded-QPAo50Am.mjs";import{liveQuery as S}from"./packem_shared/liveQuery-eE9zMaxo.mjs";import{liveTopic as E}from"./packem_shared/liveTopic-Cz1BDkMP.mjs";import{mutate as N}from"./packem_shared/mutate-Dg5AiM8y.mjs";import{mutator as b}from"./packem_shared/mutator-DjG1yGk8.mjs";import{infiniteQuery as G,paginatedQuery as K}from"./packem_shared/infiniteQuery-CnLj_eFx.mjs";import{presence as R}from"./packem_shared/presence-NK13Gvdk.mjs";import{rateLimit as _}from"./packem_shared/rateLimit-B3h9qzh-.mjs";import{runAction as q}from"./packem_shared/runAction-BfiPq4Xz.mjs";import{stream as z}from"./packem_shared/stream-BuhiwhIH.mjs";import{subscription as D}from"./packem_shared/subscription-zJv48q6C.mjs";import{voiceAgent as H}from"./packem_shared/voiceAgent-DppK8OxH.mjs";import{SKIP as M}from"@lunora/client/query";export{g as LUNORA_CLIENT,M as SKIP,e as agent,p as agentChat,f as agentState,x as agentToolEvents,i as auth,u as authGate,v as connectionStatus,h as flag,y as flags,C as hydratePreloaded,G as infiniteQuery,l as injectLunoraClient,S as liveQuery,E as liveTopic,N as mutate,b as mutator,K as paginatedQuery,R as presence,s as provideLunora,_ as rateLimit,q as runAction,z as stream,D as subscription,H as voiceAgent};
@@ -0,0 +1 @@
1
+ import{InjectionToken as t,makeEnvironmentProviders as i,inject as c}from"@angular/core";import{LunoraClient as r}from"@lunora/client";const o=()=>globalThis.location?.origin??"",e=new t("lunora.client",{factory:()=>new r({url:o()}),providedIn:"root"}),s=(n={})=>i([{provide:e,useFactory:()=>n instanceof r?n:new r({...n,url:n.url??o()})}]),a=()=>c(e),m=n=>n??a();export{e as LUNORA_CLIENT,a as injectLunoraClient,s as provideLunora,m as resolveLunoraClient};
@@ -0,0 +1 @@
1
+ import{computed as o,signal as R}from"@angular/core";import{resolveLunoraClient as h}from"./LUNORA_CLIENT-B0toApHY.mjs";import{subscription as v}from"./subscription-zJv48q6C.mjs";const x=t=>{const{api:i,cancel:c,onError:d,run:l,runArgs:u,threadKey:n}=t,a=h(t.client),{data:f,error:m}=v(i.agents.agentThread,{key:n},{client:a,destroyRef:t.destroyRef,onError:d}),r=o(()=>f()),y=o(()=>r()?.status),s=R(!1),g=async(e,p)=>{s.set(!0);try{await a.mutation(l,{input:e,threadKey:n,...u,...p})}finally{s.set(!1)}};return{cancel:async()=>{const e=r()?.instanceId;c===void 0||e===void 0||await a.mutation(c,{instanceId:e,threadKey:n})},error:m,pending:s.asReadonly(),run:g,status:y,thread:r}};export{x as agent};
@@ -0,0 +1 @@
1
+ import{computed as o,signal as J}from"@angular/core";import{reconcileOptimistic as w,maxSeq as A}from"@lunora/client";import{resolveLunoraClient as Q}from"./LUNORA_CLIENT-B0toApHY.mjs";import{stream as U}from"./stream-BuhiwhIH.mjs";import{subscription as h}from"./subscription-zJv48q6C.mjs";const V={__lunoraRef:""},W=[],rt=d=>{const{api:a,cancel:v,limit:f,onError:m,send:R,sendArgs:E,stream:S,threadKey:n}=d,r=Q(d.client),{destroyRef:l}=d,x=f===void 0?{key:n}:{key:n,limit:f},{data:_,error:b}=h(a.agents.agentMessages,x,{client:r,destroyRef:l,onError:m}),{data:I,error:T}=h(a.agents.agentThread,{key:n},{client:r,destroyRef:l,onError:m}),{data:D,error:G}=h(a.agents.agentApprovalGrants,{key:n},{client:r,destroyRef:l,onError:m}),q=o(()=>b()??T()??G()),C=S===void 0?"skip":{key:n},{chunks:j}=U(S??V,C,{client:r,destroyRef:l}),i=J([]);let k=0;const u=o(()=>I()),M=o(()=>u()?.status),p=o(()=>_()??[]),O=o(()=>{const t=p(),e=w(i(),t);if(e.length===0)return t;const s=A(t);return[...t,...e.map((c,y)=>({content:c.content,optimistic:!0,role:"user",seq:s+1+y}))]}),F=o(()=>{const t=p().filter(e=>e.role==="assistant").length;return j().filter(e=>e.kind!=="progress"&&e.threadKey===n&&e.turn>=t).map(e=>e.text).join("")}),K=async(t,e)=>{const s=k;k+=1;const c=A(p());i.set([...w(i(),p()),{content:t,id:s,maxDurableSeqAtSend:c}]);try{await r.mutation(R,{input:t,threadKey:n,...E,...e})}catch(y){throw i.set(i().filter(H=>H.id!==s)),y}},g=async(t,e,s)=>{const c=u()?.instanceId;if(c===void 0)throw new Error(`agentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await r.mutation(a.agents.agentResolveApproval,{decision:t,instanceId:c,threadKey:n,toolCallId:e,...s===void 0?{}:{note:s}})},N=async(t,e)=>g("approve",t,e),L=async(t,e)=>g("approve_for_thread",t,e),P=async(t,e)=>g("reject",t,e),Y=async t=>{await r.mutation(a.agents.agentRevokeApprovalGrant,{threadKey:n,toolName:t})},$=async(t,e)=>{await r.mutation(a.agents.agentSupplySecret,{secret:e,threadKey:n,toolCallId:t},{onlineOnly:!0})},z=async t=>{await r.mutation(a.agents.agentDeclineSecret,{threadKey:n,toolCallId:t})},B=async()=>{const t=u()?.instanceId;v===void 0||t===void 0||await r.mutation(v,{instanceId:t,threadKey:n})};return{approvalGrants:o(()=>D()??W),approve:N,approveForThread:L,cancel:B,declineSecret:z,error:q,messages:O,reject:P,revokeGrant:Y,send:K,status:M,streamingText:F,supplySecret:$}};export{rt as agentChat};
@@ -0,0 +1 @@
1
+ import{computed as c}from"@angular/core";import{subscription as n}from"./subscription-zJv48q6C.mjs";const d=t=>{const{data:e,error:r}=n(t.api.agents.agentState,{key:t.threadKey},{client:t.client,destroyRef:t.destroyRef}),a=c(()=>e());return{error:r,state:a}};export{d as agentState};
@@ -0,0 +1 @@
1
+ import{computed as v}from"@angular/core";import{resolveLunoraClient as f}from"./LUNORA_CLIENT-B0toApHY.mjs";import{stream as C}from"./stream-BuhiwhIH.mjs";import{subscription as E}from"./subscription-zJv48q6C.mjs";const y={__lunoraRef:""},I=[],N={awaiting_approval:"awaiting-approval",awaiting_secret:"awaiting-secret"},_=t=>{const o=t.status===void 0?void 0:N[t.status];if(o!==void 0)return{seq:t.seq,type:o,...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}},k=t=>{if(t.role==="assistant"&&t.toolCalls)return t.toolCalls.map(r=>({input:r.input,seq:t.seq,toolCallId:r.id,toolName:r.name,type:"call"}));if(t.role!=="tool")return;const o=_(t);return o!==void 0?[o]:[{output:t.content,seq:t.seq,type:"result",...t.status==="approved"||t.status==="rejected"?{status:t.status}:{},...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}]},R=t=>{const{api:o,limit:r,stream:e,threadKey:l}=t,a=f(t.client),{destroyRef:i}=t,s=r===void 0?{key:l}:{key:l,limit:r},{data:u}=E(o.agents.agentMessages,s,{client:a,destroyRef:i}),c=e===void 0?"skip":{key:l},{chunks:p}=C(e??y,c,{client:a,destroyRef:i});return{events:v(()=>{const d=(u()??I).flatMap(n=>k(n)??[]);for(const n of p())n.kind==="progress"&&n.threadKey===l&&d.push({data:n.data,toolCallId:n.toolCallId,type:"progress"});return d})}};export{R as agentToolEvents};
@@ -0,0 +1 @@
1
+ import{inject as h,DestroyRef as k,signal as o,computed as c}from"@angular/core";import{getIdentityStore as l,isLoadingStatus as y,isAuthenticatedStatus as m}from"@lunora/client/auth";import{resolveLunoraClient as A}from"./LUNORA_CLIENT-B0toApHY.mjs";const T=(s={})=>{const t=A(s.client),n=s.destroyRef??h(k),e=l(t),u=o(t.getAuthToken()),r=o(e.getUser()),a=o(e.getStatus()),i=t.onAuthTokenChange(()=>{u.set(t.getAuthToken())}),d=e.subscribe(()=>{r.set(e.getUser()),a.set(e.getStatus())});return n.onDestroy(()=>{i(),d()}),{setToken:g=>{t.setAuthToken(g)},status:a.asReadonly(),token:u.asReadonly(),user:r.asReadonly()}},p=(s={})=>{const{status:t}=T(s),n=c(()=>y(t()));return{isAuthenticated:c(()=>m(t())),isLoading:n}};export{T as auth,p as authGate};
@@ -0,0 +1 @@
1
+ import{inject as r,DestroyRef as i,signal as a}from"@angular/core";import{resolveLunoraClient as u}from"./LUNORA_CLIENT-B0toApHY.mjs";const y=(t={})=>{const n=u(t.client),e=t.destroyRef??r(i),o=a(n.connectionStatus()),s=n.onConnectionStatus(c=>{o.set(c)});return e.onDestroy(s),o.asReadonly()};export{y as connectionStatus};
@@ -0,0 +1 @@
1
+ import{inject as l,DestroyRef as u,signal as a}from"@angular/core";import{resolveLunoraClient as i}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as d}from"./platform-DGTu4Ucl.mjs";const m="__lunora_flags__:eval",_=t=>{const e=typeof t;return e==="boolean"||e==="number"||e==="string"?e:"object"},v={__lunoraRef:m},y=(t,e,n)=>{try{return t.subscribe(v,{default:e.default,key:e.key,type:_(e.default)},c=>{n(c)},{onError:()=>{n(e.default)}})}catch{return()=>{}}},k=(t,e,n={})=>{const c=i(n.client),f=n.destroyRef===void 0,o=n.destroyRef??l(u),r=a(e);return d(f)&&o.onDestroy(y(c,{default:e,key:t},s=>{r.set(s)})),r.asReadonly()},h=(t,e={})=>{const n=i(e.client),c=e.destroyRef===void 0,f=e.destroyRef??l(u),o=a({...t});if(!d(c))return o.asReadonly();const r=[];for(const[s,b]of Object.entries(t))r.push(y(n,{default:b,key:s},R=>{o.set({...o(),[s]:R})}));return f.onDestroy(()=>{for(const s of r)s()}),o.asReadonly()};export{k as flag,h as flags};
@@ -0,0 +1 @@
1
+ import{inject as v,DestroyRef as h,signal as s}from"@angular/core";import{resolveLunoraClient as b}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as p}from"./platform-DGTu4Ucl.mjs";const j=(i,e={})=>{const o=b(e.client),c=e.destroyRef===void 0,d=e.destroyRef??v(h),{args:a,functionPath:f,shardKey:y,value:l}=i,t=s(o.identityEpoch()===0?l:void 0),n=s(void 0),u={__lunoraRef:f};if(p(c)){const R=o.subscribe(u,a,r=>{t.set(r),n.set(void 0)},{onError:r=>{n.set(r)},shardKey:y}),m=o.onIdentityChange(()=>{t.set(void 0)});d.onDestroy(()=>{m(),R()})}return{data:t.asReadonly(),error:n.asReadonly()}};export{j as hydratePreloaded};
@@ -0,0 +1 @@
1
+ import{computed as g,inject as q,DestroyRef as z,signal as S}from"@angular/core";import{initialPages as J,derivePaginationStatus as W,applyLoadMore as T,rebalance as U}from"@lunora/client/pagination";import{stableWireKey as X}from"@lunora/wire";import{resolveLunoraClient as B}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as E,a as Y}from"./platform-DGTu4Ucl.mjs";const Z=(a,t)=>`${a}::${X(t)}`,_=(a,t)=>({...t,paginationOpts:{cursor:a.lower,endCursor:a.upper,numItems:a.numItems}}),$=(a,t,s,d)=>{const c=B(s.client),K=s.destroyRef===void 0&&d===void 0,{initialNumItems:i,shardKey:R}=s,h=a.__lunoraRef,w=t==="skip"?{}:t,e=S(J(i)),x=S([]),O=S("LoadingFirstPage"),C=S(void 0),P=new Map,f=new Map,b=new Set,D=new WeakMap,v=u=>{let n=D.get(u);return n===void 0&&(n=Z(h,_(u,w)),D.set(u,n)),n},L=()=>{const n=e().map(o=>{const l=v(o);return f.get(l)});x.set(n);const{status:p}=W(t==="skip",n);O.set(p)},G=(u,n)=>{for(const p of n){const o=v(p);if(f.has(o))continue;const l=u.find(r=>r.lower===p.lower);if(l){const r=f.get(v(l));r&&f.set(o,r)}}},H=u=>{const n=new Set;for(const o of u)n.add(v(o));for(const[o,l]of P)n.has(l.currentKey)||(l.unsub(),P.delete(o),f.delete(l.currentKey));const p=new Set([...P.values()].map(o=>o.currentKey));for(const o of u){const l=_(o,w),r=v(o);if(p.has(r))continue;const y={currentKey:r,unsub:void 0};b.add(r);const I=c.subscribe(a,l,M=>{if(f.set(y.currentKey,M),b.delete(y.currentKey),C.set(void 0),L(),b.size===0){const m=e(),k=U(m,x());k&&(G(m,k),e.set(k),F(k),L())}},{onError:M=>{b.delete(r),C.set(M);const m=e(),k=m.at(-1);m.length>1&&k&&!f.has(r)&&v(k)===r&&(e.set(m.slice(0,-1)),F(e())),L(),s.onError?.(M)},shardKey:R});y.unsub=I,P.set(r,y),p.add(r)}};let j=!1,N=!1;const F=u=>{if(j){N=!0;return}j=!0;try{let n=u;do N=!1,H(n),n=e();while(N)}finally{j=!1}};t!=="skip"&&E(K)&&F(e()),L();const Q=()=>{for(const u of P.values())u.unsub();P.clear(),f.clear()};return d===void 0?(s.destroyRef??q(z)).onDestroy(Q):d(Q),{error:C,loadMore:u=>{if(t==="skip")return;const{nextCursor:n,status:p}=W(!1,x());if(p!=="CanLoadMore")return;const o=T(e(),n,u);if(!o)return;const l=e().at(-1),r=o.at(-2);if(l&&r){const y=v(l),I=v(r),M=P.get(y);if(M&&y!==I){const m=f.get(y);m&&f.set(I,m),M.unsub(),P.delete(y),f.delete(y)}}C.set(void 0),e.set(o),F(e()),L()},pageResults:x,skipped:g(()=>t==="skip"),status:O}},V=(a,t,s)=>{if(typeof t!="function")return $(a,t,s);const d=B(s.client),c=s.destroyRef===void 0,K=s.destroyRef??q(z),i=S(void 0);return E(c)&&Y(t,{destroyRef:K,injector:s.injector},(R,h)=>{const w=[];i.set($(a,R,{...s,client:d},e=>w.push(e))),h(()=>{for(const e of w)e()})}),{error:g(()=>i()?.error()),loadMore:R=>{i()?.loadMore(R)},pageResults:g(()=>i()?.pageResults()??[]),skipped:g(()=>i()?.skipped()??t()==="skip"),status:g(()=>i()?.status()??"LoadingFirstPage")}},re=(a,t,s)=>{const d=V(a,t,s),c=g(()=>d.pageResults().flatMap(i=>i?.page??[])),K=g(()=>{const i=d.status();return!d.skipped()&&(i==="LoadingFirstPage"||i==="LoadingMore")});return{error:d.error,isLoading:K,loadMore:d.loadMore,results:c,status:d.status}},ae=(a,t,s)=>{const{initialNumItems:d}=s,c=V(a,t,s),K=g(()=>c.pageResults().flatMap(e=>e?[e.page]:[])),i=g(()=>!c.skipped()&&c.status()==="LoadingFirstPage"),R=g(()=>c.status()==="CanLoadMore"),h=g(()=>!c.skipped()&&c.status()==="LoadingMore"),w=e=>{c.loadMore(e??d)};return{error:c.error,fetchNextPage:w,hasNextPage:R,isFetchingNextPage:h,isLoading:i,pages:K,status:c.status}};export{ae as infiniteQuery,re as paginatedQuery};
@@ -0,0 +1 @@
1
+ import{inject as u,DestroyRef as y,signal as v}from"@angular/core";import{createQuerySubscription as m}from"@lunora/client/query";import{resolveLunoraClient as R}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as p,a as b}from"./platform-DGTu4Ucl.mjs";const g=(c,t,e={})=>{const i=R(e.client),a=e.destroyRef===void 0,s=e.destroyRef??u(y),o=v(void 0),n=(r,f)=>{o.set(void 0);const l=m(i,c,r,{onData:d=>{o.set(d)},onError:e.onError,onReset:()=>{o.set(void 0)}},{shardKey:e.shardKey});f(l)};return p(a)&&(typeof t=="function"?b(t,{destroyRef:s,injector:e.injector},n):n(t,r=>s.onDestroy(r))),o.asReadonly()};export{g as liveQuery};
@@ -0,0 +1 @@
1
+ import{inject as D,DestroyRef as E,signal as d}from"@angular/core";import{liveTopicSubscription as K,subscribeLiveTopic as p}from"@lunora/client";import{resolveLunoraClient as j}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as x,a as C}from"./platform-DGTu4Ucl.mjs";const v=e=>({headers:e.headers,maxDelayMs:e.maxDelayMs,retryDelay:e.retryDelay,sessionKey:e.sessionKey,topic:e.topic,url:e.url,withCredentials:e.withCredentials}),L=(e,t={})=>{const u=j(t.client),m=t.destroyRef===void 0,i=t.destroyRef??D(E),n=d(void 0),s=d(void 0),h=typeof e=="function"?e:()=>e,{sessionKey:c,shardKey:y}=t,f=r=>typeof r=="function"?r():r,a=()=>K(u,h(),{...t,sessionKey:f(c),shardKey:f(y)}),l=(r,b)=>{n.set(void 0),s.set(void 0);const R=p({...r,onError:o=>{s.set(o),t.onError?.(o)},onEvent:o=>{n.set(o),s.set(void 0),t.onEvent?.(o)}});b(R)};return x(m)&&(typeof e=="function"||typeof c=="function"||typeof y=="function"?C(()=>v(a()),{destroyRef:i,injector:t.injector},l):l(v(a()),r=>i.onDestroy(r))),{error:s.asReadonly(),lastEvent:n.asReadonly()}};export{L as liveTopic};
@@ -0,0 +1 @@
1
+ import{resolveLunoraClient as c}from"./LUNORA_CLIENT-B0toApHY.mjs";const l=(t,o,n={})=>{const{client:e,...r}=n,s=r;return c(e).mutation(t,o,s)};export{l as mutate};
@@ -0,0 +1 @@
1
+ import{signal as o,computed as d}from"@angular/core";import{createMutatorRunner as c}from"@lunora/client";const u=n=>{const r=o(void 0),e=o(!1),s=d(()=>r()!==void 0),{mutate:a,reset:i}=c(n,{setError:t=>{r.set(t)},setPending:t=>{e.set(t)}});return{error:r.asReadonly(),isError:s,mutate:a,pending:e.asReadonly(),reset:i}};export{u as mutator};
@@ -0,0 +1 @@
1
+ import{inject as i,PLATFORM_ID as c,computed as a,effect as u,untracked as d,NgZone as f}from"@angular/core";import{stableWireKey as l}from"@lunora/wire";const v=e=>e?i(c,{optional:!0})!=="server":!0,p=e=>{const r=e?i(f,{optional:!0}):void 0;return r?t=>r.runOutsideAngular(t):t=>t()},y=(e,r)=>p(e)(r),h=(e,r,t)=>{let n;const s=a(()=>l(e()));try{n=u(o=>{s(),d(()=>{t(e(),o)})},{injector:r.injector,manualCleanup:!0})}catch(o){throw r.injector!==void 0?o:new Error("reactive `args` need an injection context: call this primitive from a component/service field or constructor, or pass `injector` alongside `destroyRef`.",{cause:o})}r.destroyRef.onDestroy(()=>{n.destroy()})};export{h as a,p as o,y as r,v as s};
@@ -0,0 +1 @@
1
+ import{inject as S,DestroyRef as U,signal as v}from"@angular/core";import{resolveLunoraClient as C}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as E,r as A}from"./platform-DGTu4Ucl.mjs";const w=t=>{if(!Number.isFinite(t)||t<=0)throw new RangeError(`presence intervalMs must be a positive number, got ${String(t)}`)},L=()=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const t=crypto.getRandomValues(new Uint8Array(16));return Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},V=1e4,H=(t,e)=>{const s=C(e.client),u=e.destroyRef===void 0,p=e.destroyRef??S(U),{heartbeat:b,listPresent:g,shardKey:i}=e,f=e.intervalMs??V,a=e.sessionId??L(),y=v(void 0),c=v(void 0);w(f);let d=e.data,l=!1;const o=()=>{const n={roomId:t,sessionId:a};d!==void 0&&(n.data=d),s.mutation(b,n,{shardKey:i}).catch(()=>{})},R=n=>{d=n,l&&o()};if(E(u)){l=!0;const n=s.acquireConnectionContext({roomId:t,sessionId:a},{shardKey:i});o();const m=()=>{typeof document<"u"&&document.visibilityState==="visible"&&o()},I=A(u,()=>(typeof document<"u"&&document.addEventListener("visibilitychange",m),setInterval(o,f))),h={roomId:t},D=s.subscribe(g,h,r=>{y.set(r),c.set(void 0)},{onError:r=>{c.set(r),e.onError?.(r)},shardKey:i});p.onDestroy(()=>{l=!1,clearInterval(I),typeof document<"u"&&document.removeEventListener("visibilitychange",m),n(),D()})}return{error:c.asReadonly(),present:y.asReadonly(),sessionId:a,setData:R}};export{H as presence};
@@ -0,0 +1 @@
1
+ import{inject as w,DestroyRef as y,signal as p,computed as v}from"@angular/core";import{evaluate as f}from"@lunora/ratelimit";const R=(o,r={})=>{const m=r.destroyRef??w(y),n=r.now??Date.now,k=r.tickMs??1e3;let t;const i=()=>f(o,t,{consume:!1,count:1,now:n(),reserve:!1}).status,e=p(i()),a=()=>{e.set(i())};let s;const l=()=>{s!==void 0&&(clearInterval(s),s=void 0)},d=()=>{e().ok||s!==void 0||(s=setInterval(()=>{a(),e().ok&&l()},k))};return d(),m.onDestroy(()=>{l()}),{check:(u=1)=>f(o,t,{consume:!1,count:u,now:n(),reserve:!1}).status.ok,consume:(u=1)=>{const c=f(o,t,{consume:!0,count:u,now:n(),reserve:!1});return c.value!==void 0&&(t=c.value),a(),d(),c.status},disabled:v(()=>!e().ok),ok:v(()=>e().ok),reset:()=>{t=void 0,l(),a()},retryAfter:v(()=>e().retryAfter)}};export{R as rateLimit};
@@ -0,0 +1 @@
1
+ import{resolveLunoraClient as e}from"./LUNORA_CLIENT-B0toApHY.mjs";const l=(n,o,t={})=>{const{client:r,...c}=t;return e(r).action(n,o,c)};export{l as runAction};
@@ -0,0 +1 @@
1
+ import{inject as R,DestroyRef as b,signal as n}from"@angular/core";import{resolveLunoraClient as k}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as p}from"./platform-DGTu4Ucl.mjs";const g=(u,o,e={})=>{const d=k(e.client),m=e.destroyRef??R(b),y=e.destroyRef===void 0,a=n([]),c=n(void 0),t=n("idle");let s=!0,l;const f=()=>{s=!1,l?.()};if(o!=="skip"&&p(y)){t.set("streaming");const i=d.stream(u,o,{durable:e.durable,maxBuffer:e.maxBuffer,shardKey:e.shardKey});l=()=>{i.cancel()},(async()=>{try{for await(const r of i){if(!s)return;a.update(h=>[...h,r])}s&&t.set("complete")}catch(r){if(!s)return;c.set(r instanceof Error?r:new Error(String(r))),t.set("error")}})().catch(()=>{})}return m.onDestroy(f),{cancel:f,chunks:a.asReadonly(),error:c.asReadonly(),status:t.asReadonly()}};export{g as stream};
@@ -0,0 +1 @@
1
+ import{inject as m,DestroyRef as R,signal as a}from"@angular/core";import{createQuerySubscription as p}from"@lunora/client/query";import{resolveLunoraClient as b}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as h,a as j}from"./platform-DGTu4Ucl.mjs";const C=(d,n,e={})=>{const f=b(e.client),v=e.destroyRef===void 0,i=e.destroyRef??m(R),l=e.onError,o=a(void 0),r=a(void 0),c=(t,u)=>{if(o.set(void 0),r.set(void 0),t==="skip")return;const y=p(f,d,t,{onData:s=>{o.set(s),r.set(void 0)},onError:s=>{r.set(s),o.set(void 0),l?.(s)},onReset:()=>{o.set(void 0)}},{shardKey:e.shardKey});u(y)};return h(v)&&(typeof n=="function"?j(n,{destroyRef:i,injector:e.injector},c):c(n,t=>i.onDestroy(t))),{data:o.asReadonly(),error:r.asReadonly()}};export{C as subscription};
@@ -0,0 +1 @@
1
+ import{inject as B,DestroyRef as K,signal as T}from"@angular/core";import{resolveLunoraClient as V}from"./LUNORA_CLIENT-B0toApHY.mjs";import{o as q}from"./platform-DGTu4Ucl.mjs";const D="/_lunora/ws",j="/_lunora/voice/",J=4001,L=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,G=e=>{const s=e.startsWith("agents:")?e.slice(7):e;return s.endsWith("Voice")?s.slice(0,-5):s},X=(e,s)=>{if(s===void 0||s==="")return L(e);if(s.endsWith(D))return s.slice(0,-D.length);try{return new URL(s).origin}catch{return L(e)}},z=e=>{const s=X(e.httpUrl,e.wsUrl),r=s.endsWith("/")?s.slice(0,-1):s,i=new URLSearchParams({threadKey:e.threadKey});return`${r}${j}${encodeURIComponent(e.agent)}?${i.toString()}`},Q=(e,s)=>{if(s?.code===J)return new Error(`${e}: authentication token expired — refresh the credential and start a new call`)},Y=(e,s,r)=>{const i=e.currentIdentity();return e.onAuthTokenChange(()=>{e.currentIdentity()!==i&&r(new Error(`${s}: the signed-in identity changed during the call — the session was ended; start a new call`))})},Z=16e3,ee=e=>{if(e.length===0)return 0;let s=0;for(const r of e)s+=r*r;return Math.sqrt(s/e.length)},te=(e,s)=>{const r=s/Z,i=r>1?Math.floor(e.length/r):e.length,k=new ArrayBuffer(i*2),l=new DataView(k);for(let u=0;u<i;u+=1){const y=e[Math.floor(u*r)]??0,d=Math.max(-1,Math.min(1,y));l.setInt16(u*2,d<0?d*32768:d*32767,!0)}return new Uint8Array(k)},ne=async e=>{const s=globalThis,r=s.navigator?.mediaDevices?.getUserMedia.bind(s.navigator.mediaDevices),i=s.AudioContext??s.webkitAudioContext;if(!r||!i)throw new Error("voiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const k=await r({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),l=new i,u=l.createMediaStreamSource(k),y=l.createScriptProcessor(4096,1,1);let d=!1,m=!1,c=0,g=0;return y.onaudioprocess=p=>{const f=p.inputBuffer.getChannelData(0),a=d?0:ee(f);if(e.onLevel(a),d)return;if(e.onAudio(te(f,l.sampleRate)),e.isTurnActive()){g=a>=e.interruptThreshold?g+1:0,g>=e.interruptChunks&&(g=0,e.onInterrupt());return}g=0;const S=f.length/l.sampleRate*1e3;if(a>=e.silenceThreshold){m=!0,c=0;return}m&&(c+=S,c>=e.silenceDurationMs&&(m=!1,c=0,e.onSilence()))},u.connect(y),y.connect(l.destination),{setMuted:p=>{d=p},stop:()=>{y.disconnect(),u.disconnect();for(const p of k.getTracks())p.stop();l.close()}}},se=()=>{const e=globalThis,s=e.AudioContext??e.webkitAudioContext;if(!s)throw new Error("voiceAgent: audio playback requires AudioContext (no browser audio available)");const r=new s,i=new Set;let k=0,l=Promise.resolve(),u=0;const y=async(c,g)=>{if(g!==u)return;let p;try{p=await r.decodeAudioData(c.buffer)}catch{return}if(g!==u)return;const f=r.createBufferSource();f.buffer=p,f.connect(r.destination);const a=Math.max(r.currentTime,k);f.start(a),k=a+p.duration,i.add(f),f.onended=()=>{i.delete(f)}},d=c=>{const g=Uint8Array.from(c),p=u;l=l.then(()=>y(g,p))},m=()=>{u+=1;for(const c of i)try{c.stop()}catch{}i.clear(),k=r.currentTime};return{enqueue:d,interrupt:m,stop:()=>{m(),r.close()}}},F=1,re=.01,oe=1200,ae=.15,ie=3,de=e=>{const{createMicrophone:s=ne,createSpeaker:r=se,createSocket:i,interruptChunks:k=ie,interruptThreshold:l=ae,silenceDurationMs:u=oe,silenceThreshold:y=re,threadKey:d,voice:m}=e,c=V(e.client),g=e.destroyRef===void 0,p=e.destroyRef??B(K),f=q(g),a=T("idle"),S=T(!1),_=T(""),v=T(""),x=T(0),R=T(!1),w=T(void 0);let o,b=!1;const M=n=>{const t=o?.socket;return t?.readyState===F?(t.send(JSON.stringify(n)),!0):!1},E=()=>{const n=o;if(o=void 0,n){n.unwatchIdentity?.(),n.microphone?.stop(),n.speaker?.stop(),n.socket.onmessage=null,n.socket.onerror=null,n.socket.onclose=null;try{n.socket.close()}catch{}}b=!1,S.set(!1),a.set("idle"),x.set(0)},W=E,N=n=>{const t=o;switch(n.type){case"assistant_delta":{t&&(t.speaking=!0),a.set("speaking"),v.update(I=>I+n.text);break}case"assistant_discarded":{t&&(t.suppressAudio=!0),t?.speaker?.interrupt(),v.set("");break}case"assistant_done":{t&&(t.awaitingTurn=!1,t.speaking=!1),v.set(n.text),a.set("listening");break}case"error":{t&&(t.awaitingTurn=!1,t.speaking=!1),w.set(new Error(n.message)),a.set("listening");break}case"interrupted":{t&&(t.awaitingTurn=!1,t.speaking=!1,t.suppressAudio=!1),t?.speaker?.interrupt(),a.set("listening");break}case"ready":{t&&(t.audioFormat=n.audioFormat,t.suppressAudio=!1),S.set(!0),a.set("listening");break}case"user_transcript":{t&&(t.suppressAudio=!1),_.set(n.text),v.set(""),a.set("thinking");break}}},O=n=>{const t=o;!t||t.suppressAudio||(t.speaker??=r({audioFormat:t.audioFormat}),t.speaking=!0,a.set("speaking"),t.speaker.enqueue(n))},P=async()=>{if(o||b)return;b=!0,w.set(void 0),_.set(""),v.set("");let n;try{const t=z({agent:G(m.__lunoraRef),httpUrl:c.url,threadKey:typeof d=="function"?d():d,wsUrl:c.wsUrl}),I=i??(h=>{const C=c.getWebSocketImpl();if(!C)throw new Error("voiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new C(h)}),A=f(()=>I(t));A.binaryType="arraybuffer",n={audioFormat:"mp3",microphone:void 0,socket:A,speaker:void 0,speaking:!1,awaitingTurn:!1,suppressAudio:!1,unwatchIdentity:void 0},o=n,n.unwatchIdentity=Y(c,"voiceAgent",h=>{o===n&&(w.set(h),E())}),A.onmessage=h=>{if(typeof h.data=="string"){try{N(JSON.parse(h.data))}catch{}return}O(new Uint8Array(h.data))},A.onerror=()=>{w.set(new Error("voiceAgent: voice socket error"))},A.onclose=h=>{if(o!==n)return;const C=Q("voiceAgent",h);C&&w.set(C),E()};const U=await f(async()=>s({interruptChunks:k,interruptThreshold:l,isTurnActive:()=>(o?.speaking??!1)||(o?.awaitingTurn??!1),onAudio:h=>{A.readyState===F&&A.send(h)},onInterrupt:()=>{M({type:"interrupt"}),o?.speaker?.interrupt(),o&&(o.awaitingTurn=!1,o.speaking=!1,o.suppressAudio=!0),a.set("listening")},onLevel:h=>{x.set(h)},onSilence:()=>{M({type:"commit"}),o&&(o.awaitingTurn=!0),a.set("thinking")},silenceDurationMs:u,silenceThreshold:y}));o===n?(n.microphone=U,R.set(!1),n.speaking||a.set("listening")):U.stop()}catch(t){o===n&&(w.set(t instanceof Error?t:new Error(String(t))),E())}finally{b=!1}},H=()=>{const n=!R();return o?.microphone?.setMuted(n),R.set(n),n},$=n=>{M({text:n,type:"text"})&&(o&&(o.awaitingTurn=!0),a.set("thinking"))};return p.onDestroy(E),{audioLevel:x.asReadonly(),connected:S.asReadonly(),endCall:W,error:w.asReadonly(),interimTranscript:v.asReadonly(),isMuted:R.asReadonly(),sendText:$,startCall:P,status:a.asReadonly(),toggleMute:H,transcript:_.asReadonly()}};export{de as voiceAgent};
@@ -0,0 +1 @@
1
+ export { type ArgsOf, type AuthLike, type FunctionReference, type HeadersSource, type Preloaded, type ReturnOf, type ServerClientOptions, type ServerSession, createServerClient, deserializePreloaded, getServerSession, preloadQuery, preloadedQueryResult, serializePreloaded } from '@lunora/client/ssr';
@@ -0,0 +1 @@
1
+ export { type ArgsOf, type AuthLike, type FunctionReference, type HeadersSource, type Preloaded, type ReturnOf, type ServerClientOptions, type ServerSession, createServerClient, deserializePreloaded, getServerSession, preloadQuery, preloadedQueryResult, serializePreloaded } from '@lunora/client/ssr';
@@ -0,0 +1 @@
1
+ import{createServerClient as d,deserializePreloaded as l,getServerSession as a,preloadQuery as o,preloadedQueryResult as i,serializePreloaded as s}from"@lunora/client/ssr";export{d as createServerClient,l as deserializePreloaded,a as getServerSession,o as preloadQuery,i as preloadedQueryResult,s as serializePreloaded};
package/dist/upload.d.mts CHANGED
@@ -1,3 +1,23 @@
1
+ /**
2
+ * `@lunora/angular/upload` — end-user file-upload signals.
3
+ *
4
+ * The admin `uploadStorageObject` path on `LunoraClient` is a one-shot PUT gated
5
+ * by an `adminToken` — right for the Studio file browser, wrong for end users.
6
+ * This module gives end-user browsers progress, pause/resume, large-file
7
+ * resumable uploads and per-part retry by wrapping `@lunora/client/upload` (the
8
+ * framework-neutral core, itself a re-export of `@visulima/storage-client` —
9
+ * Lunora does not hand-roll the uploader) in Angular signals. Point {@link upload}
10
+ * at a route backed by `@lunora/storage/upload`'s RLS-gated handler — end-user
11
+ * uploads gated by _your_ per-user policy, not an `adminToken`.
12
+ *
13
+ * Unlike the React/Vue/Solid/Svelte adapters, this one is hand-written rather
14
+ * than a re-export: `@visulima/storage-client` ships no `/angular` entry. It
15
+ * wraps the TUS / chunked-REST surface (identical shape on both — progress,
16
+ * pause, resume, abort) that `createUpload` defaults to; batch multipart
17
+ * uploads have a different shape (`uploadBatch`, per-item abort) and aren't
18
+ * wrapped here — call `createMultipartAdapter` (re-exported below) directly
19
+ * for that.
20
+ */
1
21
  import { Signal, DestroyRef } from '@angular/core';
2
22
  import { UploadResult, CreateUploadOptions, UploadProtocol } from '@lunora/client/upload';
3
23
  export { type ChunkedRestAdapter, type ChunkedRestAdapterOptions, type FingerprintFunction, type HeadersResolver, type MultipartAdapter, type MultipartAdapterOptions, type OnBeforeRequest, type RequestOptions, RestrictionError, type TusAdapter, type TusAdapterOptions, type UploadAdapter, UploadError, type UploadRestrictions, type UploadResult, createChunkedRestAdapter, createMultipartAdapter, createTusAdapter, createUpload } from '@lunora/client/upload';
package/dist/upload.d.ts CHANGED
@@ -1,3 +1,23 @@
1
+ /**
2
+ * `@lunora/angular/upload` — end-user file-upload signals.
3
+ *
4
+ * The admin `uploadStorageObject` path on `LunoraClient` is a one-shot PUT gated
5
+ * by an `adminToken` — right for the Studio file browser, wrong for end users.
6
+ * This module gives end-user browsers progress, pause/resume, large-file
7
+ * resumable uploads and per-part retry by wrapping `@lunora/client/upload` (the
8
+ * framework-neutral core, itself a re-export of `@visulima/storage-client` —
9
+ * Lunora does not hand-roll the uploader) in Angular signals. Point {@link upload}
10
+ * at a route backed by `@lunora/storage/upload`'s RLS-gated handler — end-user
11
+ * uploads gated by _your_ per-user policy, not an `adminToken`.
12
+ *
13
+ * Unlike the React/Vue/Solid/Svelte adapters, this one is hand-written rather
14
+ * than a re-export: `@visulima/storage-client` ships no `/angular` entry. It
15
+ * wraps the TUS / chunked-REST surface (identical shape on both — progress,
16
+ * pause, resume, abort) that `createUpload` defaults to; batch multipart
17
+ * uploads have a different shape (`uploadBatch`, per-item abort) and aren't
18
+ * wrapped here — call `createMultipartAdapter` (re-exported below) directly
19
+ * for that.
20
+ */
1
21
  import { Signal, DestroyRef } from '@angular/core';
2
22
  import { UploadResult, CreateUploadOptions, UploadProtocol } from '@lunora/client/upload';
3
23
  export { type ChunkedRestAdapter, type ChunkedRestAdapterOptions, type FingerprintFunction, type HeadersResolver, type MultipartAdapter, type MultipartAdapterOptions, type OnBeforeRequest, type RequestOptions, RestrictionError, type TusAdapter, type TusAdapterOptions, type UploadAdapter, UploadError, type UploadRestrictions, type UploadResult, createChunkedRestAdapter, createMultipartAdapter, createTusAdapter, createUpload } from '@lunora/client/upload';
package/dist/upload.mjs CHANGED
@@ -1 +1 @@
1
- import{inject as m,DestroyRef as y,signal as s}from"@angular/core";import{createUpload as E}from"@lunora/client/upload";import{RestrictionError as A,UploadError as b,createChunkedRestAdapter as C,createMultipartAdapter as D,createTusAdapter as P,createUpload as S}from"@lunora/client/upload";import{UploadControl as k}from"@visulima/storage-client";const v=l=>{const{destroyRef:i,...u}=l,c=i??m(y),r=E(u),n=s(0),t=s("idle"),d=s(void 0),o=s(void 0),a=s(!1);r.setOnStart(()=>{t.set("uploading")}),r.setOnProgress(e=>{n.set(e)}),r.setOnFinish(e=>{d.set(e),t.set("success")}),r.setOnError(e=>{o.set(e),t.set("error")});const f=e=>(o.set(void 0),d.set(void 0),n.set(0),a.set(!1),t.set("uploading"),r.upload(e)),R=()=>{t()==="uploading"&&(r.pause(),a.set(!0),t.set("paused"))},g=()=>{t()==="paused"&&r.resume().then(()=>{a.set(!1),t.set("uploading")}).catch(e=>{o.set(e instanceof Error?e:new Error(String(e))),t.set("error")})},p=()=>{r.abort()};return c.onDestroy(p),{abort:p,error:o.asReadonly(),isPaused:a.asReadonly(),pause:R,progress:n.asReadonly(),result:d.asReadonly(),resume:g,start:f,status:t.asReadonly()}};export{A as RestrictionError,k as UploadControl,b as UploadError,C as createChunkedRestAdapter,D as createMultipartAdapter,P as createTusAdapter,S as createUpload,v as upload};
1
+ import{inject as g,DestroyRef as m,signal as r}from"@angular/core";import{createUpload as v}from"@lunora/client/upload";import{RestrictionError as D,UploadError as E,createChunkedRestAdapter as P,createMultipartAdapter as b,createTusAdapter as C,createUpload as S}from"@lunora/client/upload";import{UploadControl as k}from"@visulima/storage-client";const x=p=>{const{destroyRef:c,...u}=p,l=c??g(m),s=v(u),n=r(0),t=r("idle"),d=r(void 0),o=r(void 0),a=r(!1);s.setOnStart(()=>{t.set("uploading")}),s.setOnProgress(e=>{n.set(e)}),s.setOnFinish(e=>{d.set(e),t.set("success")}),s.setOnError(e=>{o.set(e),t.set("error")});const f=e=>(o.set(void 0),d.set(void 0),n.set(0),a.set(!1),t.set("uploading"),s.upload(e)),R=()=>{t()==="uploading"&&(s.pause(),a.set(!0),t.set("paused"))},y=()=>{t()==="paused"&&s.resume().then(()=>{a.set(!1),t.set("uploading")}).catch(e=>{o.set(e instanceof Error?e:new Error(String(e))),t.set("error")})},i=()=>{s.abort()};return l.onDestroy(i),{abort:i,error:o.asReadonly(),isPaused:a.asReadonly(),pause:R,progress:n.asReadonly(),result:d.asReadonly(),resume:y,start:f,status:t.asReadonly()}};export{D as RestrictionError,k as UploadControl,E as UploadError,P as createChunkedRestAdapter,b as createMultipartAdapter,C as createTusAdapter,S as createUpload,x as upload};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/angular",
3
- "version": "1.0.0-alpha.26",
3
+ "version": "1.0.0-alpha.260",
4
4
  "description": "Angular reactive adapter for Lunora — signal-based live queries and mutations",
5
5
  "keywords": [
6
6
  "angular",
@@ -39,6 +39,10 @@
39
39
  "types": "./dist/index.d.ts",
40
40
  "import": "./dist/index.mjs"
41
41
  },
42
+ "./server": {
43
+ "types": "./dist/server.d.ts",
44
+ "import": "./dist/server.mjs"
45
+ },
42
46
  "./upload": {
43
47
  "types": "./dist/upload.d.ts",
44
48
  "import": "./dist/upload.mjs"
@@ -49,9 +53,10 @@
49
53
  "access": "public"
50
54
  },
51
55
  "dependencies": {
52
- "@lunora/client": "1.0.0-alpha.42",
53
- "@lunora/ratelimit": "1.0.0-alpha.19",
54
- "@visulima/storage-client": "1.0.0"
56
+ "@lunora/client": "1.0.0-alpha.277",
57
+ "@lunora/ratelimit": "1.0.0-alpha.191",
58
+ "@lunora/wire": "1.0.0-alpha.6",
59
+ "@visulima/storage-client": "1.0.9"
55
60
  },
56
61
  "peerDependencies": {
57
62
  "@angular/core": "^19.2.0 || ^20.0.0 || ^21.0.0 || ^22.0.0"
@@ -1 +0,0 @@
1
- import{InjectionToken as i,makeEnvironmentProviders as t,inject as l}from"@angular/core";import{LunoraClient as r}from"@lunora/client";const n=()=>globalThis.location?.origin??"",e=new i("lunora.client",{factory:()=>new r({url:n()}),providedIn:"root"}),s=(o={})=>t([{provide:e,useFactory:()=>o instanceof r?o:new r({...o,url:o.url??n()})}]),a=()=>l(e),m=o=>o??a();export{e as LUNORA_CLIENT,a as injectLunoraClient,s as provideLunora,m as resolveLunoraClient};
@@ -1 +0,0 @@
1
- import{inject as g,DestroyRef as h,computed as o,signal as v}from"@angular/core";import{resolveLunoraClient as R}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{subscription as K}from"./subscription-DJeoGEDR.mjs";const b=e=>{const{api:c,cancel:i,run:d,runArgs:u,threadKey:a}=e,n=R(e.client),l=e.destroyRef??g(h),{data:y}=K(c.agents.agentThread,{key:a},{client:n,destroyRef:l}),r=o(()=>y()),f=o(()=>r()?.status),s=v(!1),m=async(t,p)=>{s.set(!0);try{await n.mutation(d,{input:t,threadKey:a,...u,...p})}finally{s.set(!1)}};return{cancel:async()=>{const t=r()?.instanceId;i===void 0||t===void 0||await n.mutation(i,{instanceId:t,threadKey:a})},pending:s.asReadonly(),run:m,status:f,thread:r}};export{b as agent};
@@ -1 +0,0 @@
1
- import{inject as M,DestroyRef as E,signal as F,computed as i}from"@angular/core";import{reconcileOptimistic as R,maxSeq as k}from"@lunora/client";import{resolveLunoraClient as L}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{stream as N}from"./stream-CcvHiJf2.mjs";import{subscription as w}from"./subscription-DJeoGEDR.mjs";const O={__lunoraRef:""},H=d=>{const{api:l,cancel:y,limit:f,send:I,sendArgs:x,stream:h,threadKey:n}=d,s=L(d.client),m=d.destroyRef??M(E),j=f===void 0?{key:n}:{key:n,limit:f},{data:C}=w(l.agents.agentMessages,j,{client:s,destroyRef:m}),{data:K}=w(l.agents.agentThread,{key:n},{client:s,destroyRef:m}),A=h===void 0?"skip":{key:n},{chunks:S}=N(h??O,A,{client:s,destroyRef:m}),r=F([]);let g=0;const p=i(()=>K()),b=i(()=>p()?.status),c=i(()=>C()??[]),q=i(()=>{const t=c(),e=R(r(),t);if(e.length===0)return t;const a=k(t);return[...t,...e.map((o,u)=>({content:o.content,optimistic:!0,role:"user",seq:a+1+u}))]}),T=i(()=>{const t=c().filter(e=>e.role==="assistant").length;return S().filter(e=>e.kind!=="progress"&&e.threadKey===n&&e.turn>=t).map(e=>e.text).join("")}),_=async(t,e)=>{const a=g;g+=1;const o=k(c());r.set([...R(r(),c()),{content:t,id:a,maxDurableSeqAtSend:o}]);try{await s.mutation(I,{input:t,threadKey:n,...x,...e})}catch(u){throw r.set(r().filter(D=>D.id!==a)),u}},v=async(t,e,a)=>{const o=p()?.instanceId;if(o===void 0)throw new Error(`agentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await s.mutation(l.agents.agentResolveApproval,{decision:t,instanceId:o,threadKey:n,toolCallId:e,...a===void 0?{}:{note:a}})};return{approve:async(t,e)=>v("approve",t,e),cancel:async()=>{const t=p()?.instanceId;y===void 0||t===void 0||await s.mutation(y,{instanceId:t,threadKey:n})},messages:q,reject:async(t,e)=>v("reject",t,e),send:_,status:b,streamingText:T}};export{H as agentChat};
@@ -1 +0,0 @@
1
- import{computed as a}from"@angular/core";import{subscription as n}from"./subscription-DJeoGEDR.mjs";const c=t=>{const{data:r,error:e}=n(t.api.agents.agentState,{key:t.threadKey},{client:t.client,destroyRef:t.destroyRef}),o=a(()=>r());return{error:e,state:o}};export{c as agentState};
@@ -1 +0,0 @@
1
- import{inject as c,DestroyRef as f,computed as y}from"@angular/core";import{resolveLunoraClient as C}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{stream as v}from"./stream-CcvHiJf2.mjs";import{subscription as g}from"./subscription-DJeoGEDR.mjs";const I={__lunoraRef:""},N=[],k=t=>{if(t.role==="assistant"&&t.toolCalls)return t.toolCalls.map(l=>({input:l.input,seq:t.seq,toolCallId:l.id,toolName:l.name,type:"call"}));if(t.role==="tool")return t.status==="awaiting_approval"?[{seq:t.seq,type:"awaiting-approval",...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}]:[{output:t.content,seq:t.seq,type:"result",...t.status==="approved"||t.status==="rejected"?{status:t.status}:{},...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}]},j=t=>{const{api:l,limit:s,stream:e,threadKey:a}=t,r=C(t.client),i=t.destroyRef??c(f),d=s===void 0?{key:a}:{key:a,limit:s},{data:p}=g(l.agents.agentMessages,d,{client:r,destroyRef:i}),m=e===void 0?"skip":{key:a},{chunks:u}=v(e??I,m,{client:r,destroyRef:i});return{events:y(()=>{const n=(p()??N).flatMap(o=>k(o)??[]);for(const o of u())o.kind==="progress"&&o.threadKey===a&&n.push({data:o.data,toolCallId:o.toolCallId,type:"progress"});return n})}};export{j as agentToolEvents};
@@ -1 +0,0 @@
1
- import{inject as g,DestroyRef as h,signal as u,computed as i}from"@angular/core";import{getIdentityStore as d}from"@lunora/client/auth";import{resolveLunoraClient as k}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";const m=(o={})=>{const e=k(o.client),n=o.destroyRef??g(h),t=d(e),r=u(e.getAuthToken()),s=u(t.getUser()),l=e.onAuthTokenChange(()=>{r.set(e.getAuthToken())}),a=t.subscribe(()=>{s.set(t.getUser())});return n.onDestroy(()=>{l(),a()}),{setToken:c=>{e.setAuthToken(c)},token:r.asReadonly(),user:s.asReadonly()}},A=(o={})=>{const{token:e,user:n}=m(o),t=i(()=>e()!==null&&n()===null);return{isAuthenticated:i(()=>e()!==null&&n()!==null),isLoading:t}};export{m as auth,A as authGate};
@@ -1 +0,0 @@
1
- import{inject as c,DestroyRef as i,signal as a}from"@angular/core";import{resolveLunoraClient as l}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";const m=(o={})=>{const n=l(o.client),e=o.destroyRef??c(i),t=a(n.connectionStatus()),s=n.onConnectionStatus(r=>{t.set(r)});return e.onDestroy(s),t.asReadonly()};export{m as connectionStatus};
@@ -1 +0,0 @@
1
- import{inject as f,DestroyRef as y,signal as u}from"@angular/core";import{resolveLunoraClient as i}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";const d="__lunora_flags__:eval",b=r=>{const t=typeof r;return t==="boolean"||t==="number"||t==="string"?t:"object"},p={__lunoraRef:d},m=(r,t,s={})=>{const l=i(s.client),e=s.destroyRef??f(y),c=b(t),o=u(t);let n;try{n=l.subscribe(p,{context:s.context,default:t,key:r,type:c},a=>{o.set(a)},{onError:()=>{o.set(t)}})}catch{}return n&&e.onDestroy(n),o.asReadonly()},x=(r,t={})=>{const s=i(t.client),l=t.destroyRef??f(y),e=u({...r}),c=[];for(const[o,n]of Object.entries(r))try{const a=s.subscribe(p,{context:t.context,default:n,key:o,type:b(n)},_=>{e.set({...e(),[o]:_})},{onError:()=>{e.set({...e(),[o]:n})}});c.push(a)}catch{}return l.onDestroy(()=>{for(const o of c)o()}),e.asReadonly()};export{m as flag,x as flags};
@@ -1 +0,0 @@
1
- import{inject as m,DestroyRef as R,signal as t}from"@angular/core";import{resolveLunoraClient as h}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{s as v}from"./platform-BGZypnc9.mjs";const K=(a,o={})=>{const n=h(o.client),i=o.destroyRef===void 0,d=o.destroyRef??m(R),{args:l,functionPath:f,shardKey:y,value:c}=a,s=t(c),r=t(void 0),u={__lunoraRef:f};if(v(i)){const p=n.subscribe(u,l,e=>{s.set(e),r.set(void 0)},{onError:e=>{r.set(e)},shardKey:y});d.onDestroy(p)}return{data:s.asReadonly(),error:r.asReadonly()}};export{K as hydratePreloaded};
@@ -1 +0,0 @@
1
- import{computed as j,inject as Q,DestroyRef as W,signal as C}from"@angular/core";import{initialPages as q,derivePaginationStatus as J,applyLoadMore as z,rebalance as V}from"@lunora/client/pagination";import{resolveLunoraClient as G}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{s as H}from"./platform-BGZypnc9.mjs";const X=(e,r)=>e<r?-1:e>r?1:0,F=e=>{if(e===void 0)return"null";if(typeof e=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t=>F(t)).join(",")}]`;const r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype){const t=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${t} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const n=e,c=Object.keys(n).toSorted(X),a=[];for(const t of c){const s=n[t];s!==void 0&&a.push(`${JSON.stringify(t)}:${F(s)}`)}return`{${a.join(",")}}`},_=e=>{let r="";for(let n=0;n<e.length;n+=32768)r+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(r)},u="$lunora.wire$",T=64,Y="__proto__",Z=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},v=(e,r=0)=>{if(r>T)throw new RangeError(`wire-codec: value nesting exceeds the ${T}-level limit`);if(e===void 0)return[u,"undefined"];if(e===null)return null;const n=typeof e;if(n==="bigint")return[u,"bigint",e.toString()];if(n==="number"){const t=e;return Number.isNaN(t)?[u,"nan"]:t===1/0?[u,"inf"]:t===-1/0?[u,"-inf"]:t}if(n!=="object")return e;if(e instanceof Date)return[u,"date",v(e.getTime(),r+1)];if(e instanceof Error){const t=e,s={};for(const y of Object.keys(t))t[y]!==void 0&&(s[y]=v(t[y],r+1));const l=[u,"error",t.name,t.message,s];return t.cause!==void 0&&l.push(v(t.cause,r+1)),l}if(e instanceof URL)return[u,"url",e.href];if(e instanceof Map)return[u,"map",[...e.entries()].map(([t,s])=>[v(t,r+1),v(s,r+1)])];if(e instanceof Set)return[u,"set",[...e].map(t=>v(t,r+1))];if(e instanceof ArrayBuffer)return[u,"bytes",_(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,s=t.constructor.name,l=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return s==="Uint8Array"?[u,"bytes",_(l)]:[u,"bytes",_(l),s]}if(Array.isArray(e)){const t=e.map(s=>v(s,r+1));return t.length>0&&t[0]===u?[u,"arr",t]:t}if(!Z(e)){const t=e.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${t} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const c=e,a={};for(const t of Object.keys(c)){const s=c[t];if(s===void 0)continue;const l=v(s,r+1);t===Y?Object.defineProperty(a,t,{configurable:!0,enumerable:!0,value:l,writable:!0}):a[t]=l}return a},ee=e=>F(v(e)),S=(e,r)=>`${e}::${ee(r)}`,L=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),U=(e,r,n)=>{const c=G(n.client),a=n.destroyRef===void 0,t=n.destroyRef??Q(W),{initialNumItems:s,shardKey:l}=n,y=e.__lunoraRef,d=r==="skip"?{}:r,w=C(q(s)),$=C([]),I=C("LoadingFirstPage"),O=new Map,m=new Map,A=new Set,M=()=>{const f=w().map(h=>{const o=S(y,L(h,d));return m.get(o)});$.set(f);const{status:g}=J(r==="skip",f);I.set(g)},B=(f,g)=>{const h=o=>S(y,L(o,d));for(const o of g){const p=h(o);if(m.has(p))continue;const b=f.find(i=>i.lower===o.lower);if(b){const i=m.get(h(b));i&&m.set(p,i)}}},D=f=>{const g=new Set;for(const o of f)g.add(S(y,L(o,d)));for(const[o,p]of O)g.has(p.currentKey)||(p.unsub(),O.delete(o),m.delete(p.currentKey));const h=new Set([...O.values()].map(o=>o.currentKey));for(const o of f){const p=L(o,d),b=S(y,p);if(h.has(b))continue;const i={currentKey:b,unsub:void 0};A.add(b);const K=c.subscribe(e,p,P=>{if(m.set(i.currentKey,P),A.delete(i.currentKey),M(),A.size===0){const N=w(),k=V(N,$());k&&(B(N,k),w.set(k),E(k),M())}},{onError:()=>{A.delete(i.currentKey),M()},shardKey:l});i.unsub=K,O.set(b,i),h.add(b)}};let R=!1,x=!1;const E=f=>{if(R){x=!0;return}R=!0;try{let g=f;do x=!1,D(g),g=w();while(x)}finally{R=!1}};return r!=="skip"&&H(a)&&E(w()),M(),t.onDestroy(()=>{for(const f of O.values())f.unsub();O.clear(),m.clear()}),{loadMore:f=>{if(r==="skip")return;const{nextCursor:g,status:h}=J(!1,$());if(h!=="CanLoadMore")return;const o=z(w(),g,f);if(!o)return;const p=w().at(-1),b=o.at(-2);if(p&&b){const i=S(y,L(p,d)),K=S(y,L(b,d)),P=O.get(i);if(P&&i!==K){const N=m.get(i);N&&m.set(K,N),P.unsub(),O.delete(i),m.delete(i)}}w.set(o),E(w()),M()},pageResults:$,status:I}},oe=(e,r,n)=>{const c=U(e,r,n),a=j(()=>c.pageResults().flatMap(t=>t?.page??[]));return{isLoading:j(()=>{const t=c.status();return t==="LoadingFirstPage"||t==="LoadingMore"}),loadMore:c.loadMore,results:a,status:c.status}},ae=(e,r,n)=>{const{initialNumItems:c}=n,a=U(e,r,n),t=j(()=>a.pageResults().flatMap(d=>d?[d.page]:[])),s=j(()=>a.status()==="LoadingFirstPage"),l=j(()=>a.status()==="CanLoadMore"),y=j(()=>a.status()==="LoadingMore");return{fetchNextPage:d=>{a.loadMore(d??c)},hasNextPage:l,isFetchingNextPage:y,isLoading:s,pages:t,status:a.status}};export{ae as infiniteQuery,oe as paginatedQuery};
@@ -1 +0,0 @@
1
- import{inject as y,DestroyRef as c,signal as f}from"@angular/core";import{createQuerySubscription as m}from"@lunora/client/query";import{resolveLunoraClient as p}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{s as u}from"./platform-BGZypnc9.mjs";const D=(t,e,o={})=>{const s=p(o.client),i=o.destroyRef===void 0,n=o.destroyRef??y(c),r=f(void 0);if(u(i)){const a=m(s,t,e,{onData:d=>{r.set(d)},onError:o.onError,onReset:()=>{r.set(void 0)}},{shardKey:o.shardKey});n.onDestroy(a)}return r.asReadonly()};export{D as liveQuery};
@@ -1 +0,0 @@
1
- import{resolveLunoraClient as i}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";const u=(t,o,r={})=>{const{client:e,...n}=r;return i(e).mutation(t,o,n)};export{u as mutate};
@@ -1 +0,0 @@
1
- import{signal as o,computed as m}from"@angular/core";import{createMutatorRunner as d}from"@lunora/client";const c=s=>{const r=o(void 0),t=o(!1),n=m(()=>r()!==void 0),{mutate:a,reset:i}=d(s,{setError:e=>{r.set(e)},setPending:e=>{t.set(e)}});return{error:r.asReadonly(),isError:n,mutate:a,pending:t.asReadonly(),reset:i}};export{c as mutator};
@@ -1 +0,0 @@
1
- import{inject as n,PLATFORM_ID as o,NgZone as u}from"@angular/core";const i=r=>r?n(o,{optional:!0})!=="server":!0,a=(r,t)=>{const e=r?n(u,{optional:!0}):void 0;return e?e.runOutsideAngular(t):t()};export{a as r,i as s};
@@ -1 +0,0 @@
1
- import{inject as h,DestroyRef as R,signal as D}from"@angular/core";import{resolveLunoraClient as S}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{s as $,r as U}from"./platform-BGZypnc9.mjs";const w=(e="sess")=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const t=crypto.getRandomValues(new Uint8Array(16));return`${e}-${Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}`}}return`${e}-${Date.now().toString(36)}`},A=1e4,E=(e,t)=>{const n=S(t.client),d=t.destroyRef===void 0,y=t.destroyRef??h(R),{heartbeat:p,listPresent:f,shardKey:i}=t,r=t.intervalMs??A,a=t.sessionId??w(),u=D(void 0);if(!Number.isFinite(r)||r<=0)throw new RangeError(`presence intervalMs must be a positive number, got ${String(r)}`);let c=t.data;const s=()=>{const o={roomId:e,sessionId:a};c!==void 0&&(o.data=c),n.mutation(p,o,{shardKey:i}).catch(()=>{})},l=o=>{c=o,s()};if($(d)){const o=n.acquireConnectionContext({roomId:e,sessionId:a},{shardKey:i});s();const m=()=>{typeof document<"u"&&document.visibilityState==="visible"&&s()},v=U(d,()=>(typeof document<"u"&&document.addEventListener("visibilitychange",m),setInterval(s,r))),g={roomId:e},b=n.subscribe(f,g,I=>{u.set(I)},{shardKey:i});y.onDestroy(()=>{clearInterval(v),typeof document<"u"&&document.removeEventListener("visibilitychange",m),o(),b()})}return{present:u.asReadonly(),sessionId:a,setData:l}};export{E as presence};
@@ -1 +0,0 @@
1
- import{inject as w,DestroyRef as y,signal as p,computed as i}from"@angular/core";import{evaluate as v}from"@lunora/ratelimit";const A=(s,r={})=>{const m=r.destroyRef??w(y),n=r.now??Date.now,k=r.tickMs??1e3;let t;const f=()=>v(s,t,{consume:!1,count:1,now:n(),reserve:!1}).status,e=p(f()),a=()=>{e.set(f())};let o;const c=()=>{o!==void 0&&(clearInterval(o),o=void 0)},d=()=>{e().ok||o!==void 0||(o=setInterval(()=>{a(),e().ok&&c()},k))};return d(),m.onDestroy(()=>{c()}),{check:(u=1)=>v(s,t,{consume:!1,count:u,now:n(),reserve:!1}).status.ok,consume:(u=1)=>{const l=v(s,t,{consume:!0,count:u,now:n(),reserve:!1});return l.value!==void 0&&(t=l.value),a(),d(),l.status},disabled:i(()=>!e().ok),ok:i(()=>e().ok),reset:()=>{t=void 0,c(),a()},retryAfter:i(()=>e().retryAfter)}};export{A as rateLimit};
@@ -1 +0,0 @@
1
- import{inject as p,DestroyRef as h,signal as n}from"@angular/core";import{resolveLunoraClient as R}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";const k=(m,o,t={})=>{const u=R(t.client),d=t.destroyRef??p(h),a=n([]),c=n(void 0),r=n("idle");let s=!0,i;const f=()=>{s=!1,i?.()};if(o!=="skip"){r.set("streaming");const l=u.stream(m,o,{maxBuffer:t.maxBuffer,shardKey:t.shardKey});i=()=>{l.cancel()},(async()=>{try{for await(const e of l){if(!s)return;a.update(y=>[...y,e])}s&&r.set("complete")}catch(e){if(!s)return;c.set(e instanceof Error?e:new Error(String(e))),r.set("error")}})().catch(()=>{})}return d.onDestroy(f),{cancel:f,chunks:a.asReadonly(),error:c.asReadonly(),status:r.asReadonly()}};export{k as stream};
@@ -1 +0,0 @@
1
- import{inject as y,DestroyRef as m,signal as i}from"@angular/core";import{createQuerySubscription as u}from"@lunora/client/query";import{resolveLunoraClient as l}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{s as v}from"./platform-BGZypnc9.mjs";const E=(n,e,o={})=>{const a=l(o.client),d=o.destroyRef===void 0,c=o.destroyRef??y(m),r=i(void 0),s=i(void 0);if(e!=="skip"&&v(d)){const p=o.onError,f=u(a,n,e,{onData:t=>{r.set(t),s.set(void 0)},onError:t=>{s.set(t),r.set(void 0),p?.(t)},onReset:()=>{r.set(void 0)}},{shardKey:o.shardKey});c.onDestroy(f)}return{data:r.asReadonly(),error:s.asReadonly()}};export{E as subscription};
@@ -1 +0,0 @@
1
- import{inject as L,DestroyRef as W,signal as v}from"@angular/core";import{resolveLunoraClient as I}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";const B=e=>{if(e.length===0)return 0;let o=0;for(const n of e)o+=n*n;return Math.sqrt(o/e.length)},J=(e,o)=>{const n=o/16e3,a=n>1?Math.floor(e.length/n):e.length,d=new ArrayBuffer(a*2),i=new DataView(d);for(let l=0;l<a;l+=1){const g=e[Math.floor(l*n)]??0,h=Math.max(-1,Math.min(1,g));i.setInt16(l*2,h<0?h*32768:h*32767,!0)}return new Uint8Array(d)},K=async e=>{const o=globalThis,n=o.navigator?.mediaDevices?.getUserMedia.bind(o.navigator.mediaDevices),a=o.AudioContext??o.webkitAudioContext;if(!n||!a)throw new Error("voiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await n({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),i=new a,l=i.createMediaStreamSource(d),g=i.createScriptProcessor(4096,1,1);let h=!1,m=!1,p=0,f=0;return g.onaudioprocess=r=>{const u=r.inputBuffer.getChannelData(0),k=h?0:B(u);if(e.onLevel(k),h)return;if(e.onAudio(J(u,i.sampleRate)),e.isSpeaking()){f=k>=e.interruptThreshold?f+1:0,f>=e.interruptChunks&&(f=0,e.onInterrupt());return}f=0;const w=u.length/i.sampleRate*1e3;if(k>=e.silenceThreshold){m=!0,p=0;return}m&&(p+=w,p>=e.silenceDurationMs&&(m=!1,p=0,e.onSilence()))},l.connect(g),g.connect(i.destination),{setMuted:r=>{h=r},stop:()=>{g.disconnect(),l.disconnect();for(const r of d.getTracks())r.stop();i.close()}}},N=()=>{const e=globalThis,o=e.AudioContext??e.webkitAudioContext;if(!o)throw new Error("voiceAgent: audio playback requires AudioContext (no browser audio available)");const n=new o,a=new Set;let d=0,i=Promise.resolve(),l=0;const g=async(p,f)=>{if(f!==l)return;let r;try{r=await n.decodeAudioData(p.buffer)}catch{return}if(f!==l)return;const u=n.createBufferSource();u.buffer=r,u.connect(n.destination);const k=Math.max(n.currentTime,d);u.start(k),d=k+r.duration,a.add(u),u.onended=()=>{a.delete(u)}},h=p=>{const f=Uint8Array.from(p),r=l;i=i.then(()=>g(f,r))},m=()=>{l+=1;for(const p of a)try{p.stop()}catch{}a.clear(),d=n.currentTime};return{enqueue:h,interrupt:m,stop:()=>{m(),n.close()}}},D=1,P=.01,V=1200,j=.15,O=3,z=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,G=e=>{const o=e.__lunoraRef,n=o.startsWith("agents:")?o.slice(7):o;return n.endsWith("Voice")?n.slice(0,-5):n},H=(e,o,n)=>{const a=z(e),d=a.endsWith("/")?a.slice(0,-1):a,i=new URLSearchParams({threadKey:n});return`${d}/_lunora/voice/${encodeURIComponent(o)}?${i.toString()}`},Y=e=>{const{createMicrophone:o=K,createSpeaker:n=N,createSocket:a,interruptChunks:d=O,interruptThreshold:i=j,silenceDurationMs:l=V,silenceThreshold:g=P,threadKey:h,voice:m}=e,p=I(e.client),f=e.destroyRef??L(W),r=v("idle"),u=v(!1),k=v(""),w=v(""),x=v(0),S=v(!1),b=v(void 0);let c,M=!1;const T=s=>{const t=c?.socket;return t?.readyState===D?(t.send(JSON.stringify(s)),!0):!1},C=()=>{const s=c;if(c=void 0,s){s.microphone?.stop(),s.speaker?.stop();try{s.socket.close()}catch{}}M=!1,u.set(!1),r.set("idle"),x.set(0)},U=C,$=s=>{const t=c;switch(s.type){case"assistant_delta":{t&&(t.speaking=!0),r.set("speaking"),w.update(A=>A+s.text);break}case"assistant_done":{t&&(t.speaking=!1),w.set(s.text),r.set("listening");break}case"error":{t&&(t.speaking=!1),b.set(new Error(s.message)),r.set("listening");break}case"interrupted":{t&&(t.speaking=!1,t.suppressAudio=!1),t?.speaker?.interrupt(),r.set("listening");break}case"ready":{t&&(t.audioFormat=s.audioFormat,t.suppressAudio=!1),u.set(!0),r.set("listening");break}case"user_transcript":{t&&(t.suppressAudio=!1),k.set(s.text),w.set(""),r.set("thinking");break}}},E=s=>{const t=c;!t||t.suppressAudio||(t.speaker??=n({audioFormat:t.audioFormat}),t.speaking=!0,r.set("speaking"),t.speaker.enqueue(s))},_=async()=>{if(!(c||M)){M=!0,b.set(void 0),k.set(""),w.set("");try{const s=H(p.url,G(m),h),t=(a??(y=>new globalThis.WebSocket(y)))(s);t.binaryType="arraybuffer";const A={audioFormat:"mp3",microphone:void 0,socket:t,speaker:void 0,speaking:!1,suppressAudio:!1};c=A,t.onmessage=y=>{if(typeof y.data=="string"){try{$(JSON.parse(y.data))}catch{}return}E(new Uint8Array(y.data))},t.onerror=()=>{b.set(new Error("voiceAgent: voice socket error"))},t.onclose=()=>{c===A&&C()};const R=await o({interruptChunks:d,interruptThreshold:i,isSpeaking:()=>c?.speaking??!1,onAudio:y=>{t.readyState===D&&t.send(y)},onInterrupt:()=>{T({type:"interrupt"}),c?.speaker?.interrupt(),c&&(c.speaking=!1,c.suppressAudio=!0),r.set("listening")},onLevel:y=>{x.set(y)},onSilence:()=>{T({type:"commit"}),r.set("thinking")},silenceDurationMs:l,silenceThreshold:g});c===A?(A.microphone=R,S.set(!1),r.set("listening")):R.stop()}catch(s){b.set(s instanceof Error?s:new Error(String(s))),C()}finally{M=!1}}},q=()=>{const s=!S();return c?.microphone?.setMuted(s),S.set(s),s},F=s=>{T({text:s,type:"text"})&&r.set("thinking")};return f.onDestroy(C),{audioLevel:x.asReadonly(),connected:u.asReadonly(),endCall:U,error:b.asReadonly(),interimTranscript:w.asReadonly(),isMuted:S.asReadonly(),sendText:F,startCall:_,status:r.asReadonly(),toggleMute:q,transcript:k.asReadonly()}};export{Y as voiceAgent};