@lunora/angular 1.0.0-alpha.13 → 1.0.0-alpha.15

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 (40) hide show
  1. package/dist/index.mjs +1 -19
  2. package/dist/packem_shared/LUNORA_CLIENT-B0pGE0Tv.mjs +1 -0
  3. package/dist/packem_shared/agent-C-GavfBl.mjs +1 -0
  4. package/dist/packem_shared/agentChat-HRYt8rOf.mjs +1 -0
  5. package/dist/packem_shared/agentState-BAfa0QuC.mjs +1 -0
  6. package/dist/packem_shared/agentToolEvents-CBTZ_DsO.mjs +1 -0
  7. package/dist/packem_shared/auth-wTtWvuVS.mjs +1 -0
  8. package/dist/packem_shared/connectionStatus-C53UhkPi.mjs +1 -0
  9. package/dist/packem_shared/flag-BYFWoQTg.mjs +1 -0
  10. package/dist/packem_shared/hydratePreloaded-BKHgpXzQ.mjs +1 -0
  11. package/dist/packem_shared/infiniteQuery-YvF0in16.mjs +1 -0
  12. package/dist/packem_shared/liveQuery-DEIqmTPj.mjs +1 -0
  13. package/dist/packem_shared/mutate-DR8Uo8Hs.mjs +1 -0
  14. package/dist/packem_shared/mutator-Cw6jpG06.mjs +1 -0
  15. package/dist/packem_shared/platform-BGZypnc9.mjs +1 -0
  16. package/dist/packem_shared/presence-BMrTlOCF.mjs +1 -0
  17. package/dist/packem_shared/rateLimit-CQazDrPJ.mjs +1 -0
  18. package/dist/packem_shared/stream-CcvHiJf2.mjs +1 -0
  19. package/dist/packem_shared/subscription-DJeoGEDR.mjs +1 -0
  20. package/dist/packem_shared/voiceAgent-CwlzrEjH.mjs +1 -0
  21. package/package.json +3 -3
  22. package/dist/packem_shared/LUNORA_CLIENT-DHUfNu9x.mjs +0 -23
  23. package/dist/packem_shared/agent-DDKvrG4u.mjs +0 -31
  24. package/dist/packem_shared/agentChat-DDZlxK1v.mjs +0 -111
  25. package/dist/packem_shared/agentState-C8GWf3t3.mjs +0 -10
  26. package/dist/packem_shared/agentToolEvents-sXgYggvi.mjs +0 -59
  27. package/dist/packem_shared/auth-Df9N87Z4.mjs +0 -27
  28. package/dist/packem_shared/connectionStatus-BlLodleK.mjs +0 -15
  29. package/dist/packem_shared/flag-CGBo90HJ.mjs +0 -70
  30. package/dist/packem_shared/hydratePreloaded-DIpD1cAM.mjs +0 -33
  31. package/dist/packem_shared/infiniteQuery-nboKfr5E.mjs +0 -221
  32. package/dist/packem_shared/liveQuery-DVxKidjM.mjs +0 -32
  33. package/dist/packem_shared/mutate-D3rEHwbb.mjs +0 -8
  34. package/dist/packem_shared/mutator-BHL8bakL.mjs +0 -19
  35. package/dist/packem_shared/platform-Dg8Bppgq.mjs +0 -14
  36. package/dist/packem_shared/presence-BTuq19dS.mjs +0 -77
  37. package/dist/packem_shared/rateLimit-I4kRT9qV.mjs +0 -58
  38. package/dist/packem_shared/stream-PL64AghO.mjs +0 -47
  39. package/dist/packem_shared/subscription-oZ-WTmpp.mjs +0 -39
  40. package/dist/packem_shared/voiceAgent-DwbrDnB9.mjs +0 -401
package/dist/index.mjs CHANGED
@@ -1,19 +1 @@
1
- export { agent } from './packem_shared/agent-DDKvrG4u.mjs';
2
- export { agentChat } from './packem_shared/agentChat-DDZlxK1v.mjs';
3
- export { agentState } from './packem_shared/agentState-C8GWf3t3.mjs';
4
- export { agentToolEvents } from './packem_shared/agentToolEvents-sXgYggvi.mjs';
5
- export { auth } from './packem_shared/auth-Df9N87Z4.mjs';
6
- export { LUNORA_CLIENT, injectLunoraClient, provideLunora } from './packem_shared/LUNORA_CLIENT-DHUfNu9x.mjs';
7
- export { connectionStatus } from './packem_shared/connectionStatus-BlLodleK.mjs';
8
- export { flag, flags } from './packem_shared/flag-CGBo90HJ.mjs';
9
- export { hydratePreloaded } from './packem_shared/hydratePreloaded-DIpD1cAM.mjs';
10
- export { liveQuery } from './packem_shared/liveQuery-DVxKidjM.mjs';
11
- export { mutate } from './packem_shared/mutate-D3rEHwbb.mjs';
12
- export { mutator } from './packem_shared/mutator-BHL8bakL.mjs';
13
- export { infiniteQuery, paginatedQuery } from './packem_shared/infiniteQuery-nboKfr5E.mjs';
14
- export { presence } from './packem_shared/presence-BTuq19dS.mjs';
15
- export { rateLimit } from './packem_shared/rateLimit-I4kRT9qV.mjs';
16
- export { stream } from './packem_shared/stream-PL64AghO.mjs';
17
- export { subscription } from './packem_shared/subscription-oZ-WTmpp.mjs';
18
- export { voiceAgent } from './packem_shared/voiceAgent-DwbrDnB9.mjs';
19
- export { SKIP } from '@lunora/client/query';
1
+ import{agent as e}from"./packem_shared/agent-C-GavfBl.mjs";import{agentChat as m}from"./packem_shared/agentChat-HRYt8rOf.mjs";import{agentState as f}from"./packem_shared/agentState-BAfa0QuC.mjs";import{agentToolEvents as x}from"./packem_shared/agentToolEvents-CBTZ_DsO.mjs";import{auth as i}from"./packem_shared/auth-wTtWvuVS.mjs";import{LUNORA_CLIENT as g,injectLunoraClient as s,provideLunora as c}from"./packem_shared/LUNORA_CLIENT-B0pGE0Tv.mjs";import{connectionStatus as d}from"./packem_shared/connectionStatus-C53UhkPi.mjs";import{flag as v,flags as y}from"./packem_shared/flag-BYFWoQTg.mjs";import{hydratePreloaded as C}from"./packem_shared/hydratePreloaded-BKHgpXzQ.mjs";import{liveQuery as S}from"./packem_shared/liveQuery-DEIqmTPj.mjs";import{mutate as E}from"./packem_shared/mutate-DR8Uo8Hs.mjs";import{mutator as N}from"./packem_shared/mutator-Cw6jpG06.mjs";import{infiniteQuery as T,paginatedQuery as b}from"./packem_shared/infiniteQuery-YvF0in16.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-CwlzrEjH.mjs";import{SKIP as D}from"@lunora/client/query";export{g as LUNORA_CLIENT,D as SKIP,e as agent,m as agentChat,f as agentState,x as agentToolEvents,i as auth,d as connectionStatus,v as flag,y as flags,C as hydratePreloaded,T as infiniteQuery,s as injectLunoraClient,S as liveQuery,E as mutate,N as mutator,b as paginatedQuery,K as presence,c as provideLunora,R as rateLimit,_ as stream,q as subscription,z as voiceAgent};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
1
+ import{inject as E,DestroyRef as T,signal as L,computed as m}from"@angular/core";import{resolveLunoraClient as M}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{stream as U}from"./stream-CcvHiJf2.mjs";import{subscription as I}from"./subscription-DJeoGEDR.mjs";const _={__lunoraRef:""},C=(d,s)=>{const l=s.filter(i=>i.role==="user"),u=new Set;return d.filter(i=>{for(let o=i.durableUserCountAtSend;o<l.length;o+=1){const f=l[o];if(f!==void 0&&!u.has(o)&&f.content===i.content)return u.add(o),!1}return!0})},F=d=>{const{api:s,cancel:l,limit:u,send:i,sendArgs:o,stream:f,threadKey:r}=d,a=M(d.client),v=d.destroyRef??E(T),R=u===void 0?{key:r}:{key:r,limit:u},{data:k}=I(s.agents.agentMessages,R,{client:a,destroyRef:v}),{data:A}=I(s.agents.agentThread,{key:r},{client:a,destroyRef:v}),K=f===void 0?"skip":{key:r},{chunks:j}=U(f??_,K,{client:a,destroyRef:v}),h=L([]);let w=0;const g=m(()=>A()),b=m(()=>g()?.status),y=m(()=>k()??[]),S=m(()=>{const e=y(),t=C(h(),e);if(t.length===0)return e;let n=-1;for(const c of e)c.seq>n&&(n=c.seq);return[...e,...t.map((c,p)=>({content:c.content,optimistic:!0,role:"user",seq:n+1+p}))]}),q=m(()=>{const e=y().filter(t=>t.role==="assistant").length;return j().filter(t=>t.kind!=="progress"&&t.threadKey===r&&t.turn>=e).map(t=>t.text).join("")});return{approve:async(e,t)=>{const n=g()?.instanceId;if(n===void 0)throw new Error("agentChat: cannot approve — no in-flight run (thread has no instanceId)");await a.mutation(s.agents.agentResolveApproval,{decision:"approve",instanceId:n,threadKey:r,toolCallId:e,...t===void 0?{}:{note:t}})},cancel:async()=>{const e=g()?.instanceId;l===void 0||e===void 0||await a.mutation(l,{instanceId:e,threadKey:r})},messages:S,reject:async(e,t)=>{const n=g()?.instanceId;if(n===void 0)throw new Error("agentChat: cannot reject — no in-flight run (thread has no instanceId)");await a.mutation(s.agents.agentResolveApproval,{decision:"reject",instanceId:n,threadKey:r,toolCallId:e,...t===void 0?{}:{note:t}})},send:async(e,t)=>{const n=w;w+=1;const c=y().filter(p=>p.role==="user").length;h.set([...C(h(),y()),{content:e,durableUserCountAtSend:c,id:n}]);try{await a.mutation(i,{input:e,threadKey:r,...o,...t})}catch(p){throw h.set(h().filter(x=>x.id!==n)),p}},status:b,streamingText:q}};export{F as agentChat};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
1
+ import{inject as l,DestroyRef as h,signal as s}from"@angular/core";import{getIdentityStore as k}from"@lunora/client/auth";import{resolveLunoraClient as m}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";const T=(o={})=>{const e=m(o.client),i=o.destroyRef??l(h),t=k(e),r=s(e.getAuthToken()),n=s(t.getUser()),u=e.onAuthTokenChange(()=>{r.set(e.getAuthToken())}),a=t.subscribe(()=>{n.set(t.getUser())});return i.onDestroy(()=>{u(),a()}),{setToken:g=>{e.setAuthToken(g)},token:r.asReadonly(),user:n.asReadonly()}};export{T as auth};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
1
+ import{computed as K,inject as j,DestroyRef as q,signal as O}from"@angular/core";import{initialPages as z,derivePaginationStatus as E,applyLoadMore as A,rebalance as J}from"@lunora/client/pagination";import{resolveLunoraClient as T}from"./LUNORA_CLIENT-B0pGE0Tv.mjs";import{s as B}from"./platform-BGZypnc9.mjs";const M=(r,s)=>`${r}::${JSON.stringify(s)}`,b=(r,s)=>({...s,paginationOpts:{cursor:r.lower,endCursor:r.upper,numItems:r.numItems}}),Q=(r,s,d)=>{const y=T(d.client),f=d.destroyRef===void 0,p=d.destroyRef??j(q),{initialNumItems:L,shardKey:x}=d,m=r.__lunoraRef,u=s==="skip"?{}:s,o=O(z(L)),R=O([]),D=O("LoadingFirstPage"),h=new Map,l=new Map,v=new Set,w=()=>{const n=o().map(g=>{const e=M(m,b(g,u));return l.get(e)});R.set(n);const{status:i}=E(s==="skip",n);D.set(i)},_=(n,i)=>{const g=e=>M(m,b(e,u));for(const e of i){const a=g(e);if(l.has(a))continue;const c=n.find(t=>t.lower===e.lower);if(c){const t=l.get(g(c));t&&l.set(a,t)}}},$=n=>{const i=new Set;for(const e of n)i.add(M(m,b(e,u)));for(const[e,a]of h)i.has(a.currentKey)||(a.unsub(),h.delete(e),l.delete(a.currentKey));const g=new Set([...h.values()].map(e=>e.currentKey));for(const e of n){const a=b(e,u),c=M(m,a);if(g.has(c))continue;const t={currentKey:c,unsub:void 0};v.add(c);const F=y.subscribe(r,a,N=>{if(l.set(t.currentKey,N),v.delete(t.currentKey),w(),v.size===0){const P=o(),S=J(P,R());S&&(_(P,S),o.set(S),C(S),w())}},{onError:()=>{v.delete(t.currentKey),w()},shardKey:x});t.unsub=F,h.set(c,t),g.add(c)}};let I=!1,k=!1;const C=n=>{if(I){k=!0;return}I=!0;try{let i=n;do k=!1,$(i),i=o();while(k)}finally{I=!1}};return s!=="skip"&&B(f)&&C(o()),w(),p.onDestroy(()=>{for(const n of h.values())n.unsub();h.clear(),l.clear()}),{loadMore:n=>{if(s==="skip")return;const{nextCursor:i,status:g}=E(!1,R());if(g!=="CanLoadMore")return;const e=A(o(),i,n);if(!e)return;const a=o().at(-1),c=e.at(-2);if(a&&c){const t=M(m,b(a,u)),F=M(m,b(c,u)),N=h.get(t);if(N&&t!==F){const P=l.get(t);P&&l.set(F,P),N.unsub(),h.delete(t),l.delete(t)}}o.set(e),C(o()),w()},pageResults:R,status:D}},W=(r,s,d)=>{const y=Q(r,s,d),f=K(()=>{const p=[];for(const L of y.pageResults())L&&p.push(...L.page);return p});return{isLoading:K(()=>{const p=y.status();return p==="LoadingFirstPage"||p==="LoadingMore"}),loadMore:y.loadMore,results:f,status:y.status}},X=(r,s,d)=>{const{initialNumItems:y}=d,f=Q(r,s,d),p=K(()=>{const u=[];for(const o of f.pageResults())o&&u.push(o.page);return u}),L=K(()=>f.status()==="LoadingFirstPage"),x=K(()=>f.status()==="CanLoadMore"),m=K(()=>f.status()==="LoadingMore");return{fetchNextPage:u=>{f.loadMore(u??y)},hasNextPage:x,isFetchingNextPage:m,isLoading:L,pages:p,status:f.status}};export{X as infiniteQuery,W as paginatedQuery};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/angular",
3
- "version": "1.0.0-alpha.13",
3
+ "version": "1.0.0-alpha.15",
4
4
  "description": "Angular reactive adapter for Lunora — signal-based live queries and mutations",
5
5
  "keywords": [
6
6
  "angular",
@@ -45,8 +45,8 @@
45
45
  "access": "public"
46
46
  },
47
47
  "dependencies": {
48
- "@lunora/client": "1.0.0-alpha.27",
49
- "@lunora/ratelimit": "1.0.0-alpha.9"
48
+ "@lunora/client": "1.0.0-alpha.29",
49
+ "@lunora/ratelimit": "1.0.0-alpha.10"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@angular/core": "^19.2.0 || ^20.0.0 || ^21.0.0 || ^22.0.0"
@@ -1,23 +0,0 @@
1
- import { InjectionToken, makeEnvironmentProviders, inject } from '@angular/core';
2
- import { LunoraClient } from '@lunora/client';
3
-
4
- const sameOriginUrl = () => globalThis.location?.origin ?? "";
5
- const LUNORA_CLIENT = new InjectionToken("lunora.client", {
6
- factory: () => new LunoraClient({ url: sameOriginUrl() }),
7
- providedIn: "root"
8
- });
9
- const provideLunora = (optionsOrClient = {}) => makeEnvironmentProviders([
10
- {
11
- provide: LUNORA_CLIENT,
12
- useFactory: () => {
13
- if (optionsOrClient instanceof LunoraClient) {
14
- return optionsOrClient;
15
- }
16
- return new LunoraClient({ ...optionsOrClient, url: optionsOrClient.url ?? sameOriginUrl() });
17
- }
18
- }
19
- ]);
20
- const injectLunoraClient = () => inject(LUNORA_CLIENT);
21
- const resolveLunoraClient = (client) => client ?? injectLunoraClient();
22
-
23
- export { LUNORA_CLIENT, injectLunoraClient, provideLunora, resolveLunoraClient };
@@ -1,31 +0,0 @@
1
- import { inject, DestroyRef, computed, signal } from '@angular/core';
2
- import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
- import { subscription } from './subscription-oZ-WTmpp.mjs';
4
-
5
- const agent = (options) => {
6
- const { api, cancel: cancelReference, run: runReference, runArgs, threadKey } = options;
7
- const client = resolveLunoraClient(options.client);
8
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
9
- const { data: threadData } = subscription(api.agents.agentThread, { key: threadKey }, { client, destroyRef });
10
- const thread = computed(() => threadData());
11
- const status = computed(() => thread()?.status);
12
- const pending = signal(false);
13
- const run = async (input, arguments_) => {
14
- pending.set(true);
15
- try {
16
- await client.mutation(runReference, { input, threadKey, ...runArgs, ...arguments_ });
17
- } finally {
18
- pending.set(false);
19
- }
20
- };
21
- const cancel = async () => {
22
- const instanceId = thread()?.instanceId;
23
- if (cancelReference === void 0 || instanceId === void 0) {
24
- return;
25
- }
26
- await client.mutation(cancelReference, { instanceId, threadKey });
27
- };
28
- return { cancel, pending: pending.asReadonly(), run, status, thread };
29
- };
30
-
31
- export { agent };
@@ -1,111 +0,0 @@
1
- import { inject, DestroyRef, signal, computed } from '@angular/core';
2
- import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
- import { stream } from './stream-PL64AghO.mjs';
4
- import { subscription } from './subscription-oZ-WTmpp.mjs';
5
-
6
- const NO_STREAM_REF = { __lunoraRef: "" };
7
- const reconcileOptimistic = (optimistic, durable) => {
8
- const durableUserRows = durable.filter((message) => message.role === "user");
9
- const consumed = /* @__PURE__ */ new Set();
10
- return optimistic.filter((pending) => {
11
- for (let index = pending.durableUserCountAtSend; index < durableUserRows.length; index += 1) {
12
- const row = durableUserRows[index];
13
- if (row !== void 0 && !consumed.has(index) && row.content === pending.content) {
14
- consumed.add(index);
15
- return false;
16
- }
17
- }
18
- return true;
19
- });
20
- };
21
- const agentChat = (options) => {
22
- const { api, cancel: cancelReference, limit, send: sendReference, sendArgs, stream: streamReference, threadKey } = options;
23
- const client = resolveLunoraClient(options.client);
24
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
25
- const messagesArguments = limit === void 0 ? { key: threadKey } : { key: threadKey, limit };
26
- const { data: history } = subscription(api.agents.agentMessages, messagesArguments, { client, destroyRef });
27
- const { data: threadData } = subscription(api.agents.agentThread, { key: threadKey }, { client, destroyRef });
28
- const streamArguments = streamReference === void 0 ? "skip" : { key: threadKey };
29
- const { chunks } = stream(streamReference ?? NO_STREAM_REF, streamArguments, { client, destroyRef });
30
- const optimistic = signal([]);
31
- let nextId = 0;
32
- const thread = computed(() => threadData());
33
- const status = computed(() => thread()?.status);
34
- const durable = computed(() => history() ?? []);
35
- const messages = computed(() => {
36
- const rows = durable();
37
- const visible = reconcileOptimistic(optimistic(), rows);
38
- if (visible.length === 0) {
39
- return rows;
40
- }
41
- let maxDurableSeq = -1;
42
- for (const message of rows) {
43
- if (message.seq > maxDurableSeq) {
44
- maxDurableSeq = message.seq;
45
- }
46
- }
47
- return [
48
- ...rows,
49
- ...visible.map((pending, index) => {
50
- return {
51
- content: pending.content,
52
- optimistic: true,
53
- role: "user",
54
- seq: maxDurableSeq + 1 + index
55
- };
56
- })
57
- ];
58
- });
59
- const streamingText = computed(() => {
60
- const assistantCount = durable().filter((message) => message.role === "assistant").length;
61
- return chunks().filter((event) => event.kind !== "progress" && event.threadKey === threadKey && event.turn >= assistantCount).map((delta) => delta.text).join("");
62
- });
63
- const send = async (input, arguments_) => {
64
- const id = nextId;
65
- nextId += 1;
66
- const durableUserCountAtSend = durable().filter((message) => message.role === "user").length;
67
- optimistic.set([...reconcileOptimistic(optimistic(), durable()), { content: input, durableUserCountAtSend, id }]);
68
- try {
69
- await client.mutation(sendReference, { input, threadKey, ...sendArgs, ...arguments_ });
70
- } catch (error) {
71
- optimistic.set(optimistic().filter((pending) => pending.id !== id));
72
- throw error;
73
- }
74
- };
75
- const approve = async (toolCallId, note) => {
76
- const instanceId = thread()?.instanceId;
77
- if (instanceId === void 0) {
78
- throw new Error("agentChat: cannot approve — no in-flight run (thread has no instanceId)");
79
- }
80
- await client.mutation(api.agents.agentResolveApproval, {
81
- decision: "approve",
82
- instanceId,
83
- threadKey,
84
- toolCallId,
85
- ...note === void 0 ? {} : { note }
86
- });
87
- };
88
- const reject = async (toolCallId, note) => {
89
- const instanceId = thread()?.instanceId;
90
- if (instanceId === void 0) {
91
- throw new Error("agentChat: cannot reject — no in-flight run (thread has no instanceId)");
92
- }
93
- await client.mutation(api.agents.agentResolveApproval, {
94
- decision: "reject",
95
- instanceId,
96
- threadKey,
97
- toolCallId,
98
- ...note === void 0 ? {} : { note }
99
- });
100
- };
101
- const cancel = async () => {
102
- const instanceId = thread()?.instanceId;
103
- if (cancelReference === void 0 || instanceId === void 0) {
104
- return;
105
- }
106
- await client.mutation(cancelReference, { instanceId, threadKey });
107
- };
108
- return { approve, cancel, messages, reject, send, status, streamingText };
109
- };
110
-
111
- export { agentChat };
@@ -1,10 +0,0 @@
1
- import { computed } from '@angular/core';
2
- import { subscription } from './subscription-oZ-WTmpp.mjs';
3
-
4
- const agentState = (options) => {
5
- const { data, error } = subscription(options.api.agents.agentState, { key: options.threadKey }, { client: options.client, destroyRef: options.destroyRef });
6
- const state = computed(() => data());
7
- return { error, state };
8
- };
9
-
10
- export { agentState };
@@ -1,59 +0,0 @@
1
- import { inject, DestroyRef, computed } from '@angular/core';
2
- import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
- import { stream } from './stream-PL64AghO.mjs';
4
- import { subscription } from './subscription-oZ-WTmpp.mjs';
5
-
6
- const NO_STREAM_REF = { __lunoraRef: "" };
7
- const EMPTY_MESSAGES = [];
8
- const toDurableEvent = (message) => {
9
- if (message.role === "assistant" && message.toolCalls) {
10
- return message.toolCalls.map((call) => {
11
- return { input: call.input, seq: message.seq, toolCallId: call.id, toolName: call.name, type: "call" };
12
- });
13
- }
14
- if (message.role !== "tool") {
15
- return void 0;
16
- }
17
- if (message.status === "awaiting_approval") {
18
- return [
19
- {
20
- seq: message.seq,
21
- type: "awaiting-approval",
22
- ...message.toolCallId === void 0 ? {} : { toolCallId: message.toolCallId },
23
- ...message.toolName === void 0 ? {} : { toolName: message.toolName }
24
- }
25
- ];
26
- }
27
- return [
28
- {
29
- output: message.content,
30
- seq: message.seq,
31
- type: "result",
32
- ...message.status === "approved" || message.status === "rejected" ? { status: message.status } : {},
33
- ...message.toolCallId === void 0 ? {} : { toolCallId: message.toolCallId },
34
- ...message.toolName === void 0 ? {} : { toolName: message.toolName }
35
- }
36
- ];
37
- };
38
- const agentToolEvents = (options) => {
39
- const { api, limit, stream: streamReference, threadKey } = options;
40
- const client = resolveLunoraClient(options.client);
41
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
42
- const messagesArguments = limit === void 0 ? { key: threadKey } : { key: threadKey, limit };
43
- const { data: history } = subscription(api.agents.agentMessages, messagesArguments, { client, destroyRef });
44
- const streamArguments = streamReference === void 0 ? "skip" : { key: threadKey };
45
- const { chunks } = stream(streamReference ?? NO_STREAM_REF, streamArguments, { client, destroyRef });
46
- const events = computed(() => {
47
- const durable = history() ?? EMPTY_MESSAGES;
48
- const derived = durable.flatMap((message) => toDurableEvent(message) ?? []);
49
- for (const event of chunks()) {
50
- if (event.kind === "progress" && event.threadKey === threadKey) {
51
- derived.push({ data: event.data, toolCallId: event.toolCallId, type: "progress" });
52
- }
53
- }
54
- return derived;
55
- });
56
- return { events };
57
- };
58
-
59
- export { agentToolEvents };
@@ -1,27 +0,0 @@
1
- import { inject, DestroyRef, signal } from '@angular/core';
2
- import { getIdentityStore } from '@lunora/client/auth';
3
- import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
4
-
5
- const auth = (options = {}) => {
6
- const client = resolveLunoraClient(options.client);
7
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
8
- const store = getIdentityStore(client);
9
- const token = signal(client.getAuthToken());
10
- const user = signal(store.getUser());
11
- const unsubToken = client.onAuthTokenChange(() => {
12
- token.set(client.getAuthToken());
13
- });
14
- const unsubUser = store.subscribe(() => {
15
- user.set(store.getUser());
16
- });
17
- destroyRef.onDestroy(() => {
18
- unsubToken();
19
- unsubUser();
20
- });
21
- const setToken = (next) => {
22
- client.setAuthToken(next);
23
- };
24
- return { setToken, token: token.asReadonly(), user: user.asReadonly() };
25
- };
26
-
27
- export { auth };
@@ -1,15 +0,0 @@
1
- import { inject, DestroyRef, signal } from '@angular/core';
2
- import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
-
4
- const connectionStatus = (options = {}) => {
5
- const client = resolveLunoraClient(options.client);
6
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
7
- const status = signal(client.connectionStatus());
8
- const unsubscribe = client.onConnectionStatus((next) => {
9
- status.set(next);
10
- });
11
- destroyRef.onDestroy(unsubscribe);
12
- return status.asReadonly();
13
- };
14
-
15
- export { connectionStatus };
@@ -1,70 +0,0 @@
1
- import { inject, DestroyRef, signal } from '@angular/core';
2
- import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
-
4
- const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
5
- const flagKind = (value) => {
6
- const kind = typeof value;
7
- if (kind === "boolean" || kind === "number" || kind === "string") {
8
- return kind;
9
- }
10
- return "object";
11
- };
12
- const flagsReference = { __lunoraRef: FLAGS_EVAL_PATH };
13
- const flag = (key, defaultValue, options = {}) => {
14
- const client = resolveLunoraClient(options.client);
15
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
16
- const type = flagKind(defaultValue);
17
- const value = signal(defaultValue);
18
- let unsubscribe;
19
- try {
20
- unsubscribe = client.subscribe(
21
- flagsReference,
22
- { context: options.context, default: defaultValue, key, type },
23
- (next) => {
24
- value.set(next);
25
- },
26
- {
27
- onError: () => {
28
- value.set(defaultValue);
29
- }
30
- }
31
- );
32
- } catch {
33
- }
34
- if (unsubscribe) {
35
- destroyRef.onDestroy(unsubscribe);
36
- }
37
- return value.asReadonly();
38
- };
39
- const flags = (flagDefaults, options = {}) => {
40
- const client = resolveLunoraClient(options.client);
41
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
42
- const values = signal({ ...flagDefaults });
43
- const unsubscribes = [];
44
- for (const [key, defaultValue] of Object.entries(flagDefaults)) {
45
- try {
46
- const unsub = client.subscribe(
47
- flagsReference,
48
- { context: options.context, default: defaultValue, key, type: flagKind(defaultValue) },
49
- (next) => {
50
- values.set({ ...values(), [key]: next });
51
- },
52
- {
53
- onError: () => {
54
- values.set({ ...values(), [key]: defaultValue });
55
- }
56
- }
57
- );
58
- unsubscribes.push(unsub);
59
- } catch {
60
- }
61
- }
62
- destroyRef.onDestroy(() => {
63
- for (const unsubscribe of unsubscribes) {
64
- unsubscribe();
65
- }
66
- });
67
- return values.asReadonly();
68
- };
69
-
70
- export { flag, flags };
@@ -1,33 +0,0 @@
1
- import { inject, DestroyRef, signal } from '@angular/core';
2
- import { resolveLunoraClient } from './LUNORA_CLIENT-DHUfNu9x.mjs';
3
- import { s as shouldOpenSubscription } from './platform-Dg8Bppgq.mjs';
4
-
5
- const hydratePreloaded = (preloaded, options = {}) => {
6
- const client = resolveLunoraClient(options.client);
7
- const fromInjectionContext = options.destroyRef === void 0;
8
- const destroyRef = options.destroyRef ?? inject(DestroyRef);
9
- const { args, functionPath, shardKey, value } = preloaded;
10
- const data = signal(value);
11
- const error = signal(void 0);
12
- const functionReference = { __lunoraRef: functionPath };
13
- if (shouldOpenSubscription(fromInjectionContext)) {
14
- const unsubscribe = client.subscribe(
15
- functionReference,
16
- args,
17
- (next) => {
18
- data.set(next);
19
- error.set(void 0);
20
- },
21
- {
22
- onError: (error_) => {
23
- error.set(error_);
24
- },
25
- shardKey
26
- }
27
- );
28
- destroyRef.onDestroy(unsubscribe);
29
- }
30
- return { data: data.asReadonly(), error: error.asReadonly() };
31
- };
32
-
33
- export { hydratePreloaded };