@lunora/angular 1.0.0-alpha.33 → 1.0.0-alpha.35

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 (43) hide show
  1. package/dist/index.d.mts +17 -1
  2. package/dist/index.d.ts +17 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/LUNORA_CLIENT-B0toApHY.mjs +1 -0
  5. package/dist/packem_shared/agent-DcC06SOO.mjs +1 -0
  6. package/dist/packem_shared/agentChat-Cit2jdK_.mjs +1 -0
  7. package/dist/packem_shared/agentState-CBH9dKb7.mjs +1 -0
  8. package/dist/packem_shared/agentToolEvents-DSNEBf37.mjs +1 -0
  9. package/dist/packem_shared/auth-BgwruT_M.mjs +1 -0
  10. package/dist/packem_shared/connectionStatus-UhmuwzMa.mjs +1 -0
  11. package/dist/packem_shared/flag-orUoJY7A.mjs +1 -0
  12. package/dist/packem_shared/hydratePreloaded-DYqgj4Y1.mjs +1 -0
  13. package/dist/packem_shared/infiniteQuery-C1vVL3Nk.mjs +1 -0
  14. package/dist/packem_shared/liveQuery-DR3i-aOo.mjs +1 -0
  15. package/dist/packem_shared/mutate-BZvLQLyu.mjs +1 -0
  16. package/dist/packem_shared/mutator-DjG1yGk8.mjs +1 -0
  17. package/dist/packem_shared/platform-1MW9DnW6.mjs +1 -0
  18. package/dist/packem_shared/presence-BfPC_yqX.mjs +1 -0
  19. package/dist/packem_shared/rateLimit-B3h9qzh-.mjs +1 -0
  20. package/dist/packem_shared/stream-CcjYdpzt.mjs +1 -0
  21. package/dist/packem_shared/subscription-CWp5w6K4.mjs +1 -0
  22. package/dist/packem_shared/voiceAgent-CzyUcUKj.mjs +1 -0
  23. package/dist/upload.mjs +1 -1
  24. package/package.json +4 -4
  25. package/dist/packem_shared/LUNORA_CLIENT-B0pGE0Tv.mjs +0 -1
  26. package/dist/packem_shared/agent-C-GavfBl.mjs +0 -1
  27. package/dist/packem_shared/agentChat-DVHf7gsd.mjs +0 -1
  28. package/dist/packem_shared/agentState-BAfa0QuC.mjs +0 -1
  29. package/dist/packem_shared/agentToolEvents-CBTZ_DsO.mjs +0 -1
  30. package/dist/packem_shared/auth-BTEtMnGG.mjs +0 -1
  31. package/dist/packem_shared/connectionStatus-C53UhkPi.mjs +0 -1
  32. package/dist/packem_shared/flag-BYFWoQTg.mjs +0 -1
  33. package/dist/packem_shared/hydratePreloaded-BKHgpXzQ.mjs +0 -1
  34. package/dist/packem_shared/infiniteQuery-DyWJIpUr.mjs +0 -1
  35. package/dist/packem_shared/liveQuery-DEIqmTPj.mjs +0 -1
  36. package/dist/packem_shared/mutate-DR8Uo8Hs.mjs +0 -1
  37. package/dist/packem_shared/mutator-Cw6jpG06.mjs +0 -1
  38. package/dist/packem_shared/platform-BGZypnc9.mjs +0 -1
  39. package/dist/packem_shared/presence-BMrTlOCF.mjs +0 -1
  40. package/dist/packem_shared/rateLimit-CQazDrPJ.mjs +0 -1
  41. package/dist/packem_shared/stream-CcvHiJf2.mjs +0 -1
  42. package/dist/packem_shared/subscription-DJeoGEDR.mjs +0 -1
  43. package/dist/packem_shared/voiceAgent-DUFVwTWi.mjs +0 -1
package/dist/index.d.mts CHANGED
@@ -1336,4 +1336,20 @@ interface VoiceAgentResult {
1336
1336
  * @experimental
1337
1337
  */
1338
1338
  declare const voiceAgent: (options: VoiceAgentOptions) => VoiceAgentResult;
1339
- export { type AgentApi, type AgentChatApi, type AgentChatMessage, type AgentChatOptions, type AgentChatResult, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentResult, type AgentStateApi, type AgentStateOptions, type AgentStateResult, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentTokenStreamReference, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsOptions, type AgentToolEventsResult, type AuthGateResult, type AuthOptions, type AuthResult, type ConnectionStatusOptions, type FlagContext, type FlagOptions, type FlagValue, type FlagsOptions, type HeartbeatReference, type HydratePreloadedOptions, type HydratePreloadedResult, type InfiniteQueryResult, LUNORA_CLIENT, type ListPresentReference, type LiveQueryOptions, type MutateOptions, type MutatorResult, type PaginatedQueryOptions, type PaginatedQueryResult, type PresenceOptions, type PresenceResult, type ProvideLunoraOptions, type RateLimitOptions, type RateLimitResult, type StreamOptions, type StreamResult, type StreamStatus, type SubscriptionOptions, type SubscriptionResult, type VoiceAgentOptions, type VoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, agent, agentChat, agentState, agentToolEvents, auth, authGate, connectionStatus, flag, flags, hydratePreloaded, infiniteQuery, injectLunoraClient, liveQuery, mutate, mutator, paginatedQuery, presence, provideLunora, rateLimit, stream, subscription, voiceAgent };
1339
+ export { type AgentApi, type AgentChatApi, type AgentChatMessage, type AgentChatOptions, type AgentChatResult, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentResult, type AgentStateApi, type AgentStateOptions, type AgentStateResult, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentTokenStreamReference, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsOptions, type AgentToolEventsResult, type AuthGateResult, type AuthOptions, type AuthResult, type ConnectionStatusOptions, type FlagContext, type FlagOptions, type FlagValue, type FlagsOptions, type HeartbeatReference, type HydratePreloadedOptions, type HydratePreloadedResult, type InfiniteQueryResult, LUNORA_CLIENT, type ListPresentReference, type LiveQueryOptions, type MutateOptions, type MutatorResult, type PaginatedQueryOptions, type PaginatedQueryResult, type PresenceOptions, type PresenceResult,
1340
+ /**
1341
+ * The Angular adapter for Lunora.
1342
+ *
1343
+ * Thin, idiomatic glue over the framework-neutral `@lunora/client`. Angular
1344
+ * signals map directly onto Lunora's per-subscription deltas, so a live query is
1345
+ * just a `signal` the WebSocket writes to.
1346
+ *
1347
+ * `provideLunora` / `LUNORA_CLIENT` / `injectLunoraClient` are the injectable
1348
+ * provider carrying one `LunoraClient` (opens its socket lazily), wired once in the
1349
+ * application config. `liveQuery` is a live-query `signal` that opens a
1350
+ * subscription and updates on every delta, torn down automatically on
1351
+ * `DestroyRef.onDestroy`. `mutate` runs a mutation (optimistic updates + offline
1352
+ * queue pass through to the client). `connectionStatus` is a `signal` of the
1353
+ * aggregate live-socket status.
1354
+ */
1355
+ type ProvideLunoraOptions, type RateLimitOptions, type RateLimitResult, type StreamOptions, type StreamResult, type StreamStatus, type SubscriptionOptions, type SubscriptionResult, type VoiceAgentOptions, type VoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, agent, agentChat, agentState, agentToolEvents, auth, authGate, connectionStatus, flag, flags, hydratePreloaded, infiniteQuery, injectLunoraClient, liveQuery, mutate, mutator, paginatedQuery, presence, provideLunora, rateLimit, stream, subscription, voiceAgent };
package/dist/index.d.ts CHANGED
@@ -1336,4 +1336,20 @@ interface VoiceAgentResult {
1336
1336
  * @experimental
1337
1337
  */
1338
1338
  declare const voiceAgent: (options: VoiceAgentOptions) => VoiceAgentResult;
1339
- export { type AgentApi, type AgentChatApi, type AgentChatMessage, type AgentChatOptions, type AgentChatResult, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentResult, type AgentStateApi, type AgentStateOptions, type AgentStateResult, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentTokenStreamReference, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsOptions, type AgentToolEventsResult, type AuthGateResult, type AuthOptions, type AuthResult, type ConnectionStatusOptions, type FlagContext, type FlagOptions, type FlagValue, type FlagsOptions, type HeartbeatReference, type HydratePreloadedOptions, type HydratePreloadedResult, type InfiniteQueryResult, LUNORA_CLIENT, type ListPresentReference, type LiveQueryOptions, type MutateOptions, type MutatorResult, type PaginatedQueryOptions, type PaginatedQueryResult, type PresenceOptions, type PresenceResult, type ProvideLunoraOptions, type RateLimitOptions, type RateLimitResult, type StreamOptions, type StreamResult, type StreamStatus, type SubscriptionOptions, type SubscriptionResult, type VoiceAgentOptions, type VoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, agent, agentChat, agentState, agentToolEvents, auth, authGate, connectionStatus, flag, flags, hydratePreloaded, infiniteQuery, injectLunoraClient, liveQuery, mutate, mutator, paginatedQuery, presence, provideLunora, rateLimit, stream, subscription, voiceAgent };
1339
+ export { type AgentApi, type AgentChatApi, type AgentChatMessage, type AgentChatOptions, type AgentChatResult, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentResult, type AgentStateApi, type AgentStateOptions, type AgentStateResult, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentTokenStreamReference, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsOptions, type AgentToolEventsResult, type AuthGateResult, type AuthOptions, type AuthResult, type ConnectionStatusOptions, type FlagContext, type FlagOptions, type FlagValue, type FlagsOptions, type HeartbeatReference, type HydratePreloadedOptions, type HydratePreloadedResult, type InfiniteQueryResult, LUNORA_CLIENT, type ListPresentReference, type LiveQueryOptions, type MutateOptions, type MutatorResult, type PaginatedQueryOptions, type PaginatedQueryResult, type PresenceOptions, type PresenceResult,
1340
+ /**
1341
+ * The Angular adapter for Lunora.
1342
+ *
1343
+ * Thin, idiomatic glue over the framework-neutral `@lunora/client`. Angular
1344
+ * signals map directly onto Lunora's per-subscription deltas, so a live query is
1345
+ * just a `signal` the WebSocket writes to.
1346
+ *
1347
+ * `provideLunora` / `LUNORA_CLIENT` / `injectLunoraClient` are the injectable
1348
+ * provider carrying one `LunoraClient` (opens its socket lazily), wired once in the
1349
+ * application config. `liveQuery` is a live-query `signal` that opens a
1350
+ * subscription and updates on every delta, torn down automatically on
1351
+ * `DestroyRef.onDestroy`. `mutate` runs a mutation (optimistic updates + offline
1352
+ * queue pass through to the client). `connectionStatus` is a `signal` of the
1353
+ * aggregate live-socket status.
1354
+ */
1355
+ type ProvideLunoraOptions, type RateLimitOptions, type RateLimitResult, type StreamOptions, type StreamResult, type StreamStatus, type SubscriptionOptions, type SubscriptionResult, type VoiceAgentOptions, type VoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, agent, agentChat, agentState, agentToolEvents, auth, authGate, connectionStatus, flag, flags, hydratePreloaded, infiniteQuery, injectLunoraClient, liveQuery, mutate, mutator, paginatedQuery, presence, provideLunora, rateLimit, stream, subscription, voiceAgent };
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-DcC06SOO.mjs";import{agentChat as m}from"./packem_shared/agentChat-Cit2jdK_.mjs";import{agentState as a}from"./packem_shared/agentState-CBH9dKb7.mjs";import{agentToolEvents as x}from"./packem_shared/agentToolEvents-DSNEBf37.mjs";import{auth as i,authGate as u}from"./packem_shared/auth-BgwruT_M.mjs";import{LUNORA_CLIENT as s,injectLunoraClient as c,provideLunora as l}from"./packem_shared/LUNORA_CLIENT-B0toApHY.mjs";import{connectionStatus as L}from"./packem_shared/connectionStatus-UhmuwzMa.mjs";import{flag as v,flags as y}from"./packem_shared/flag-orUoJY7A.mjs";import{hydratePreloaded as Q}from"./packem_shared/hydratePreloaded-DYqgj4Y1.mjs";import{liveQuery as A}from"./packem_shared/liveQuery-DR3i-aOo.mjs";import{mutate as I}from"./packem_shared/mutate-BZvLQLyu.mjs";import{mutator as P}from"./packem_shared/mutator-DjG1yGk8.mjs";import{infiniteQuery as b,paginatedQuery as j}from"./packem_shared/infiniteQuery-C1vVL3Nk.mjs";import{presence as K}from"./packem_shared/presence-BfPC_yqX.mjs";import{rateLimit as R}from"./packem_shared/rateLimit-B3h9qzh-.mjs";import{stream as _}from"./packem_shared/stream-CcjYdpzt.mjs";import{subscription as q}from"./packem_shared/subscription-CWp5w6K4.mjs";import{voiceAgent as z}from"./packem_shared/voiceAgent-CzyUcUKj.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};
@@ -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{inject as p,DestroyRef as R,computed as o,signal as h}from"@angular/core";import{resolveLunoraClient as v}from"./LUNORA_CLIENT-B0toApHY.mjs";import{subscription as w}from"./subscription-CWp5w6K4.mjs";const k=e=>{const{api:i,cancel:r,run:d,runArgs:l,threadKey:n}=e,a=v(e.client),u=e.destroyRef??p(R),{data:f}=w(i.agents.agentThread,{key:n},{client:a,destroyRef:u}),s=o(()=>f()),y=o(()=>s()?.status),c=h(!1),m=async(t,g)=>{c.set(!0);try{await a.mutation(d,{input:t,threadKey:n,...l,...g})}finally{c.set(!1)}};return{cancel:async()=>{const t=s()?.instanceId;r===void 0||t===void 0||await a.mutation(r,{instanceId:t,threadKey:n})},pending:c.asReadonly(),run:m,status:y,thread:s}};export{k as agent};
@@ -0,0 +1 @@
1
+ import{inject as K,DestroyRef as M,signal as O,computed as c}from"@angular/core";import{reconcileOptimistic as R,maxSeq as k}from"@lunora/client";import{resolveLunoraClient as F}from"./LUNORA_CLIENT-B0toApHY.mjs";import{stream as L}from"./stream-CcjYdpzt.mjs";import{subscription as w}from"./subscription-CWp5w6K4.mjs";const N={__lunoraRef:""},U=m=>{const{api:d,cancel:g,limit:f,send:x,sendArgs:A,stream:h,threadKey:n}=m,r=F(m.client),l=m.destroyRef??K(M),I=f===void 0?{key:n}:{key:n,limit:f},{data:b}=w(d.agents.agentMessages,I,{client:r,destroyRef:l}),{data:j}=w(d.agents.agentThread,{key:n},{client:r,destroyRef:l}),S=h===void 0?"skip":{key:n},{chunks:q}=L(h??N,S,{client:r,destroyRef:l}),o=O([]);let y=0;const u=c(()=>j()),C=c(()=>u()?.status),i=c(()=>b()??[]),D=c(()=>{const t=i(),e=R(o(),t);if(e.length===0)return t;const s=k(t);return[...t,...e.map((a,p)=>({content:a.content,optimistic:!0,role:"user",seq:s+1+p}))]}),_=c(()=>{const t=i().filter(e=>e.role==="assistant").length;return q().filter(e=>e.kind!=="progress"&&e.threadKey===n&&e.turn>=t).map(e=>e.text).join("")}),E=async(t,e)=>{const s=y;y+=1;const a=k(i());o.set([...R(o(),i()),{content:t,id:s,maxDurableSeqAtSend:a}]);try{await r.mutation(x,{input:t,threadKey:n,...A,...e})}catch(p){throw o.set(o().filter(T=>T.id!==s)),p}},v=async(t,e,s)=>{const a=u()?.instanceId;if(a===void 0)throw new Error(`agentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await r.mutation(d.agents.agentResolveApproval,{decision:t,instanceId:a,threadKey:n,toolCallId:e,...s===void 0?{}:{note:s}})};return{approve:async(t,e)=>v("approve",t,e),cancel:async()=>{const t=u()?.instanceId;g===void 0||t===void 0||await r.mutation(g,{instanceId:t,threadKey:n})},messages:D,reject:async(t,e)=>v("reject",t,e),send:E,status:C,streamingText:_}};export{U as agentChat};
@@ -0,0 +1 @@
1
+ import{computed as c}from"@angular/core";import{subscription as n}from"./subscription-CWp5w6K4.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{inject as v,DestroyRef as f,computed as y}from"@angular/core";import{resolveLunoraClient as C}from"./LUNORA_CLIENT-B0toApHY.mjs";import{stream as I}from"./stream-CcjYdpzt.mjs";import{subscription as N}from"./subscription-CWp5w6K4.mjs";const m={__lunoraRef:""},E=[],R=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 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}}]},A=t=>{const{api:r,limit:e,stream:n,threadKey:l}=t,a=C(t.client),i=t.destroyRef??v(f),u=e===void 0?{key:l}:{key:l,limit:e},{data:s}=N(r.agents.agentMessages,u,{client:a,destroyRef:i}),p=n===void 0?"skip":{key:l},{chunks:c}=I(n??m,p,{client:a,destroyRef:i});return{events:y(()=>{const d=(s()??E).flatMap(o=>R(o)??[]);for(const o of c())o.kind==="progress"&&o.threadKey===l&&d.push({data:o.data,toolCallId:o.toolCallId,type:"progress"});return d})}};export{A as agentToolEvents};
@@ -0,0 +1 @@
1
+ import{inject as k,DestroyRef as d,signal as u,computed as c}from"@angular/core";import{getIdentityStore as h}from"@lunora/client/auth";import{resolveLunoraClient as g}from"./LUNORA_CLIENT-B0toApHY.mjs";const m=(n={})=>{const t=g(n.client),o=n.destroyRef??k(d),e=h(t),s=u(t.getAuthToken()),r=u(e.getUser()),i=t.onAuthTokenChange(()=>{s.set(t.getAuthToken())}),l=e.subscribe(()=>{r.set(e.getUser())});return o.onDestroy(()=>{i(),l()}),{setToken:a=>{t.setAuthToken(a)},token:s.asReadonly(),user:r.asReadonly()}},R=(n={})=>{const{token:t,user:o}=m(n),e=c(()=>t()!==null&&o()===null);return{isAuthenticated:c(()=>t()!==null&&o()!==null),isLoading:e}};export{m as auth,R 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 i,signal as a}from"@angular/core";import{resolveLunoraClient as b}from"./LUNORA_CLIENT-B0toApHY.mjs";const d="__lunora_flags__:eval",y=o=>{const e=typeof o;return e==="boolean"||e==="number"||e==="string"?e:"object"},R={__lunoraRef:d},x=(o,e,r={})=>{const f=b(r.client),n=r.destroyRef??l(i),c=y(e),t=a(e);let s;try{s=f.subscribe(R,{context:r.context,default:e,key:o,type:c},u=>{t.set(u)},{onError:()=>{t.set(e)}})}catch{}return s&&n.onDestroy(s),t.asReadonly()},v=(o,e={})=>{const r=b(e.client),f=e.destroyRef??l(i),n=a({...o}),c=[];for(const[t,s]of Object.entries(o))try{const u=r.subscribe(R,{context:e.context,default:s,key:t,type:y(s)},_=>{n.set({...n(),[t]:_})},{onError:()=>{n.set({...n(),[t]:s})}});c.push(u)}catch{}return f.onDestroy(()=>{for(const t of c)t()}),n.asReadonly()};export{x as flag,v as flags};
@@ -0,0 +1 @@
1
+ import{inject as m,DestroyRef as b,signal as n}from"@angular/core";import{resolveLunoraClient as v}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as h}from"./platform-1MW9DnW6.mjs";const x=(s,e={})=>{const c=v(e.client),a=e.destroyRef===void 0,i=e.destroyRef??m(b),{args:d,functionPath:f,shardKey:l,value:u}=s,t=n(u),o=n(void 0),y={__lunoraRef:f};if(h(a)){const R=c.subscribe(y,d,r=>{t.set(r),o.set(void 0)},{onError:r=>{o.set(r)},shardKey:l});i.onDestroy(R)}return{data:t.asReadonly(),error:o.asReadonly()}};export{x as hydratePreloaded};
@@ -0,0 +1 @@
1
+ import{computed as O,inject as Q,DestroyRef as V,signal as T}from"@angular/core";import{initialPages as q,derivePaginationStatus as F,applyLoadMore as z,rebalance as G}from"@lunora/client/pagination";import{resolveLunoraClient as H}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as X}from"./platform-1MW9DnW6.mjs";const Y=(t,n)=>t<n?-1:t>n?1:0,I=t=>{if(t===void 0)return"null";if(typeof t=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(e=>I(e)).join(",")}]`;const n=Object.getPrototypeOf(t);if(n!==null&&n!==Object.prototype){const e=t.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${e} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const i=t,s=Object.keys(i).toSorted(Y),c=[];for(const e of s){const r=i[e];r!==void 0&&c.push(`${JSON.stringify(e)}:${I(r)}`)}return`{${c.join(",")}}`},_=t=>{let n="";for(let s=0;s<t.length;s+=32768)n+=String.fromCharCode(...t.subarray(s,s+32768));return btoa(n)},u="$lunora.wire$",U=64,Z="__proto__",v=t=>{if(t===null||typeof t!="object")return!1;const n=Object.getPrototypeOf(t);return n===null||n===Object.prototype},P=(t,n=0)=>{if(n>U)throw new RangeError(`wire-codec: value nesting exceeds the ${U}-level limit`);if(t===void 0)return[u,"undefined"];if(t===null)return null;const i=typeof t;if(i==="bigint")return[u,"bigint",t.toString()];if(i==="number"){const e=t;return Number.isNaN(e)?[u,"nan"]:e===1/0?[u,"inf"]:e===-1/0?[u,"-inf"]:e}if(i!=="object")return t;if(t instanceof Date)return[u,"date",P(t.getTime(),n+1)];if(t instanceof Error){const e=t,r={};for(const l of Object.keys(e))e[l]!==void 0&&(r[l]=P(e[l],n+1));const d=[u,"error",e.name,e.message,r];return e.cause!==void 0&&d.push(P(e.cause,n+1)),d}if(t instanceof URL)return[u,"url",t.href];if(t instanceof Map)return[u,"map",[...t.entries()].map(([e,r])=>[P(e,n+1),P(r,n+1)])];if(t instanceof Set)return[u,"set",[...t].map(e=>P(e,n+1))];if(t instanceof ArrayBuffer)return[u,"bytes",_(new Uint8Array(t)),"ArrayBuffer"];if(ArrayBuffer.isView(t)){const e=t,r=e.constructor.name,d=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return r==="Uint8Array"?[u,"bytes",_(d)]:[u,"bytes",_(d),r]}if(Array.isArray(t)){const e=t.map(r=>P(r,n+1));return e.length>0&&e[0]===u?[u,"arr",e]:e}if(!v(t)){const e=t.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${e} 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 s=t,c={};for(const e of Object.keys(s)){const r=s[e];if(r===void 0)continue;const d=P(r,n+1);e===Z?Object.defineProperty(c,e,{configurable:!0,enumerable:!0,value:d,writable:!0}):c[e]=d}return c},tt=t=>I(P(t)),K=(t,n)=>`${t}::${tt(n)}`,k=(t,n)=>({...n,paginationOpts:{cursor:t.lower,endCursor:t.upper,numItems:t.numItems}}),D=(t,n,i)=>{const s=H(i.client),c=i.destroyRef===void 0,e=i.destroyRef??Q(V),{initialNumItems:r,shardKey:d}=i,l=t.__lunoraRef,h=n==="skip"?{}:n,f=T(q(r)),L=T([]),B=T("LoadingFirstPage"),S=new Map,m=new Map,N=new Set,j=()=>{const g=f().map(o=>{const y=K(l,k(o,h));return m.get(y)});L.set(g);const{status:w}=F(n==="skip",g);B.set(w)},J=(p,g)=>{const w=o=>K(l,k(o,h));for(const o of g){const y=w(o);if(m.has(y))continue;const b=p.find(a=>a.lower===o.lower);if(b){const a=m.get(w(b));a&&m.set(y,a)}}},W=p=>{const g=new Set;for(const o of p)g.add(K(l,k(o,h)));for(const[o,y]of S)g.has(y.currentKey)||(y.unsub(),S.delete(o),m.delete(y.currentKey));const w=new Set([...S.values()].map(o=>o.currentKey));for(const o of p){const y=k(o,h),b=K(l,y);if(w.has(b))continue;const a={currentKey:b,unsub:void 0};N.add(b);const R=s.subscribe(t,y,A=>{if(m.set(a.currentKey,A),N.delete(a.currentKey),j(),N.size===0){const M=f(),x=G(M,L());x&&(J(M,x),f.set(x),C(x),j())}},{onError:()=>{N.delete(a.currentKey),j()},shardKey:d});a.unsub=R,S.set(b,a),w.add(b)}};let E=!1,$=!1;const C=p=>{if(E){$=!0;return}E=!0;try{let g=p;do $=!1,W(g),g=f();while($)}finally{E=!1}};return n!=="skip"&&X(c)&&C(f()),j(),e.onDestroy(()=>{for(const p of S.values())p.unsub();S.clear(),m.clear()}),{loadMore:p=>{if(n==="skip")return;const{nextCursor:g,status:w}=F(!1,L());if(w!=="CanLoadMore")return;const o=z(f(),g,p);if(!o)return;const y=f().at(-1),b=o.at(-2);if(y&&b){const a=K(l,k(y,h)),R=K(l,k(b,h)),A=S.get(a);if(A&&a!==R){const M=m.get(a);M&&m.set(R,M),A.unsub(),S.delete(a),m.delete(a)}}f.set(o),C(f()),j()},pageResults:L,status:B}},it=(t,n,i)=>{const s=D(t,n,i),c=O(()=>s.pageResults().flatMap(r=>r?.page??[]));return{isLoading:O(()=>{const r=s.status();return r==="LoadingFirstPage"||r==="LoadingMore"}),loadMore:s.loadMore,results:c,status:s.status}},ct=(t,n,i)=>{const{initialNumItems:s}=i,c=D(t,n,i),e=O(()=>c.pageResults().flatMap(f=>f?[f.page]:[])),r=O(()=>c.status()==="LoadingFirstPage"),d=O(()=>c.status()==="CanLoadMore"),l=O(()=>c.status()==="LoadingMore");return{fetchNextPage:f=>{c.loadMore(f??s)},hasNextPage:d,isFetchingNextPage:l,isLoading:r,pages:e,status:c.status}};export{ct as infiniteQuery,it as paginatedQuery};
@@ -0,0 +1 @@
1
+ import{inject as d,DestroyRef as f,signal as u}from"@angular/core";import{createQuerySubscription as y}from"@lunora/client/query";import{resolveLunoraClient as l}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as m}from"./platform-1MW9DnW6.mjs";const h=(o,t,e={})=>{const n=l(e.client),s=e.destroyRef===void 0,i=e.destroyRef??d(f),r=u(void 0);if(m(s)){const c=y(n,o,t,{onData:a=>{r.set(a)},onError:e.onError,onReset:()=>{r.set(void 0)}},{shardKey:e.shardKey});i.onDestroy(c)}return r.asReadonly()};export{h as liveQuery};
@@ -0,0 +1 @@
1
+ import{resolveLunoraClient as i}from"./LUNORA_CLIENT-B0toApHY.mjs";const a=(t,o,n={})=>{const{client:e,...r}=n;return i(e).mutation(t,o,r)};export{a 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 o,PLATFORM_ID as u,NgZone as e}from"@angular/core";const i=r=>r?o(u,{optional:!0})!=="server":!0,a=(r,n)=>{const t=r?o(e,{optional:!0}):void 0;return t?t.runOutsideAngular(n):n()};export{a as r,i as s};
@@ -0,0 +1 @@
1
+ import{inject as D,DestroyRef as S,signal as h}from"@angular/core";import{resolveLunoraClient as I}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as A,r as C}from"./platform-1MW9DnW6.mjs";const U=(t="sess")=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const e=crypto.getRandomValues(new Uint8Array(16));return`${t}-${Array.from(e,s=>s.toString(16).padStart(2,"0")).join("")}`}}return`${t}-${Date.now().toString(36)}`},E=1e4,M=(t,e)=>{const s=I(e.client),d=e.destroyRef===void 0,l=e.destroyRef??D(S),{heartbeat:y,listPresent:m,shardKey:i}=e,o=e.intervalMs??E,a=e.sessionId??U(),u=h(void 0);if(!Number.isFinite(o)||o<=0)throw new RangeError(`presence intervalMs must be a positive number, got ${String(o)}`);let c=e.data;const r=()=>{const n={roomId:t,sessionId:a};c!==void 0&&(n.data=c),s.mutation(y,n,{shardKey:i}).catch(()=>{})},v=n=>{c=n,r()};if(A(d)){const n=s.acquireConnectionContext({roomId:t,sessionId:a},{shardKey:i});r();const f=()=>{typeof document<"u"&&document.visibilityState==="visible"&&r()},b=C(d,()=>(typeof document<"u"&&document.addEventListener("visibilitychange",f),setInterval(r,o))),p={roomId:t},g=s.subscribe(m,p,R=>{u.set(R)},{shardKey:i});l.onDestroy(()=>{clearInterval(b),typeof document<"u"&&document.removeEventListener("visibilitychange",f),n(),g()})}return{present:u.asReadonly(),sessionId:a,setData:v}};export{M 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{inject as h,DestroyRef as R,signal as a}from"@angular/core";import{resolveLunoraClient as k}from"./LUNORA_CLIENT-B0toApHY.mjs";const x=(u,n,r={})=>{const m=k(r.client),y=r.destroyRef??h(R),c=a([]),o=a(void 0),t=a("idle");let s=!0,l;const f=()=>{s=!1,l?.()};if(n!=="skip"){t.set("streaming");const i=m.stream(u,n,{maxBuffer:r.maxBuffer,shardKey:r.shardKey});l=()=>{i.cancel()},(async()=>{try{for await(const e of i){if(!s)return;c.update(d=>[...d,e])}s&&t.set("complete")}catch(e){if(!s)return;o.set(e instanceof Error?e:new Error(String(e))),t.set("error")}})().catch(()=>{})}return y.onDestroy(f),{cancel:f,chunks:c.asReadonly(),error:o.asReadonly(),status:t.asReadonly()}};export{x as stream};
@@ -0,0 +1 @@
1
+ import{inject as y,DestroyRef as m,signal as n}from"@angular/core";import{createQuerySubscription as l}from"@lunora/client/query";import{resolveLunoraClient as v}from"./LUNORA_CLIENT-B0toApHY.mjs";import{s as R}from"./platform-1MW9DnW6.mjs";const E=(i,s,o={})=>{const c=v(o.client),d=o.destroyRef===void 0,a=o.destroyRef??y(m),r=n(void 0),t=n(void 0);if(s!=="skip"&&R(d)){const f=o.onError,u=l(c,i,s,{onData:e=>{r.set(e),t.set(void 0)},onError:e=>{t.set(e),r.set(void 0),f?.(e)},onReset:()=>{r.set(void 0)}},{shardKey:o.shardKey});a.onDestroy(u)}return{data:r.asReadonly(),error:t.asReadonly()}};export{E as subscription};
@@ -0,0 +1 @@
1
+ import{inject as P,DestroyRef as W,signal as w}from"@angular/core";import{resolveLunoraClient as H}from"./LUNORA_CLIENT-B0toApHY.mjs";const O=16e3,q=e=>{if(e.length===0)return 0;let r=0;for(const o of e)r+=o*o;return Math.sqrt(r/e.length)},B=(e,r)=>{const o=r/O,a=o>1?Math.floor(e.length/o):e.length,d=new ArrayBuffer(a*2),i=new DataView(d);for(let u=0;u<a;u+=1){const k=e[Math.floor(u*o)]??0,f=Math.max(-1,Math.min(1,k));i.setInt16(u*2,f<0?f*32768:f*32767,!0)}return new Uint8Array(d)},$=async e=>{const r=globalThis,o=r.navigator?.mediaDevices?.getUserMedia.bind(r.navigator.mediaDevices),a=r.AudioContext??r.webkitAudioContext;if(!o||!a)throw new Error("voiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await o({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),i=new a,u=i.createMediaStreamSource(d),k=i.createScriptProcessor(4096,1,1);let f=!1,A=!1,p=0,h=0;return k.onaudioprocess=s=>{const l=s.inputBuffer.getChannelData(0),g=f?0:q(l);if(e.onLevel(g),f)return;if(e.onAudio(B(l,i.sampleRate)),e.isSpeaking()){h=g>=e.interruptThreshold?h+1:0,h>=e.interruptChunks&&(h=0,e.onInterrupt());return}h=0;const S=l.length/i.sampleRate*1e3;if(g>=e.silenceThreshold){A=!0,p=0;return}A&&(p+=S,p>=e.silenceDurationMs&&(A=!1,p=0,e.onSilence()))},u.connect(k),k.connect(i.destination),{setMuted:s=>{f=s},stop:()=>{k.disconnect(),u.disconnect();for(const s of d.getTracks())s.stop();i.close()}}},V=()=>{const e=globalThis,r=e.AudioContext??e.webkitAudioContext;if(!r)throw new Error("voiceAgent: audio playback requires AudioContext (no browser audio available)");const o=new r,a=new Set;let d=0,i=Promise.resolve(),u=0;const k=async(p,h)=>{if(h!==u)return;let s;try{s=await o.decodeAudioData(p.buffer)}catch{return}if(h!==u)return;const l=o.createBufferSource();l.buffer=s,l.connect(o.destination);const g=Math.max(o.currentTime,d);l.start(g),d=g+s.duration,a.add(l),l.onended=()=>{a.delete(l)}},f=p=>{const h=Uint8Array.from(p),s=u;i=i.then(()=>k(h,s))},A=()=>{u+=1;for(const p of a)try{p.stop()}catch{}a.clear(),d=o.currentTime};return{enqueue:f,interrupt:A,stop:()=>{A(),o.close()}}},_=1,J=.01,K=1200,j=.15,G=3,z=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,Q=e=>{const r=e.__lunoraRef,o=r.startsWith("agents:")?r.slice(7):r;return o.endsWith("Voice")?o.slice(0,-5):o},X=(e,r,o)=>{const a=z(e),d=a.endsWith("/")?a.slice(0,-1):a,i=new URLSearchParams({threadKey:o});return`${d}/_lunora/voice/${encodeURIComponent(r)}?${i.toString()}`},ee=e=>{const{createMicrophone:r=$,createSpeaker:o=V,createSocket:a,interruptChunks:d=G,interruptThreshold:i=j,silenceDurationMs:u=K,silenceThreshold:k=J,threadKey:f,voice:A}=e,p=H(e.client),h=e.destroyRef??P(W),s=w("idle"),l=w(!1),g=w(""),S=w(""),E=w(0),T=w(!1),v=w(void 0);let c,b=!1;const M=t=>{const n=c?.socket;return n?.readyState===_?(n.send(JSON.stringify(t)),!0):!1},R=()=>{const t=c;if(c=void 0,t){t.microphone?.stop(),t.speaker?.stop();try{t.socket.close()}catch{}}b=!1,l.set(!1),s.set("idle"),E.set(0)},U=R,D=t=>{const n=c;switch(t.type){case"assistant_delta":{n&&(n.speaking=!0),s.set("speaking"),S.update(m=>m+t.text);break}case"assistant_done":{n&&(n.speaking=!1),S.set(t.text),s.set("listening");break}case"error":{n&&(n.speaking=!1),v.set(new Error(t.message)),s.set("listening");break}case"interrupted":{n&&(n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),s.set("listening");break}case"ready":{n&&(n.audioFormat=t.audioFormat,n.suppressAudio=!1),l.set(!0),s.set("listening");break}case"user_transcript":{n&&(n.suppressAudio=!1),g.set(t.text),S.set(""),s.set("thinking");break}}},L=t=>{const n=c;!n||n.suppressAudio||(n.speaker??=o({audioFormat:n.audioFormat}),n.speaking=!0,s.set("speaking"),n.speaker.enqueue(t))},F=async()=>{if(!(c||b)){b=!0,v.set(void 0),g.set(""),S.set("");try{const t=X(p.url,Q(A),f),m=(a??(y=>new globalThis.WebSocket(y)))(t);m.binaryType="arraybuffer";const C={audioFormat:"mp3",microphone:void 0,socket:m,speaker:void 0,speaking:!1,suppressAudio:!1};c=C,m.onmessage=y=>{if(typeof y.data=="string"){try{D(JSON.parse(y.data))}catch{}return}L(new Uint8Array(y.data))},m.onerror=()=>{v.set(new Error("voiceAgent: voice socket error"))},m.onclose=()=>{c===C&&R()};const x=await r({interruptChunks:d,interruptThreshold:i,isSpeaking:()=>c?.speaking??!1,onAudio:y=>{m.readyState===_&&m.send(y)},onInterrupt:()=>{M({type:"interrupt"}),c?.speaker?.interrupt(),c&&(c.speaking=!1,c.suppressAudio=!0),s.set("listening")},onLevel:y=>{E.set(y)},onSilence:()=>{M({type:"commit"}),s.set("thinking")},silenceDurationMs:u,silenceThreshold:k});c===C?(C.microphone=x,T.set(!1),s.set("listening")):x.stop()}catch(t){v.set(t instanceof Error?t:new Error(String(t))),R()}finally{b=!1}}},N=()=>{const t=!T();return c?.microphone?.setMuted(t),T.set(t),t},I=t=>{M({text:t,type:"text"})&&s.set("thinking")};return h.onDestroy(R),{audioLevel:E.asReadonly(),connected:l.asReadonly(),endCall:U,error:v.asReadonly(),interimTranscript:S.asReadonly(),isMuted:T.asReadonly(),sendText:I,startCall:F,status:s.asReadonly(),toggleMute:N,transcript:g.asReadonly()}};export{ee as voiceAgent};
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.33",
3
+ "version": "1.0.0-alpha.35",
4
4
  "description": "Angular reactive adapter for Lunora — signal-based live queries and mutations",
5
5
  "keywords": [
6
6
  "angular",
@@ -53,9 +53,9 @@
53
53
  "access": "public"
54
54
  },
55
55
  "dependencies": {
56
- "@lunora/client": "1.0.0-alpha.49",
57
- "@lunora/ratelimit": "1.0.0-alpha.22",
58
- "@visulima/storage-client": "1.0.0"
56
+ "@lunora/client": "1.0.0-alpha.51",
57
+ "@lunora/ratelimit": "1.0.0-alpha.23",
58
+ "@visulima/storage-client": "1.0.2"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@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};