@lunora/react 1.0.0-alpha.43 → 1.0.0-alpha.45

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 (33) hide show
  1. package/dist/index.d.mts +36 -36
  2. package/dist/index.d.ts +36 -36
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/{AuthLoading-eLWn4Z7G.mjs → AuthLoading-C5eyDVbk.mjs} +1 -1
  5. package/dist/packem_shared/LunoraProvider-D6ZS72le.mjs +2 -0
  6. package/dist/packem_shared/{hydratePreloaded-CJjZRtQr.mjs → hydratePreloaded-BvPwhOFD.mjs} +1 -1
  7. package/dist/packem_shared/stream-state-ksURgmCA.mjs +1 -0
  8. package/dist/packem_shared/{use-paginated-core-ClJ0EeGx.mjs → use-paginated-core-_ZSkVafW.mjs} +1 -1
  9. package/dist/packem_shared/{useAgent-CkK3jOWX.mjs → useAgent-0Ozf4MwG.mjs} +1 -1
  10. package/dist/packem_shared/useAgentChat-CJpe5Mg9.mjs +2 -0
  11. package/dist/packem_shared/{useAgentState-D7NrtQNb.mjs → useAgentState-CyY_I9m2.mjs} +1 -1
  12. package/dist/packem_shared/{useAgentToolEvents-c88SqJWg.mjs → useAgentToolEvents-oXtLad4O.mjs} +1 -1
  13. package/dist/packem_shared/{useAuth-CWkJn7i9.mjs → useAuth-BKsFAcDG.mjs} +1 -1
  14. package/dist/packem_shared/{useAuthSessions-Dw4Zhtxa.mjs → useAuthSessions-DCiiklg1.mjs} +1 -1
  15. package/dist/packem_shared/{useAuthState-jnCMkIwt.mjs → useAuthState-DrW2_avK.mjs} +1 -1
  16. package/dist/packem_shared/{useClientQuery-EPo__hzu.mjs → useClientQuery-DFKZurlC.mjs} +1 -1
  17. package/dist/packem_shared/{useConnectionStatus-PL5D-S7t.mjs → useConnectionStatus-CiMP3Mmy.mjs} +1 -1
  18. package/dist/packem_shared/{useFlag-Dh7bXXPx.mjs → useFlag-Bj6cjeim.mjs} +1 -1
  19. package/dist/packem_shared/useHttpStream-6Mx4bTfB.mjs +2 -0
  20. package/dist/packem_shared/{useInfiniteQuery-RrCwLOXK.mjs → useInfiniteQuery-CgT2zfA-.mjs} +1 -1
  21. package/dist/packem_shared/{useMutation-B4uL3Rde.mjs → useMutation-C_8Nu0F4.mjs} +1 -1
  22. package/dist/packem_shared/{usePaginatedQuery-CfPP4EZz.mjs → usePaginatedQuery-CSs8g5Z7.mjs} +1 -1
  23. package/dist/packem_shared/{usePresence-xAbekAr_.mjs → usePresence-Bfa9ESum.mjs} +1 -1
  24. package/dist/packem_shared/{useQuery-C1IKYNQp.mjs → useQuery-CDk67eFh.mjs} +1 -1
  25. package/dist/packem_shared/useStream-B1USJrJG.mjs +2 -0
  26. package/dist/packem_shared/{useSubscription-NfJ0mdhL.mjs → useSubscription-CoFTfvYX.mjs} +1 -1
  27. package/dist/packem_shared/useVoiceAgent-CO0EiOoc.mjs +2 -0
  28. package/package.json +4 -4
  29. package/dist/packem_shared/LunoraProvider-InsjxtOB.mjs +0 -2
  30. package/dist/packem_shared/useAgentChat-vZrUmH0I.mjs +0 -2
  31. package/dist/packem_shared/useHttpStream-DFswZrRk.mjs +0 -2
  32. package/dist/packem_shared/useStream-CZqDeZ3D.mjs +0 -2
  33. package/dist/packem_shared/useVoiceAgent-4gj2W2jc.mjs +0 -2
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { LunoraClient, OptimisticUpdate, User, AuthImpersonation, AuthSession, AuthUser, FunctionReference, ClientQueryRef, ConnectionStatus, ArgsOf, ReturnOf, HttpStreamRef, HttpStreamArgsOf, HttpStreamChunkOf, MutatorHandle, Preloaded } from '@lunora/client';
2
+ import { LunoraClient, OptimisticUpdate, User, AuthImpersonation, AuthSession, AuthUser, FunctionReference, ClientQueryRef, ConnectionStatus, HttpStreamRef, HttpStreamArgsOf, HttpStreamChunkOf, ReturnOf, ArgsOf, MutatorHandle, Preloaded } from '@lunora/client';
3
3
  export { type ArgsOf, type ClientQueryRef, type FunctionReference, type HttpStreamArgsOf, type HttpStreamChunkOf, type HttpStreamRef, type LunoraClient, type LunoraErrorCode, type MutatorHandle, type MutatorTransaction, type OptimisticLocalStore, type OptimisticUpdate, type Preloaded, type ReturnOf, type User, createClientQuery, getErrorCode, getRetryAfterMs, isConflictError, isForbiddenError, isRateLimitedError, isUnauthorizedError } from '@lunora/client';
4
4
  import { QueryClient } from '@tanstack/react-query';
5
5
  export { type L as LunoraQueryOptions, l as lunoraQueryOptions } from "./packem_shared/query-options.d-CdgGQ9s4.mjs";
@@ -46,7 +46,7 @@ interface LunoraProviderProps {
46
46
  * route through the offline queue on the client), and `gcTime: 5min` (keep
47
47
  * results around for a short return-to-view window).
48
48
  *
49
- * If a parent `<QueryClientProvider>` is already mounted, the provider
49
+ * If a parent `<QueryClientProvider>` is already mounted, the provider
50
50
  * uses *that* client and does NOT install an inner one (so apps with their
51
51
  * own setup don't double-wrap).
52
52
  */
@@ -59,7 +59,7 @@ interface LunoraProviderProps {
59
59
  */
60
60
  declare const LunoraProvider: ({ children, client, queryClient }: LunoraProviderProps) => ReactElement;
61
61
  /**
62
- * Read the {@link LunoraClient} from the nearest `&lt;LunoraProvider>`. Kept
62
+ * Read the {@link LunoraClient} from the nearest `<LunoraProvider>`. Kept
63
63
  * colocated with the provider for back-compat.
64
64
  */
65
65
  declare const useLunora: () => LunoraClient;
@@ -373,14 +373,14 @@ interface UseAgentOptions {
373
373
  api: UseAgentApi;
374
374
  /**
375
375
  * Optional app mutation over the agent's cancel path
376
- * (`ctx.agents.&lt;name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
376
+ * (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
377
377
  * When omitted (or no run is in flight) {@link UseAgentResult.cancel} is a
378
378
  * no-op.
379
379
  */
380
380
  cancel?: FunctionReference<"mutation">;
381
381
  /**
382
382
  * The app mutation that starts (or continues) a run — a thin wrapper over
383
- * `ctx.agents.&lt;name>.run(...)`. Called with `{ threadKey, input }` merged with
383
+ * `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
384
384
  * {@link UseAgentOptions.runArgs} and the per-call args.
385
385
  */
386
386
  run: FunctionReference<"mutation">;
@@ -412,7 +412,7 @@ interface UseAgentResult {
412
412
  * `useAgentChat`.
413
413
  *
414
414
  * `run` and `cancel` stay generic over the app-defined mutations that wrap
415
- * `ctx.agents.&lt;name>.run` / `.cancel`, so the hook hard-codes no function names
415
+ * `ctx.agents.<name>.run` / `.cancel`, so the hook hard-codes no function names
416
416
  * beyond the `agents:*` surface.
417
417
  */
418
418
  declare const useAgent: (options: UseAgentOptions) => UseAgentResult;
@@ -524,7 +524,7 @@ interface UseAgentChatOptions {
524
524
  api: UseAgentChatApi;
525
525
  /**
526
526
  * Optional app mutation over the agent's cancel path
527
- * (`ctx.agents.&lt;name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
527
+ * (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
528
528
  * When omitted (or no run is in flight) {@link UseAgentChatResult.cancel} is a
529
529
  * no-op.
530
530
  */
@@ -533,7 +533,7 @@ interface UseAgentChatOptions {
533
533
  limit?: number;
534
534
  /**
535
535
  * The app mutation that starts (or continues) a run — a thin wrapper over
536
- * `ctx.agents.&lt;name>.run(...)`. Called with `{ threadKey, input }` merged with
536
+ * `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
537
537
  * {@link UseAgentChatOptions.sendArgs} and the per-call args.
538
538
  */
539
539
  send: FunctionReference<"mutation">;
@@ -797,29 +797,6 @@ declare const useFlag: <T extends FlagValue>(key: string, defaultValue: T, conte
797
797
  declare const useFlags: <T extends Record<string, FlagValue>>(flags: T, context?: FlagContext) => T;
798
798
  /** The lifecycle of a stream the hook is observing. */
799
799
  type UseStreamStatus = "complete" | "error" | "idle" | "streaming";
800
- interface UseStreamResult<T> {
801
- /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
802
- cancel: () => void;
803
- /** Chunks the server has pushed so far, in arrival order. */
804
- chunks: ReadonlyArray<T>;
805
- error: Error | undefined;
806
- status: UseStreamStatus;
807
- }
808
- interface UseStreamOptions {
809
- /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
810
- maxBuffer?: number;
811
- shardKey?: string;
812
- }
813
- /**
814
- * Subscribe to a streaming query. Returns the chunks pushed so far plus a
815
- * lifecycle status and a cancel function. Changing `fn` or the serialized
816
- * `args` resets the stream — the previous iterator is cancelled and a fresh
817
- * one opens with empty `chunks`.
818
- *
819
- * Pass `"skip"` for `args` to keep the hook mounted without opening a stream
820
- * (mirrors `useQuery` / `useSubscription`).
821
- */
822
- declare const useStream: <F extends FunctionReference<"stream">>(function_: F, args: "skip" | ArgsOf<F>, options?: UseStreamOptions) => UseStreamResult<ReturnOf<F>>;
823
800
  /**
824
801
  * Result shape returned by {@link useHttpStream}.
825
802
  * @experimental Part of the HTTP-SSE stream surface.
@@ -841,7 +818,7 @@ interface UseHttpStreamOptions {
841
818
  maxBuffer?: number;
842
819
  }
843
820
  /**
844
- * Consume an **HTTP-SSE route stream** (`httpRoute.&lt;verb>(path).stream()`) via
821
+ * Consume an **HTTP-SSE route stream** (`httpRoute.<verb>(path).stream()`) via
845
822
  * `client.httpStream`. Distinct from `useStream`, which consumes the WS
846
823
  * procedure stream (`kind: "stream"`). Returns the chunks received so far plus
847
824
  * a lifecycle status and a cancel function. Changing the route or the
@@ -1117,6 +1094,29 @@ interface UseRateLimitResult {
1117
1094
  * `useMemo`) so the `consume`/`check` callbacks keep a steady identity.
1118
1095
  */
1119
1096
  declare const useRateLimit: (config: RateLimitConfig, options?: UseRateLimitOptions) => UseRateLimitResult;
1097
+ interface UseStreamResult<T> {
1098
+ /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
1099
+ cancel: () => void;
1100
+ /** Chunks the server has pushed so far, in arrival order. */
1101
+ chunks: ReadonlyArray<T>;
1102
+ error: Error | undefined;
1103
+ status: UseStreamStatus;
1104
+ }
1105
+ interface UseStreamOptions {
1106
+ /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
1107
+ maxBuffer?: number;
1108
+ shardKey?: string;
1109
+ }
1110
+ /**
1111
+ * Subscribe to a streaming query. Returns the chunks pushed so far plus a
1112
+ * lifecycle status and a cancel function. Changing `fn` or the serialized
1113
+ * `args` resets the stream — the previous iterator is cancelled and a fresh
1114
+ * one opens with empty `chunks`.
1115
+ *
1116
+ * Pass `"skip"` for `args` to keep the hook mounted without opening a stream
1117
+ * (mirrors `useQuery` / `useSubscription`).
1118
+ */
1119
+ declare const useStream: <F extends FunctionReference<"stream">>(function_: F, args: "skip" | ArgsOf<F>, options?: UseStreamOptions) => UseStreamResult<ReturnOf<F>>;
1120
1120
  /**
1121
1121
  * Subscribe to a real-time stream from the server. Unlike `useQuery`, this
1122
1122
  * hook does not issue an initial HTTP fetch — it only delivers values that
@@ -1180,9 +1180,9 @@ type CreateSpeaker = (config: {
1180
1180
  audioFormat: VoiceAudioFormat;
1181
1181
  }) => VoiceSpeaker;
1182
1182
  /**
1183
- * The `agents.&lt;name>Voice` reference codegen emits for a voice-enabled agent — a
1183
+ * The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
1184
1184
  * live, WS-backed session keyed by `threadKey`. A structural subset of the
1185
- * generated member, so passing `api.agents.&lt;name>Voice` type-checks.
1185
+ * generated member, so passing `api.agents.<name>Voice` type-checks.
1186
1186
  */
1187
1187
  type VoiceReference = FunctionReference<"stream", {
1188
1188
  threadKey: string;
@@ -1224,7 +1224,7 @@ interface UseVoiceAgentOptions {
1224
1224
  silenceThreshold?: number;
1225
1225
  /** The thread to converse on — shared with the agent's text turns. */
1226
1226
  threadKey: string;
1227
- /** The generated `api.agents.&lt;name>Voice` reference — identifies the voice DO endpoint. */
1227
+ /** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
1228
1228
  voice: VoiceReference;
1229
1229
  }
1230
1230
  interface UseVoiceAgentResult {
@@ -1256,7 +1256,7 @@ interface UseVoiceAgentResult {
1256
1256
  * WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
1257
1257
  * streams the agent's synthesized speech back through the browser's audio output,
1258
1258
  * and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
1259
- * `audioLevel`) to React state. Pass the generated `api.agents.&lt;name>Voice`
1259
+ * `audioLevel`) to React state. Pass the generated `api.agents.<name>Voice`
1260
1260
  * reference (never a string), matching `useAgentChat`'s reference-passing style.
1261
1261
  *
1262
1262
  * v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { LunoraClient, OptimisticUpdate, User, AuthImpersonation, AuthSession, AuthUser, FunctionReference, ClientQueryRef, ConnectionStatus, ArgsOf, ReturnOf, HttpStreamRef, HttpStreamArgsOf, HttpStreamChunkOf, MutatorHandle, Preloaded } from '@lunora/client';
2
+ import { LunoraClient, OptimisticUpdate, User, AuthImpersonation, AuthSession, AuthUser, FunctionReference, ClientQueryRef, ConnectionStatus, HttpStreamRef, HttpStreamArgsOf, HttpStreamChunkOf, ReturnOf, ArgsOf, MutatorHandle, Preloaded } from '@lunora/client';
3
3
  export { type ArgsOf, type ClientQueryRef, type FunctionReference, type HttpStreamArgsOf, type HttpStreamChunkOf, type HttpStreamRef, type LunoraClient, type LunoraErrorCode, type MutatorHandle, type MutatorTransaction, type OptimisticLocalStore, type OptimisticUpdate, type Preloaded, type ReturnOf, type User, createClientQuery, getErrorCode, getRetryAfterMs, isConflictError, isForbiddenError, isRateLimitedError, isUnauthorizedError } from '@lunora/client';
4
4
  import { QueryClient } from '@tanstack/react-query';
5
5
  export { type L as LunoraQueryOptions, l as lunoraQueryOptions } from "./packem_shared/query-options.d-CdgGQ9s4.js";
@@ -46,7 +46,7 @@ interface LunoraProviderProps {
46
46
  * route through the offline queue on the client), and `gcTime: 5min` (keep
47
47
  * results around for a short return-to-view window).
48
48
  *
49
- * If a parent `&lt;QueryClientProvider>` is already mounted, the provider
49
+ * If a parent `<QueryClientProvider>` is already mounted, the provider
50
50
  * uses *that* client and does NOT install an inner one (so apps with their
51
51
  * own setup don't double-wrap).
52
52
  */
@@ -59,7 +59,7 @@ interface LunoraProviderProps {
59
59
  */
60
60
  declare const LunoraProvider: ({ children, client, queryClient }: LunoraProviderProps) => ReactElement;
61
61
  /**
62
- * Read the {@link LunoraClient} from the nearest `&lt;LunoraProvider>`. Kept
62
+ * Read the {@link LunoraClient} from the nearest `<LunoraProvider>`. Kept
63
63
  * colocated with the provider for back-compat.
64
64
  */
65
65
  declare const useLunora: () => LunoraClient;
@@ -373,14 +373,14 @@ interface UseAgentOptions {
373
373
  api: UseAgentApi;
374
374
  /**
375
375
  * Optional app mutation over the agent's cancel path
376
- * (`ctx.agents.&lt;name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
376
+ * (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
377
377
  * When omitted (or no run is in flight) {@link UseAgentResult.cancel} is a
378
378
  * no-op.
379
379
  */
380
380
  cancel?: FunctionReference<"mutation">;
381
381
  /**
382
382
  * The app mutation that starts (or continues) a run — a thin wrapper over
383
- * `ctx.agents.&lt;name>.run(...)`. Called with `{ threadKey, input }` merged with
383
+ * `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
384
384
  * {@link UseAgentOptions.runArgs} and the per-call args.
385
385
  */
386
386
  run: FunctionReference<"mutation">;
@@ -412,7 +412,7 @@ interface UseAgentResult {
412
412
  * `useAgentChat`.
413
413
  *
414
414
  * `run` and `cancel` stay generic over the app-defined mutations that wrap
415
- * `ctx.agents.&lt;name>.run` / `.cancel`, so the hook hard-codes no function names
415
+ * `ctx.agents.<name>.run` / `.cancel`, so the hook hard-codes no function names
416
416
  * beyond the `agents:*` surface.
417
417
  */
418
418
  declare const useAgent: (options: UseAgentOptions) => UseAgentResult;
@@ -524,7 +524,7 @@ interface UseAgentChatOptions {
524
524
  api: UseAgentChatApi;
525
525
  /**
526
526
  * Optional app mutation over the agent's cancel path
527
- * (`ctx.agents.&lt;name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
527
+ * (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
528
528
  * When omitted (or no run is in flight) {@link UseAgentChatResult.cancel} is a
529
529
  * no-op.
530
530
  */
@@ -533,7 +533,7 @@ interface UseAgentChatOptions {
533
533
  limit?: number;
534
534
  /**
535
535
  * The app mutation that starts (or continues) a run — a thin wrapper over
536
- * `ctx.agents.&lt;name>.run(...)`. Called with `{ threadKey, input }` merged with
536
+ * `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
537
537
  * {@link UseAgentChatOptions.sendArgs} and the per-call args.
538
538
  */
539
539
  send: FunctionReference<"mutation">;
@@ -797,29 +797,6 @@ declare const useFlag: <T extends FlagValue>(key: string, defaultValue: T, conte
797
797
  declare const useFlags: <T extends Record<string, FlagValue>>(flags: T, context?: FlagContext) => T;
798
798
  /** The lifecycle of a stream the hook is observing. */
799
799
  type UseStreamStatus = "complete" | "error" | "idle" | "streaming";
800
- interface UseStreamResult<T> {
801
- /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
802
- cancel: () => void;
803
- /** Chunks the server has pushed so far, in arrival order. */
804
- chunks: ReadonlyArray<T>;
805
- error: Error | undefined;
806
- status: UseStreamStatus;
807
- }
808
- interface UseStreamOptions {
809
- /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
810
- maxBuffer?: number;
811
- shardKey?: string;
812
- }
813
- /**
814
- * Subscribe to a streaming query. Returns the chunks pushed so far plus a
815
- * lifecycle status and a cancel function. Changing `fn` or the serialized
816
- * `args` resets the stream — the previous iterator is cancelled and a fresh
817
- * one opens with empty `chunks`.
818
- *
819
- * Pass `"skip"` for `args` to keep the hook mounted without opening a stream
820
- * (mirrors `useQuery` / `useSubscription`).
821
- */
822
- declare const useStream: <F extends FunctionReference<"stream">>(function_: F, args: "skip" | ArgsOf<F>, options?: UseStreamOptions) => UseStreamResult<ReturnOf<F>>;
823
800
  /**
824
801
  * Result shape returned by {@link useHttpStream}.
825
802
  * @experimental Part of the HTTP-SSE stream surface.
@@ -841,7 +818,7 @@ interface UseHttpStreamOptions {
841
818
  maxBuffer?: number;
842
819
  }
843
820
  /**
844
- * Consume an **HTTP-SSE route stream** (`httpRoute.&lt;verb>(path).stream()`) via
821
+ * Consume an **HTTP-SSE route stream** (`httpRoute.<verb>(path).stream()`) via
845
822
  * `client.httpStream`. Distinct from `useStream`, which consumes the WS
846
823
  * procedure stream (`kind: "stream"`). Returns the chunks received so far plus
847
824
  * a lifecycle status and a cancel function. Changing the route or the
@@ -1117,6 +1094,29 @@ interface UseRateLimitResult {
1117
1094
  * `useMemo`) so the `consume`/`check` callbacks keep a steady identity.
1118
1095
  */
1119
1096
  declare const useRateLimit: (config: RateLimitConfig, options?: UseRateLimitOptions) => UseRateLimitResult;
1097
+ interface UseStreamResult<T> {
1098
+ /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
1099
+ cancel: () => void;
1100
+ /** Chunks the server has pushed so far, in arrival order. */
1101
+ chunks: ReadonlyArray<T>;
1102
+ error: Error | undefined;
1103
+ status: UseStreamStatus;
1104
+ }
1105
+ interface UseStreamOptions {
1106
+ /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
1107
+ maxBuffer?: number;
1108
+ shardKey?: string;
1109
+ }
1110
+ /**
1111
+ * Subscribe to a streaming query. Returns the chunks pushed so far plus a
1112
+ * lifecycle status and a cancel function. Changing `fn` or the serialized
1113
+ * `args` resets the stream — the previous iterator is cancelled and a fresh
1114
+ * one opens with empty `chunks`.
1115
+ *
1116
+ * Pass `"skip"` for `args` to keep the hook mounted without opening a stream
1117
+ * (mirrors `useQuery` / `useSubscription`).
1118
+ */
1119
+ declare const useStream: <F extends FunctionReference<"stream">>(function_: F, args: "skip" | ArgsOf<F>, options?: UseStreamOptions) => UseStreamResult<ReturnOf<F>>;
1120
1120
  /**
1121
1121
  * Subscribe to a real-time stream from the server. Unlike `useQuery`, this
1122
1122
  * hook does not issue an initial HTTP fetch — it only delivers values that
@@ -1180,9 +1180,9 @@ type CreateSpeaker = (config: {
1180
1180
  audioFormat: VoiceAudioFormat;
1181
1181
  }) => VoiceSpeaker;
1182
1182
  /**
1183
- * The `agents.&lt;name>Voice` reference codegen emits for a voice-enabled agent — a
1183
+ * The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
1184
1184
  * live, WS-backed session keyed by `threadKey`. A structural subset of the
1185
- * generated member, so passing `api.agents.&lt;name>Voice` type-checks.
1185
+ * generated member, so passing `api.agents.<name>Voice` type-checks.
1186
1186
  */
1187
1187
  type VoiceReference = FunctionReference<"stream", {
1188
1188
  threadKey: string;
@@ -1224,7 +1224,7 @@ interface UseVoiceAgentOptions {
1224
1224
  silenceThreshold?: number;
1225
1225
  /** The thread to converse on — shared with the agent's text turns. */
1226
1226
  threadKey: string;
1227
- /** The generated `api.agents.&lt;name>Voice` reference — identifies the voice DO endpoint. */
1227
+ /** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
1228
1228
  voice: VoiceReference;
1229
1229
  }
1230
1230
  interface UseVoiceAgentResult {
@@ -1256,7 +1256,7 @@ interface UseVoiceAgentResult {
1256
1256
  * WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
1257
1257
  * streams the agent's synthesized speech back through the browser's audio output,
1258
1258
  * and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
1259
- * `audioLevel`) to React state. Pass the generated `api.agents.&lt;name>Voice`
1259
+ * `audioLevel`) to React state. Pass the generated `api.agents.<name>Voice`
1260
1260
  * reference (never a string), matching `useAgentChat`'s reference-passing style.
1261
1261
  *
1262
1262
  * v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{AuthLoading as t,Authenticated as o,Unauthenticated as u}from"./packem_shared/AuthLoading-eLWn4Z7G.mjs";import{useAuthState as a}from"./packem_shared/useAuthState-jnCMkIwt.mjs";import{LunoraProvider as f,useLunora as n}from"./packem_shared/LunoraProvider-InsjxtOB.mjs";import{CheckoutButton as i,CustomerPortalButton as d,useCheckout as x}from"./packem_shared/CheckoutButton-DS_DKgNf.mjs";import{lunoraQueryOptions as h}from"./packem_shared/lunoraQueryOptions-DWEJoNnh.mjs";import{useAuthSessions as A,useAuthUsers as c,useImpersonate as C,useOrganizations as U}from"./packem_shared/useAuthSessions-Dw4Zhtxa.mjs";import{useAgent as E}from"./packem_shared/useAgent-CkK3jOWX.mjs";import{useAgentChat as Q}from"./packem_shared/useAgentChat-vZrUmH0I.mjs";import{useAgentState as L}from"./packem_shared/useAgentState-D7NrtQNb.mjs";import{useAgentToolEvents as F}from"./packem_shared/useAgentToolEvents-c88SqJWg.mjs";import{default as k}from"./packem_shared/useAuth-CWkJn7i9.mjs";import{default as b}from"./packem_shared/useClientQuery-EPo__hzu.mjs";import{default as z}from"./packem_shared/useConnectionStatus-PL5D-S7t.mjs";import{useFlag as O,useFlags as T}from"./packem_shared/useFlag-Dh7bXXPx.mjs";import{useHttpStream as V}from"./packem_shared/useHttpStream-DFswZrRk.mjs";import{default as q}from"./packem_shared/useInfiniteQuery-RrCwLOXK.mjs";import{useMutation as D}from"./packem_shared/useMutation-B4uL3Rde.mjs";import{useMutator as J}from"./packem_shared/useMutator-D3CGrk5-.mjs";import{usePaginatedQuery as N}from"./packem_shared/usePaginatedQuery-CfPP4EZz.mjs";import{hydratePreloaded as X,default as Y}from"./packem_shared/hydratePreloaded-CJjZRtQr.mjs";import{usePresence as _}from"./packem_shared/usePresence-xAbekAr_.mjs";import{default as ee}from"./packem_shared/useQuery-C1IKYNQp.mjs";import{useRateLimit as te}from"./packem_shared/useRateLimit-DqikMrX9.mjs";import{useStream as ue}from"./packem_shared/useStream-CZqDeZ3D.mjs";import{default as ae}from"./packem_shared/useSubscription-NfJ0mdhL.mjs";import{useVoiceAgent as fe}from"./packem_shared/useVoiceAgent-4gj2W2jc.mjs";import{createClientQuery as me,getErrorCode as ie,getRetryAfterMs as de,isConflictError as xe,isForbiddenError as le,isRateLimitedError as he,isUnauthorizedError as ge}from"@lunora/client";import{RestrictionError as ce,UploadControl as Ce,UploadError as Ue}from"@visulima/storage-client";import{useChunkedRestUpload as Ee,useFileInput as Pe,useMultipartUpload as Qe,usePasteUpload as Se,useTusUpload as Le,useUpload as Re}from"@visulima/storage-client/react";export{t as AuthLoading,o as Authenticated,i as CheckoutButton,d as CustomerPortalButton,f as LunoraProvider,ce as RestrictionError,u as Unauthenticated,Ce as UploadControl,Ue as UploadError,me as createClientQuery,ie as getErrorCode,de as getRetryAfterMs,X as hydratePreloaded,xe as isConflictError,le as isForbiddenError,he as isRateLimitedError,ge as isUnauthorizedError,h as lunoraQueryOptions,E as useAgent,Q as useAgentChat,L as useAgentState,F as useAgentToolEvents,k as useAuth,A as useAuthSessions,a as useAuthState,c as useAuthUsers,x as useCheckout,Ee as useChunkedRestUpload,b as useClientQuery,z as useConnectionStatus,Pe as useFileInput,O as useFlag,T as useFlags,V as useHttpStream,C as useImpersonate,q as useInfiniteQuery,n as useLunora,Qe as useMultipartUpload,D as useMutation,J as useMutator,U as useOrganizations,N as usePaginatedQuery,Se as usePasteUpload,Y as usePreloadedQuery,_ as usePresence,ee as useQuery,te as useRateLimit,ue as useStream,ae as useSubscription,Le as useTusUpload,Re as useUpload,fe as useVoiceAgent};
2
+ import{AuthLoading as t,Authenticated as o,Unauthenticated as u}from"./packem_shared/AuthLoading-C5eyDVbk.mjs";import{useAuthState as a}from"./packem_shared/useAuthState-DrW2_avK.mjs";import{LunoraProvider as f,useLunora as n}from"./packem_shared/LunoraProvider-D6ZS72le.mjs";import{CheckoutButton as i,CustomerPortalButton as d,useCheckout as x}from"./packem_shared/CheckoutButton-DS_DKgNf.mjs";import{lunoraQueryOptions as h}from"./packem_shared/lunoraQueryOptions-DWEJoNnh.mjs";import{useAuthSessions as A,useAuthUsers as c,useImpersonate as C,useOrganizations as U}from"./packem_shared/useAuthSessions-DCiiklg1.mjs";import{useAgent as E}from"./packem_shared/useAgent-0Ozf4MwG.mjs";import{useAgentChat as Q}from"./packem_shared/useAgentChat-CJpe5Mg9.mjs";import{useAgentState as L}from"./packem_shared/useAgentState-CyY_I9m2.mjs";import{useAgentToolEvents as F}from"./packem_shared/useAgentToolEvents-oXtLad4O.mjs";import{default as k}from"./packem_shared/useAuth-BKsFAcDG.mjs";import{default as b}from"./packem_shared/useClientQuery-DFKZurlC.mjs";import{default as z}from"./packem_shared/useConnectionStatus-CiMP3Mmy.mjs";import{useFlag as O,useFlags as T}from"./packem_shared/useFlag-Bj6cjeim.mjs";import{useHttpStream as V}from"./packem_shared/useHttpStream-6Mx4bTfB.mjs";import{default as q}from"./packem_shared/useInfiniteQuery-CgT2zfA-.mjs";import{useMutation as D}from"./packem_shared/useMutation-C_8Nu0F4.mjs";import{useMutator as J}from"./packem_shared/useMutator-D3CGrk5-.mjs";import{usePaginatedQuery as N}from"./packem_shared/usePaginatedQuery-CSs8g5Z7.mjs";import{hydratePreloaded as X,default as Y}from"./packem_shared/hydratePreloaded-BvPwhOFD.mjs";import{usePresence as _}from"./packem_shared/usePresence-Bfa9ESum.mjs";import{default as ee}from"./packem_shared/useQuery-CDk67eFh.mjs";import{useRateLimit as te}from"./packem_shared/useRateLimit-DqikMrX9.mjs";import{useStream as ue}from"./packem_shared/useStream-B1USJrJG.mjs";import{default as ae}from"./packem_shared/useSubscription-CoFTfvYX.mjs";import{useVoiceAgent as fe}from"./packem_shared/useVoiceAgent-CO0EiOoc.mjs";import{createClientQuery as me,getErrorCode as ie,getRetryAfterMs as de,isConflictError as xe,isForbiddenError as le,isRateLimitedError as he,isUnauthorizedError as ge}from"@lunora/client";import{RestrictionError as ce,UploadControl as Ce,UploadError as Ue}from"@visulima/storage-client";import{useChunkedRestUpload as Ee,useFileInput as Pe,useMultipartUpload as Qe,usePasteUpload as Se,useTusUpload as Le,useUpload as Re}from"@visulima/storage-client/react";export{t as AuthLoading,o as Authenticated,i as CheckoutButton,d as CustomerPortalButton,f as LunoraProvider,ce as RestrictionError,u as Unauthenticated,Ce as UploadControl,Ue as UploadError,me as createClientQuery,ie as getErrorCode,de as getRetryAfterMs,X as hydratePreloaded,xe as isConflictError,le as isForbiddenError,he as isRateLimitedError,ge as isUnauthorizedError,h as lunoraQueryOptions,E as useAgent,Q as useAgentChat,L as useAgentState,F as useAgentToolEvents,k as useAuth,A as useAuthSessions,a as useAuthState,c as useAuthUsers,x as useCheckout,Ee as useChunkedRestUpload,b as useClientQuery,z as useConnectionStatus,Pe as useFileInput,O as useFlag,T as useFlags,V as useHttpStream,C as useImpersonate,q as useInfiniteQuery,n as useLunora,Qe as useMultipartUpload,D as useMutation,J as useMutator,U as useOrganizations,N as usePaginatedQuery,Se as usePasteUpload,Y as usePreloadedQuery,_ as usePresence,ee as useQuery,te as useRateLimit,ue as useStream,ae as useSubscription,Le as useTusUpload,Re as useUpload,fe as useVoiceAgent};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{useAuthState as i}from"./useAuthState-jnCMkIwt.mjs";const a=t=>{const{children:n}=t,{isAuthenticated:e}=i();return e?n:void 0},r=t=>{const{children:n}=t,{isAuthenticated:e,isLoading:d}=i();return!d&&!e?n:void 0},s=t=>{const{children:n}=t,{isLoading:e}=i();return e?n:void 0};export{s as AuthLoading,a as Authenticated,r as Unauthenticated};
2
+ import{useAuthState as i}from"./useAuthState-DrW2_avK.mjs";const a=t=>{const{children:n}=t,{isAuthenticated:e}=i();return e?n:void 0},r=t=>{const{children:n}=t,{isAuthenticated:e,isLoading:d}=i();return!d&&!e?n:void 0},s=t=>{const{children:n}=t,{isLoading:e}=i();return e?n:void 0};export{s as AuthLoading,a as Authenticated,r as Unauthenticated};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as I}from"react/compiler-runtime";import{LunoraError as y}from"@lunora/errors";import{QueryClientContext as C,QueryClientProvider as L,QueryClient as h}from"@tanstack/react-query";import{createContext as N,use as d,useState as T}from"react";import{jsx as c}from"react/jsx-runtime";const f=N(null),v=()=>new h({defaultOptions:{mutations:{retry:0},queries:{gcTime:5*6e4,retry:0,staleTime:Number.POSITIVE_INFINITY}}}),b=t=>{const e=I(9),{children:m,client:a,queryClient:n}=t,r=d(C);let o;e[0]!==r||e[1]!==n?(o=()=>n??r??v(),e[0]=r,e[1]=n,e[2]=o):o=e[2];const[p]=T(o),i=n??r??p;let u;e[3]!==m||e[4]!==a?(u=c(f,{value:a,children:m}),e[3]=m,e[4]=a,e[5]=u):u=e[5];const s=u;if(r===i)return s;let l;return e[6]!==s||e[7]!==i?(l=c(L,{client:i,children:s}),e[6]=s,e[7]=i,e[8]=l):l=e[8],l},q=()=>{const t=d(f);if(!t)throw new y("INTERNAL","useLunora must be used inside <LunoraProvider />");return t};export{b as LunoraProvider,q as useLunora};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as l}from"react/compiler-runtime";import{useQueryClient as d,useQuery as p}from"@tanstack/react-query";import{useEffect as h}from"react";import{b as I}from"./cache-DJEsSdUx.mjs";import{useLunora as q}from"./LunoraProvider-InsjxtOB.mjs";import{i as K,y as N}from"./query-key-DV_Vu-6c.mjs";const P=function(o){const r=l(4),e=q(),t=d(),{args:u,functionPath:c,shardKey:i,value:s}=o,n={__lunoraRef:c},m=N(n,u,i),{data:y}=p({initialData:s,queryFn:()=>e.query(n,u,{shardKey:i}),queryKey:m,staleTime:Number.POSITIVE_INFINITY}),f=K(m);let a;return r[0]!==e||r[1]!==t||r[2]!==f?(a=[e,t,f],r[0]=e,r[1]=t,r[2]=f,r[3]=a):a=r[3],h(()=>I(e).attach(t,m,n,u,i),a),y===void 0?s:y},F=function(o){return P(o)};export{P as default,F as hydratePreloaded};
2
+ import{c as l}from"react/compiler-runtime";import{useQueryClient as d,useQuery as p}from"@tanstack/react-query";import{useEffect as h}from"react";import{b as I}from"./cache-DJEsSdUx.mjs";import{useLunora as q}from"./LunoraProvider-D6ZS72le.mjs";import{i as K,y as N}from"./query-key-DV_Vu-6c.mjs";const P=function(o){const r=l(4),e=q(),t=d(),{args:u,functionPath:c,shardKey:i,value:s}=o,n={__lunoraRef:c},m=N(n,u,i),{data:y}=p({initialData:s,queryFn:()=>e.query(n,u,{shardKey:i}),queryKey:m,staleTime:Number.POSITIVE_INFINITY}),f=K(m);let a;return r[0]!==e||r[1]!==t||r[2]!==f?(a=[e,t,f],r[0]=e,r[1]=t,r[2]=f,r[3]=a):a=r[3],h(()=>I(e).attach(t,m,n,u,i),a),y===void 0?s:y},F=function(o){return P(o)};export{P as default,F as hydratePreloaded};
@@ -0,0 +1 @@
1
+ const u=function(r,t){switch(t.type){case"chunk":return{chunks:[...r.chunks,t.chunk],error:void 0,status:"streaming"};case"complete":return{...r,status:"complete"};case"error":return{...r,error:t.error,status:"error"};case"reset":return{chunks:[],error:void 0,status:"idle"};case"start":return{...r,status:"streaming"};default:return r}},a=function(r,t){let n=!0,c=!1;const s=()=>{c||(c=!0,r.cancel())};return(async()=>{try{for await(const e of r){if(!n)return;t({chunk:e,type:"chunk"})}n&&t({type:"complete"})}catch(e){if(!n)return;t({error:e instanceof Error?e:new Error(String(e)),type:"error"})}})().catch(()=>{}),{cancel:s,cleanup:()=>{n=!1,s()}}};export{u as o,a as u};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{initialPages as R,rebalance as O,derivePaginationStatus as S,applyLoadMore as P}from"@lunora/client/pagination";import{useQueryClient as j}from"@tanstack/react-query";import{useRef as d,useReducer as B,useState as E,useEffect as m,useCallback as N}from"react";import{b as T}from"./cache-DJEsSdUx.mjs";import{useLunora as $}from"./LunoraProvider-InsjxtOB.mjs";import{i,y as I}from"./query-key-DV_Vu-6c.mjs";const z=function(o){const f=d(void 0);return f.current??=o(),f},X=function(o,f,x){const a=$(),n=j(),{initialNumItems:g,shardKey:p}=x,u=f==="skip",y=u?{}:f,[,L]=B(e=>e+1,0),[w,h]=E(()=>R(g)),k=`${i(I(o,y,p))}::${String(g)}`,A=d(k);A.current!==k&&(A.current=k,h(R(g)));const l=w.map(e=>{const t={...y,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}},s=I(o,t,p);return{args:t,key:s}}),M=l.map(({key:e})=>i(e)).join("|"),K=d({baseArgs:y,entries:[],fn:o,shardKey:p});m(()=>{K.current={baseArgs:y,entries:l,fn:o,shardKey:p}});const v=z(()=>new Map),Q=d(a);m(()=>{const e=v.current;if(Q.current!==a){for(const r of e.values())r();e.clear(),Q.current=a}if(u){for(const r of e.values())r();e.clear();return}const t=K.current,s=T(a),b=new Set(t.entries.map(({key:r})=>i(r)));for(const[r,c]of e)b.has(r)||(c(),e.delete(r));for(const r of t.entries){const c=i(r.key);e.has(c)||(n.fetchQuery({queryFn:()=>a.query(t.fn,r.args,{shardKey:t.shardKey}),queryKey:r.key,staleTime:0}).catch(()=>{}),e.set(c,s.attach(n,r.key,t.fn,r.args,t.shardKey)))}},[a,n,M,u]),m(()=>()=>{for(const e of v.current.values())e();v.current.clear()},[]),m(()=>n.getQueryCache().subscribe(e=>{if(e.type!=="updated")return;const t=i(e.query.queryKey);l.some(({key:s})=>i(s)===t)&&L()}),[n,M]);const C=u?[]:l.map(({key:e})=>n.getQueryData(e));m(()=>{if(u)return;const e=O(w,C);e&&h(e)});const{status:D}=S(u,C);return{loadMore:N(e=>{h(t=>{const s=K.current,b=t.map(q=>{const F={...s.baseArgs,paginationOpts:{cursor:q.lower,endCursor:q.upper,numItems:q.numItems}};return n.getQueryData(I(s.fn,F,s.shardKey))}),{nextCursor:r,status:c}=S(!1,b);return P(t,c==="CanLoadMore"?r:void 0,e)??t})},[n]),pageResults:C,status:D}};export{X as B};
2
+ import{initialPages as R,rebalance as O,derivePaginationStatus as S,applyLoadMore as P}from"@lunora/client/pagination";import{useQueryClient as j}from"@tanstack/react-query";import{useRef as d,useReducer as B,useState as E,useEffect as m,useCallback as N}from"react";import{b as T}from"./cache-DJEsSdUx.mjs";import{useLunora as $}from"./LunoraProvider-D6ZS72le.mjs";import{i,y as I}from"./query-key-DV_Vu-6c.mjs";const z=function(o){const f=d(void 0);return f.current??=o(),f},X=function(o,f,x){const a=$(),n=j(),{initialNumItems:g,shardKey:p}=x,u=f==="skip",y=u?{}:f,[,L]=B(e=>e+1,0),[w,h]=E(()=>R(g)),k=`${i(I(o,y,p))}::${String(g)}`,A=d(k);A.current!==k&&(A.current=k,h(R(g)));const l=w.map(e=>{const t={...y,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}},s=I(o,t,p);return{args:t,key:s}}),M=l.map(({key:e})=>i(e)).join("|"),K=d({baseArgs:y,entries:[],fn:o,shardKey:p});m(()=>{K.current={baseArgs:y,entries:l,fn:o,shardKey:p}});const v=z(()=>new Map),Q=d(a);m(()=>{const e=v.current;if(Q.current!==a){for(const r of e.values())r();e.clear(),Q.current=a}if(u){for(const r of e.values())r();e.clear();return}const t=K.current,s=T(a),b=new Set(t.entries.map(({key:r})=>i(r)));for(const[r,c]of e)b.has(r)||(c(),e.delete(r));for(const r of t.entries){const c=i(r.key);e.has(c)||(n.fetchQuery({queryFn:()=>a.query(t.fn,r.args,{shardKey:t.shardKey}),queryKey:r.key,staleTime:0}).catch(()=>{}),e.set(c,s.attach(n,r.key,t.fn,r.args,t.shardKey)))}},[a,n,M,u]),m(()=>()=>{for(const e of v.current.values())e();v.current.clear()},[]),m(()=>n.getQueryCache().subscribe(e=>{if(e.type!=="updated")return;const t=i(e.query.queryKey);l.some(({key:s})=>i(s)===t)&&L()}),[n,M]);const C=u?[]:l.map(({key:e})=>n.getQueryData(e));m(()=>{if(u)return;const e=O(w,C);e&&h(e)});const{status:D}=S(u,C);return{loadMore:N(e=>{h(t=>{const s=K.current,b=t.map(q=>{const F={...s.baseArgs,paginationOpts:{cursor:q.lower,endCursor:q.upper,numItems:q.numItems}};return n.getQueryData(I(s.fn,F,s.shardKey))}),{nextCursor:r,status:c}=S(!1,b);return P(t,c==="CanLoadMore"?r:void 0,e)??t})},[n]),pageResults:C,status:D}};export{X as B};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as T}from"react/compiler-runtime";import{useMutation as h}from"./useMutation-B4uL3Rde.mjs";import $ from"./useSubscription-NfJ0mdhL.mjs";const b={__lunoraRef:""},M=f=>{const t=T(17),{api:w,cancel:a,run:A,runArgs:u,threadKey:e}=f,r=h(A),K=h(a??b);let s;t[0]!==e?(s={key:e},t[0]=e,t[1]=s):s=t[1];const{data:_}=$(w.agents.agentThread,s),n=_,p=n?.status,i=n?.instanceId,{mutate:g}=r,{mutate:l}=K;let o;t[2]!==u||t[3]!==g||t[4]!==e?(o=async(v,I)=>{await g({input:v,threadKey:e,...u,...I})},t[2]=u,t[3]=g,t[4]=e,t[5]=o):o=t[5];const m=o;let c;t[6]!==l||t[7]!==a||t[8]!==i||t[9]!==e?(c=async()=>{a===void 0||i===void 0||await l({instanceId:i,threadKey:e})},t[6]=l,t[7]=a,t[8]=i,t[9]=e,t[10]=c):c=t[10];const y=c;let d;return t[11]!==y||t[12]!==m||t[13]!==r.pending||t[14]!==p||t[15]!==n?(d={cancel:y,pending:r.pending,run:m,status:p,thread:n},t[11]=y,t[12]=m,t[13]=r.pending,t[14]=p,t[15]=n,t[16]=d):d=t[16],d};export{M as useAgent};
2
+ import{c as T}from"react/compiler-runtime";import{useMutation as h}from"./useMutation-C_8Nu0F4.mjs";import $ from"./useSubscription-CoFTfvYX.mjs";const b={__lunoraRef:""},M=f=>{const t=T(17),{api:w,cancel:a,run:A,runArgs:u,threadKey:e}=f,r=h(A),K=h(a??b);let s;t[0]!==e?(s={key:e},t[0]=e,t[1]=s):s=t[1];const{data:_}=$(w.agents.agentThread,s),n=_,p=n?.status,i=n?.instanceId,{mutate:g}=r,{mutate:l}=K;let o;t[2]!==u||t[3]!==g||t[4]!==e?(o=async(v,I)=>{await g({input:v,threadKey:e,...u,...I})},t[2]=u,t[3]=g,t[4]=e,t[5]=o):o=t[5];const m=o;let c;t[6]!==l||t[7]!==a||t[8]!==i||t[9]!==e?(c=async()=>{a===void 0||i===void 0||await l({instanceId:i,threadKey:e})},t[6]=l,t[7]=a,t[8]=i,t[9]=e,t[10]=c):c=t[10];const y=c;let d;return t[11]!==y||t[12]!==m||t[13]!==r.pending||t[14]!==p||t[15]!==n?(d={cancel:y,pending:r.pending,run:m,status:p,thread:n},t[11]=y,t[12]=m,t[13]=r.pending,t[14]=p,t[15]=n,t[16]=d):d=t[16],d};export{M as useAgent};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as rt}from"react/compiler-runtime";import{reconcileOptimistic as W,maxSeq as X}from"@lunora/client";import{useState as it,useRef as ct}from"react";import{useMutation as Q}from"./useMutation-C_8Nu0F4.mjs";import{useStream as lt}from"./useStream-B1USJrJG.mjs";import Y from"./useSubscription-CoFTfvYX.mjs";const mt={__lunoraRef:""},ut={__lunoraRef:""},dt=[],St=c=>{const t=rt(47),{api:K,cancel:m,limit:u,send:Z,sendArgs:C,stream:d,threadKey:e}=c;let p;t[0]!==u||t[1]!==e?(p=u===void 0?{key:e}:{key:e,limit:u},t[0]=u,t[1]=e,t[2]=p):p=t[2];const B=p,{data:G}=Y(K.agents.agentMessages,B);let f;t[3]!==e?(f={key:e},t[3]=e,t[4]=f):f=t[4];const{data:H}=Y(K.agents.agentThread,f);let h;t[5]!==d||t[6]!==e?(h=d===void 0?"skip":{key:e},t[5]=d,t[6]=e,t[7]=h):h=t[7];const J=h,{chunks:R}=lt(d??ut,J),tt=Q(Z),et=Q(m??mt),nt=Q(K.agents.agentResolveApproval);let g;t[8]===Symbol.for("react.memo_cache_sentinel")?(g=[],t[8]=g):g=t[8];const[$,U]=it(g),j=ct(0),V=H,q=V?.status,o=V?.instanceId,s=G??dt;let y;if(t[9]!==s||t[10]!==$){const n=W($,s),a=X(s);y=n.length===0?s:[...s,...n.map((r,N)=>({content:r.content,optimistic:!0,role:"user",seq:a+1+N}))],t[9]=s,t[10]=$,t[11]=y}else y=t[11];const b=y;let v;t[12]!==s?(v=s.filter(pt),t[12]=s,t[13]=v):v=t[13];const l=v.length;let k;if(t[14]!==l||t[15]!==R||t[16]!==e){let n;t[18]!==l||t[19]!==e?(n=a=>a.kind!=="progress"&&a.threadKey===e&&a.turn>=l,t[18]=l,t[19]=e,t[20]=n):n=t[20],k=R.filter(n).map(ft).join(""),t[14]=l,t[15]=R,t[16]=e,t[17]=k}else k=t[17];const E=k,{mutate:M}=tt,{mutate:T}=et,{mutate:D}=nt;let w;t[21]!==s||t[22]!==C||t[23]!==M||t[24]!==e?(w=async(n,a)=>{const r=j.current;j.current=j.current+1;const N=X(s);U(P=>[...W(P,s),{content:n,id:r,maxDurableSeqAtSend:N}]);try{await M({input:n,threadKey:e,...C,...a})}catch(P){const st=P;throw U(at=>at.filter(ot=>ot.id!==r)),st}},t[21]=s,t[22]=C,t[23]=M,t[24]=e,t[25]=w):w=t[25];const O=w;let S;t[26]!==o||t[27]!==D||t[28]!==e?(S=async(n,a,r)=>{if(o===void 0)throw new Error(`useAgentChat: cannot ${n} — no in-flight run (thread has no instanceId)`);await D({decision:n,instanceId:o,threadKey:e,toolCallId:a,...r===void 0?{}:{note:r}})},t[26]=o,t[27]=D,t[28]=e,t[29]=S):S=t[29];const i=S;let _;t[30]!==i?(_=(n,a)=>i("approve",n,a),t[30]=i,t[31]=_):_=t[31];const z=_;let x;t[32]!==i?(x=(n,a)=>i("reject",n,a),t[32]=i,t[33]=x):x=t[33];const F=x;let A;t[34]!==T||t[35]!==m||t[36]!==o||t[37]!==e?(A=async()=>{m===void 0||o===void 0||await T({instanceId:o,threadKey:e})},t[34]=T,t[35]=m,t[36]=o,t[37]=e,t[38]=A):A=t[38];const L=A;let I;return t[39]!==z||t[40]!==L||t[41]!==b||t[42]!==F||t[43]!==O||t[44]!==q||t[45]!==E?(I={approve:z,cancel:L,messages:b,reject:F,send:O,status:q,streamingText:E},t[39]=z,t[40]=L,t[41]=b,t[42]=F,t[43]=O,t[44]=q,t[45]=E,t[46]=I):I=t[46],I};function pt(c){return c.role==="assistant"}function ft(c){return c.text}export{St as useAgentChat};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c}from"react/compiler-runtime";import d from"./useSubscription-NfJ0mdhL.mjs";const p=t=>{const e=c(5);let r;e[0]!==t.threadKey?(r={key:t.threadKey},e[0]=t.threadKey,e[1]=r):r=e[1];const{data:s,error:o}=d(t.api.agents.agentState,r),n=s;let a;return e[2]!==o||e[3]!==n?(a={error:o,state:n},e[2]=o,e[3]=n,e[4]=a):a=e[4],a};export{p as useAgentState};
2
+ import{c}from"react/compiler-runtime";import d from"./useSubscription-CoFTfvYX.mjs";const p=t=>{const e=c(5);let r;e[0]!==t.threadKey?(r={key:t.threadKey},e[0]=t.threadKey,e[1]=r):r=e[1];const{data:s,error:o}=d(t.api.agents.agentState,r),n=s;let a;return e[2]!==o||e[3]!==n?(a={error:o,state:n},e[2]=o,e[3]=n,e[4]=a):a=e[4],a};export{p as useAgentState};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as v}from"react/compiler-runtime";import{useStream as g}from"./useStream-CZqDeZ3D.mjs";import y from"./useSubscription-NfJ0mdhL.mjs";const I={__lunoraRef:""},k=[],N=l=>{if(l.role==="assistant"&&l.toolCalls)return l.toolCalls.map(o=>({input:o.input,seq:l.seq,toolCallId:o.id,toolName:o.name,type:"call"}));if(l.role==="tool")return l.status==="awaiting_approval"?[{seq:l.seq,type:"awaiting-approval",...l.toolCallId===void 0?{}:{toolCallId:l.toolCallId},...l.toolName===void 0?{}:{toolName:l.toolName}}]:[{output:l.content,seq:l.seq,type:"result",...l.status==="approved"||l.status==="rejected"?{status:l.status}:{},...l.toolCallId===void 0?{}:{toolCallId:l.toolCallId},...l.toolName===void 0?{}:{toolName:l.toolName}}]},_=l=>{const o=v(12),{api:m,limit:a,stream:s,threadKey:t}=l;let r;o[0]!==a||o[1]!==t?(r=a===void 0?{key:t}:{key:t,limit:a},o[0]=a,o[1]=t,o[2]=r):r=o[2];const c=r,{data:f}=y(m.agents.agentMessages,c);let i;o[3]!==s||o[4]!==t?(i=s===void 0?"skip":{key:t},o[3]=s,o[4]=t,o[5]=i):i=o[5];const C=i,{chunks:p}=g(s??I,C),u=f??k;let e;if(o[6]!==p||o[7]!==u||o[8]!==t){e=u.flatMap(q);for(const d of p)d.kind==="progress"&&d.threadKey===t&&e.push({data:d.data,toolCallId:d.toolCallId,type:"progress"});o[6]=p,o[7]=u,o[8]=t,o[9]=e}else e=o[9];let n;return o[10]!==e?(n={events:e},o[10]=e,o[11]=n):n=o[11],n};function q(l){return N(l)??[]}export{_ as useAgentToolEvents};
2
+ import{c as v}from"react/compiler-runtime";import{useStream as g}from"./useStream-B1USJrJG.mjs";import y from"./useSubscription-CoFTfvYX.mjs";const I={__lunoraRef:""},k=[],N=l=>{if(l.role==="assistant"&&l.toolCalls)return l.toolCalls.map(o=>({input:o.input,seq:l.seq,toolCallId:o.id,toolName:o.name,type:"call"}));if(l.role==="tool")return l.status==="awaiting_approval"?[{seq:l.seq,type:"awaiting-approval",...l.toolCallId===void 0?{}:{toolCallId:l.toolCallId},...l.toolName===void 0?{}:{toolName:l.toolName}}]:[{output:l.content,seq:l.seq,type:"result",...l.status==="approved"||l.status==="rejected"?{status:l.status}:{},...l.toolCallId===void 0?{}:{toolCallId:l.toolCallId},...l.toolName===void 0?{}:{toolName:l.toolName}}]},_=l=>{const o=v(12),{api:m,limit:a,stream:s,threadKey:t}=l;let r;o[0]!==a||o[1]!==t?(r=a===void 0?{key:t}:{key:t,limit:a},o[0]=a,o[1]=t,o[2]=r):r=o[2];const c=r,{data:f}=y(m.agents.agentMessages,c);let i;o[3]!==s||o[4]!==t?(i=s===void 0?"skip":{key:t},o[3]=s,o[4]=t,o[5]=i):i=o[5];const C=i,{chunks:p}=g(s??I,C),u=f??k;let e;if(o[6]!==p||o[7]!==u||o[8]!==t){e=u.flatMap(q);for(const d of p)d.kind==="progress"&&d.threadKey===t&&e.push({data:d.data,toolCallId:d.toolCallId,type:"progress"});o[6]=p,o[7]=u,o[8]=t,o[9]=e}else e=o[9];let n;return o[10]!==e?(n={events:e},o[10]=e,o[11]=n):n=o[11],n};function q(l){return N(l)??[]}export{_ as useAgentToolEvents};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as m}from"react/compiler-runtime";import{useSyncExternalStore as f}from"react";import{useLunora as p}from"./LunoraProvider-InsjxtOB.mjs";const g=new WeakMap,T=t=>{const e=new Set;let r=null;const a=()=>{for(const n of e)n()};let o=0;const s=n=>{r!==n&&(r=n,a())},l=()=>{o+=1;const n=o;if(t.getAuthToken()===null){s(null);return}t.getCurrentUser().then(u=>{n===o&&s(u)}).catch(()=>{n===o&&s(null)})};let c;return{getSnapshot:()=>r,subscribe:n=>{const u=e.size===0;return e.add(n),u&&(c=t.onAuthTokenChange(l),l()),()=>{e.delete(n),e.size===0&&(c?.(),c=void 0)}}}},d=t=>{let e=g.get(t);return e||(e=T(t),g.set(t,e)),e},v=()=>{const t=m(12),e=p();let r;t[0]!==e?(r=d(e),t[0]=e,t[1]=r):r=t[1];const a=r;let o,s,l;t[2]!==e?(o=k=>e.onAuthTokenChange(k),s=()=>e.getAuthToken(),l=()=>e.getAuthToken(),t[2]=e,t[3]=o,t[4]=s,t[5]=l):(o=t[3],s=t[4],l=t[5]);const c=f(o,s,l),n=f(a.subscribe,a.getSnapshot,A);let u;t[6]!==e?(u=k=>{e.setAuthToken(k)},t[6]=e,t[7]=u):u=t[7];const i=u;let h;return t[8]!==i||t[9]!==c||t[10]!==n?(h={setToken:i,token:c,user:n},t[8]=i,t[9]=c,t[10]=n,t[11]=h):h=t[11],h};function A(){return null}export{v as default};
2
+ import{c as m}from"react/compiler-runtime";import{useSyncExternalStore as f}from"react";import{useLunora as p}from"./LunoraProvider-D6ZS72le.mjs";const g=new WeakMap,T=t=>{const e=new Set;let r=null;const a=()=>{for(const n of e)n()};let o=0;const s=n=>{r!==n&&(r=n,a())},l=()=>{o+=1;const n=o;if(t.getAuthToken()===null){s(null);return}t.getCurrentUser().then(u=>{n===o&&s(u)}).catch(()=>{n===o&&s(null)})};let c;return{getSnapshot:()=>r,subscribe:n=>{const u=e.size===0;return e.add(n),u&&(c=t.onAuthTokenChange(l),l()),()=>{e.delete(n),e.size===0&&(c?.(),c=void 0)}}}},d=t=>{let e=g.get(t);return e||(e=T(t),g.set(t,e)),e},v=()=>{const t=m(12),e=p();let r;t[0]!==e?(r=d(e),t[0]=e,t[1]=r):r=t[1];const a=r;let o,s,l;t[2]!==e?(o=k=>e.onAuthTokenChange(k),s=()=>e.getAuthToken(),l=()=>e.getAuthToken(),t[2]=e,t[3]=o,t[4]=s,t[5]=l):(o=t[3],s=t[4],l=t[5]);const c=f(o,s,l),n=f(a.subscribe,a.getSnapshot,A);let u;t[6]!==e?(u=k=>{e.setAuthToken(k)},t[6]=e,t[7]=u):u=t[7];const i=u;let h;return t[8]!==i||t[9]!==c||t[10]!==n?(h={setToken:i,token:c,user:n},t[8]=i,t[9]=c,t[10]=n,t[11]=h):h=t[11],h};function A(){return null}export{v as default};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as y}from"react/compiler-runtime";import{useMutation as b,useQuery as F,keepPreviousData as v}from"@tanstack/react-query";import{useState as A,useSyncExternalStore as I}from"react";import{useLunora as S}from"./LunoraProvider-InsjxtOB.mjs";const D="lunora-react-admin-auth",P=50;function z(t,e,n,d={}){const{enabled:o=!0,pageSize:u=P}=d,[i,r]=A(u),l=I(f=>t.onAuthTokenChange(f),()=>t.currentIdentity(),()=>t.currentIdentity()),s=[D,l??"anon",...e,i],a=F({enabled:o,placeholderData:v,queryFn:()=>n(i),queryKey:s,staleTime:0}),c=a.data?.rows,h=a.data?.total,m=h!==void 0&&c!==void 0&&c.length<h,p=()=>{m&&r(f=>f+u)},g=()=>{a.refetch().catch(()=>{})};return{data:c,error:a.error??void 0,hasMore:m,loadMore:p,loading:a.isLoading,refetch:g,total:h}}const V=t=>{const e=y(20);let n;e[0]!==t?(n=t===void 0?{}:t,e[0]=t,e[1]=n):n=e[1];const d=n,o=S(),{enabled:u,filterField:i,filterValue:r,pageSize:l,search:s,searchField:a,sortBy:c,sortDirection:h}=d;let m;e[2]!==i||e[3]!==r||e[4]!==s||e[5]!==a||e[6]!==c||e[7]!==h?(m=["users",{filterField:i,filterValue:r,search:s,searchField:a,sortBy:c,sortDirection:h}],e[2]=i,e[3]=r,e[4]=s,e[5]=a,e[6]=c,e[7]=h,e[8]=m):m=e[8];let p;e[9]!==o||e[10]!==i||e[11]!==r||e[12]!==s||e[13]!==a||e[14]!==c||e[15]!==h?(p=f=>o.listAuthUsers({filterField:i,filterValue:r,limit:f,search:s,searchField:a,sortBy:c,sortDirection:h}),e[9]=o,e[10]=i,e[11]=r,e[12]=s,e[13]=a,e[14]=c,e[15]=h,e[16]=p):p=e[16];let g;return e[17]!==u||e[18]!==l?(g={enabled:u,pageSize:l},e[17]=u,e[18]=l,e[19]=g):g=e[19],z(o,m,p,g)},k=t=>{const e=y(8);let n;e[0]!==t?(n=t===void 0?{}:t,e[0]=t,e[1]=n):n=e[1];const d=n,o=S(),{enabled:u,pageSize:i}=d;let r;e[2]===Symbol.for("react.memo_cache_sentinel")?(r=["organizations"],e[2]=r):r=e[2];let l;e[3]!==o?(l=a=>o.listAuthOrganizations({limit:a}),e[3]=o,e[4]=l):l=e[4];let s;return e[5]!==u||e[6]!==i?(s={enabled:u,pageSize:i},e[5]=u,e[6]=i,e[7]=s):s=e[7],z(o,r,l,s)},q=t=>{const e=y(10);let n;e[0]!==t?(n=t===void 0?{}:t,e[0]=t,e[1]=n):n=e[1];const d=n,o=S(),{enabled:u,pageSize:i,userId:r}=d;let l;e[2]!==r?(l=["sessions",{userId:r}],e[2]=r,e[3]=l):l=e[3];let s;e[4]!==o||e[5]!==r?(s=c=>o.listAuthSessions({limit:c,userId:r}),e[4]=o,e[5]=r,e[6]=s):s=e[6];let a;return e[7]!==u||e[8]!==i?(a={enabled:u,pageSize:i},e[7]=u,e[8]=i,e[9]=a):a=e[9],z(o,l,s,a)},x=()=>{const t=y(10),e=S();let n;t[0]!==e?(n={mutationFn:a=>e.impersonateAuthUser({userId:a})},t[0]=e,t[1]=n):n=t[1];const d=b(n),{mutateAsync:o,reset:u}=d;let i;t[2]!==o?(i=a=>o(a),t[2]=o,t[3]=i):i=t[3];const r=i,l=d.error??void 0;let s;return t[4]!==r||t[5]!==d.data||t[6]!==d.isPending||t[7]!==u||t[8]!==l?(s={data:d.data,error:l,impersonate:r,pending:d.isPending,reset:u},t[4]=r,t[5]=d.data,t[6]=d.isPending,t[7]=u,t[8]=l,t[9]=s):s=t[9],s};export{q as useAuthSessions,V as useAuthUsers,x as useImpersonate,k as useOrganizations};
2
+ import{c as y}from"react/compiler-runtime";import{useMutation as b,useQuery as F,keepPreviousData as v}from"@tanstack/react-query";import{useState as A,useSyncExternalStore as I}from"react";import{useLunora as S}from"./LunoraProvider-D6ZS72le.mjs";const D="lunora-react-admin-auth",P=50;function z(t,e,n,d={}){const{enabled:o=!0,pageSize:u=P}=d,[i,r]=A(u),l=I(f=>t.onAuthTokenChange(f),()=>t.currentIdentity(),()=>t.currentIdentity()),s=[D,l??"anon",...e,i],a=F({enabled:o,placeholderData:v,queryFn:()=>n(i),queryKey:s,staleTime:0}),c=a.data?.rows,h=a.data?.total,m=h!==void 0&&c!==void 0&&c.length<h,p=()=>{m&&r(f=>f+u)},g=()=>{a.refetch().catch(()=>{})};return{data:c,error:a.error??void 0,hasMore:m,loadMore:p,loading:a.isLoading,refetch:g,total:h}}const V=t=>{const e=y(20);let n;e[0]!==t?(n=t===void 0?{}:t,e[0]=t,e[1]=n):n=e[1];const d=n,o=S(),{enabled:u,filterField:i,filterValue:r,pageSize:l,search:s,searchField:a,sortBy:c,sortDirection:h}=d;let m;e[2]!==i||e[3]!==r||e[4]!==s||e[5]!==a||e[6]!==c||e[7]!==h?(m=["users",{filterField:i,filterValue:r,search:s,searchField:a,sortBy:c,sortDirection:h}],e[2]=i,e[3]=r,e[4]=s,e[5]=a,e[6]=c,e[7]=h,e[8]=m):m=e[8];let p;e[9]!==o||e[10]!==i||e[11]!==r||e[12]!==s||e[13]!==a||e[14]!==c||e[15]!==h?(p=f=>o.listAuthUsers({filterField:i,filterValue:r,limit:f,search:s,searchField:a,sortBy:c,sortDirection:h}),e[9]=o,e[10]=i,e[11]=r,e[12]=s,e[13]=a,e[14]=c,e[15]=h,e[16]=p):p=e[16];let g;return e[17]!==u||e[18]!==l?(g={enabled:u,pageSize:l},e[17]=u,e[18]=l,e[19]=g):g=e[19],z(o,m,p,g)},k=t=>{const e=y(8);let n;e[0]!==t?(n=t===void 0?{}:t,e[0]=t,e[1]=n):n=e[1];const d=n,o=S(),{enabled:u,pageSize:i}=d;let r;e[2]===Symbol.for("react.memo_cache_sentinel")?(r=["organizations"],e[2]=r):r=e[2];let l;e[3]!==o?(l=a=>o.listAuthOrganizations({limit:a}),e[3]=o,e[4]=l):l=e[4];let s;return e[5]!==u||e[6]!==i?(s={enabled:u,pageSize:i},e[5]=u,e[6]=i,e[7]=s):s=e[7],z(o,r,l,s)},q=t=>{const e=y(10);let n;e[0]!==t?(n=t===void 0?{}:t,e[0]=t,e[1]=n):n=e[1];const d=n,o=S(),{enabled:u,pageSize:i,userId:r}=d;let l;e[2]!==r?(l=["sessions",{userId:r}],e[2]=r,e[3]=l):l=e[3];let s;e[4]!==o||e[5]!==r?(s=c=>o.listAuthSessions({limit:c,userId:r}),e[4]=o,e[5]=r,e[6]=s):s=e[6];let a;return e[7]!==u||e[8]!==i?(a={enabled:u,pageSize:i},e[7]=u,e[8]=i,e[9]=a):a=e[9],z(o,l,s,a)},x=()=>{const t=y(10),e=S();let n;t[0]!==e?(n={mutationFn:a=>e.impersonateAuthUser({userId:a})},t[0]=e,t[1]=n):n=t[1];const d=b(n),{mutateAsync:o,reset:u}=d;let i;t[2]!==o?(i=a=>o(a),t[2]=o,t[3]=i):i=t[3];const r=i,l=d.error??void 0;let s;return t[4]!==r||t[5]!==d.data||t[6]!==d.isPending||t[7]!==u||t[8]!==l?(s={data:d.data,error:l,impersonate:r,pending:d.isPending,reset:u},t[4]=r,t[5]=d.data,t[6]=d.isPending,t[7]=u,t[8]=l,t[9]=s):s=t[9],s};export{q as useAuthSessions,V as useAuthUsers,x as useImpersonate,k as useOrganizations};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as i}from"react/compiler-runtime";import{useSyncExternalStore as s}from"react";import a from"./useAuth-CWkJn7i9.mjs";const c=()=>()=>{},S=()=>{const t=i(3),{token:u}=a(),o=s(c,f,m),e=o&&u!==null,n=!o;let r;return t[0]!==e||t[1]!==n?(r={isAuthenticated:e,isLoading:n},t[0]=e,t[1]=n,t[2]=r):r=t[2],r};function f(){return!0}function m(){return!1}export{S as useAuthState};
2
+ import{c as i}from"react/compiler-runtime";import{useSyncExternalStore as s}from"react";import a from"./useAuth-BKsFAcDG.mjs";const c=()=>()=>{},S=()=>{const t=i(3),{token:u}=a(),o=s(c,f,m),e=o&&u!==null,n=!o;let r;return t[0]!==e||t[1]!==n?(r={isAuthenticated:e,isLoading:n},t[0]=e,t[1]=n,t[2]=r):r=t[2],r};function f(){return!0}function m(){return!1}export{S as useAuthState};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{useCallback as u,useSyncExternalStore as i}from"react";import{useLunora as l}from"./LunoraProvider-InsjxtOB.mjs";const y=t=>{const e=l(),s=u(r=>e.subscribeClientQuery(t,()=>{r()}),[e,t.key]),n=i(s,()=>e.getClientQuery(t),()=>e.getClientQuery(t)),o=u(r=>{e.setClientQuery(t,r)},[e,t]);return[n,o]};export{y as default};
2
+ import{useCallback as u,useSyncExternalStore as i}from"react";import{useLunora as l}from"./LunoraProvider-D6ZS72le.mjs";const y=t=>{const e=l(),s=u(r=>e.subscribeClientQuery(t,()=>{r()}),[e,t.key]),n=i(s,()=>e.getClientQuery(t),()=>e.getClientQuery(t)),o=u(r=>{e.setClientQuery(t,r)},[e,t]);return[n,o]};export{y as default};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as a}from"react/compiler-runtime";import{useSyncExternalStore as s}from"react";import{useLunora as u}from"./LunoraProvider-InsjxtOB.mjs";const f=()=>{const t=a(4),o=u();let n,e,r;return t[0]!==o?(n=c=>o.onConnectionStatus(()=>{c()}),e=()=>o.connectionStatus(),r=()=>o.connectionStatus(),t[0]=o,t[1]=n,t[2]=e,t[3]=r):(n=t[1],e=t[2],r=t[3]),s(n,e,r)};export{f as default};
2
+ import{c as a}from"react/compiler-runtime";import{useSyncExternalStore as s}from"react";import{useLunora as u}from"./LunoraProvider-D6ZS72le.mjs";const f=()=>{const t=a(4),o=u();let n,e,r;return t[0]!==o?(n=c=>o.onConnectionStatus(()=>{c()}),e=()=>o.connectionStatus(),r=()=>o.connectionStatus(),t[0]=o,t[1]=n,t[2]=e,t[3]=r):(n=t[1],e=t[2],r=t[3]),s(n,e,r)};export{f as default};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{useState as _,useRef as y,useEffect as d}from"react";import{useLunora as h}from"./LunoraProvider-InsjxtOB.mjs";import{e as m}from"./stable-key-BSG0zK_E.mjs";const k="__lunora_flags__:eval",F=e=>{const t=typeof e;return t==="boolean"||t==="number"||t==="string"?t:"object"},v={__lunoraRef:k},A=(e,t,r)=>{const g=h(),[a,u]=_(t),c=F(t),n=r===void 0?"":m(r),s=`${e}::${c}::${n}`,f=y(s);f.current!==s&&(f.current=s,u(t));const l=y({context:r,defaultValue:t});return d(()=>{l.current={context:r,defaultValue:t}}),d(()=>{let i=!1;const{context:x,defaultValue:b}=l.current;u(b);let o;try{o=g.subscribe(v,{context:x,default:b,key:e,type:c},p=>{i||u(p)})}catch{return()=>{i=!0}}return()=>{i=!0,o()}},[g,e,c,n]),a},C=(e,t)=>{const r=h(),[g,a]=_(e),u=m(e),c=t===void 0?"":m(t),n=`${u}::${c}`,s=y(n);s.current!==n&&(s.current=n,a(e));const f=y({context:t,flags:e});return d(()=>{f.current={context:t,flags:e}}),d(()=>{let l=!1;const{context:i,flags:x}=f.current;a(x);const b=[];for(const[o,p]of Object.entries(x))try{b.push(r.subscribe(v,{context:i,default:p,key:o,type:F(p)},V=>{l||a(j=>({...j,[o]:V}))}))}catch{}return()=>{l=!0;for(const o of b)o()}},[r,u,c]),g};export{A as useFlag,C as useFlags};
2
+ import{useState as _,useRef as y,useEffect as d}from"react";import{useLunora as h}from"./LunoraProvider-D6ZS72le.mjs";import{e as m}from"./stable-key-BSG0zK_E.mjs";const k="__lunora_flags__:eval",F=e=>{const t=typeof e;return t==="boolean"||t==="number"||t==="string"?t:"object"},v={__lunoraRef:k},A=(e,t,r)=>{const g=h(),[a,u]=_(t),c=F(t),n=r===void 0?"":m(r),s=`${e}::${c}::${n}`,f=y(s);f.current!==s&&(f.current=s,u(t));const l=y({context:r,defaultValue:t});return d(()=>{l.current={context:r,defaultValue:t}}),d(()=>{let i=!1;const{context:x,defaultValue:b}=l.current;u(b);let o;try{o=g.subscribe(v,{context:x,default:b,key:e,type:c},p=>{i||u(p)})}catch{return()=>{i=!0}}return()=>{i=!0,o()}},[g,e,c,n]),a},C=(e,t)=>{const r=h(),[g,a]=_(e),u=m(e),c=t===void 0?"":m(t),n=`${u}::${c}`,s=y(n);s.current!==n&&(s.current=n,a(e));const f=y({context:t,flags:e});return d(()=>{f.current={context:t,flags:e}}),d(()=>{let l=!1;const{context:i,flags:x}=f.current;a(x);const b=[];for(const[o,p]of Object.entries(x))try{b.push(r.subscribe(v,{context:i,default:p,key:o,type:F(p)},V=>{l||a(j=>({...j,[o]:V}))}))}catch{}return()=>{l=!0;for(const o of b)o()}},[r,u,c]),g};export{A as useFlag,C as useFlags};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as S}from"react/compiler-runtime";import{useReducer as $,useRef as v,useEffect as _}from"react";import{useLunora as b}from"./LunoraProvider-D6ZS72le.mjs";import{o as E,u as R}from"./stream-state-ksURgmCA.mjs";import{e as H}from"./stable-key-BSG0zK_E.mjs";const z=(r,s,a)=>{const e=S(24);let m;e[0]!==a?(m=a===void 0?{}:a,e[0]=a,e[1]=m):m=e[1];const u=m,c=b();let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f={chunks:[],error:void 0,status:"idle"},e[2]=f):f=e[2];const[t,n]=$(E,f),o=s==="skip";let p;e[3]!==s||e[4]!==o?(p=o?"skip":H(s),e[3]=s,e[4]=o,e[5]=p):p=e[5];const x=p,k=v(void 0);let i;e[6]!==s||e[7]!==c||e[8]!==u.maxBuffer||e[9]!==r||e[10]!==o?(i=()=>{if(o)return n({type:"reset"}),L;n({type:"reset"}),n({type:"start"});const{cancel:B,cleanup:y}=R(c.httpStream(r,s,{maxBuffer:u.maxBuffer}),n);return k.current=B,()=>{y(),k.current=void 0}},e[6]=s,e[7]=c,e[8]=u.maxBuffer,e[9]=r,e[10]=o,e[11]=i):i=e[11];let h;e[12]!==c||e[13]!==u.maxBuffer||e[14]!==r.method||e[15]!==r.path||e[16]!==x||e[17]!==o?(h=[c,r.method,r.path,x,o,u.maxBuffer],e[12]=c,e[13]=u.maxBuffer,e[14]=r.method,e[15]=r.path,e[16]=x,e[17]=o,e[18]=h):h=e[18],_(i,h);let l;e[19]===Symbol.for("react.memo_cache_sentinel")?(l=()=>{k.current?.()},e[19]=l):l=e[19];let d;return e[20]!==t.chunks||e[21]!==t.error||e[22]!==t.status?(d={cancel:l,chunks:t.chunks,error:t.error,status:t.status},e[20]=t.chunks,e[21]=t.error,e[22]=t.status,e[23]=d):d=e[23],d};function L(){}export{z as useHttpStream};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as P}from"react/compiler-runtime";import{useRef as k,useEffect as F}from"react";import{B as y}from"./use-paginated-core-ClJ0EeGx.mjs";const B=(M,c,g)=>{const e=P(15),{initialNumItems:o}=g,{loadMore:s,pageResults:f,status:a}=y(M,c==="skip"?"skip":c,g),N=c==="skip";let t;if(e[0]!==f){t=[];for(const u of f)u&&t.push(u.page);e[0]=f,e[1]=t}else t=e[1];let r;e[2]!==o||e[3]!==s?(r={defaultNumItems:o,loadMore:s},e[2]=o,e[3]=s,e[4]=r):r=e[4];const h=k(r);let i;e[5]!==o||e[6]!==s?(i=()=>{h.current={defaultNumItems:o,loadMore:s}},e[5]=o,e[6]=s,e[7]=i):i=e[7],F(i);let m;e[8]===Symbol.for("react.memo_cache_sentinel")?(m=u=>{const{defaultNumItems:I,loadMore:L}=h.current;L(u??I)},e[8]=m):m=e[8];const x=m,l=a==="CanLoadMore",d=!N&&a==="LoadingMore",p=!N&&a==="LoadingFirstPage";let n;return e[9]!==t||e[10]!==a||e[11]!==l||e[12]!==d||e[13]!==p?(n={fetchNextPage:x,hasNextPage:l,isFetchingNextPage:d,isLoading:p,pages:t,status:a},e[9]=t,e[10]=a,e[11]=l,e[12]=d,e[13]=p,e[14]=n):n=e[14],n};export{B as default};
2
+ import{c as P}from"react/compiler-runtime";import{useRef as k,useEffect as F}from"react";import{B as y}from"./use-paginated-core-_ZSkVafW.mjs";const B=(M,c,g)=>{const e=P(15),{initialNumItems:o}=g,{loadMore:s,pageResults:f,status:a}=y(M,c==="skip"?"skip":c,g),N=c==="skip";let t;if(e[0]!==f){t=[];for(const u of f)u&&t.push(u.page);e[0]=f,e[1]=t}else t=e[1];let r;e[2]!==o||e[3]!==s?(r={defaultNumItems:o,loadMore:s},e[2]=o,e[3]=s,e[4]=r):r=e[4];const h=k(r);let i;e[5]!==o||e[6]!==s?(i=()=>{h.current={defaultNumItems:o,loadMore:s}},e[5]=o,e[6]=s,e[7]=i):i=e[7],F(i);let m;e[8]===Symbol.for("react.memo_cache_sentinel")?(m=u=>{const{defaultNumItems:I,loadMore:L}=h.current;L(u??I)},e[8]=m):m=e[8];const x=m,l=a==="CanLoadMore",d=!N&&a==="LoadingMore",p=!N&&a==="LoadingFirstPage";let n;return e[9]!==t||e[10]!==a||e[11]!==l||e[12]!==d||e[13]!==p?(n={fetchNextPage:x,hasNextPage:l,isFetchingNextPage:d,isLoading:p,pages:t,status:a},e[9]=t,e[10]=a,e[11]=l,e[12]=d,e[13]=p,e[14]=n):n=e[14],n};export{B as default};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{useMutation as E}from"@tanstack/react-query";import{useRef as M,useState as O,useCallback as c}from"react";import{useLunora as U}from"./LunoraProvider-InsjxtOB.mjs";const b=d=>{const f=U(),o=M(0),[a,p]=O(!1),g=E({mutationFn:({args:t,options:r})=>f.mutation(d,t,r),onMutate:()=>{o.current+=1,p(!0)},onSettled:()=>{o.current-=1,p(o.current>0)}}),{data:s,error:i,isError:n,mutateAsync:e,reset:u}=g,l=c((t,r)=>e({args:t,options:r}),[e]),m=c(t=>({data:s,error:i,isError:n,mutate:(r,h)=>e({args:r,options:{optimisticUpdate:t,...h}}),pending:a,reset:u,withOptimisticUpdate:m}),[e,s,i,n,a,u]);return{data:s,error:i,isError:n,mutate:l,pending:a,reset:u,withOptimisticUpdate:m}};export{b as useMutation};
2
+ import{useMutation as E}from"@tanstack/react-query";import{useRef as M,useState as O,useCallback as c}from"react";import{useLunora as U}from"./LunoraProvider-D6ZS72le.mjs";const b=d=>{const f=U(),o=M(0),[a,p]=O(!1),g=E({mutationFn:({args:t,options:r})=>f.mutation(d,t,r),onMutate:()=>{o.current+=1,p(!0)},onSettled:()=>{o.current-=1,p(o.current>0)}}),{data:s,error:i,isError:n,mutateAsync:e,reset:u}=g,l=c((t,r)=>e({args:t,options:r}),[e]),m=c(t=>({data:s,error:i,isError:n,mutate:(r,h)=>e({args:r,options:{optimisticUpdate:t,...h}}),pending:a,reset:u,withOptimisticUpdate:m}),[e,s,i,n,a,u]);return{data:s,error:i,isError:n,mutate:l,pending:a,reset:u,withOptimisticUpdate:m}};export{b as useMutation};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as g}from"react/compiler-runtime";import{B as l}from"./use-paginated-core-ClJ0EeGx.mjs";const m=(u,a,c)=>{const s=g(7),{loadMore:r,pageResults:i,status:t}=l(u,a==="skip"?"skip":a,c);let o;if(s[0]!==i){o=[];for(const p of i)p&&o.push(...p.page);s[0]=i,s[1]=o}else o=s[1];const n=a!=="skip"&&(t==="LoadingFirstPage"||t==="LoadingMore");let e;return s[2]!==r||s[3]!==o||s[4]!==t||s[5]!==n?(e={isLoading:n,loadMore:r,results:o,status:t},s[2]=r,s[3]=o,s[4]=t,s[5]=n,s[6]=e):e=s[6],e};export{m as usePaginatedQuery};
2
+ import{c as g}from"react/compiler-runtime";import{B as l}from"./use-paginated-core-_ZSkVafW.mjs";const m=(u,a,c)=>{const s=g(7),{loadMore:r,pageResults:i,status:t}=l(u,a==="skip"?"skip":a,c);let o;if(s[0]!==i){o=[];for(const p of i)p&&o.push(...p.page);s[0]=i,s[1]=o}else o=s[1];const n=a!=="skip"&&(t==="LoadingFirstPage"||t==="LoadingMore");let e;return s[2]!==r||s[3]!==o||s[4]!==t||s[5]!==n?(e={isLoading:n,loadMore:r,results:o,status:t},s[2]=r,s[3]=o,s[4]=t,s[5]=n,s[6]=e):e=s[6],e};export{m as usePaginatedQuery};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{useMemo as S,useState as U,useRef as I,useEffect as c,useCallback as p}from"react";import{useLunora as $}from"./LunoraProvider-InsjxtOB.mjs";const D=(e="sess")=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const s=crypto.getRandomValues(new Uint8Array(16));return`${e}-${Array.from(s,t=>t.toString(16).padStart(2,"0")).join("")}`}}return`${e}-${Date.now().toString(36)}`},L=1e4,P=(e,s)=>{const t=$(),{heartbeat:m,intervalMs:y=L,listPresent:f,shardKey:o}=s,i=S(()=>s.sessionId??D(),[s.sessionId]),[h,v]=U(void 0),u=I(s.data),l=I({client:t,heartbeat:m,roomId:e,sessionId:i,shardKey:o});c(()=>{l.current={client:t,heartbeat:m,roomId:e,sessionId:i,shardKey:o}});const n=p(()=>{const{client:r,heartbeat:a,roomId:d,sessionId:K,shardKey:g}=l.current,R={roomId:d,sessionId:K,...u.current===void 0?{}:{data:u.current}};r.mutation(a,R,{shardKey:g}).catch(()=>{})},[]),b=p(r=>{u.current=r,n()},[n]);return c(()=>{n();const r=setInterval(n,y),a=()=>{typeof document<"u"&&document.visibilityState==="visible"&&n()};return typeof document<"u"&&document.addEventListener("visibilitychange",a),()=>{clearInterval(r),typeof document<"u"&&document.removeEventListener("visibilitychange",a)}},[n,y]),c(()=>t.acquireConnectionContext({roomId:e,sessionId:i},{shardKey:o}),[t,e,i,o]),c(()=>{let r=!1;const a=t.subscribe(f,{roomId:e},d=>{r||v(d)},{shardKey:o});return()=>{r=!0,a()}},[t,f.__lunoraRef,e,o]),{present:h,sessionId:i,setData:b}};export{P as usePresence};
2
+ import{useMemo as S,useState as U,useRef as I,useEffect as c,useCallback as p}from"react";import{useLunora as $}from"./LunoraProvider-D6ZS72le.mjs";const D=(e="sess")=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const s=crypto.getRandomValues(new Uint8Array(16));return`${e}-${Array.from(s,t=>t.toString(16).padStart(2,"0")).join("")}`}}return`${e}-${Date.now().toString(36)}`},L=1e4,P=(e,s)=>{const t=$(),{heartbeat:m,intervalMs:y=L,listPresent:f,shardKey:o}=s,i=S(()=>s.sessionId??D(),[s.sessionId]),[h,v]=U(void 0),u=I(s.data),l=I({client:t,heartbeat:m,roomId:e,sessionId:i,shardKey:o});c(()=>{l.current={client:t,heartbeat:m,roomId:e,sessionId:i,shardKey:o}});const n=p(()=>{const{client:r,heartbeat:a,roomId:d,sessionId:K,shardKey:g}=l.current,R={roomId:d,sessionId:K,...u.current===void 0?{}:{data:u.current}};r.mutation(a,R,{shardKey:g}).catch(()=>{})},[]),b=p(r=>{u.current=r,n()},[n]);return c(()=>{n();const r=setInterval(n,y),a=()=>{typeof document<"u"&&document.visibilityState==="visible"&&n()};return typeof document<"u"&&document.addEventListener("visibilitychange",a),()=>{clearInterval(r),typeof document<"u"&&document.removeEventListener("visibilitychange",a)}},[n,y]),c(()=>t.acquireConnectionContext({roomId:e,sessionId:i},{shardKey:o}),[t,e,i,o]),c(()=>{let r=!1;const a=t.subscribe(f,{roomId:e},d=>{r||v(d)},{shardKey:o});return()=>{r=!0,a()}},[t,f.__lunoraRef,e,o]),{present:h,sessionId:i,setData:b}};export{P as usePresence};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as N}from"react/compiler-runtime";import{useQueryClient as Q,useQuery as R}from"@tanstack/react-query";import{useState as q,useEffect as h}from"react";import{b as v}from"./cache-DJEsSdUx.mjs";import{useLunora as K}from"./LunoraProvider-InsjxtOB.mjs";import{i as T,y as _}from"./query-key-DV_Vu-6c.mjs";const C=(a,c,p)=>{const e=N(9),l=p===void 0?{}:p,r=K(),i=Q(),{shardKey:u}=l,t=c==="skip",n=t?{}:c,s=_(a,n,u),[o,b]=q(r.isReady);let m,y;e[0]!==r||e[1]!==o?(m=()=>{o||r.whenReady().then(()=>{b(!0)})},y=[r,o],e[0]=r,e[1]=o,e[2]=m,e[3]=y):(m=e[2],y=e[3]),h(m,y);const I=t?void 0:r.peekHydratedQuery(a.__lunoraRef,n,u),{data:$}=R({enabled:!t&&o,initialData:I,queryFn:()=>r.query(a,n,{shardKey:u}),queryKey:s,staleTime:Number.POSITIVE_INFINITY}),f=T(s);let d;return e[4]!==r||e[5]!==i||e[6]!==t||e[7]!==f?(d=[r,i,f,t],e[4]=r,e[5]=i,e[6]=t,e[7]=f,e[8]=d):d=e[8],h(()=>t?k:v(r).attach(i,s,a,n,u),d),t?void 0:$};function k(){}export{C as default};
2
+ import{c as N}from"react/compiler-runtime";import{useQueryClient as Q,useQuery as R}from"@tanstack/react-query";import{useState as q,useEffect as h}from"react";import{b as v}from"./cache-DJEsSdUx.mjs";import{useLunora as K}from"./LunoraProvider-D6ZS72le.mjs";import{i as T,y as _}from"./query-key-DV_Vu-6c.mjs";const C=(a,c,p)=>{const e=N(9),l=p===void 0?{}:p,r=K(),i=Q(),{shardKey:u}=l,t=c==="skip",n=t?{}:c,s=_(a,n,u),[o,b]=q(r.isReady);let m,y;e[0]!==r||e[1]!==o?(m=()=>{o||r.whenReady().then(()=>{b(!0)})},y=[r,o],e[0]=r,e[1]=o,e[2]=m,e[3]=y):(m=e[2],y=e[3]),h(m,y);const I=t?void 0:r.peekHydratedQuery(a.__lunoraRef,n,u),{data:$}=R({enabled:!t&&o,initialData:I,queryFn:()=>r.query(a,n,{shardKey:u}),queryKey:s,staleTime:Number.POSITIVE_INFINITY}),f=T(s);let d;return e[4]!==r||e[5]!==i||e[6]!==t||e[7]!==f?(d=[r,i,f,t],e[4]=r,e[5]=i,e[6]=t,e[7]=f,e[8]=d):d=e[8],h(()=>t?k:v(r).attach(i,s,a,n,u),d),t?void 0:$};function k(){}export{C as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as B}from"react/compiler-runtime";import{useReducer as K,useRef as R,useEffect as v}from"react";import{useLunora as S}from"./LunoraProvider-D6ZS72le.mjs";import{o as b,u as E}from"./stream-state-ksURgmCA.mjs";import{t as L}from"./wire-key-BjAV3_Rq.mjs";const z=(u,o,f)=>{const e=B(25);let a;e[0]!==f?(a=f===void 0?{}:f,e[0]=f,e[1]=a):a=e[1];const r=a,c=S();let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m={chunks:[],error:void 0,status:"idle"},e[2]=m):m=e[2];const[t,n]=K(b,m),s=o==="skip";let l;e[3]!==o||e[4]!==s?(l=s?"skip":L(o),e[3]=o,e[4]=s,e[5]=l):l=e[5];const y=l,_=R(void 0);let i;e[6]!==o||e[7]!==c||e[8]!==u||e[9]!==r.maxBuffer||e[10]!==r.shardKey||e[11]!==s?(i=()=>{if(s)return n({type:"reset"}),T;n({type:"reset"}),n({type:"start"});const{cancel:x,cleanup:k}=E(c.stream(u,o,{maxBuffer:r.maxBuffer,shardKey:r.shardKey}),n);return _.current=x,()=>{k(),_.current=void 0}},e[6]=o,e[7]=c,e[8]=u,e[9]=r.maxBuffer,e[10]=r.shardKey,e[11]=s,e[12]=i):i=e[12];let h;e[13]!==c||e[14]!==u.__lunoraRef||e[15]!==r.maxBuffer||e[16]!==r.shardKey||e[17]!==y||e[18]!==s?(h=[c,u.__lunoraRef,y,s,r.shardKey,r.maxBuffer],e[13]=c,e[14]=u.__lunoraRef,e[15]=r.maxBuffer,e[16]=r.shardKey,e[17]=y,e[18]=s,e[19]=h):h=e[19],v(i,h);let d;e[20]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{_.current?.()},e[20]=d):d=e[20];let p;return e[21]!==t.chunks||e[22]!==t.error||e[23]!==t.status?(p={cancel:d,chunks:t.chunks,error:t.error,status:t.status},e[21]=t.chunks,e[22]=t.error,e[23]=t.status,e[24]=p):p=e[24],p};function T(){}export{z as useStream};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as b}from"react/compiler-runtime";import{createQuerySubscription as w}from"@lunora/client/query";import{useState as x,useRef as q,useEffect as v}from"react";import{useLunora as A}from"./LunoraProvider-InsjxtOB.mjs";import{t as D}from"./wire-key-BjAV3_Rq.mjs";const B=(o,r,n)=>{const e=b(22);let u;e[0]!==n?(u=n===void 0?{}:n,e[0]=n,e[1]=u):u=e[1];const a=u,s=A();let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={data:void 0,error:void 0},e[2]=c):c=e[2];const[g,p]=x(c),t=r==="skip";let d;e[3]!==r||e[4]!==t?(d=t?"skip":D(r),e[3]=r,e[4]=t,e[5]=d):d=e[5];const y=d;let f;e[6]!==r||e[7]!==o?(f={args:r,fn:o},e[6]=r,e[7]=o,e[8]=f):f=e[8];const _=q(f);let i;e[9]!==r||e[10]!==o?(i=()=>{_.current={args:r,fn:o}},e[9]=r,e[10]=o,e[11]=i):i=e[11],v(i);let l;e[12]!==s||e[13]!==a.shardKey||e[14]!==t?(l=()=>{if(t)return p({data:void 0,error:void 0}),L;let h=!1;const{args:k,fn:E}=_.current,R=w(s,E,k,{onData:K=>{h||p({data:K,error:void 0})},onError:K=>{const S=new Error(K.message);queueMicrotask(()=>{h||p({data:void 0,error:S})})}},{shardKey:a.shardKey});return()=>{h=!0,R()}},e[12]=s,e[13]=a.shardKey,e[14]=t,e[15]=l):l=e[15];let m;return e[16]!==s||e[17]!==o.__lunoraRef||e[18]!==a.shardKey||e[19]!==y||e[20]!==t?(m=[s,o.__lunoraRef,y,a.shardKey,t],e[16]=s,e[17]=o.__lunoraRef,e[18]=a.shardKey,e[19]=y,e[20]=t,e[21]=m):m=e[21],v(l,m),g};function L(){}export{B as default};
2
+ import{c as b}from"react/compiler-runtime";import{createQuerySubscription as w}from"@lunora/client/query";import{useState as x,useRef as q,useEffect as v}from"react";import{useLunora as A}from"./LunoraProvider-D6ZS72le.mjs";import{t as D}from"./wire-key-BjAV3_Rq.mjs";const B=(o,r,n)=>{const e=b(22);let u;e[0]!==n?(u=n===void 0?{}:n,e[0]=n,e[1]=u):u=e[1];const a=u,s=A();let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={data:void 0,error:void 0},e[2]=c):c=e[2];const[g,p]=x(c),t=r==="skip";let d;e[3]!==r||e[4]!==t?(d=t?"skip":D(r),e[3]=r,e[4]=t,e[5]=d):d=e[5];const y=d;let f;e[6]!==r||e[7]!==o?(f={args:r,fn:o},e[6]=r,e[7]=o,e[8]=f):f=e[8];const _=q(f);let i;e[9]!==r||e[10]!==o?(i=()=>{_.current={args:r,fn:o}},e[9]=r,e[10]=o,e[11]=i):i=e[11],v(i);let l;e[12]!==s||e[13]!==a.shardKey||e[14]!==t?(l=()=>{if(t)return p({data:void 0,error:void 0}),L;let h=!1;const{args:k,fn:E}=_.current,R=w(s,E,k,{onData:K=>{h||p({data:K,error:void 0})},onError:K=>{const S=new Error(K.message);queueMicrotask(()=>{h||p({data:void 0,error:S})})}},{shardKey:a.shardKey});return()=>{h=!0,R()}},e[12]=s,e[13]=a.shardKey,e[14]=t,e[15]=l):l=e[15];let m;return e[16]!==s||e[17]!==o.__lunoraRef||e[18]!==a.shardKey||e[19]!==y||e[20]!==t?(m=[s,o.__lunoraRef,y,a.shardKey,t],e[16]=s,e[17]=o.__lunoraRef,e[18]=a.shardKey,e[19]=y,e[20]=t,e[21]=m):m=e[21],v(l,m),g};function L(){}export{B as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{useState as y,useRef as F,useCallback as b,useEffect as O}from"react";import{useLunora as J}from"./LunoraProvider-D6ZS72le.mjs";const G=t=>{if(t.length===0)return 0;let o=0;for(const n of t)o+=n*n;return Math.sqrt(o/t.length)},H=(t,o)=>{const n=o/16e3,a=n>1?Math.floor(t.length/n):t.length,l=new ArrayBuffer(a*2),i=new DataView(l);for(let c=0;c<a;c+=1){const g=t[Math.floor(c*n)]??0,d=Math.max(-1,Math.min(1,g));i.setInt16(c*2,d<0?d*32768:d*32767,!0)}return new Uint8Array(l)},Q=async t=>{const o=globalThis,n=o.navigator?.mediaDevices?.getUserMedia.bind(o.navigator.mediaDevices),a=o.AudioContext??o.webkitAudioContext;if(!n||!a)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const l=await n({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),i=new a,c=i.createMediaStreamSource(l),g=i.createScriptProcessor(4096,1,1);let d=!1,k=!1,p=0,f=0;return g.onaudioprocess=s=>{const h=s.inputBuffer.getChannelData(0),m=d?0:G(h);if(t.onLevel(m),d)return;if(t.onAudio(H(h,i.sampleRate)),t.isSpeaking()){f=m>=t.interruptThreshold?f+1:0,f>=t.interruptChunks&&(f=0,t.onInterrupt());return}f=0;const T=h.length/i.sampleRate*1e3;if(m>=t.silenceThreshold){k=!0,p=0;return}k&&(p+=T,p>=t.silenceDurationMs&&(k=!1,p=0,t.onSilence()))},c.connect(g),g.connect(i.destination),{setMuted:s=>{d=s},stop:()=>{g.disconnect(),c.disconnect();for(const s of l.getTracks())s.stop();i.close()}}},X=()=>{const t=globalThis,o=t.AudioContext??t.webkitAudioContext;if(!o)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const n=new o,a=new Set;let l=0,i=Promise.resolve(),c=0;const g=async(p,f)=>{if(f!==c)return;let s;try{s=await n.decodeAudioData(p.buffer)}catch{return}if(f!==c)return;const h=n.createBufferSource();h.buffer=s,h.connect(n.destination);const m=Math.max(n.currentTime,l);h.start(m),l=m+s.duration,a.add(h),h.onended=()=>{a.delete(h)}},d=p=>{const f=Uint8Array.from(p),s=c;i=i.then(()=>g(f,s))},k=()=>{c+=1;for(const p of a)try{p.stop()}catch{}a.clear(),l=n.currentTime};return{enqueue:d,interrupt:k,stop:()=>{k(),n.close()}}},I=1,Y=.01,Z=1200,j=.15,z=3,ee=t=>t.startsWith("https://")?`wss://${t.slice(8)}`:t.startsWith("http://")?`ws://${t.slice(7)}`:t,te=t=>{const o=t.__lunoraRef,n=o.startsWith("agents:")?o.slice(7):o;return n.endsWith("Voice")?n.slice(0,-5):n},re=(t,o,n)=>{const a=ee(t),l=a.endsWith("/")?a.slice(0,-1):a,i=new URLSearchParams({threadKey:n});return`${l}/_lunora/voice/${encodeURIComponent(o)}?${i.toString()}`},oe=t=>{const{createMicrophone:o=Q,createSpeaker:n=X,createSocket:a,interruptChunks:l=z,interruptThreshold:i=j,silenceDurationMs:c=Z,silenceThreshold:g=Y,threadKey:d,voice:k}=t,p=J(),[f,s]=y("idle"),[h,m]=y(!1),[T,E]=y(""),[q,M]=y(""),[L,$]=y(0),[D,U]=y(!1),[B,x]=y(void 0),u=F(void 0),C=F(!1),v=b(r=>{const e=u.current?.socket;return e?.readyState===I?(e.send(JSON.stringify(r)),!0):!1},[]),A=b(()=>{const r=u.current;if(u.current=void 0,r){r.microphone?.stop(),r.speaker?.stop();try{r.socket.close()}catch{}}C.current=!1,m(!1),s("idle"),$(0)},[]),V=b(r=>{const e=u.current;switch(r.type){case"assistant_delta":{e&&(e.speaking=!0),s("speaking"),M(S=>S+r.text);break}case"assistant_done":{e&&(e.speaking=!1),M(r.text),s("listening");break}case"error":{e&&(e.speaking=!1),x(new Error(r.message)),s("listening");break}case"interrupted":{e&&(e.speaking=!1,e.suppressAudio=!1),e?.speaker?.interrupt(),s("listening");break}case"ready":{e&&(e.audioFormat=r.audioFormat,e.suppressAudio=!1),m(!0),s("listening");break}case"user_transcript":{e&&(e.suppressAudio=!1),E(r.text),M(""),s("thinking");break}}},[]),W=b(r=>{const e=u.current;!e||e.suppressAudio||(e.speaker??=n({audioFormat:e.audioFormat}),e.speaking=!0,s("speaking"),e.speaker.enqueue(r))},[n]),P=b(async()=>{if(!(u.current||C.current)){C.current=!0,x(void 0),E(""),M("");try{const r=re(p.url,te(k),d),e=(a??(w=>{const _=p.getWebSocketImpl();if(!_)throw new Error("useVoiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new _(w)}))(r);e.binaryType="arraybuffer";const S={audioFormat:"mp3",microphone:void 0,socket:e,speaker:void 0,speaking:!1,suppressAudio:!1};u.current=S,e.onmessage=w=>{if(typeof w.data=="string"){try{V(JSON.parse(w.data))}catch{}return}W(new Uint8Array(w.data))},e.onerror=()=>{x(new Error("useVoiceAgent: voice socket error"))},e.onclose=()=>{u.current===S&&A()};const R=await o({interruptChunks:l,interruptThreshold:i,isSpeaking:()=>u.current?.speaking??!1,onAudio:w=>{e.readyState===I&&e.send(w)},onInterrupt:()=>{v({type:"interrupt"}),u.current?.speaker?.interrupt(),u.current&&(u.current.speaking=!1,u.current.suppressAudio=!0),s("listening")},onLevel:$,onSilence:()=>{v({type:"commit"}),s("thinking")},silenceDurationMs:c,silenceThreshold:g});u.current===S?(S.microphone=R,U(!1),s("listening")):R.stop()}catch(r){x(r instanceof Error?r:new Error(String(r))),A()}finally{C.current=!1}}},[p,o,a,W,V,l,i,v,c,g,A,d,k]),K=b(()=>{const r=!D;return u.current?.microphone?.setMuted(r),U(r),r},[D]),N=b(r=>{v({text:r,type:"text"})&&s("thinking")},[v]);return O(()=>A,[A]),{audioLevel:L,connected:h,endCall:A,error:B,interimTranscript:q,isMuted:D,sendText:N,startCall:P,status:f,toggleMute:K,transcript:T}};export{oe as useVoiceAgent};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/react",
3
- "version": "1.0.0-alpha.43",
3
+ "version": "1.0.0-alpha.45",
4
4
  "description": "React hooks for Lunora: useQuery, useMutation, useSubscription, and useAuth",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -53,9 +53,9 @@
53
53
  "access": "public"
54
54
  },
55
55
  "dependencies": {
56
- "@lunora/client": "1.0.0-alpha.39",
57
- "@lunora/errors": "1.0.0-alpha.13",
58
- "@lunora/ratelimit": "1.0.0-alpha.16",
56
+ "@lunora/client": "1.0.0-alpha.41",
57
+ "@lunora/errors": "1.0.0-alpha.15",
58
+ "@lunora/ratelimit": "1.0.0-alpha.18",
59
59
  "@visulima/storage-client": "1.0.0"
60
60
  },
61
61
  "peerDependencies": {
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{c as L}from"react/compiler-runtime";import{LunoraError as d}from"@lunora/errors";import{QueryClientContext as y,QueryClientProvider as C,QueryClient as N}from"@tanstack/react-query";import{createContext as h,use as f,useState as v}from"react";import{jsx as c}from"react/jsx-runtime";const p=h(null),T=()=>new N({defaultOptions:{mutations:{retry:0},queries:{gcTime:5*6e4,retry:0,staleTime:Number.POSITIVE_INFINITY}}}),b=o=>{const e=L(9),{children:a,client:m,queryClient:n}=o,r=f(y);let i;e[0]!==r||e[1]!==n?(i=()=>n??r??T(),e[0]=r,e[1]=n,e[2]=i):i=e[2];const[I]=v(i),t=n??r??I;if(!t)throw new d("INTERNAL","LunoraProvider: failed to resolve a QueryClient");let u;e[3]!==a||e[4]!==m?(u=c(p,{value:m,children:a}),e[3]=a,e[4]=m,e[5]=u):u=e[5];const l=u;if(r===t)return l;let s;return e[6]!==l||e[7]!==t?(s=c(C,{client:t,children:l}),e[6]=l,e[7]=t,e[8]=s):s=e[8],s},q=()=>{const o=f(p);if(!o)throw new d("INTERNAL","useLunora must be used inside <LunoraProvider />");return o};export{b as LunoraProvider,q as useLunora};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{c as ot}from"react/compiler-runtime";import{reconcileOptimistic as Q,maxSeq as U}from"@lunora/client";import{useState as st,useRef as rt}from"react";import{useMutation as J}from"./useMutation-B4uL3Rde.mjs";import{useStream as it}from"./useStream-CZqDeZ3D.mjs";import V from"./useSubscription-NfJ0mdhL.mjs";const ct={__lunoraRef:""},lt={__lunoraRef:""},dt=[],wt=i=>{const t=ot(47),{api:S,cancel:l,limit:d,send:W,sendArgs:_,stream:u,threadKey:e}=i;let m;t[0]!==d||t[1]!==e?(m=d===void 0?{key:e}:{key:e,limit:d},t[0]=d,t[1]=e,t[2]=m):m=t[2];const X=m,{data:Y}=V(S.agents.agentMessages,X);let h;t[3]!==e?(h={key:e},t[3]=e,t[4]=h):h=t[4];const{data:Z}=V(S.agents.agentThread,h);let p;t[5]!==u||t[6]!==e?(p=u===void 0?"skip":{key:e},t[5]=u,t[6]=e,t[7]=p):p=t[7];const z=p,{chunks:x}=it(u??lt,z),B=J(W),L=J(l??ct),tt=J(S.agents.agentResolveApproval);let f;t[8]===Symbol.for("react.memo_cache_sentinel")?(f=[],t[8]=f):f=t[8];const[j,N]=st(f),R=rt(0),P=Z,q=P?.status,s=P?.instanceId,a=Y??dt;let g;if(t[9]!==a||t[10]!==j){const n=Q(j,a),o=U(a);g=n.length===0?a:[...a,...n.map((K,G)=>({content:K.content,optimistic:!0,role:"user",seq:o+1+G}))],t[9]=a,t[10]=j,t[11]=g}else g=t[11];const T=g;let y;t[12]!==a?(y=a.filter(ut),t[12]=a,t[13]=y):y=t[13];const c=y.length;let v;if(t[14]!==c||t[15]!==x||t[16]!==e){let n;t[18]!==c||t[19]!==e?(n=o=>o.kind!=="progress"&&o.threadKey===e&&o.turn>=c,t[18]=c,t[19]=e,t[20]=n):n=t[20],v=x.filter(n).map(mt).join(""),t[14]=c,t[15]=x,t[16]=e,t[17]=v}else v=t[17];const b=v,{mutate:E}=B,{mutate:M}=L,{mutate:r}=tt;let w;t[21]!==a||t[22]!==_||t[23]!==E||t[24]!==e?(w=async(n,o)=>{const K=R.current;R.current=R.current+1;const G=U(a);N(H=>[...Q(H,a),{content:n,id:K,maxDurableSeqAtSend:G}]);try{await E({input:n,threadKey:e,..._,...o})}catch(H){const et=H;throw N(nt=>nt.filter(at=>at.id!==K)),et}},t[21]=a,t[22]=_,t[23]=E,t[24]=e,t[25]=w):w=t[25];const $=w;let I;t[26]!==s||t[27]!==r||t[28]!==e?(I=async(n,o)=>{if(s===void 0)throw new Error("useAgentChat: cannot approve — no in-flight run (thread has no instanceId)");await r({decision:"approve",instanceId:s,threadKey:e,toolCallId:n,...o===void 0?{}:{note:o}})},t[26]=s,t[27]=r,t[28]=e,t[29]=I):I=t[29];const D=I;let k;t[30]!==s||t[31]!==r||t[32]!==e?(k=async(n,o)=>{if(s===void 0)throw new Error("useAgentChat: cannot reject — no in-flight run (thread has no instanceId)");await r({decision:"reject",instanceId:s,threadKey:e,toolCallId:n,...o===void 0?{}:{note:o}})},t[30]=s,t[31]=r,t[32]=e,t[33]=k):k=t[33];const O=k;let A;t[34]!==M||t[35]!==l||t[36]!==s||t[37]!==e?(A=async()=>{l===void 0||s===void 0||await M({instanceId:s,threadKey:e})},t[34]=M,t[35]=l,t[36]=s,t[37]=e,t[38]=A):A=t[38];const F=A;let C;return t[39]!==D||t[40]!==F||t[41]!==T||t[42]!==O||t[43]!==$||t[44]!==q||t[45]!==b?(C={approve:D,cancel:F,messages:T,reject:O,send:$,status:q,streamingText:b},t[39]=D,t[40]=F,t[41]=T,t[42]=O,t[43]=$,t[44]=q,t[45]=b,t[46]=C):C=t[46],C};function ut(i){return i.role==="assistant"}function mt(i){return i.text}export{wt as useAgentChat};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{useReducer as l,useRef as d,useEffect as y}from"react";import{useLunora as v}from"./LunoraProvider-InsjxtOB.mjs";import{e as x}from"./stable-key-BSG0zK_E.mjs";const g=function(r,t){switch(t.type){case"chunk":return{chunks:[...r.chunks,t.chunk],error:void 0,status:"streaming"};case"complete":return{...r,status:"complete"};case"error":return{...r,error:t.error,status:"error"};case"reset":return{chunks:[],error:void 0,status:"idle"};case"start":return{...r,status:"streaming"};default:return r}},R=(r,t,o={})=>{const f=v(),[n,e]=l(g,{chunks:[],error:void 0,status:"idle"}),c=t==="skip",h=c?"skip":x(t),a=d(void 0);return y(()=>{if(c)return e({type:"reset"}),()=>{};e({type:"reset"}),e({type:"start"});let u=!0,i=!1;const p=f.httpStream(r,t,{maxBuffer:o.maxBuffer}),m=()=>{i||(i=!0,p.cancel())};return a.current=m,(async()=>{try{for await(const s of p){if(!u)return;e({chunk:s,type:"chunk"})}u&&e({type:"complete"})}catch(s){if(!u)return;const k=s instanceof Error?s:new Error(String(s));e({error:k,type:"error"})}})().catch(()=>{}),()=>{u=!1,m(),a.current=void 0}},[f,r.method,r.path,h,c,o.maxBuffer]),{cancel:()=>{a.current?.()},chunks:n.chunks,error:n.error,status:n.status}};export{R as useHttpStream};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{useReducer as l,useRef as k,useEffect as y}from"react";import{useLunora as v}from"./LunoraProvider-InsjxtOB.mjs";import{t as x}from"./wire-key-BjAV3_Rq.mjs";const g=function(r,e){switch(e.type){case"chunk":return{chunks:[...r.chunks,e.chunk],error:void 0,status:"streaming"};case"complete":return{...r,status:"complete"};case"error":return{...r,error:e.error,status:"error"};case"reset":return{chunks:[],error:void 0,status:"idle"};case"start":return{...r,status:"streaming"};default:return r}},K=(r,e,u={})=>{const f=v(),[a,t]=l(g,{chunks:[],error:void 0,status:"idle"}),c=e==="skip",p=c?"skip":x(e),o=k(void 0);return y(()=>{if(c)return t({type:"reset"}),()=>{};t({type:"reset"}),t({type:"start"});let n=!0,i=!1;const h=f.stream(r,e,{maxBuffer:u.maxBuffer,shardKey:u.shardKey}),m=()=>{i||(i=!0,h.cancel())};return o.current=m,(async()=>{try{for await(const s of h){if(!n)return;t({chunk:s,type:"chunk"})}n&&t({type:"complete"})}catch(s){if(!n)return;const d=s instanceof Error?s:new Error(String(s));t({error:d,type:"error"})}})().catch(()=>{}),()=>{n=!1,m(),o.current=void 0}},[f,r.__lunoraRef,p,c,u.shardKey,u.maxBuffer]),{cancel:()=>{o.current?.()},chunks:a.chunks,error:a.error,status:a.status}};export{K as useStream};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{useState as A,useRef as F,useCallback as w,useEffect as O}from"react";import{useLunora as H}from"./LunoraProvider-InsjxtOB.mjs";const Q=t=>{if(t.length===0)return 0;let o=0;for(const n of t)o+=n*n;return Math.sqrt(o/t.length)},X=(t,o)=>{const n=o/16e3,a=n>1?Math.floor(t.length/n):t.length,l=new ArrayBuffer(a*2),i=new DataView(l);for(let c=0;c<a;c+=1){const g=t[Math.floor(c*n)]??0,d=Math.max(-1,Math.min(1,g));i.setInt16(c*2,d<0?d*32768:d*32767,!0)}return new Uint8Array(l)},Y=async t=>{const o=globalThis,n=o.navigator?.mediaDevices?.getUserMedia.bind(o.navigator.mediaDevices),a=o.AudioContext??o.webkitAudioContext;if(!n||!a)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const l=await n({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),i=new a,c=i.createMediaStreamSource(l),g=i.createScriptProcessor(4096,1,1);let d=!1,k=!1,p=0,f=0;return g.onaudioprocess=s=>{const h=s.inputBuffer.getChannelData(0),m=d?0:Q(h);if(t.onLevel(m),d)return;if(t.onAudio(X(h,i.sampleRate)),t.isSpeaking()){f=m>=t.interruptThreshold?f+1:0,f>=t.interruptChunks&&(f=0,t.onInterrupt());return}f=0;const T=h.length/i.sampleRate*1e3;if(m>=t.silenceThreshold){k=!0,p=0;return}k&&(p+=T,p>=t.silenceDurationMs&&(k=!1,p=0,t.onSilence()))},c.connect(g),g.connect(i.destination),{setMuted:s=>{d=s},stop:()=>{g.disconnect(),c.disconnect();for(const s of l.getTracks())s.stop();i.close()}}},Z=()=>{const t=globalThis,o=t.AudioContext??t.webkitAudioContext;if(!o)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const n=new o,a=new Set;let l=0,i=Promise.resolve(),c=0;const g=async(p,f)=>{if(f!==c)return;let s;try{s=await n.decodeAudioData(p.buffer)}catch{return}if(f!==c)return;const h=n.createBufferSource();h.buffer=s,h.connect(n.destination);const m=Math.max(n.currentTime,l);h.start(m),l=m+s.duration,a.add(h),h.onended=()=>{a.delete(h)}},d=p=>{const f=Uint8Array.from(p),s=c;i=i.then(()=>g(f,s))},k=()=>{c+=1;for(const p of a)try{p.stop()}catch{}a.clear(),l=n.currentTime};return{enqueue:d,interrupt:k,stop:()=>{k(),n.close()}}},I=1,j=.01,z=1200,G=.15,ee=3,te=t=>t.startsWith("https://")?`wss://${t.slice(8)}`:t.startsWith("http://")?`ws://${t.slice(7)}`:t,re=t=>{const o=t.__lunoraRef,n=o.startsWith("agents:")?o.slice(7):o;return n.endsWith("Voice")?n.slice(0,-5):n},ne=(t,o,n)=>{const a=te(t),l=a.endsWith("/")?a.slice(0,-1):a,i=new URLSearchParams({threadKey:n});return`${l}/_lunora/voice/${encodeURIComponent(o)}?${i.toString()}`},ae=t=>{const{createMicrophone:o=Y,createSpeaker:n=Z,createSocket:a,interruptChunks:l=ee,interruptThreshold:i=G,silenceDurationMs:c=z,silenceThreshold:g=j,threadKey:d,voice:k}=t,p=H(),[f,s]=A("idle"),[h,m]=A(!1),[T,E]=A(""),[q,M]=A(""),[L,$]=A(0),[D,U]=A(!1),[B,x]=A(void 0),u=F(void 0),C=F(!1),v=w(r=>{const e=u.current?.socket;return e?.readyState===I?(e.send(JSON.stringify(r)),!0):!1},[]),y=w(()=>{const r=u.current;if(u.current=void 0,r){r.microphone?.stop(),r.speaker?.stop();try{r.socket.close()}catch{}}C.current=!1,m(!1),s("idle"),$(0)},[]),P=w(()=>{y()},[y]),V=w(r=>{const e=u.current;switch(r.type){case"assistant_delta":{e&&(e.speaking=!0),s("speaking"),M(S=>S+r.text);break}case"assistant_done":{e&&(e.speaking=!1),M(r.text),s("listening");break}case"error":{e&&(e.speaking=!1),x(new Error(r.message)),s("listening");break}case"interrupted":{e&&(e.speaking=!1,e.suppressAudio=!1),e?.speaker?.interrupt(),s("listening");break}case"ready":{e&&(e.audioFormat=r.audioFormat,e.suppressAudio=!1),m(!0),s("listening");break}case"user_transcript":{e&&(e.suppressAudio=!1),E(r.text),M(""),s("thinking");break}}},[]),W=w(r=>{const e=u.current;!e||e.suppressAudio||(e.speaker??=n({audioFormat:e.audioFormat}),e.speaking=!0,s("speaking"),e.speaker.enqueue(r))},[n]),J=w(async()=>{if(!(u.current||C.current)){C.current=!0,x(void 0),E(""),M("");try{const r=ne(p.url,re(k),d),e=(a??(b=>{const _=p.getWebSocketImpl();if(!_)throw new Error("useVoiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new _(b)}))(r);e.binaryType="arraybuffer";const S={audioFormat:"mp3",microphone:void 0,socket:e,speaker:void 0,speaking:!1,suppressAudio:!1};u.current=S,e.onmessage=b=>{if(typeof b.data=="string"){try{V(JSON.parse(b.data))}catch{}return}W(new Uint8Array(b.data))},e.onerror=()=>{x(new Error("useVoiceAgent: voice socket error"))},e.onclose=()=>{u.current===S&&y()};const R=await o({interruptChunks:l,interruptThreshold:i,isSpeaking:()=>u.current?.speaking??!1,onAudio:b=>{e.readyState===I&&e.send(b)},onInterrupt:()=>{v({type:"interrupt"}),u.current?.speaker?.interrupt(),u.current&&(u.current.speaking=!1,u.current.suppressAudio=!0),s("listening")},onLevel:$,onSilence:()=>{v({type:"commit"}),s("thinking")},silenceDurationMs:c,silenceThreshold:g});u.current===S?(S.microphone=R,U(!1),s("listening")):R.stop()}catch(r){x(r instanceof Error?r:new Error(String(r))),y()}finally{C.current=!1}}},[p,o,a,W,V,l,i,v,c,g,y,d,k]),K=w(()=>{const r=!D;return u.current?.microphone?.setMuted(r),U(r),r},[D]),N=w(r=>{v({text:r,type:"text"})&&s("thinking")},[v]);return O(()=>y,[y]),{audioLevel:L,connected:h,endCall:P,error:B,interimTranscript:q,isMuted:D,sendText:N,startCall:J,status:f,toggleMute:K,transcript:T}};export{ae as useVoiceAgent};