@lunora/solid 1.0.0-alpha.52 → 1.0.0-alpha.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { LunoraClient, FunctionReference, User, ConnectionStatus, ArgsOf, MutationCallOptions, ReturnOf, MutatorHandle, Preloaded } from '@lunora/client';
1
+ import { LunoraClient, FunctionReference, ArgsOf, ActionCallOptions, ReturnOf, User, ConnectionStatus, MutationCallOptions, MutatorHandle, Preloaded } from '@lunora/client';
2
2
  export type { ArgsOf, FunctionReference, MutatorHandle, MutatorTransaction, OptimisticUpdate, Preloaded, ReturnOf, Unsubscribe } from '@lunora/client';
3
3
  import { Context, Accessor, JSX } from 'solid-js';
4
4
  import { PaginationStatus } from '@lunora/client/pagination';
@@ -21,6 +21,52 @@ declare const LunoraContext: Context<LunoraClient | undefined>;
21
21
  * `useLunora` has the same contract.
22
22
  */
23
23
  declare const useLunora: () => LunoraClient;
24
+ interface ActionHandle<F extends FunctionReference> {
25
+ /** Invoke the action. Resolves with the server result; rejects on failure. */
26
+ call: (args: ArgsOf<F>, options?: ActionCallOptions) => Promise<ReturnOf<F>>;
27
+ /** The latest invocation's resolved value, or `undefined` before the first success. */
28
+ data: Accessor<ReturnOf<F> | undefined>;
29
+ /** The latest invocation's error, or `undefined`. */
30
+ error: Accessor<Error | undefined>;
31
+ /** `true` while any invocation from this handle is in flight (ref-counted, so overlapping calls compose). */
32
+ pending: Accessor<boolean>;
33
+ /** Clear `data`/`error` back to idle. */
34
+ reset: () => void;
35
+ }
36
+ /**
37
+ * The transport surface {@link createAction} actually needs — just
38
+ * `client.action`. Narrowed so the primitive can be exercised against a stub in
39
+ * tests without constructing a full `LunoraClient`.
40
+ */
41
+ interface ActionClient<F extends FunctionReference> {
42
+ action: (function_: F, args: ArgsOf<F>, options?: ActionCallOptions) => Promise<ReturnOf<F>>;
43
+ }
44
+ /**
45
+ * Build an action handle bound to an explicit client. Internal seam used by the
46
+ * provider-bound {@link createAction}; exported for tests that inject a stub.
47
+ * The ref-counted pending + error-normalize orchestration is the shared
48
+ * `createCallRunner` from `@lunora/client`; only the reactive sinks (Solid
49
+ * signals) are adapter-specific.
50
+ *
51
+ * `data`/`error` follow the adapter-wide contract: both track the LATEST
52
+ * invocation (an earlier call settling later cannot clobber a newer one), a
53
+ * success clears `error`, and a failure leaves the previous `data` in place.
54
+ * `reset()` clears both; it does not cancel an in-flight call.
55
+ */
56
+ declare const createActionForClient: <F extends FunctionReference>(client: ActionClient<F>, function_: F) => ActionHandle<F>;
57
+ /**
58
+ * Returns a reactive handle `{ call, pending, data, error, reset }` for the
59
+ * given action reference, bound to the `LunoraClient` from the nearest
60
+ * `<LunoraProvider>`.
61
+ *
62
+ * **Narrower than `createMutation` on purpose:** no `optimistic` /
63
+ * `optimisticUpdate` call options. An optimistic update patches the subscription
64
+ * cache on the assumption a write will land; an action is not a write — it runs
65
+ * in the Worker, may call a third party, and has no declared effect on any
66
+ * query. Offering the option would imply a rollback guarantee nothing can
67
+ * honour.
68
+ */
69
+ declare const createAction: <F extends FunctionReference>(function_: F) => ActionHandle<F>;
24
70
  /**
25
71
  * The lifecycle status stored on an agent thread. Client-safe mirror of
26
72
  * `@lunora/agent`'s `AgentThreadStatus` — re-declared here (rather than imported)
@@ -519,8 +565,13 @@ interface MutationClient<F extends FunctionReference> {
519
565
  * Build a mutation handle bound to an explicit client. Internal seam used by the
520
566
  * provider-bound {@link createMutation}; exported for tests that inject a stub.
521
567
  * The ref-counted pending + error-normalize orchestration is the shared
522
- * `createMutationRunner` from `@lunora/client`; only the reactive sinks (Solid
568
+ * `createCallRunner` from `@lunora/client`; only the reactive sinks (Solid
523
569
  * signals) are adapter-specific.
570
+ *
571
+ * `data`/`error` follow the adapter-wide contract: both track the LATEST
572
+ * invocation (an earlier call settling later cannot clobber a newer one), a
573
+ * success clears `error`, and a failure leaves the previous `data` in place.
574
+ * `reset()` clears both; it does not cancel an in-flight call.
524
575
  */
525
576
  declare const createMutationForClient: <F extends FunctionReference>(client: MutationClient<F>, function_: F) => MutationHandle<F>;
526
577
  /**
@@ -972,7 +1023,7 @@ interface LunoraProviderProps {
972
1023
  * ```
973
1024
  */
974
1025
  declare const LunoraProvider: (props: LunoraProviderProps) => JSX.Element;
975
- export { type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, Authenticated, type CreateAgentApi, type CreateAgentChatApi, type CreateAgentChatOptions, type CreateAgentChatResult, type CreateAgentOptions, type CreateAgentResult, type CreateAgentStateApi, type CreateAgentStateOptions, type CreateAgentStateResult, type CreateAgentToolEventsApi, type CreateAgentToolEventsOptions, type CreateAgentToolEventsResult, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateStreamOptions, type CreateStreamResult, type CreateStreamStatus, type CreateSubscriptionResult, type CreateVoiceAgentOptions, type CreateVoiceAgentResult, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider,
1026
+ export { type ActionClient, type ActionHandle, type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, Authenticated, type CreateAgentApi, type CreateAgentChatApi, type CreateAgentChatOptions, type CreateAgentChatResult, type CreateAgentOptions, type CreateAgentResult, type CreateAgentStateApi, type CreateAgentStateOptions, type CreateAgentStateResult, type CreateAgentToolEventsApi, type CreateAgentToolEventsOptions, type CreateAgentToolEventsResult, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateStreamOptions, type CreateStreamResult, type CreateStreamStatus, type CreateSubscriptionResult, type CreateVoiceAgentOptions, type CreateVoiceAgentResult, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider,
976
1027
  /**
977
1028
  * SolidJS adapter for Lunora.
978
1029
  *
@@ -991,4 +1042,4 @@ export { type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, ty
991
1042
  * framework-neutral server contract) — call it from your SolidStart route loader
992
1043
  * and hand the resulting `Preloaded` token to `hydratePreloaded`.
993
1044
  */
994
- type LunoraProviderProps, type MutationClient, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, createAgent, createAgentChat, createAgentState, createAgentToolEvents, createAuth, createConnectionStatus, createFlag, createFlags, createInfiniteQuery, createMutation, createMutationForClient, createMutator, createPaginatedQuery, createPresence, createQuery, createRateLimit, createStream, createSubscription, createVoiceAgent, hydratePreloaded, useLunora };
1045
+ type LunoraProviderProps, type MutationClient, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, createAction, createActionForClient, createAgent, createAgentChat, createAgentState, createAgentToolEvents, createAuth, createConnectionStatus, createFlag, createFlags, createInfiniteQuery, createMutation, createMutationForClient, createMutator, createPaginatedQuery, createPresence, createQuery, createRateLimit, createStream, createSubscription, createVoiceAgent, hydratePreloaded, useLunora };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LunoraClient, FunctionReference, User, ConnectionStatus, ArgsOf, MutationCallOptions, ReturnOf, MutatorHandle, Preloaded } from '@lunora/client';
1
+ import { LunoraClient, FunctionReference, ArgsOf, ActionCallOptions, ReturnOf, User, ConnectionStatus, MutationCallOptions, MutatorHandle, Preloaded } from '@lunora/client';
2
2
  export type { ArgsOf, FunctionReference, MutatorHandle, MutatorTransaction, OptimisticUpdate, Preloaded, ReturnOf, Unsubscribe } from '@lunora/client';
3
3
  import { Context, Accessor, JSX } from 'solid-js';
4
4
  import { PaginationStatus } from '@lunora/client/pagination';
@@ -21,6 +21,52 @@ declare const LunoraContext: Context<LunoraClient | undefined>;
21
21
  * `useLunora` has the same contract.
22
22
  */
23
23
  declare const useLunora: () => LunoraClient;
24
+ interface ActionHandle<F extends FunctionReference> {
25
+ /** Invoke the action. Resolves with the server result; rejects on failure. */
26
+ call: (args: ArgsOf<F>, options?: ActionCallOptions) => Promise<ReturnOf<F>>;
27
+ /** The latest invocation's resolved value, or `undefined` before the first success. */
28
+ data: Accessor<ReturnOf<F> | undefined>;
29
+ /** The latest invocation's error, or `undefined`. */
30
+ error: Accessor<Error | undefined>;
31
+ /** `true` while any invocation from this handle is in flight (ref-counted, so overlapping calls compose). */
32
+ pending: Accessor<boolean>;
33
+ /** Clear `data`/`error` back to idle. */
34
+ reset: () => void;
35
+ }
36
+ /**
37
+ * The transport surface {@link createAction} actually needs — just
38
+ * `client.action`. Narrowed so the primitive can be exercised against a stub in
39
+ * tests without constructing a full `LunoraClient`.
40
+ */
41
+ interface ActionClient<F extends FunctionReference> {
42
+ action: (function_: F, args: ArgsOf<F>, options?: ActionCallOptions) => Promise<ReturnOf<F>>;
43
+ }
44
+ /**
45
+ * Build an action handle bound to an explicit client. Internal seam used by the
46
+ * provider-bound {@link createAction}; exported for tests that inject a stub.
47
+ * The ref-counted pending + error-normalize orchestration is the shared
48
+ * `createCallRunner` from `@lunora/client`; only the reactive sinks (Solid
49
+ * signals) are adapter-specific.
50
+ *
51
+ * `data`/`error` follow the adapter-wide contract: both track the LATEST
52
+ * invocation (an earlier call settling later cannot clobber a newer one), a
53
+ * success clears `error`, and a failure leaves the previous `data` in place.
54
+ * `reset()` clears both; it does not cancel an in-flight call.
55
+ */
56
+ declare const createActionForClient: <F extends FunctionReference>(client: ActionClient<F>, function_: F) => ActionHandle<F>;
57
+ /**
58
+ * Returns a reactive handle `{ call, pending, data, error, reset }` for the
59
+ * given action reference, bound to the `LunoraClient` from the nearest
60
+ * `<LunoraProvider>`.
61
+ *
62
+ * **Narrower than `createMutation` on purpose:** no `optimistic` /
63
+ * `optimisticUpdate` call options. An optimistic update patches the subscription
64
+ * cache on the assumption a write will land; an action is not a write — it runs
65
+ * in the Worker, may call a third party, and has no declared effect on any
66
+ * query. Offering the option would imply a rollback guarantee nothing can
67
+ * honour.
68
+ */
69
+ declare const createAction: <F extends FunctionReference>(function_: F) => ActionHandle<F>;
24
70
  /**
25
71
  * The lifecycle status stored on an agent thread. Client-safe mirror of
26
72
  * `@lunora/agent`'s `AgentThreadStatus` — re-declared here (rather than imported)
@@ -519,8 +565,13 @@ interface MutationClient<F extends FunctionReference> {
519
565
  * Build a mutation handle bound to an explicit client. Internal seam used by the
520
566
  * provider-bound {@link createMutation}; exported for tests that inject a stub.
521
567
  * The ref-counted pending + error-normalize orchestration is the shared
522
- * `createMutationRunner` from `@lunora/client`; only the reactive sinks (Solid
568
+ * `createCallRunner` from `@lunora/client`; only the reactive sinks (Solid
523
569
  * signals) are adapter-specific.
570
+ *
571
+ * `data`/`error` follow the adapter-wide contract: both track the LATEST
572
+ * invocation (an earlier call settling later cannot clobber a newer one), a
573
+ * success clears `error`, and a failure leaves the previous `data` in place.
574
+ * `reset()` clears both; it does not cancel an in-flight call.
524
575
  */
525
576
  declare const createMutationForClient: <F extends FunctionReference>(client: MutationClient<F>, function_: F) => MutationHandle<F>;
526
577
  /**
@@ -972,7 +1023,7 @@ interface LunoraProviderProps {
972
1023
  * ```
973
1024
  */
974
1025
  declare const LunoraProvider: (props: LunoraProviderProps) => JSX.Element;
975
- export { type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, Authenticated, type CreateAgentApi, type CreateAgentChatApi, type CreateAgentChatOptions, type CreateAgentChatResult, type CreateAgentOptions, type CreateAgentResult, type CreateAgentStateApi, type CreateAgentStateOptions, type CreateAgentStateResult, type CreateAgentToolEventsApi, type CreateAgentToolEventsOptions, type CreateAgentToolEventsResult, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateStreamOptions, type CreateStreamResult, type CreateStreamStatus, type CreateSubscriptionResult, type CreateVoiceAgentOptions, type CreateVoiceAgentResult, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider,
1026
+ export { type ActionClient, type ActionHandle, type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, Authenticated, type CreateAgentApi, type CreateAgentChatApi, type CreateAgentChatOptions, type CreateAgentChatResult, type CreateAgentOptions, type CreateAgentResult, type CreateAgentStateApi, type CreateAgentStateOptions, type CreateAgentStateResult, type CreateAgentToolEventsApi, type CreateAgentToolEventsOptions, type CreateAgentToolEventsResult, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateStreamOptions, type CreateStreamResult, type CreateStreamStatus, type CreateSubscriptionResult, type CreateVoiceAgentOptions, type CreateVoiceAgentResult, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider,
976
1027
  /**
977
1028
  * SolidJS adapter for Lunora.
978
1029
  *
@@ -991,4 +1042,4 @@ export { type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, ty
991
1042
  * framework-neutral server contract) — call it from your SolidStart route loader
992
1043
  * and hand the resulting `Preloaded` token to `hydratePreloaded`.
993
1044
  */
994
- type LunoraProviderProps, type MutationClient, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, createAgent, createAgentChat, createAgentState, createAgentToolEvents, createAuth, createConnectionStatus, createFlag, createFlags, createInfiniteQuery, createMutation, createMutationForClient, createMutator, createPaginatedQuery, createPresence, createQuery, createRateLimit, createStream, createSubscription, createVoiceAgent, hydratePreloaded, useLunora };
1045
+ type LunoraProviderProps, type MutationClient, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, Unauthenticated, type UseAuthResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, createAction, createActionForClient, createAgent, createAgentChat, createAgentState, createAgentToolEvents, createAuth, createConnectionStatus, createFlag, createFlags, createInfiniteQuery, createMutation, createMutationForClient, createMutator, createPaginatedQuery, createPresence, createQuery, createRateLimit, createStream, createSubscription, createVoiceAgent, hydratePreloaded, useLunora };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{LunoraContext as r,useLunora as o}from"./packem_shared/LunoraContext-Ck27Dk1M.mjs";import{createAgent as c}from"./packem_shared/createAgent-CMq5pclb.mjs";import{createAgentChat as f}from"./packem_shared/createAgentChat-DvfhYedI.mjs";import{createAgentState as p}from"./packem_shared/createAgentState-DZ8VhNFw.mjs";import{createAgentToolEvents as u}from"./packem_shared/createAgentToolEvents-B2n2MhZT.mjs";import{AuthLoading as d,Authenticated as g,Unauthenticated as s,createAuth as A}from"./packem_shared/AuthLoading-Cw7P46Me.mjs";import{default as h}from"./packem_shared/createConnectionStatus-atEsI2Uf.mjs";import{createFlag as y,createFlags as C}from"./packem_shared/createFlag-5Q9XxBVg.mjs";import{createMutation as S,createMutationForClient as F}from"./packem_shared/createMutation-BXofV9Hm.mjs";import{createMutator as Q}from"./packem_shared/createMutator-q9cMjGKv.mjs";import{createInfiniteQuery as b,createPaginatedQuery as E}from"./packem_shared/createInfiniteQuery-DLnUulMv.mjs";import{createPresence as R}from"./packem_shared/createPresence-DU6JX44t.mjs";import{createQuery as U}from"./packem_shared/createQuery-Mf7pD2Wc.mjs";import{createRateLimit as j}from"./packem_shared/createRateLimit-CIVWrD5H.mjs";import{createStream as q}from"./packem_shared/createStream-wnMAf-xL.mjs";import{createSubscription as z}from"./packem_shared/createSubscription-CkJjcYO4.mjs";import{createVoiceAgent as D}from"./packem_shared/createVoiceAgent-DoOhsqq_.mjs";import{default as H}from"./packem_shared/hydratePreloaded-DaixZhLe.mjs";import{LunoraProvider as K}from"./packem_shared/LunoraProvider-DMXdQNLA.mjs";export{d as AuthLoading,g as Authenticated,r as LunoraContext,K as LunoraProvider,s as Unauthenticated,c as createAgent,f as createAgentChat,p as createAgentState,u as createAgentToolEvents,A as createAuth,h as createConnectionStatus,y as createFlag,C as createFlags,b as createInfiniteQuery,S as createMutation,F as createMutationForClient,Q as createMutator,E as createPaginatedQuery,R as createPresence,U as createQuery,j as createRateLimit,q as createStream,z as createSubscription,D as createVoiceAgent,H as hydratePreloaded,o as useLunora};
1
+ import{LunoraContext as r,useLunora as o}from"./packem_shared/LunoraContext-Ck27Dk1M.mjs";import{createAction as c,createActionForClient as n}from"./packem_shared/createAction-CbGirc8n.mjs";import{createAgent as m}from"./packem_shared/createAgent-CvY_sduu.mjs";import{createAgentChat as x}from"./packem_shared/createAgentChat-BONQ21Fr.mjs";import{createAgentState as u}from"./packem_shared/createAgentState-D6iGuFht.mjs";import{createAgentToolEvents as A}from"./packem_shared/createAgentToolEvents-Beu0Hk7M.mjs";import{AuthLoading as l,Authenticated as s,Unauthenticated as h,createAuth as C}from"./packem_shared/AuthLoading-Cw7P46Me.mjs";import{default as y}from"./packem_shared/createConnectionStatus-atEsI2Uf.mjs";import{createFlag as P,createFlags as S}from"./packem_shared/createFlag-DEnyyD3z.mjs";import{createMutation as Q,createMutationForClient as v}from"./packem_shared/createMutation-DE50ca4x.mjs";import{createMutator as E}from"./packem_shared/createMutator-q9cMjGKv.mjs";import{createInfiniteQuery as R,createPaginatedQuery as T}from"./packem_shared/createInfiniteQuery-DLnUulMv.mjs";import{createPresence as V}from"./packem_shared/createPresence-DU6JX44t.mjs";import{createQuery as k}from"./packem_shared/createQuery-Mf7pD2Wc.mjs";import{createRateLimit as w}from"./packem_shared/createRateLimit-CIVWrD5H.mjs";import{createStream as B}from"./packem_shared/createStream-wnMAf-xL.mjs";import{createSubscription as G}from"./packem_shared/createSubscription-CkJjcYO4.mjs";import{createVoiceAgent as J}from"./packem_shared/createVoiceAgent-zdX0zuEH.mjs";import{default as N}from"./packem_shared/hydratePreloaded-DaixZhLe.mjs";import{LunoraProvider as W}from"./packem_shared/LunoraProvider-DMXdQNLA.mjs";export{l as AuthLoading,s as Authenticated,r as LunoraContext,W as LunoraProvider,h as Unauthenticated,c as createAction,n as createActionForClient,m as createAgent,x as createAgentChat,u as createAgentState,A as createAgentToolEvents,C as createAuth,y as createConnectionStatus,P as createFlag,S as createFlags,R as createInfiniteQuery,Q as createMutation,v as createMutationForClient,E as createMutator,T as createPaginatedQuery,V as createPresence,k as createQuery,w as createRateLimit,B as createStream,G as createSubscription,J as createVoiceAgent,N as hydratePreloaded,o as useLunora};
@@ -0,0 +1 @@
1
+ import{createCallRunner as m}from"@lunora/client";import{createSignal as r}from"solid-js";import{useLunora as p}from"./LunoraContext-Ck27Dk1M.mjs";const u=(t,c)=>{const[s,n]=r(void 0),[a,e]=r(void 0),[i,l]=r(!1);return{call:m((o,d)=>t.action(c,o,d),{setError:e,setPending:l,setResult:o=>{n(()=>o),e(void 0)}}),data:s,error:a,pending:i,reset:()=>{n(()=>{}),e(void 0)}}},R=t=>u(p(),t);export{R as createAction,u as createActionForClient};
@@ -1 +1 @@
1
- import{createMemo as s}from"solid-js";import{createMutation as i}from"./createMutation-BXofV9Hm.mjs";import{createSubscription as M}from"./createSubscription-CkJjcYO4.mjs";const l={__lunoraRef:""},c=t=>typeof t=="function"?t():t,K=t=>{const{api:u,cancel:r,run:d,runArgs:f,threadKey:n}=t,o=i(d),m=i(r??l),{data:p}=M(u.agents.agentThread,()=>({key:c(n)})),a=s(()=>p()),y=s(()=>a()?.status),g=async(e,h)=>{await o.mutate({input:e,threadKey:c(n),...f,...h})};return{cancel:async()=>{const e=a()?.instanceId;r===void 0||e===void 0||await m.mutate({instanceId:e,threadKey:c(n)})},pending:o.pending,run:g,status:y,thread:a}};export{l as NO_MUTATION_REF,K as createAgent,c as resolveMaybe};
1
+ import{createMemo as s}from"solid-js";import{createMutation as i}from"./createMutation-DE50ca4x.mjs";import{createSubscription as M}from"./createSubscription-CkJjcYO4.mjs";const l={__lunoraRef:""},c=t=>typeof t=="function"?t():t,K=t=>{const{api:u,cancel:r,run:d,runArgs:f,threadKey:n}=t,o=i(d),m=i(r??l),{data:p}=M(u.agents.agentThread,()=>({key:c(n)})),a=s(()=>p()),y=s(()=>a()?.status),g=async(e,h)=>{await o.mutate({input:e,threadKey:c(n),...f,...h})};return{cancel:async()=>{const e=a()?.instanceId;r===void 0||e===void 0||await m.mutate({instanceId:e,threadKey:c(n)})},pending:o.pending,run:g,status:y,thread:a}};export{l as NO_MUTATION_REF,K as createAgent,c as resolveMaybe};
@@ -1 +1 @@
1
- import{reconcileOptimistic as v,maxSeq as A}from"@lunora/client";import{createSignal as F,createMemo as c}from"solid-js";import{resolveMaybe as a,NO_MUTATION_REF as U}from"./createAgent-CMq5pclb.mjs";import{createMutation as u}from"./createMutation-BXofV9Hm.mjs";import{createStream as $}from"./createStream-wnMAf-xL.mjs";import{createSubscription as M}from"./createSubscription-CkJjcYO4.mjs";const z={__lunoraRef:""},X=R=>{const{api:m,cancel:l,limit:p,send:S,sendArgs:k,stream:h,threadKey:r}=R,{data:w}=M(m.agents.agentMessages,()=>{const t=a(r);return p===void 0?{key:t}:{key:t,limit:p}}),{data:x}=M(m.agents.agentThread,()=>({key:a(r)})),I=h===void 0?"skip":()=>({key:a(r)}),{chunks:b}=$(h??z,I),_=u(S),K=u(l??U),O=u(m.agents.agentResolveApproval),[T,g]=F([]);let f=0;const d=c(()=>x()),j=c(()=>d()?.status),i=c(()=>w()??[]),q=c(()=>{const t=i(),n=v(T(),t);if(n.length===0)return t;const e=A(t);return[...t,...n.map((s,o)=>({content:s.content,optimistic:!0,role:"user",seq:e+1+o}))]}),E=c(()=>{const t=a(r),n=i().filter(e=>e.role==="assistant").length;return b().filter(e=>e.kind!=="progress"&&e.threadKey===t&&e.turn>=n).map(e=>e.text).join("")}),C=async(t,n)=>{const e=f;f+=1;const s=A(i());g(o=>[...v(o,i()),{content:t,id:e,maxDurableSeqAtSend:s}]);try{await _.mutate({input:t,threadKey:a(r),...k,...n})}catch(o){throw g(D=>D.filter(N=>N.id!==e)),o}},y=async(t,n,e)=>{const s=d()?.instanceId;if(s===void 0)throw new Error(`createAgentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await O.mutate({decision:t,instanceId:s,threadKey:a(r),toolCallId:n,...e===void 0?{}:{note:e}})};return{approve:async(t,n)=>y("approve",t,n),cancel:async()=>{const t=d()?.instanceId;l===void 0||t===void 0||await K.mutate({instanceId:t,threadKey:a(r)})},messages:q,reject:async(t,n)=>y("reject",t,n),send:C,status:j,streamingText:E}};export{X as createAgentChat};
1
+ import{reconcileOptimistic as v,maxSeq as A}from"@lunora/client";import{createSignal as F,createMemo as c}from"solid-js";import{resolveMaybe as a,NO_MUTATION_REF as U}from"./createAgent-CvY_sduu.mjs";import{createMutation as u}from"./createMutation-DE50ca4x.mjs";import{createStream as $}from"./createStream-wnMAf-xL.mjs";import{createSubscription as M}from"./createSubscription-CkJjcYO4.mjs";const z={__lunoraRef:""},X=R=>{const{api:m,cancel:l,limit:p,send:S,sendArgs:k,stream:h,threadKey:r}=R,{data:w}=M(m.agents.agentMessages,()=>{const t=a(r);return p===void 0?{key:t}:{key:t,limit:p}}),{data:x}=M(m.agents.agentThread,()=>({key:a(r)})),I=h===void 0?"skip":()=>({key:a(r)}),{chunks:b}=$(h??z,I),_=u(S),K=u(l??U),O=u(m.agents.agentResolveApproval),[T,g]=F([]);let f=0;const d=c(()=>x()),j=c(()=>d()?.status),i=c(()=>w()??[]),q=c(()=>{const t=i(),n=v(T(),t);if(n.length===0)return t;const e=A(t);return[...t,...n.map((s,o)=>({content:s.content,optimistic:!0,role:"user",seq:e+1+o}))]}),E=c(()=>{const t=a(r),n=i().filter(e=>e.role==="assistant").length;return b().filter(e=>e.kind!=="progress"&&e.threadKey===t&&e.turn>=n).map(e=>e.text).join("")}),C=async(t,n)=>{const e=f;f+=1;const s=A(i());g(o=>[...v(o,i()),{content:t,id:e,maxDurableSeqAtSend:s}]);try{await _.mutate({input:t,threadKey:a(r),...k,...n})}catch(o){throw g(D=>D.filter(N=>N.id!==e)),o}},y=async(t,n,e)=>{const s=d()?.instanceId;if(s===void 0)throw new Error(`createAgentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await O.mutate({decision:t,instanceId:s,threadKey:a(r),toolCallId:n,...e===void 0?{}:{note:e}})};return{approve:async(t,n)=>y("approve",t,n),cancel:async()=>{const t=d()?.instanceId;l===void 0||t===void 0||await K.mutate({instanceId:t,threadKey:a(r)})},messages:q,reject:async(t,n)=>y("reject",t,n),send:C,status:j,streamingText:E}};export{X as createAgentChat};
@@ -1 +1 @@
1
- import{createMemo as o}from"solid-js";import{resolveMaybe as n}from"./createAgent-CMq5pclb.mjs";import{createSubscription as c}from"./createSubscription-CkJjcYO4.mjs";const p=e=>{const{data:t,error:r}=c(e.api.agents.agentState,()=>({key:n(e.threadKey)})),a=o(()=>t());return{error:r,state:a}};export{p as createAgentState};
1
+ import{createMemo as o}from"solid-js";import{resolveMaybe as n}from"./createAgent-CvY_sduu.mjs";import{createSubscription as c}from"./createSubscription-CkJjcYO4.mjs";const p=e=>{const{data:t,error:r}=c(e.api.agents.agentState,()=>({key:n(e.threadKey)})),a=o(()=>t());return{error:r,state:a}};export{p as createAgentState};
@@ -1 +1 @@
1
- import{createMemo as v}from"solid-js";import{resolveMaybe as n}from"./createAgent-CMq5pclb.mjs";import{createStream as f}from"./createStream-wnMAf-xL.mjs";import{createSubscription as y}from"./createSubscription-CkJjcYO4.mjs";const C={__lunoraRef:""},I=[],N=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}}]},_=t=>{const{api:r,limit:a,stream:i,threadKey:e}=t,u=()=>{const l=n(e);return a===void 0?{key:l}:{key:l,limit:a}},{data:p}=y(r.agents.agentMessages,u),s=i===void 0?"skip":()=>({key:n(e)}),{chunks:c}=f(i??C,s);return{events:v(()=>{const l=n(e),d=(p()??I).flatMap(o=>N(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{_ as createAgentToolEvents};
1
+ import{createMemo as v}from"solid-js";import{resolveMaybe as n}from"./createAgent-CvY_sduu.mjs";import{createStream as f}from"./createStream-wnMAf-xL.mjs";import{createSubscription as y}from"./createSubscription-CkJjcYO4.mjs";const C={__lunoraRef:""},I=[],N=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}}]},_=t=>{const{api:r,limit:a,stream:i,threadKey:e}=t,u=()=>{const l=n(e);return a===void 0?{key:l}:{key:l,limit:a}},{data:p}=y(r.agents.agentMessages,u),s=i===void 0?"skip":()=>({key:n(e)}),{chunks:c}=f(i??C,s);return{events:v(()=>{const l=n(e),d=(p()??I).flatMap(o=>N(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{_ as createAgentToolEvents};
@@ -1 +1 @@
1
- import{createSignal as f,createEffect as p,on as m,onCleanup as y}from"solid-js";import{s as _}from"./stable-key-BrNca3-v.mjs";import{useLunora as g}from"./LunoraContext-Ck27Dk1M.mjs";import{resolveMaybe as r}from"./createAgent-CMq5pclb.mjs";const h="__lunora_flags__:eval",v=t=>{const e=typeof t;return e==="boolean"||e==="number"||e==="string"?e:"object"},C={__lunoraRef:h},$=t=>t===void 0?"":_(t),S=(t,e,s)=>{const a=g(),c=v(e),[b,u]=f(e);return p(m(()=>`${r(t)} ${$(r(s))}`,()=>{const i=r(t),n=r(s);u(()=>e);let o;try{o=a.subscribe(C,{context:n,default:e,key:i,type:c},l=>{u(()=>l)})}catch{return}y(o)})),b},j=(t,e)=>{const s=g(),[a,c]=f(t),b=_(t);return p(m(()=>`${b} ${$(r(e))}`,()=>{const u=r(e);c(()=>t);const i=[];for(const[n,o]of Object.entries(t))try{i.push(s.subscribe(C,{context:u,default:o,key:n,type:v(o)},l=>{c(d=>({...d,[n]:l}))}))}catch{}y(()=>{for(const n of i)n()})})),a};export{S as createFlag,j as createFlags};
1
+ import{createSignal as f,createEffect as p,on as m,onCleanup as y}from"solid-js";import{s as _}from"./stable-key-BrNca3-v.mjs";import{useLunora as g}from"./LunoraContext-Ck27Dk1M.mjs";import{resolveMaybe as r}from"./createAgent-CvY_sduu.mjs";const h="__lunora_flags__:eval",v=t=>{const e=typeof t;return e==="boolean"||e==="number"||e==="string"?e:"object"},C={__lunoraRef:h},$=t=>t===void 0?"":_(t),S=(t,e,s)=>{const a=g(),c=v(e),[b,u]=f(e);return p(m(()=>`${r(t)} ${$(r(s))}`,()=>{const i=r(t),n=r(s);u(()=>e);let o;try{o=a.subscribe(C,{context:n,default:e,key:i,type:c},l=>{u(()=>l)})}catch{return}y(o)})),b},j=(t,e)=>{const s=g(),[a,c]=f(t),b=_(t);return p(m(()=>`${b} ${$(r(e))}`,()=>{const u=r(e);c(()=>t);const i=[];for(const[n,o]of Object.entries(t))try{i.push(s.subscribe(C,{context:u,default:o,key:n,type:v(o)},l=>{c(d=>({...d,[n]:l}))}))}catch{}y(()=>{for(const n of i)n()})})),a};export{S as createFlag,j as createFlags};
@@ -0,0 +1 @@
1
+ import{createCallRunner as l}from"@lunora/client";import{createSignal as s}from"solid-js";import{useLunora as p}from"./LunoraContext-Ck27Dk1M.mjs";const v=(e,o)=>{const[r,t]=s(void 0),[n,a]=s(void 0),[c,u]=s(!1),m=l((i,d)=>e.mutation(o,i,d),{setError:a,setPending:u,setResult:i=>{t(()=>i),a(void 0)}});return{data:r,error:n,mutate:m,pending:c,reset:()=>{t(()=>{}),a(void 0)}}},R=e=>{const o=p();return v({mutation:(r,t,n)=>o.mutation(r,t,n)},e)};export{R as createMutation,v as createMutationForClient};
@@ -1 +1 @@
1
- import{createSignal as w,onCleanup as B}from"solid-js";import{useLunora as $}from"./LunoraContext-Ck27Dk1M.mjs";import{resolveMaybe as J}from"./createAgent-CMq5pclb.mjs";const K=16e3,G=e=>{if(e.length===0)return 0;let s=0;for(const o of e)s+=o*o;return Math.sqrt(s/e.length)},j=(e,s)=>{const o=s/K,a=o>1?Math.floor(e.length/o):e.length,l=new ArrayBuffer(a*2),i=new DataView(l);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(l)},z=async e=>{const s=globalThis,o=s.navigator?.mediaDevices?.getUserMedia.bind(s.navigator.mediaDevices),a=s.AudioContext??s.webkitAudioContext;if(!o||!a)throw new Error("createVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const l=await o({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),i=new a,u=i.createMediaStreamSource(l),k=i.createScriptProcessor(4096,1,1);let f=!1,A=!1,d=0,p=0;return k.onaudioprocess=r=>{const h=r.inputBuffer.getChannelData(0),g=f?0:G(h);if(e.onLevel(g),f)return;if(e.onAudio(j(h,i.sampleRate)),e.isSpeaking()){p=g>=e.interruptThreshold?p+1:0,p>=e.interruptChunks&&(p=0,e.onInterrupt());return}p=0;const E=h.length/i.sampleRate*1e3;if(g>=e.silenceThreshold){A=!0,d=0;return}A&&(d+=E,d>=e.silenceDurationMs&&(A=!1,d=0,e.onSilence()))},u.connect(k),k.connect(i.destination),{setMuted:r=>{f=r},stop:()=>{k.disconnect(),u.disconnect();for(const r of l.getTracks())r.stop();i.close()}}},Q=()=>{const e=globalThis,s=e.AudioContext??e.webkitAudioContext;if(!s)throw new Error("createVoiceAgent: audio playback requires AudioContext (no browser audio available)");const o=new s,a=new Set;let l=0,i=Promise.resolve(),u=0;const k=async(d,p)=>{if(p!==u)return;let r;try{r=await o.decodeAudioData(d.buffer)}catch{return}if(p!==u)return;const h=o.createBufferSource();h.buffer=r,h.connect(o.destination);const g=Math.max(o.currentTime,l);h.start(g),l=g+r.duration,a.add(h),h.onended=()=>{a.delete(h)}},f=d=>{const p=Uint8Array.from(d),r=u;i=i.then(()=>k(p,r))},A=()=>{u+=1;for(const d of a)try{d.stop()}catch{}a.clear(),l=o.currentTime};return{enqueue:f,interrupt:A,stop:()=>{A(),o.close()}}},D=1,X=.01,Y=1200,Z=.15,ee=3,te=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,ne=e=>{const s=e.__lunoraRef,o=s.startsWith("agents:")?s.slice(7):s;return o.endsWith("Voice")?o.slice(0,-5):o},oe=(e,s,o)=>{const a=te(e),l=a.endsWith("/")?a.slice(0,-1):a,i=new URLSearchParams({threadKey:o});return`${l}/_lunora/voice/${encodeURIComponent(s)}?${i.toString()}`},ie=e=>{const{createMicrophone:s=z,createSpeaker:o=Q,createSocket:a,interruptChunks:l=ee,interruptThreshold:i=Z,silenceDurationMs:u=Y,silenceThreshold:k=X,threadKey:f,voice:A}=e,d=$(),[p,r]=w("idle"),[h,g]=w(!1),[E,x]=w(""),[F,y]=w(""),[I,_]=w(0),[U,L]=w(!1),[N,T]=w(void 0);let c,b=!1;const M=t=>{const n=c?.socket;return n?.readyState===D?(n.send(JSON.stringify(t)),!0):!1},C=()=>{const t=c;if(c=void 0,t){t.microphone?.stop(),t.speaker?.stop();try{t.socket.close()}catch{}}b=!1,g(!1),r("idle"),_(0)},P=C,W=t=>{const n=c;switch(t.type){case"assistant_delta":{n&&(n.speaking=!0),r("speaking"),y(m=>m+t.text);break}case"assistant_done":{n&&(n.speaking=!1),y(t.text),r("listening");break}case"error":{n&&(n.speaking=!1),T(new Error(t.message)),r("listening");break}case"interrupted":{n&&(n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),r("listening");break}case"ready":{n&&(n.audioFormat=t.audioFormat,n.suppressAudio=!1),g(!0),r("listening");break}case"user_transcript":{n&&(n.suppressAudio=!1),x(t.text),y(""),r("thinking");break}}},V=t=>{const n=c;!n||n.suppressAudio||(n.speaker??=o({audioFormat:n.audioFormat}),n.speaking=!0,r("speaking"),n.speaker.enqueue(t))},H=async()=>{if(!(c||b)){b=!0,T(void 0),x(""),y("");try{const t=oe(d.url,ne(A),J(f)),m=(a??(S=>new globalThis.WebSocket(S)))(t);m.binaryType="arraybuffer";const v={audioFormat:"mp3",microphone:void 0,socket:m,speaker:void 0,speaking:!1,suppressAudio:!1};c=v,m.onmessage=S=>{if(typeof S.data=="string"){try{W(JSON.parse(S.data))}catch{}return}V(new Uint8Array(S.data))},m.onerror=()=>{T(new Error("createVoiceAgent: voice socket error"))},m.onclose=()=>{c===v&&C()};const R=await s({interruptChunks:l,interruptThreshold:i,isSpeaking:()=>c?.speaking??!1,onAudio:S=>{m.readyState===D&&m.send(S)},onInterrupt:()=>{M({type:"interrupt"}),c?.speaker?.interrupt(),c&&(c.speaking=!1,c.suppressAudio=!0),r("listening")},onLevel:S=>{_(S)},onSilence:()=>{M({type:"commit"}),r("thinking")},silenceDurationMs:u,silenceThreshold:k});c===v?(v.microphone=R,L(!1),r("listening")):R.stop()}catch(t){T(t instanceof Error?t:new Error(String(t))),C()}finally{b=!1}}},O=()=>{const t=!U();return c?.microphone?.setMuted(t),L(t),t},q=t=>{M({text:t,type:"text"})&&r("thinking")};return B(C),{audioLevel:I,connected:h,endCall:P,error:N,interimTranscript:F,isMuted:U,sendText:q,startCall:H,status:p,toggleMute:O,transcript:E}};export{ie as createVoiceAgent};
1
+ import{createSignal as w,onCleanup as B}from"solid-js";import{useLunora as $}from"./LunoraContext-Ck27Dk1M.mjs";import{resolveMaybe as J}from"./createAgent-CvY_sduu.mjs";const K=16e3,G=e=>{if(e.length===0)return 0;let s=0;for(const o of e)s+=o*o;return Math.sqrt(s/e.length)},j=(e,s)=>{const o=s/K,a=o>1?Math.floor(e.length/o):e.length,l=new ArrayBuffer(a*2),i=new DataView(l);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(l)},z=async e=>{const s=globalThis,o=s.navigator?.mediaDevices?.getUserMedia.bind(s.navigator.mediaDevices),a=s.AudioContext??s.webkitAudioContext;if(!o||!a)throw new Error("createVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const l=await o({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),i=new a,u=i.createMediaStreamSource(l),k=i.createScriptProcessor(4096,1,1);let f=!1,A=!1,d=0,p=0;return k.onaudioprocess=r=>{const h=r.inputBuffer.getChannelData(0),g=f?0:G(h);if(e.onLevel(g),f)return;if(e.onAudio(j(h,i.sampleRate)),e.isSpeaking()){p=g>=e.interruptThreshold?p+1:0,p>=e.interruptChunks&&(p=0,e.onInterrupt());return}p=0;const E=h.length/i.sampleRate*1e3;if(g>=e.silenceThreshold){A=!0,d=0;return}A&&(d+=E,d>=e.silenceDurationMs&&(A=!1,d=0,e.onSilence()))},u.connect(k),k.connect(i.destination),{setMuted:r=>{f=r},stop:()=>{k.disconnect(),u.disconnect();for(const r of l.getTracks())r.stop();i.close()}}},Q=()=>{const e=globalThis,s=e.AudioContext??e.webkitAudioContext;if(!s)throw new Error("createVoiceAgent: audio playback requires AudioContext (no browser audio available)");const o=new s,a=new Set;let l=0,i=Promise.resolve(),u=0;const k=async(d,p)=>{if(p!==u)return;let r;try{r=await o.decodeAudioData(d.buffer)}catch{return}if(p!==u)return;const h=o.createBufferSource();h.buffer=r,h.connect(o.destination);const g=Math.max(o.currentTime,l);h.start(g),l=g+r.duration,a.add(h),h.onended=()=>{a.delete(h)}},f=d=>{const p=Uint8Array.from(d),r=u;i=i.then(()=>k(p,r))},A=()=>{u+=1;for(const d of a)try{d.stop()}catch{}a.clear(),l=o.currentTime};return{enqueue:f,interrupt:A,stop:()=>{A(),o.close()}}},D=1,X=.01,Y=1200,Z=.15,ee=3,te=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,ne=e=>{const s=e.__lunoraRef,o=s.startsWith("agents:")?s.slice(7):s;return o.endsWith("Voice")?o.slice(0,-5):o},oe=(e,s,o)=>{const a=te(e),l=a.endsWith("/")?a.slice(0,-1):a,i=new URLSearchParams({threadKey:o});return`${l}/_lunora/voice/${encodeURIComponent(s)}?${i.toString()}`},ie=e=>{const{createMicrophone:s=z,createSpeaker:o=Q,createSocket:a,interruptChunks:l=ee,interruptThreshold:i=Z,silenceDurationMs:u=Y,silenceThreshold:k=X,threadKey:f,voice:A}=e,d=$(),[p,r]=w("idle"),[h,g]=w(!1),[E,x]=w(""),[F,y]=w(""),[I,_]=w(0),[U,L]=w(!1),[N,T]=w(void 0);let c,b=!1;const M=t=>{const n=c?.socket;return n?.readyState===D?(n.send(JSON.stringify(t)),!0):!1},C=()=>{const t=c;if(c=void 0,t){t.microphone?.stop(),t.speaker?.stop();try{t.socket.close()}catch{}}b=!1,g(!1),r("idle"),_(0)},P=C,W=t=>{const n=c;switch(t.type){case"assistant_delta":{n&&(n.speaking=!0),r("speaking"),y(m=>m+t.text);break}case"assistant_done":{n&&(n.speaking=!1),y(t.text),r("listening");break}case"error":{n&&(n.speaking=!1),T(new Error(t.message)),r("listening");break}case"interrupted":{n&&(n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),r("listening");break}case"ready":{n&&(n.audioFormat=t.audioFormat,n.suppressAudio=!1),g(!0),r("listening");break}case"user_transcript":{n&&(n.suppressAudio=!1),x(t.text),y(""),r("thinking");break}}},V=t=>{const n=c;!n||n.suppressAudio||(n.speaker??=o({audioFormat:n.audioFormat}),n.speaking=!0,r("speaking"),n.speaker.enqueue(t))},H=async()=>{if(!(c||b)){b=!0,T(void 0),x(""),y("");try{const t=oe(d.url,ne(A),J(f)),m=(a??(S=>new globalThis.WebSocket(S)))(t);m.binaryType="arraybuffer";const v={audioFormat:"mp3",microphone:void 0,socket:m,speaker:void 0,speaking:!1,suppressAudio:!1};c=v,m.onmessage=S=>{if(typeof S.data=="string"){try{W(JSON.parse(S.data))}catch{}return}V(new Uint8Array(S.data))},m.onerror=()=>{T(new Error("createVoiceAgent: voice socket error"))},m.onclose=()=>{c===v&&C()};const R=await s({interruptChunks:l,interruptThreshold:i,isSpeaking:()=>c?.speaking??!1,onAudio:S=>{m.readyState===D&&m.send(S)},onInterrupt:()=>{M({type:"interrupt"}),c?.speaker?.interrupt(),c&&(c.speaking=!1,c.suppressAudio=!0),r("listening")},onLevel:S=>{_(S)},onSilence:()=>{M({type:"commit"}),r("thinking")},silenceDurationMs:u,silenceThreshold:k});c===v?(v.microphone=R,L(!1),r("listening")):R.stop()}catch(t){T(t instanceof Error?t:new Error(String(t))),C()}finally{b=!1}}},O=()=>{const t=!U();return c?.microphone?.setMuted(t),L(t),t},q=t=>{M({text:t,type:"text"})&&r("thinking")};return B(C),{audioLevel:I,connected:h,endCall:P,error:N,interimTranscript:F,isMuted:U,sendText:q,startCall:H,status:p,toggleMute:O,transcript:E}};export{ie as createVoiceAgent};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/solid",
3
- "version": "1.0.0-alpha.52",
3
+ "version": "1.0.0-alpha.53",
4
4
  "description": "SolidJS adapter for Lunora — live queries, optimistic mutations, and reactive loaders",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -54,7 +54,7 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@lunora/client": "1.0.0-alpha.51",
57
+ "@lunora/client": "1.0.0-alpha.52",
58
58
  "@lunora/errors": "1.0.0-alpha.22",
59
59
  "@lunora/ratelimit": "1.0.0-alpha.23",
60
60
  "@visulima/storage-client": "1.0.2"
@@ -1 +0,0 @@
1
- import{createMutationRunner as d}from"@lunora/client";import{createSignal as a}from"solid-js";import{useLunora as l}from"./LunoraContext-Ck27Dk1M.mjs";const p=(e,o)=>{const[r,t]=a(void 0),[n,i]=a(void 0),[s,c]=a(!1),u=d(e,o,{setError:i,setPending:c,setResult:m=>{t(()=>m),i(void 0)}});return{data:r,error:n,mutate:u,pending:s,reset:()=>{t(()=>{}),i(void 0)}}},R=e=>{const o=l();return p({mutation:(r,t,n)=>o.mutation(r,t,n)},e)};export{R as createMutation,p as createMutationForClient};