@lunora/react 1.0.0-alpha.29 → 1.0.0-alpha.291

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 (78) hide show
  1. package/README.md +28 -18
  2. package/dist/index.d.mts +603 -170
  3. package/dist/index.d.ts +603 -170
  4. package/dist/index.mjs +1 -26
  5. package/dist/packem_shared/AuthLoading-Dqb9692o.mjs +2 -0
  6. package/dist/packem_shared/LunoraProvider-CypI20I0.mjs +1 -0
  7. package/dist/packem_shared/hydratePreloaded-C94hJet3.mjs +2 -0
  8. package/dist/packem_shared/lunora-provider-D15UPNFD.mjs +2 -0
  9. package/dist/packem_shared/query-core-DG86Lpnw.mjs +2 -0
  10. package/dist/packem_shared/stream-state-abygFxmy.mjs +1 -0
  11. package/dist/packem_shared/use-paginated-core-Cw465bR1.mjs +2 -0
  12. package/dist/packem_shared/useAction-CIlUzQVY.mjs +2 -0
  13. package/dist/packem_shared/useAgent-BBuc2RNx.mjs +2 -0
  14. package/dist/packem_shared/useAgentApprovals-yiIGlGck.mjs +2 -0
  15. package/dist/packem_shared/useAgentChat-Igz_15YO.mjs +2 -0
  16. package/dist/packem_shared/useAgentState-DbQmCmhH.mjs +2 -0
  17. package/dist/packem_shared/useAgentToolEvents-vgG15IZX.mjs +2 -0
  18. package/dist/packem_shared/useAuth-DTiEKNfL.mjs +2 -0
  19. package/dist/packem_shared/useAuthSessions-BSS2wfV4.mjs +2 -0
  20. package/dist/packem_shared/useAuthState-CFScqFAf.mjs +2 -0
  21. package/dist/packem_shared/useClientQuery-D01Sx8wn.mjs +2 -0
  22. package/dist/packem_shared/useConnectionStatus-VYjmmafS.mjs +2 -0
  23. package/dist/packem_shared/useFlag-CHzI2R8e.mjs +2 -0
  24. package/dist/packem_shared/useHttpStream-B32eZ6DN.mjs +2 -0
  25. package/dist/packem_shared/useInfiniteQuery-ycnpzlqm.mjs +2 -0
  26. package/dist/packem_shared/useLiveTopic-DzP_8Gf3.mjs +2 -0
  27. package/dist/packem_shared/useMutation-BfuQVXiY.mjs +2 -0
  28. package/dist/packem_shared/useMutator-BtUd-xEA.mjs +2 -0
  29. package/dist/packem_shared/usePaginatedQuery-CYB8h_E5.mjs +2 -0
  30. package/dist/packem_shared/usePresence-UDDcnYXw.mjs +2 -0
  31. package/dist/packem_shared/useQuery-BewsLSm_.mjs +2 -0
  32. package/dist/packem_shared/useRateLimit-Cckxi8m9.mjs +2 -0
  33. package/dist/packem_shared/useStream-D__0Rgzf.mjs +2 -0
  34. package/dist/packem_shared/useSubscription-P-_MNJm6.mjs +2 -0
  35. package/dist/packem_shared/useSuspenseQuery-5wC1or5S.mjs +2 -0
  36. package/dist/packem_shared/useVoiceAgent-iTIf7__2.mjs +2 -0
  37. package/dist/payment.d.mts +107 -0
  38. package/dist/payment.d.ts +107 -0
  39. package/dist/payment.mjs +2 -0
  40. package/dist/server.d.mts +74 -2
  41. package/dist/server.d.ts +74 -2
  42. package/dist/server.mjs +1 -31
  43. package/dist/upload.d.mts +24 -0
  44. package/dist/upload.d.ts +24 -0
  45. package/dist/upload.mjs +2 -0
  46. package/package.json +14 -4
  47. package/dist/packem_shared/AuthLoading-DezUWNB2.mjs +0 -33
  48. package/dist/packem_shared/CheckoutButton-DUite8jJ.mjs +0 -189
  49. package/dist/packem_shared/LunoraProvider-BsuiW4Lk.mjs +0 -81
  50. package/dist/packem_shared/cache-JeuDAXfE.mjs +0 -80
  51. package/dist/packem_shared/hydratePreloaded-2omLtadR.mjs +0 -54
  52. package/dist/packem_shared/lunoraQueryOptions-CefbPBId.mjs +0 -16
  53. package/dist/packem_shared/query-key-LGnArBTB.mjs +0 -13
  54. package/dist/packem_shared/query-options.d-CdgGQ9s4.d.mts +0 -38
  55. package/dist/packem_shared/query-options.d-CdgGQ9s4.d.ts +0 -38
  56. package/dist/packem_shared/stable-key-DePnevIy.mjs +0 -38
  57. package/dist/packem_shared/use-paginated-core-xxvd1YA0.mjs +0 -179
  58. package/dist/packem_shared/useAgent-BNLlIYHz.mjs +0 -101
  59. package/dist/packem_shared/useAgentChat-0cebQe7-.mjs +0 -304
  60. package/dist/packem_shared/useAgentState-Cqyd3Dfy.mjs +0 -37
  61. package/dist/packem_shared/useAgentToolEvents-gF7U4_KY.mjs +0 -129
  62. package/dist/packem_shared/useAuth-BSutjJaa.mjs +0 -129
  63. package/dist/packem_shared/useAuthState-CyF35qZR.mjs +0 -36
  64. package/dist/packem_shared/useClientQuery-DIkNT4QA.mjs +0 -17
  65. package/dist/packem_shared/useConnectionStatus-PJ7vyCHy.mjs +0 -30
  66. package/dist/packem_shared/useFlag-Beyeiq2b.mjs +0 -128
  67. package/dist/packem_shared/useHttpStream-oc4s1pMy.mjs +0 -127
  68. package/dist/packem_shared/useInfiniteQuery-CJNw1XaZ.mjs +0 -97
  69. package/dist/packem_shared/useMutation-BeqeIjTr.mjs +0 -67
  70. package/dist/packem_shared/useMutator-IIrLtDiM.mjs +0 -47
  71. package/dist/packem_shared/usePaginatedQuery-DWzydaVR.mjs +0 -46
  72. package/dist/packem_shared/usePresence-Rnx1Fznc.mjs +0 -115
  73. package/dist/packem_shared/useQuery-CE8_QUgh.mjs +0 -77
  74. package/dist/packem_shared/useRateLimit-DTEffQEi.mjs +0 -64
  75. package/dist/packem_shared/useStream-GYNgc9J5.mjs +0 -128
  76. package/dist/packem_shared/useSubscription-DcDlvVuI.mjs +0 -139
  77. package/dist/packem_shared/useVoiceAgent-w7fzAMSB.mjs +0 -422
  78. package/dist/packem_shared/wire-key-Bg8BJ8YM.mjs +0 -101
package/dist/index.d.mts CHANGED
@@ -1,37 +1,47 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
- import { LunoraClient, OptimisticUpdate, User, FunctionReference, ClientQueryRef, ConnectionStatus, ArgsOf, ReturnOf, HttpStreamRef, HttpStreamArgsOf, HttpStreamChunkOf, MutatorHandle, Preloaded } from '@lunora/client';
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';
2
+ import { LunoraClient, OptimisticUpdate, User, SubscriptionErrorCallback, SubscriptionError, FunctionReference, ArgsOf, ActionCallOptions, ReturnOf, AuthImpersonation, AuthSession, AuthUser, ClientQueryRef, ConnectionStatus, HttpStreamRef, HttpStreamArgsOf, HttpStreamChunkOf, LiveTopicOptions, LiveStreamSubscribeError, LiveTopicRef, OnlineOnlyOption, MutatorHandle, Preloaded } from '@lunora/client';
3
+ export { type ArgsOf, type AuthImpersonation, type AuthPage, type AuthSession, type AuthUser, 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 SubscriptionError, type SubscriptionErrorCallback, type User, createClientQuery, getErrorCode, getRetryAfterMs, isConflictError, isForbiddenError, isRateLimitedError, isUnauthorizedError } from '@lunora/client';
4
4
  import { QueryClient } from '@tanstack/react-query';
5
- export { type L as LunoraQueryOptions, l as lunoraQueryOptions } from "./packem_shared/query-options.d-CdgGQ9s4.mjs";
5
+ import { AuthStatus, AuthUsersListFilter } from '@lunora/client/auth';
6
6
  import { PaginationStatus } from '@lunora/client/pagination';
7
7
  export type { PaginationResult, PaginationStatus } from '@lunora/client/pagination';
8
8
  import { RateLimitStatus, RateLimitConfig } from '@lunora/ratelimit';
9
+ export { type LunoraQueryOptions, lunoraQueryOptions } from '@lunora/client/query';
10
+ export { RestrictionError, UploadControl, UploadError, type UploadRestrictions } from '@visulima/storage-client';
11
+ export { type UploadMethod, type UploadResult, type UseChunkedRestUploadOptions, type UseChunkedRestUploadReturn, type UseFileInputOptions, type UseFileInputReturn, type UseMultipartUploadOptions, type UseMultipartUploadReturn, type UsePasteUploadOptions, type UsePasteUploadReturn, type UseTusUploadOptions, type UseTusUploadReturn, type UseUploadOptions, type UseUploadReturn, useChunkedRestUpload, useFileInput, useMultipartUpload, usePasteUpload, useTusUpload, useUpload } from '@visulima/storage-client/react';
9
12
  interface AuthGateProps {
10
13
  children: ReactNode;
11
14
  }
12
- /** Renders `children` only once a token is set on the client (after hydration). */
15
+ /**
16
+ * Renders `children` once authentication has settled in the caller's favour — a
17
+ * credential is held and nothing has contradicted it. Follows the shared
18
+ * `AuthStatus` contract in `@lunora/client/auth`, so an unreachable identity
19
+ * endpoint keeps the gate open (with `useAuth().user` still `null`).
20
+ */
13
21
  declare const Authenticated: ({ children }: AuthGateProps) => ReactNode;
14
- /** Renders `children` only when auth has settled and no token is set. */
22
+ /** Renders `children` only when auth has settled and there is no session. */
15
23
  declare const Unauthenticated: ({ children }: AuthGateProps) => ReactNode;
16
- /** Renders `children` while auth is still settling (before hydration completes). */
24
+ /** Renders `children` while auth is still settling — before hydration, or while the first identity resolve is in flight. */
17
25
  declare const AuthLoading: ({ children }: AuthGateProps) => ReactNode;
18
26
  /**
19
- * Resolved auth-gate state. `isLoading` covers the window before the client has
20
- * hydrated — the server render and the first hydration render both report
21
- * loading, so the markup agrees and no signed-out UI flashes in.
27
+ * Resolved auth-gate state, derived from the shared `AuthStatus` contract in
28
+ * `@lunora/client/auth` — the same mapping Vue, Solid, Svelte and Angular use.
22
29
  */
23
30
  interface AuthState {
24
31
  isAuthenticated: boolean;
25
32
  isLoading: boolean;
26
33
  }
27
34
  /**
28
- * Three-state auth status for gating UI. Reports `isLoading` until the client
29
- * has hydrated, then `isAuthenticated` tracks whether a token is set on the
30
- * shared client.
35
+ * Three-state auth status for gating UI.
31
36
  *
32
- * Lunora auth is token-based and resolves synchronously once the token is
33
- * known, so the loading window is hydration rather than a server round-trip —
34
- * use it (via {@link AuthState}) to render a fallback while it settles.
37
+ * `isLoading` covers the server render and the first hydration render (the
38
+ * identity store's server snapshot is `"loading"`, so the markup agrees and no
39
+ * signed-out UI flashes in) as well as the window where a credential is held and
40
+ * its first identity resolve is still in flight.
41
+ *
42
+ * `isAuthenticated` follows the credential, not the identity record: an
43
+ * unreachable identity endpoint keeps the gate open with `user === null`. A UI
44
+ * that needs to tell that apart reads `useAuth().status`.
35
45
  */
36
46
  declare const useAuthState: () => AuthState;
37
47
  interface LunoraProviderProps {
@@ -44,7 +54,7 @@ interface LunoraProviderProps {
44
54
  * route through the offline queue on the client), and `gcTime: 5min` (keep
45
55
  * results around for a short return-to-view window).
46
56
  *
47
- * If a parent `<QueryClientProvider>` is already mounted, the provider
57
+ * If a parent `<QueryClientProvider>` is already mounted, the provider
48
58
  * uses *that* client and does NOT install an inner one (so apps with their
49
59
  * own setup don't double-wrap).
50
60
  */
@@ -57,96 +67,34 @@ interface LunoraProviderProps {
57
67
  */
58
68
  declare const LunoraProvider: ({ children, client, queryClient }: LunoraProviderProps) => ReactElement;
59
69
  /**
60
- * Read the {@link LunoraClient} from the nearest `&lt;LunoraProvider>`. Kept
70
+ * Read the {@link LunoraClient} from the nearest `<LunoraProvider>`. Kept
61
71
  * colocated with the provider for back-compat.
62
72
  */
63
73
  declare const useLunora: () => LunoraClient;
64
- /**
65
- * Client-safe mirror of `@lunora/payment`'s `Subscription`. Re-declared here
66
- * (rather than imported) so this React entry never pulls in the server-only
67
- * `@lunora/payment` module graph — the kit stays React + DOM only. Keep this in
68
- * sync with `packages/payment/src/types.ts`.
69
- */
70
- interface Subscription {
71
- readonly cancelAtPeriodEnd: boolean;
72
- readonly createdAt: number;
73
- readonly currentPeriodEnd?: number;
74
- readonly id: string;
75
- readonly priceId: string;
76
- readonly provider: "polar" | "stripe";
77
- readonly quantity: number;
78
- readonly referenceId: string;
79
- readonly state: "active" | "canceled" | "past_due" | "paused" | "trialing";
80
- readonly updatedAt: number;
81
- }
82
- /** The `{ url }` shape every checkout/portal trigger resolves to. */
83
- interface RedirectTarget {
84
- readonly url: string;
85
- }
86
- /** A thunk the app supplies that calls its own Lunora action and resolves a redirect URL. */
87
- type RedirectTrigger = () => Promise<RedirectTarget>;
88
- interface UseCheckoutResult {
89
- /** Run the trigger and redirect the browser to the resolved URL. Resolves once the redirect is issued; rejects on failure. */
90
- checkout: () => Promise<void>;
91
- /** The most recent failure, or `undefined`. */
92
- error: Error | undefined;
93
- /** `true` while the trigger is in flight (before the redirect is issued). */
94
- pending: boolean;
95
- }
96
- /**
97
- * Decoupled redirect-on-resolve primitive shared by `CheckoutButton` and
98
- * `CustomerPortalButton`. The app passes a `trigger` thunk that calls its own
99
- * Lunora action (the one wrapping `LunoraPayment.createCheckout` /
100
- * `createPortalSession`) and resolves `{ url }`; this hook awaits it, flips
101
- * `pending`, surfaces any `error`, and on success navigates via
102
- * `location.assign(url)`.
103
- *
104
- * Mirrors Convex's `CheckoutLink` / `CustomerPortalLink` flow (trigger an action
105
- * that returns a URL, then redirect) while staying agnostic of the app's
106
- * function names.
107
- */
108
- declare const useCheckout: (trigger: RedirectTrigger) => UseCheckoutResult;
109
- /**
110
- * Presentational props shared by the redirect buttons. Kept to a curated set
111
- * (rather than spreading arbitrary button attributes) so the component stays
112
- * within the repo's `react/jsx-props-no-spreading` rule while covering the
113
- * common styling / accessibility hooks.
114
- */
115
- interface RedirectButtonOwnProps {
116
- /** Accessible label when the visible `children` are icon-only. */
117
- "aria-label"?: string;
118
- children?: ReactNode;
119
- className?: string;
120
- /** Force-disable the control regardless of pending state. */
121
- disabled?: boolean;
122
- /** Called with the failure when the trigger rejects. The error is also surfaced via `useCheckout`. */
123
- onError?: (error: Error) => void;
124
- title?: string;
125
- }
126
- interface CheckoutButtonProps extends RedirectButtonOwnProps {
127
- /** Calls the app's checkout action and resolves the hosted-checkout `{ url }`. */
128
- onCheckout: RedirectTrigger;
129
- }
130
- interface CustomerPortalButtonProps extends RedirectButtonOwnProps {
131
- /** Calls the app's portal action and resolves the customer-portal `{ url }`. */
132
- onPortal: RedirectTrigger;
133
- }
134
- /**
135
- * Button that starts a hosted checkout. On click it awaits `onCheckout` (a thunk
136
- * that calls the app's checkout action) and redirects to the returned URL,
137
- * disabling itself while the request is in flight.
138
- */
139
- declare const CheckoutButton: ({ onCheckout, ...rest }: CheckoutButtonProps) => ReactNode;
140
- /**
141
- * Button that opens the provider's customer portal. On click it awaits
142
- * `onPortal` (a thunk that calls the app's portal action) and redirects to the
143
- * returned URL, disabling itself while the request is in flight.
144
- */
145
- declare const CustomerPortalButton: ({ onPortal, ...rest }: CustomerPortalButtonProps) => ReactNode;
146
74
  interface UseQueryOptions {
75
+ /**
76
+ * Called when the server pushes a subscription-scoped error (an RLS denial, a
77
+ * query that starts failing server-side). Without a handler such an error has
78
+ * nowhere to go and the hook's value simply freezes at its last good result.
79
+ */
80
+ onError?: SubscriptionErrorCallback;
147
81
  shardKey?: string;
148
82
  }
149
83
  interface UseMutationCallOptions<TCurrent = unknown, TValue = unknown, TArgs = unknown> {
84
+ /**
85
+ * Refuse rather than queue this write when the connection is down; see
86
+ * `MutationCallOptions.onlineOnly`. For a function with a `v.sensitive` argument
87
+ * the hook narrows this to `true`, since such a write is always online-only.
88
+ */
89
+ onlineOnly?: boolean;
90
+ /**
91
+ * Single-query shortcut forwarded to `client.mutation`: the transform is
92
+ * layered onto the subscription registered under **this write's own**
93
+ * `(reference, args, shardKey)` and nothing else. A `messages:send` mutation
94
+ * and a `messages:list` query share neither, so for that shape — nearly every
95
+ * shape — reach for {@link UseMutationCallOptions.optimisticUpdate}, whose
96
+ * store names the query it patches.
97
+ */
150
98
  optimistic?: (current: TCurrent | undefined) => TValue;
151
99
  /**
152
100
  * Convex-parity multi-query optimistic update forwarded to
@@ -163,9 +111,19 @@ interface UseSubscriptionResult<T> {
163
111
  interface UsePaginatedQueryOptions {
164
112
  /** Page size for the first page (and the default for `loadMore`). */
165
113
  initialNumItems: number;
114
+ /** Called when a page subscription (or its initial fetch) fails; also surfaced on `error`. */
115
+ onError?: SubscriptionErrorCallback;
166
116
  shardKey?: string;
167
117
  }
168
118
  interface UsePaginatedQueryResult<T> {
119
+ /**
120
+ * The last page failure, or `undefined`. A tail page that fails before its
121
+ * first frame is dropped so `status` returns to `"CanLoadMore"` and
122
+ * `loadMore` can retry it; the first page has nothing to fall back to and
123
+ * stays `"LoadingFirstPage"` with this set. Cleared by the next successful
124
+ * frame, by `loadMore`, or by an args change.
125
+ */
126
+ error: SubscriptionError | undefined;
169
127
  /** `true` while the first page or a `loadMore` page is in flight. */
170
128
  isLoading: boolean;
171
129
  /** Request the next page. A no-op unless `status === "CanLoadMore"`. */
@@ -177,9 +135,13 @@ interface UsePaginatedQueryResult<T> {
177
135
  interface UseInfiniteQueryOptions {
178
136
  /** Page size for the first page (and the default for `fetchNextPage`). */
179
137
  initialNumItems: number;
138
+ /** Called when a page subscription (or its initial fetch) fails; also surfaced on `error`. */
139
+ onError?: SubscriptionErrorCallback;
180
140
  shardKey?: string;
181
141
  }
182
142
  interface UseInfiniteQueryResult<T> {
143
+ /** The last page failure, or `undefined` — see `UsePaginatedQueryResult.error`. */
144
+ error: SubscriptionError | undefined;
183
145
  /** Request the next page. A no-op unless `status === "CanLoadMore"`. */
184
146
  fetchNextPage: (numberItems?: number) => void;
185
147
  /** `true` when the loaded tail reports it can load another page. */
@@ -194,9 +156,219 @@ interface UseInfiniteQueryResult<T> {
194
156
  }
195
157
  interface UseAuthResult {
196
158
  setToken: (token: string | null) => void;
159
+ /**
160
+ * The resolved auth state. Branch on this, not on `user === null` — see the
161
+ * contract in `@lunora/client/auth`; `user` is `null` both when signed out
162
+ * and when a held credential's identity could not be resolved.
163
+ */
164
+ status: AuthStatus;
197
165
  token: string | null;
198
166
  user: User | null;
199
167
  }
168
+ interface ActionHook<F extends FunctionReference> {
169
+ /**
170
+ * Invoke the action. Awaitable, and rejects on failure — the same contract
171
+ * as `useMutation`'s `mutate`.
172
+ */
173
+ call: (args: ArgsOf<F>, options?: ActionCallOptions) => Promise<ReturnOf<F>>;
174
+ /** The latest invocation's resolved value, or `undefined` before the first success. */
175
+ data: ReturnOf<F> | undefined;
176
+ /** The latest invocation's error, or `undefined`. */
177
+ error: Error | undefined;
178
+ /** `true` while ANY invocation from this hook is in flight (ref-counted, so overlapping calls compose). */
179
+ pending: boolean;
180
+ /** Clear the latest `data`/`error` back to idle. */
181
+ reset: () => void;
182
+ }
183
+ /**
184
+ * Returns `{ call, pending, data, error, reset }` for the given action reference.
185
+ * Prefer destructuring at the call site so the React linter can track
186
+ * dependencies on each field independently.
187
+ *
188
+ * Actions were the one procedure kind with no hook: `useQuery` and `useMutation`
189
+ * shipped, so every app that called an action reached for `useLunora()` and
190
+ * re-derived the same pending/error wrapper by hand. This is that wrapper, once.
191
+ *
192
+ * The request state machine is the shared `createCallRunner` from
193
+ * `@lunora/client` — the same one Vue, Solid and Svelte bind to their own
194
+ * primitives — so `pending`, error normalization and latest-invocation ordering
195
+ * behave identically in every adapter. Only the `useState` cells are React's.
196
+ * TanStack's mutation cache still carries the call so it shows up in Query
197
+ * Devtools alongside `useQuery`/`useMutation`.
198
+ *
199
+ * **Lifecycle contract** (identical across the adapters): `data` and `error`
200
+ * both track the LATEST invocation, not the last to settle — a double-click
201
+ * whose first call resolves after the second cannot overwrite the second's
202
+ * outcome. A success clears `error`; a failure leaves the previous `data` in
203
+ * place, so a transient error does not blank the view. `reset()` clears both,
204
+ * but does NOT cancel an in-flight call, whose result still lands.
205
+ *
206
+ * **Why the two TanStack defaults are overridden.** `networkMode` is `"always"`
207
+ * because the default `"online"` pauses the retryer *after* the call is already
208
+ * marked pending: offline, the promise would never settle, the spinner would
209
+ * stick, and the action would silently fire minutes later on reconnect. `retry`
210
+ * is pinned to `0` — not inherited from an app-supplied QueryClient — because
211
+ * `client.action` sends no idempotency key, so a retry after a 502 on an action
212
+ * that already ran server-side would run it a second time. `useMutation` pins
213
+ * both the same way, for a different reason: `client.mutation` queues an
214
+ * offline write itself, and a paused call would never reach that queue (it
215
+ * waits for the network itself only when the client cannot queue). An action
216
+ * has no queue at all, so offline it fails fast.
217
+ *
218
+ * **What it deliberately does not carry.** There is no `optimistic` /
219
+ * `optimisticUpdate` and no `withOptimisticUpdate`, which `useMutation` has. An
220
+ * optimistic update patches the subscription cache on the assumption the write
221
+ * will land; an action is not a write — it runs in the Worker, may call a third
222
+ * party, and has no declared effect on any query. Offering the option would
223
+ * imply a rollback guarantee nothing can honour.
224
+ *
225
+ * ```tsx
226
+ * const { call: runCommand, pending } = useAction(api.commands.run);
227
+ *
228
+ * await runCommand({ command: "lunora", args: ["verify"] });
229
+ * ```
230
+ *
231
+ * Not callable: `const run = useAction(api.x.y); run({ … })` is a `TS2349`.
232
+ * Destructure the invoker — `const { call: run } = useAction(api.x.y)`.
233
+ */
234
+ declare const useAction: <F extends FunctionReference>(function_: F) => ActionHook<F>;
235
+ /** The shape every list hook in this file returns. */
236
+ interface AdminAuthListResult<T> {
237
+ /** Rows loaded so far (the full current window, not just the latest page). `undefined` before the first response. */
238
+ readonly data: ReadonlyArray<T> | undefined;
239
+ /** The read error, or `undefined`. */
240
+ readonly error: Error | undefined;
241
+ /**
242
+ * `true` when the server reports more rows exist beyond the current window
243
+ * (`total > data.length`). `false` before the first response resolves.
244
+ */
245
+ readonly hasMore: boolean;
246
+ /** `true` only before the first response has resolved (matches TanStack's `isLoading`, not `isFetching`). */
247
+ readonly loading: boolean;
248
+ /**
249
+ * Grow the requested window by one page and re-fetch. A no-op while
250
+ * `hasMore` is `false`. This is a growing-window re-fetch (re-request
251
+ * `{ limit }` from the top), not a page-accumulator — `AuthPage` is
252
+ * offset/limit-based, not cursor-based, and there is no live delta stream
253
+ * to keep page boundaries stable against (unlike
254
+ * `@lunora/react`'s `usePaginatedQuery`). See the design doc for the
255
+ * trade-off.
256
+ */
257
+ readonly loadMore: () => void;
258
+ /** Re-run the read — e.g. after a caller performs a mutation via a plain `client.*` call (mirrors Studio's `onDone={refetchOrgs}` pattern). */
259
+ readonly refetch: () => void;
260
+ /** `AuthPage.total` — the server-reported row count across the whole collection, not just the current window. `undefined` before the first response. */
261
+ readonly total: number | undefined;
262
+ }
263
+ /** Options shared by every `useAuthUsers`-style hook. */
264
+ interface AdminAuthQueryOptions {
265
+ /** Gate the read (rules-of-hooks safe). Defaults to `true`. */
266
+ enabled?: boolean;
267
+ /** Page size for the first read; `loadMore` grows the window by this amount. Defaults to 50. */
268
+ pageSize?: number;
269
+ }
270
+ /** Options for {@link useAuthUsers}. */
271
+ interface UseAuthUsersOptions extends AdminAuthQueryOptions, AuthUsersListFilter {}
272
+ /**
273
+ * List authenticated users, paged and optionally searched/filtered/sorted.
274
+ * Hits the admin-gated `GET /_lunora/admin/auth/users` HTTP endpoint via
275
+ * `client.listAuthUsers` (never the WS/live transport) — the worker must be
276
+ * built with an `authAdmin` and `adminToken`.
277
+ *
278
+ * Mirrors `packages/studio/src/features/auth/users-panel.tsx`'s
279
+ * `useClientQuery(["lunora-auth-users", …], () => client.listAuthUsers(…))`
280
+ * read, minus the studio-specific polling (`useAutoRefresh`) — an app using
281
+ * this hook decides its own refresh cadence by calling `refetch()`.
282
+ */
283
+ declare const useAuthUsers: (options?: UseAuthUsersOptions) => AdminAuthListResult<AuthUser>;
284
+ /** Options for {@link useOrganizations}. */
285
+ type UseOrganizationsOptions = AdminAuthQueryOptions;
286
+ /**
287
+ * List organizations (requires the better-auth `organization` plugin).
288
+ * Hits `client.listAuthOrganizations` — an HTTP-only admin-gated read, same
289
+ * transport note as {@link useAuthUsers}.
290
+ *
291
+ * Mirrors `organizations-panel.tsx`'s
292
+ * `useClientQuery(["lunora-auth-orgs"], () => client.listAuthOrganizations({ limit: 100 }))`.
293
+ * Mutations (`client.createAuthOrganization`, `client.deleteAuthOrganization`,
294
+ * …) stay plain `client.*` calls; call this hook's `refetch()` afterward —
295
+ * see the design doc's "mutation ergonomics" section for why no hidden
296
+ * invalidation-on-mutate is wired in.
297
+ */
298
+ declare const useOrganizations: (options?: UseOrganizationsOptions) => AdminAuthListResult<Record<string, unknown>>;
299
+ /** Options for {@link useSignUpInvitations}. */
300
+ type UseSignUpInvitationsOptions = AdminAuthQueryOptions;
301
+ /**
302
+ * List sign-up invitations (requires the `inviteOnly` plugin). Hits
303
+ * `client.listAuthSignUpInvitations` — an HTTP-only admin-gated read, same
304
+ * transport note as {@link useAuthUsers}.
305
+ *
306
+ * Rows come back unfiltered and newest-first; a row is pending when `acceptedAt`
307
+ * is null and `expiresAt` is in the future. Mutations
308
+ * (`client.createAuthSignUpInvitation`, `client.revokeAuthSignUpInvitation`)
309
+ * stay plain `client.*` calls — call `refetch()` afterward, as the other admin
310
+ * hooks do.
311
+ */
312
+ declare const useSignUpInvitations: (options?: UseSignUpInvitationsOptions) => AdminAuthListResult<Record<string, unknown>>;
313
+ /** Options for {@link useAuthSessions}. */
314
+ interface UseAuthSessionsOptions extends AdminAuthQueryOptions {
315
+ /** Scope the list to one user's sessions; omit for the global cross-user browser. */
316
+ userId?: string;
317
+ }
318
+ /**
319
+ * List auth sessions, paged and optionally scoped to one user. Hits
320
+ * `client.listAuthSessions` — HTTP-only, same transport note as
321
+ * {@link useAuthUsers}.
322
+ *
323
+ * Mirrors `auth-sessions-panel.tsx`'s
324
+ * `useClientQuery(["lunora-auth-sessions", …], () => client.listAuthSessions({ limit }))`.
325
+ * Revoking a session (`client.revokeAuthSession`/`revokeAuthUserSessions`)
326
+ * stays a plain `client.*` call followed by this hook's `refetch()`.
327
+ */
328
+ declare const useAuthSessions: (options?: UseAuthSessionsOptions) => AdminAuthListResult<AuthSession>;
329
+ /** Everything {@link useImpersonate} returns. */
330
+ interface UseImpersonateResult {
331
+ /** The latest successful impersonation's token + user + expiry, or `undefined`. */
332
+ readonly data: AuthImpersonation | undefined;
333
+ /** The latest attempt's error, or `undefined`. */
334
+ readonly error: Error | undefined;
335
+ /**
336
+ * Mint an impersonation session for `userId`, resolving its bearer
337
+ * `AuthImpersonation`. Deliberately does **not** call
338
+ * `client.setAuthToken(...)` on the current client — see the security
339
+ * note below.
340
+ */
341
+ readonly impersonate: (userId: string) => Promise<AuthImpersonation>;
342
+ /** `true` while an impersonation request is in flight. */
343
+ readonly pending: boolean;
344
+ /** Clear `data`/`error` back to idle. */
345
+ readonly reset: () => void;
346
+ }
347
+ /**
348
+ * Mint an impersonation session via `client.impersonateAuthUser` — the one
349
+ * genuinely mutation-shaped hook of the four prototyped here (TanStack
350
+ * `useMutation` underneath, matching `@lunora/react`'s own `useMutation`
351
+ * ergonomics: `data`/`error`/`pending`/`reset`).
352
+ *
353
+ * **Security note (open question — see the design doc):** Studio's
354
+ * `user-detail-drawer.tsx` (`onImpersonate`) mints the token and displays it
355
+ * in a read-only text field; it never calls `client.setAuthToken(token)` on
356
+ * the admin's own client instance. This hook preserves that discipline
357
+ * deliberately — silently swapping the *current* session would sign the
358
+ * admin out of their own admin session with no visible transition and no
359
+ * "return to admin" path. The caller decides what to do with the resolved
360
+ * `AuthImpersonation` (open a second tab/incognito window authenticated as
361
+ * the target user, surface it for manual copy, etc.). What the ideal UX is
362
+ * (a dedicated "Acting as X — Return to admin" banner + explicit swap-back)
363
+ * is an open product question this spike does not resolve.
364
+ *
365
+ * Unlike the three list hooks, impersonating a user has no single paired
366
+ * list to invalidate (it may affect a sessions list, but not the user/org
367
+ * list currently being viewed) — mirroring Studio's own `refresh: false` on
368
+ * this action, this hook does not auto-invalidate anything. A caller that
369
+ * also renders `useAuthSessions` can call its `refetch()` explicitly.
370
+ */
371
+ declare const useImpersonate: () => UseImpersonateResult;
200
372
  /**
201
373
  * The lifecycle status stored on an agent thread. Client-safe mirror of
202
374
  * `@lunora/agent`'s `AgentThreadStatus` — re-declared here (rather than imported)
@@ -213,8 +385,12 @@ type AgentThreadStatus = "awaiting_input" | "cancelled" | "error" | "idle" | "ru
213
385
  */
214
386
  interface AgentThreadRecord {
215
387
  createdAt?: number;
216
- /** The failure message when `status === "error"`. */
217
- error?: string;
388
+ /**
389
+ * The failure message when `status === "error"`, `null` once a later run
390
+ * cleared it, absent on a thread that has never failed. Read it for
391
+ * truthiness — `null` and absent both mean "no error".
392
+ */
393
+ error?: null | string;
218
394
  /** The workflow instance id of the in-flight run — the handle `cancel` targets. */
219
395
  instanceId?: string;
220
396
  messageCount?: number;
@@ -241,14 +417,20 @@ interface UseAgentOptions {
241
417
  api: UseAgentApi;
242
418
  /**
243
419
  * Optional app mutation over the agent's cancel path
244
- * (`ctx.agents.&lt;name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
420
+ * (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
245
421
  * When omitted (or no run is in flight) {@link UseAgentResult.cancel} is a
246
422
  * no-op.
247
423
  */
248
424
  cancel?: FunctionReference<"mutation">;
425
+ /**
426
+ * Called when the live thread subscription reports an error (a session
427
+ * expiry, an RLS denial). Without it — and without reading `error` — such a
428
+ * failure is invisible and `thread` / `status` freeze at their last value.
429
+ */
430
+ onError?: SubscriptionErrorCallback;
249
431
  /**
250
432
  * The app mutation that starts (or continues) a run — a thin wrapper over
251
- * `ctx.agents.&lt;name>.run(...)`. Called with `{ threadKey, input }` merged with
433
+ * `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
252
434
  * {@link UseAgentOptions.runArgs} and the per-call args.
253
435
  */
254
436
  run: FunctionReference<"mutation">;
@@ -263,6 +445,8 @@ interface UseAgentResult {
263
445
  * no-op when no `cancel` mutation was supplied or no run is in flight.
264
446
  */
265
447
  cancel: () => Promise<void>;
448
+ /** The live thread subscription's last error, or `undefined`. */
449
+ error: Error | undefined;
266
450
  /** `true` while a `run` invocation is in flight. */
267
451
  pending: boolean;
268
452
  /** Start (or continue) a run with a user message; extra args merge over `runArgs`. */
@@ -280,10 +464,58 @@ interface UseAgentResult {
280
464
  * `useAgentChat`.
281
465
  *
282
466
  * `run` and `cancel` stay generic over the app-defined mutations that wrap
283
- * `ctx.agents.&lt;name>.run` / `.cancel`, so the hook hard-codes no function names
467
+ * `ctx.agents.<name>.run` / `.cancel`, so the hook hard-codes no function names
284
468
  * beyond the `agents:*` surface.
285
469
  */
286
470
  declare const useAgent: (options: UseAgentOptions) => UseAgentResult;
471
+ /**
472
+ * One human-in-the-loop approval a run is paused on, on a thread the caller
473
+ * owns. Carries the triple `agents.agentResolveApproval` takes, so a UI can
474
+ * approve or reject straight from the list.
475
+ */
476
+ interface PendingApproval {
477
+ agent: string;
478
+ content: string;
479
+ instanceId: string;
480
+ requestedAt: number;
481
+ threadKey: string;
482
+ threadTitle?: string;
483
+ threadUpdatedAt: number;
484
+ toolCallId: string;
485
+ toolName?: string;
486
+ }
487
+ /**
488
+ * The `agents.agentPendingApprovals` reference the hook subscribes to. A
489
+ * structural subset of the generated `api.agents` surface, so the whole
490
+ * generated `api` object is assignable. Typed as a loose record for the same
491
+ * reason `useAgentState` is: codegen cannot see the runtime row shape, so the
492
+ * hook casts to {@link PendingApproval}.
493
+ */
494
+ interface UseAgentApprovalsApi {
495
+ agents: {
496
+ agentPendingApprovals: FunctionReference<"query", {
497
+ limit?: number;
498
+ }, Record<string, unknown>[]>;
499
+ };
500
+ }
501
+ interface UseAgentApprovalsOptions {
502
+ /** The generated `api` — its `agents.agentPendingApprovals` query drives the inbox. */
503
+ api: UseAgentApprovalsApi;
504
+ }
505
+ interface UseAgentApprovalsResult {
506
+ /** The caller's pending approvals, newest thread first; `undefined` before the first frame. */
507
+ approvals: PendingApproval[] | undefined;
508
+ /** The subscription error, if the live channel reported one. */
509
+ error: Error | undefined;
510
+ }
511
+ /**
512
+ * Subscribe to the caller's approvals inbox: every run of theirs currently
513
+ * paused on a gated tool. A thin wrapper over
514
+ * `useSubscription(api.agents.agentPendingApprovals, {})` — the server pushes a
515
+ * fresh list whenever a pause starts or is resolved. Anonymous callers receive
516
+ * an empty list.
517
+ */
518
+ declare const useAgentApprovals: (options: UseAgentApprovalsOptions) => UseAgentApprovalsResult;
287
519
  /**
288
520
  * One persisted (or optimistic) thread message, as `agents:agentMessages`
289
521
  * surfaces it. Client-safe mirror of `@lunora/agent`'s `AgentMessageRow` —
@@ -301,8 +533,8 @@ interface AgentChatMessage {
301
533
  optimistic?: boolean;
302
534
  role: "assistant" | "system" | "tool" | "user";
303
535
  seq: number;
304
- /** Approval lifecycle marker on a human-in-the-loop tool message. */
305
- status?: "approved" | "awaiting_approval" | "rejected";
536
+ /** Approval or secret-request lifecycle marker on a human-in-the-loop tool message. */
537
+ status?: "approved" | "awaiting_approval" | "awaiting_secret" | "rejected";
306
538
  toolCallId?: string;
307
539
  toolCalls?: ReadonlyArray<{
308
540
  id: string;
@@ -356,7 +588,7 @@ type AgentMessagesReference$1 = FunctionReference<"query", {
356
588
  }, ReadonlyArray<Record<string, unknown>>>;
357
589
  /** The `agents:agentResolveApproval` reference — resolves a human-in-the-loop tool approval. */
358
590
  type AgentApprovalReference = FunctionReference<"mutation", {
359
- decision: "approve" | "reject";
591
+ decision: "approve" | "approve_for_thread" | "reject";
360
592
  instanceId: string;
361
593
  note?: string;
362
594
  threadKey: string;
@@ -364,10 +596,41 @@ type AgentApprovalReference = FunctionReference<"mutation", {
364
596
  }, {
365
597
  resolved: boolean;
366
598
  }>;
599
+ /** The `agents:agentSupplySecret` reference — stores a person's value for a paused `requestSecretTool` call. */
600
+ type AgentSupplySecretReference = FunctionReference<"mutation", {
601
+ secret: string;
602
+ threadKey: string;
603
+ toolCallId: string;
604
+ }, {
605
+ resolved: boolean;
606
+ }>;
607
+ /** The `agents:agentDeclineSecret` reference — refuses a paused `requestSecretTool` call. */
608
+ type AgentDeclineSecretReference = FunctionReference<"mutation", {
609
+ threadKey: string;
610
+ toolCallId: string;
611
+ }, {
612
+ resolved: boolean;
613
+ }>;
367
614
  /** The `agents:agentThread` reference — live thread status + in-flight `instanceId`. */
368
615
  type AgentThreadReference = FunctionReference<"query", {
369
616
  key: string;
370
617
  }, Record<string, unknown> | undefined>;
618
+ /** A tool approved for the rest of a thread, as `agents:agentApprovalGrants` lists it. */
619
+ interface AgentApprovalGrant {
620
+ createdAt: number;
621
+ toolName: string;
622
+ }
623
+ /** The `agents:agentApprovalGrants` reference — live thread-scoped approval grants. */
624
+ type AgentApprovalGrantsReference = FunctionReference<"query", {
625
+ key: string;
626
+ }, ReadonlyArray<AgentApprovalGrant>>;
627
+ /** The `agents:agentRevokeApprovalGrant` reference — removes a thread-scoped approval grant. */
628
+ type AgentRevokeApprovalGrantReference = FunctionReference<"mutation", {
629
+ threadKey: string;
630
+ toolName: string;
631
+ }, {
632
+ revoked: boolean;
633
+ }>;
371
634
  /**
372
635
  * An app stream reference that tees the agent's in-flight live events, keyed by
373
636
  * thread. Carries token deltas and — since `ctx.reportProgress` rides the same
@@ -382,8 +645,12 @@ type AgentTokenStreamReference = FunctionReference<"stream", {
382
645
  */
383
646
  interface UseAgentChatApi {
384
647
  agents: {
648
+ agentApprovalGrants: AgentApprovalGrantsReference;
649
+ agentDeclineSecret: AgentDeclineSecretReference;
385
650
  agentMessages: AgentMessagesReference$1;
386
651
  agentResolveApproval: AgentApprovalReference;
652
+ agentRevokeApprovalGrant: AgentRevokeApprovalGrantReference;
653
+ agentSupplySecret: AgentSupplySecretReference;
387
654
  agentThread: AgentThreadReference;
388
655
  };
389
656
  }
@@ -392,16 +659,23 @@ interface UseAgentChatOptions {
392
659
  api: UseAgentChatApi;
393
660
  /**
394
661
  * Optional app mutation over the agent's cancel path
395
- * (`ctx.agents.&lt;name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
662
+ * (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
396
663
  * When omitted (or no run is in flight) {@link UseAgentChatResult.cancel} is a
397
664
  * no-op.
398
665
  */
399
666
  cancel?: FunctionReference<"mutation">;
400
667
  /** History depth forwarded to `agents:agentMessages`. */
401
668
  limit?: number;
669
+ /**
670
+ * Called when the live history, thread, or grants subscription reports an error (a
671
+ * session expiry, an RLS denial). Without it — and without reading `error` —
672
+ * such a failure is invisible and `messages` / `status` freeze at their last
673
+ * value.
674
+ */
675
+ onError?: SubscriptionErrorCallback;
402
676
  /**
403
677
  * The app mutation that starts (or continues) a run — a thin wrapper over
404
- * `ctx.agents.&lt;name>.run(...)`. Called with `{ threadKey, input }` merged with
678
+ * `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
405
679
  * {@link UseAgentChatOptions.sendArgs} and the per-call args.
406
680
  */
407
681
  send: FunctionReference<"mutation">;
@@ -417,27 +691,47 @@ interface UseAgentChatOptions {
417
691
  threadKey: string;
418
692
  }
419
693
  interface UseAgentChatResult {
694
+ /** The tools approved for the rest of this thread, live. Empty until the grants subscription answers. */
695
+ approvalGrants: ReadonlyArray<AgentApprovalGrant>;
420
696
  /** Approve a paused human-in-the-loop tool call (optionally with a note). */
421
697
  approve: (toolCallId: string, note?: string) => Promise<void>;
698
+ /**
699
+ * Approve a paused tool call and grant that tool for the rest of the thread, so
700
+ * later calls to it run without pausing. Undo with {@link UseAgentChatResult.revokeGrant}.
701
+ */
702
+ approveForThread: (toolCallId: string, note?: string) => Promise<void>;
422
703
  /**
423
704
  * Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
424
705
  * no-op when no `cancel` mutation was supplied or no run is in flight.
425
706
  */
426
707
  cancel: () => Promise<void>;
708
+ /** Refuse a paused `requestSecretTool` call: the run resumes with a "declined" result. */
709
+ declineSecret: (toolCallId: string) => Promise<void>;
710
+ /** The history, thread, or grants subscription's last error, or `undefined`. */
711
+ error: Error | undefined;
427
712
  /** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. */
428
713
  messages: ReadonlyArray<AgentChatMessage>;
429
714
  /** Reject a paused human-in-the-loop tool call (optionally with a reason). */
430
715
  reject: (toolCallId: string, note?: string) => Promise<void>;
716
+ /** Remove a thread-scoped approval grant so the tool's gate applies again to later calls. */
717
+ revokeGrant: (toolName: string) => Promise<void>;
431
718
  /** Start (or continue) a run with a user message; extra args merge over `sendArgs`. Appends an optimistic user turn. */
432
719
  send: (input: string, args?: Record<string, unknown>) => Promise<void>;
433
720
  /** The live thread status, or `undefined` before the thread exists. */
434
721
  status: AgentThreadStatus | undefined;
435
722
  /** The in-flight turn's streamed text — live-only, empty once the turn persists to `messages`. */
436
723
  streamingText: string;
724
+ /**
725
+ * Give a paused `requestSecretTool` call its value. Always sent online-only: the
726
+ * value is never queued, persisted or replayed, and the call rejects with
727
+ * `OFFLINE_NOT_QUEUED` while the connection is down. The hook keeps no copy; a
728
+ * failure rethrows the original error.
729
+ */
730
+ supplySecret: (toolCallId: string, secret: string) => Promise<void>;
437
731
  }
438
732
  /**
439
733
  * A first-class agent chat surface: live durable history + in-flight token
440
- * streaming + the send / approve / reject / cancel writes, keyed by `threadKey`.
734
+ * streaming + the send / approve / reject / secret / cancel writes, keyed by `threadKey`.
441
735
  *
442
736
  * It composes the existing primitives rather than adding transport:
443
737
  * `useSubscription(api.agents.agentMessages)` for durable history,
@@ -530,7 +824,7 @@ interface UseAgentToolEventsOptions {
530
824
  * Optional live event stream — the same app stream function `useAgentChat`
531
825
  * uses. When supplied, ephemeral `ctx.reportProgress(...)` events for the
532
826
  * thread are surfaced as `{ type: "progress" }` entries; when omitted only the
533
- * durable lifecycle (call / result / awaiting-approval) is returned.
827
+ * durable lifecycle (call / result / awaiting-approval / awaiting-secret) is returned.
534
828
  */
535
829
  stream?: AgentLiveStreamReference;
536
830
  /** The thread whose tool activity to observe. */
@@ -538,7 +832,7 @@ interface UseAgentToolEventsOptions {
538
832
  }
539
833
  /**
540
834
  * A single tool-lifecycle event for a thread. The durable arms
541
- * (`call`/`result`/`awaiting-approval`) are derived from `agents:agentMessages`
835
+ * (`call`/`result`/`awaiting-approval`/`awaiting-secret`) are derived from `agents:agentMessages`
542
836
  * and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
543
837
  * stream and has no `seq`. Discriminate on `type`.
544
838
  */
@@ -564,6 +858,11 @@ type AgentToolEvent = {
564
858
  toolCallId?: string;
565
859
  toolName?: string;
566
860
  type: "awaiting-approval";
861
+ } | {
862
+ seq: number;
863
+ toolCallId?: string;
864
+ toolName?: string;
865
+ type: "awaiting-secret";
567
866
  };
568
867
  interface UseAgentToolEventsResult {
569
868
  /**
@@ -589,14 +888,18 @@ declare const useAgentToolEvents: (options: UseAgentToolEventsOptions) => UseAge
589
888
  /**
590
889
  * Token + identity plumbing. The token lives on the shared `LunoraClient`;
591
890
  * `setToken(jwt)` after a sign-in makes subsequent RPC calls carry the
592
- * `Authorization` header. `user` is resolved from better-auth's `get-session`
593
- * endpoint via `client.getCurrentUser()` — fetched on mount and refetched
594
- * whenever the token changes (`onAuthTokenChange`), and `null` when signed out.
595
- *
596
- * Multiple `useAuth` instances stay in sync: both `token` and `user` are read
597
- * through `useSyncExternalStore` over the shared client (and a per-client
598
- * identity store), so a `setToken` from one component re-renders every mounted
599
- * hook with the freshly-resolved user.
891
+ * `Authorization` header. `user` and `status` come from the framework-agnostic
892
+ * per-client identity store in `@lunora/client/auth` — the same store Vue,
893
+ * Solid, Svelte and Angular read, so all five agree on what "authenticated"
894
+ * means rather than each keeping a private copy of the resolve logic.
895
+ *
896
+ * `status` is the value to branch on: `user` is `null` both when signed out and
897
+ * when a held credential's identity endpoint could not be reached. See the
898
+ * contract documented on `AuthStatus`.
899
+ *
900
+ * Multiple `useAuth` instances stay in sync: token, user and status are all read
901
+ * through `useSyncExternalStore` over the shared client and its identity store,
902
+ * so a `setToken` from one component re-renders every mounted hook.
600
903
  */
601
904
  declare const useAuth: () => UseAuthResult;
602
905
  type Setter<T> = (value: T) => void;
@@ -631,8 +934,6 @@ declare const useClientQuery: <T extends unknown>(ref: ClientQueryRef<T>) => [T,
631
934
  * operator can tell a healthy live channel from a silently-dropped socket.
632
935
  */
633
936
  declare const useConnectionStatus: () => ConnectionStatus;
634
- /** A targeting context merged on top of the app's default (`defineFlags({ identify })`). */
635
- type FlagContext = Record<string, unknown>;
636
937
  /** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
637
938
  type FlagValue = boolean | number | string | {
638
939
  [key: string]: unknown;
@@ -644,53 +945,34 @@ type FlagValue = boolean | number | string | {
644
945
  * resolved value — re-pushed whenever the provider re-evaluates (e.g. a flag is
645
946
  * toggled in Cloudflare Flagship). The flag's kind is inferred from
646
947
  * `defaultValue`'s runtime type, so `useFlag("dark", false)` reads a boolean and
647
- * `useFlag("hero", "control")` a string. `context` supplies a per-call targeting
648
- * context merged on top of the app's default `identify` targeting key.
948
+ * `useFlag("hero", "control")` a string.
949
+ *
950
+ * The reactive channel is public, so the server evaluates every flag under the
951
+ * socket's own verified identity — the targeting key your `defineFlags({
952
+ * identify })` derives — and accepts no client-supplied targeting context. For
953
+ * evaluation under a context you compute, call `ctx.flags.*` inside a query,
954
+ * mutation, or action and return the resolved value.
649
955
  *
650
956
  * Evaluation runs through whatever OpenFeature provider the app wired in
651
957
  * `lunora/flags.ts`; the read never throws — a provider error resolves the
652
958
  * default (the same fail-open contract as server-side `ctx.flags`).
653
959
  */
654
- declare const useFlag: <T extends FlagValue>(key: string, defaultValue: T, context?: FlagContext) => T;
960
+ declare const useFlag: <T extends FlagValue>(key: string, defaultValue: T) => T;
655
961
  /**
656
962
  * Subscribe to several feature flags at once, live over Lunora's WebSocket.
657
963
  *
658
964
  * Pass a record of `key → defaultValue`; each flag's kind is inferred from its
659
965
  * default, and the result is the same-shaped record with resolved values (the
660
- * defaults until each evaluation lands). A single `context` applies to every
661
- * flag. This is the batched form of {@link useFlag} — one effect manages one
662
- * subscription per key, so it stays rules-of-hooks-safe even as the flag set
663
- * changes between renders.
966
+ * defaults until each evaluation lands). This is the batched form of
967
+ * {@link useFlag} — one effect manages one subscription per key, so it stays
968
+ * rules-of-hooks-safe even as the flag set changes between renders. Like
969
+ * {@link useFlag} it evaluates under the socket's server-verified identity only.
664
970
  */
665
- declare const useFlags: <T extends Record<string, FlagValue>>(flags: T, context?: FlagContext) => T;
971
+ declare const useFlags: <T extends Record<string, FlagValue>>(flags: T) => T;
666
972
  /** The lifecycle of a stream the hook is observing. */
667
973
  type UseStreamStatus = "complete" | "error" | "idle" | "streaming";
668
- interface UseStreamResult<T> {
669
- /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
670
- cancel: () => void;
671
- /** Chunks the server has pushed so far, in arrival order. */
672
- chunks: ReadonlyArray<T>;
673
- error: Error | undefined;
674
- status: UseStreamStatus;
675
- }
676
- interface UseStreamOptions {
677
- /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
678
- maxBuffer?: number;
679
- shardKey?: string;
680
- }
681
- /**
682
- * Subscribe to a streaming query. Returns the chunks pushed so far plus a
683
- * lifecycle status and a cancel function. Changing `fn` or the serialized
684
- * `args` resets the stream — the previous iterator is cancelled and a fresh
685
- * one opens with empty `chunks`.
686
- *
687
- * Pass `"skip"` for `args` to keep the hook mounted without opening a stream
688
- * (mirrors `useQuery` / `useSubscription`).
689
- */
690
- declare const useStream: <F extends FunctionReference<"stream">>(function_: F, args: "skip" | ArgsOf<F>, options?: UseStreamOptions) => UseStreamResult<ReturnOf<F>>;
691
974
  /**
692
975
  * Result shape returned by {@link useHttpStream}.
693
- * @experimental Part of the HTTP-SSE stream surface.
694
976
  */
695
977
  interface UseHttpStreamResult<T> {
696
978
  /** Force-cancel the stream (aborts the fetch) and resolve the iterator. Safe to call multiple times. */
@@ -702,14 +984,13 @@ interface UseHttpStreamResult<T> {
702
984
  }
703
985
  /**
704
986
  * Options accepted by {@link useHttpStream}.
705
- * @experimental Part of the HTTP-SSE stream surface.
706
987
  */
707
988
  interface UseHttpStreamOptions {
708
989
  /** Forwarded to `client.httpStream()` — caps the in-flight chunk buffer. */
709
990
  maxBuffer?: number;
710
991
  }
711
992
  /**
712
- * Consume an **HTTP-SSE route stream** (`httpRoute.&lt;verb>(path).stream()`) via
993
+ * Consume an **HTTP-SSE route stream** (`httpRoute.<verb>(path).stream()`) via
713
994
  * `client.httpStream`. Distinct from `useStream`, which consumes the WS
714
995
  * procedure stream (`kind: "stream"`). Returns the chunks received so far plus
715
996
  * a lifecycle status and a cancel function. Changing the route or the
@@ -719,7 +1000,6 @@ interface UseHttpStreamOptions {
719
1000
  *
720
1001
  * Pass `"skip"` for `args` to keep the hook mounted without opening a stream
721
1002
  * (mirrors `useQuery` / `useStream`).
722
- * @experimental Reconnect/POST-body/wire-fidelity design questions are still open, so the shape may change.
723
1003
  */
724
1004
  declare const useHttpStream: <Ref extends HttpStreamRef>(route: Ref, args: "skip" | HttpStreamArgsOf<Ref>, options?: UseHttpStreamOptions) => UseHttpStreamResult<HttpStreamChunkOf<Ref>>;
725
1005
  /** The args a paginated query exposes minus the framework-supplied page cursor. */
@@ -731,6 +1011,10 @@ type PageItemOf<F> = ReturnOf<F> extends {
731
1011
  /**
732
1012
  * Subscribe to a reactively-paginated query and grow the feed page by page.
733
1013
  *
1014
+ * Pass `onError` (and read `error`) to see a page failure: without it the hook
1015
+ * only reports `status`, and a first page that fails reads as an eternal
1016
+ * `isLoading`.
1017
+ *
734
1018
  * The query function must accept a `paginationOpts: { numItems, cursor,
735
1019
  * endCursor }` arg and return a `PaginationResult` (the shape
736
1020
  * `ctx.db.query(...).paginate` yields). Pages are tracked as an ordered list of
@@ -749,6 +1033,12 @@ type PageItemOf<F> = ReturnOf<F> extends {
749
1033
  * Changing `fn`, the base `args`, `initialNumItems`, or `shardKey` resets the
750
1034
  * feed to its first page. The public return shape (`results` / `status` /
751
1035
  * `loadMore`) is unchanged from the legacy keyset implementation.
1036
+ *
1037
+ * There is no total-row count here, and deliberately not: `paginate()` never
1038
+ * counts the tail, which is what keeps a page O(page) rather than O(table). For
1039
+ * a "42 of 1,203" label, subscribe to a `ctx.db.<table>.count(where)` query with
1040
+ * the same filter args via `useQuery` — it is live, so it moves with the
1041
+ * list. See the pagination concept page.
752
1042
  */
753
1043
  declare const usePaginatedQuery: <F extends FunctionReference>(function_: F, args: "skip" | PaginatedArgs<F>, options: UsePaginatedQueryOptions) => UsePaginatedQueryResult<PageItemOf<F>>;
754
1044
  /**
@@ -768,7 +1058,34 @@ declare const usePaginatedQuery: <F extends FunctionReference>(function_: F, arg
768
1058
  * keyset implementation.
769
1059
  */
770
1060
  declare const useInfiniteQuery: <F extends FunctionReference>(function_: F, args: "skip" | PaginatedArgs<F>, options: UseInfiniteQueryOptions) => UseInfiniteQueryResult<PageItemOf<F>>;
771
- type CallOptions<F extends FunctionReference> = UseMutationCallOptions<unknown, unknown, ArgsOf<F>>;
1061
+ /** Options for {@link useLiveTopic}: the transport tuning and callbacks, with the callbacks read through a ref. */
1062
+ type UseLiveTopicOptions<Payload = unknown> = LiveTopicOptions<Payload>;
1063
+ interface UseLiveTopicResult<Payload = unknown> {
1064
+ /** Set when the shard refuses the subscription (403, 409, 429 and similar). */
1065
+ error: LiveStreamSubscribeError | undefined;
1066
+ /** The last payload delivered on the topic, or `undefined` until the first event. */
1067
+ lastEvent: Payload | undefined;
1068
+ }
1069
+ /**
1070
+ * `useLiveTopic` — follow one live topic of a `defineLiveStream` for the life of
1071
+ * the component. Pass the reference `_generated/live.ts` hands out
1072
+ * (`live.posts.post({ postId })`): the stream's route is resolved against the
1073
+ * `LunoraClient` from the nearest `<LunoraProvider>`, and `lastEvent` and `onEvent`
1074
+ * are typed by the payload the topic declares.
1075
+ *
1076
+ * It is a lifecycle wrapper over `subscribeLiveTopic`: the connection itself is
1077
+ * shared by URL, so mounting this hook ten times still opens one stream. It
1078
+ * subscribes on mount, unsubscribes on unmount, and resubscribes only when the
1079
+ * connection inputs (topic, shard, credentials, headers, retry tuning) change.
1080
+ * Building the reference inline on every render is fine, since only its content
1081
+ * counts. Changing `onEvent` or `onError` identity does not resubscribe — the
1082
+ * latest callback is read through a ref.
1083
+ *
1084
+ * It is a no-op during SSR: effects do not run on the server, so the hook returns
1085
+ * its initial values there.
1086
+ */
1087
+ declare function useLiveTopic<Payload>(topic: LiveTopicRef<Payload>, options?: UseLiveTopicOptions<Payload>): UseLiveTopicResult<Payload>;
1088
+ type CallOptions<F extends FunctionReference> = OnlineOnlyOption<F> & UseMutationCallOptions<unknown, unknown, ArgsOf<F>>;
772
1089
  interface MutationHook<F extends FunctionReference> {
773
1090
  /** The latest invocation's resolved value, or `undefined` before the first success. */
774
1091
  data: ReturnOf<F> | undefined;
@@ -794,6 +1111,9 @@ interface MutationHook<F extends FunctionReference> {
794
1111
  * given mutation reference. Prefer destructuring at the call site so the React
795
1112
  * linter can track dependencies on each field independently.
796
1113
  *
1114
+ * Not callable: `const send = useMutation(api.x.y); send({ … })` is a `TS2349`.
1115
+ * Destructure the invoker — `const { mutate: send } = useMutation(api.x.y)`.
1116
+ *
797
1117
  * Built on TanStack Query's mutation cache (the same cache the query hooks use),
798
1118
  * so it composes with Query Devtools and exposes the latest call's `data`/`error`
799
1119
  * plus `reset()`. `mutate` maps to `mutateAsync`, so it stays an awaitable that
@@ -809,6 +1129,17 @@ interface MutationHook<F extends FunctionReference> {
809
1129
  * call options pass straight through to `client.mutation`, which applies and
810
1130
  * rolls them back against the Lunora subscription cache (Convex parity) — not
811
1131
  * through TanStack's `onMutate`.
1132
+ *
1133
+ * Offline, a write the client can queue reaches `client.mutation` at once,
1134
+ * which queues it (the offline queue or a durable outbox) and paints the
1135
+ * optimistic update. A write it cannot queue (before the shard's first connect,
1136
+ * or with no WebSocket) waits until the browser is online again, then sends.
1137
+ * TanStack never retries; the queue owns replays. An online-only write (`onlineOnly:
1138
+ * true`, or any call to a function with a `v.sensitive` argument) is not held for a
1139
+ * later send: it reaches `client.mutation` at once and rejects with
1140
+ * `OFFLINE_NOT_QUEUED` if the network is down. Such a call also leaves TanStack's
1141
+ * mutation cache, and with it the call's arguments, as soon as nothing observes it
1142
+ * (the hook still holds the latest call while mounted).
812
1143
  */
813
1144
  declare const useMutation: <F extends FunctionReference>(function_: F) => MutationHook<F>;
814
1145
  interface MutatorHook<TArgs> {
@@ -850,8 +1181,24 @@ declare const useMutator: <TArgs = Record<string, unknown>>(handle: MutatorHandl
850
1181
  * value directly. Apps that want to share a pre-populated QueryClient across
851
1182
  * many preloaded queries can pass their own `queryClient` to `LunoraProvider`
852
1183
  * and hydrate it themselves via TanStack's `hydrate(qc, dehydratedState)`.
1184
+ *
1185
+ * Pass `onError` to surface a subscription-scoped error the server pushes (a
1186
+ * session expiry, an RLS denial). Without it such an error is dropped and the
1187
+ * hook keeps rendering the SSR snapshot as if it were live.
1188
+ *
1189
+ * The preloaded value was read for whoever was signed in when the page loaded.
1190
+ * After a sign-out or user switch retires an identity (`client.identityEpoch()`
1191
+ * above `0`), every `usePreloadedQuery` on the client (mounted then or later)
1192
+ * stops using it and returns `undefined` until the live value arrives. So does
1193
+ * every one under a `LunoraProvider` whose `client` was swapped, mounted before
1194
+ * or after the swap — hence the `T | undefined` return type. A token
1195
+ * preloaded after the switch (a client-side navigation that preloads again) is
1196
+ * ignored too and costs a loading flash: the hook cannot tell which identity a
1197
+ * token was read under.
853
1198
  */
854
- declare const usePreloadedQuery: <T>(preloaded: Preloaded<T>) => T;
1199
+ declare const usePreloadedQuery: <T>(preloaded: Preloaded<T>, options?: {
1200
+ onError?: SubscriptionErrorCallback;
1201
+ }) => T | undefined;
855
1202
  /**
856
1203
  * The PLAN4 §1 framework-neutral name for the preloaded-hydration handoff:
857
1204
  * `hydratePreloaded(preloaded)` seeds the SSR value on the first paint, then
@@ -863,7 +1210,9 @@ declare const usePreloadedQuery: <T>(preloaded: Preloaded<T>) => T;
863
1210
  * It carries React's Rules-of-Hooks contract (it calls hooks internally), so
864
1211
  * call it like a hook — at the top level of a component, unconditionally.
865
1212
  */
866
- declare const hydratePreloaded: <T>(preloaded: Preloaded<T>) => T;
1213
+ declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, options?: {
1214
+ onError?: SubscriptionErrorCallback;
1215
+ }) => T | undefined;
867
1216
  /**
868
1217
  * `usePresence` — collaborative-awareness hook, the client half of the
869
1218
  * `@lunora/server` `definePresence` preset (Convex `@convex-dev/presence`
@@ -916,6 +1265,12 @@ interface UsePresenceOptions<H extends HeartbeatReference, L extends ListPresent
916
1265
  intervalMs?: number;
917
1266
  /** The `api.*` reference for the presence listPresent query. */
918
1267
  listPresent: L;
1268
+ /**
1269
+ * Called when the `listPresent` subscription reports an error (a session
1270
+ * expiry, an RLS denial). Without it — and without reading `error` — such a
1271
+ * failure is invisible and `present` freezes at its last value.
1272
+ */
1273
+ onError?: SubscriptionErrorCallback;
919
1274
  /**
920
1275
  * Stable id for this presence row. Defaults to a fresh per-mount id (one row
921
1276
  * per tab). Pass a user/connection id to control deduping.
@@ -925,6 +1280,8 @@ interface UsePresenceOptions<H extends HeartbeatReference, L extends ListPresent
925
1280
  shardKey?: string;
926
1281
  }
927
1282
  interface UsePresenceResult<L extends ListPresentReference> {
1283
+ /** The `listPresent` subscription's last error, or `undefined`. */
1284
+ error: SubscriptionError | undefined;
928
1285
  /** The present members for the room, as `listPresent` returns them. `undefined` until the first push. */
929
1286
  present: ReturnOf<L> | undefined;
930
1287
  /** This mount's session id (generated when not supplied). */
@@ -946,10 +1303,15 @@ declare const usePresence: <H extends HeartbeatReference, L extends ListPresentR
946
1303
  * flash before the socket round-trip.
947
1304
  *
948
1305
  * Internally this routes through TanStack Query: the queryKey is
949
- * `["lunora", fn.__lunoraRef, args, shardKey]` (TanStack hashes structurally
950
- * so an args object built in a different key order still dedupes). The
1306
+ * `["lunora", fn.__lunoraRef, stableWireKey(args), shardKey]` (the args are
1307
+ * encoded key-order-independently, so an args object built in a different key
1308
+ * order still dedupes, and wire-typed args get distinct entries). The
951
1309
  * subscription registry shares a single WS subscription across every consumer
952
1310
  * of the same queryKey; pushes call `queryClient.setQueryData(...)`.
1311
+ *
1312
+ * Pass `onError` to surface a subscription-scoped error the server pushes (an RLS
1313
+ * denial, a query that starts failing server-side). Without it such an error is
1314
+ * dropped and the returned value just freezes at its last good result.
953
1315
  */
954
1316
  declare const useQuery: <F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip", options?: UseQueryOptions) => ReturnOf<F> | undefined;
955
1317
  interface UseRateLimitOptions {
@@ -985,12 +1347,63 @@ interface UseRateLimitResult {
985
1347
  * `useMemo`) so the `consume`/`check` callbacks keep a steady identity.
986
1348
  */
987
1349
  declare const useRateLimit: (config: RateLimitConfig, options?: UseRateLimitOptions) => UseRateLimitResult;
1350
+ interface UseStreamResult<T> {
1351
+ /** Force-cancel the stream and resolve the iterator. Safe to call multiple times. */
1352
+ cancel: () => void;
1353
+ /** Chunks the server has pushed so far, in arrival order. */
1354
+ chunks: ReadonlyArray<T>;
1355
+ error: Error | undefined;
1356
+ status: UseStreamStatus;
1357
+ }
1358
+ interface UseStreamOptions {
1359
+ /**
1360
+ * Opt into resume-on-reconnect for a stream the server declared `durable`.
1361
+ * The hook keeps the chunks it already has and the socket re-attaches to the
1362
+ * same run, so a dropped connection mid-generation continues instead of
1363
+ * surfacing `STREAM_DISCONNECTED`. Has no effect on an ephemeral stream.
1364
+ */
1365
+ durable?: boolean;
1366
+ /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
1367
+ maxBuffer?: number;
1368
+ shardKey?: string;
1369
+ }
1370
+ /**
1371
+ * Subscribe to a streaming query. Returns the chunks pushed so far plus a
1372
+ * lifecycle status and a cancel function. Changing `fn` or the serialized
1373
+ * `args` resets the stream — the previous iterator is cancelled and a fresh
1374
+ * one opens with empty `chunks`.
1375
+ *
1376
+ * Pass `"skip"` for `args` to keep the hook mounted without opening a stream
1377
+ * (mirrors `useQuery` / `useSubscription`).
1378
+ */
1379
+ declare const useStream: <F extends FunctionReference<"stream">>(function_: F, args: "skip" | ArgsOf<F>, options?: UseStreamOptions) => UseStreamResult<ReturnOf<F>>;
988
1380
  /**
989
1381
  * Subscribe to a real-time stream from the server. Unlike `useQuery`, this
990
1382
  * hook does not issue an initial HTTP fetch — it only delivers values that
991
1383
  * the server pushes over the WS.
1384
+ *
1385
+ * A server-pushed error lands on `error` as a `LunoraError` carrying the
1386
+ * server's `code` (a bare `Error` only when the server sent no code), so
1387
+ * consumers can branch on the error kind; `onError` receives the raw
1388
+ * `SubscriptionError` in addition.
992
1389
  */
993
1390
  declare const useSubscription: <F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip", options?: UseQueryOptions) => UseSubscriptionResult<ReturnOf<F>>;
1391
+ /**
1392
+ * Subscribe to a server query inside a `<Suspense>` boundary.
1393
+ *
1394
+ * Unlike `useQuery` the value is never `undefined`: the component suspends
1395
+ * until the query's first value lands (the durable read cache when it already
1396
+ * holds one, otherwise the server's snapshot) and renders only with data. A
1397
+ * failed first fetch throws to the nearest error boundary.
1398
+ *
1399
+ * It shares `useQuery`'s TanStack cache entry and WebSocket subscription —
1400
+ * same query key, same registry — so mixing the two on one query costs one
1401
+ * subscription, and pushes keep the value current once it has rendered.
1402
+ *
1403
+ * There is no `"skip"`: a query that may not run is `useQuery`'s job, since a
1404
+ * suspending hook has no value to return for it.
1405
+ */
1406
+ declare const useSuspenseQuery: <F extends FunctionReference>(function_: F, args: ArgsOf<F>, options?: UseQueryOptions) => ReturnOf<F>;
994
1407
  /**
995
1408
  * Browser Web Audio subsystems for `useVoiceAgent` — the default microphone
996
1409
  * capture and speaker playback implementations injected into the hook via its
@@ -1028,8 +1441,24 @@ interface MicrophoneConfig {
1028
1441
  interruptChunks: number;
1029
1442
  /** RMS above which the user is considered to be barging in while the agent speaks. */
1030
1443
  interruptThreshold: number;
1031
- /** `true` while `status === "speaking"` — gates barge-in detection. */
1032
- isSpeaking: () => boolean;
1444
+ /**
1445
+ * `true` from the moment a turn is committed until it completes — the whole
1446
+ * `thinking` + `speaking` window, not just the audible half.
1447
+ *
1448
+ * It gates BOTH branches below, and the wider span is the point. Gated only
1449
+ * on "audibly speaking", turn detection kept running through the entire
1450
+ * STT+LLM window after a `commit`: room noise at the (deliberately low)
1451
+ * `silenceThreshold` re-armed `sawSpeech`, another quiet gap fired a SECOND
1452
+ * `commit`, and the DO refused it with "a turn is already in progress" —
1453
+ * a refusal that returns before draining the audio buffer, so the PCM
1454
+ * captured since the first commit leaked into the next utterance.
1455
+ *
1456
+ * A genuine barge-in still works in that window: it routes through the
1457
+ * `onInterrupt` branch, which needs `interruptChunks` consecutive chunks at
1458
+ * `interruptThreshold` — an order of magnitude above `silenceThreshold` —
1459
+ * and `interrupt` is exactly what the DO tells the client to send.
1460
+ */
1461
+ isTurnActive: () => boolean;
1033
1462
  /** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
1034
1463
  onAudio: (pcm: Uint8Array) => void;
1035
1464
  /** A barge-in was detected (RMS spike while the agent is speaking). */
@@ -1048,9 +1477,9 @@ type CreateSpeaker = (config: {
1048
1477
  audioFormat: VoiceAudioFormat;
1049
1478
  }) => VoiceSpeaker;
1050
1479
  /**
1051
- * The `agents.&lt;name>Voice` reference codegen emits for a voice-enabled agent — a
1480
+ * The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
1052
1481
  * live, WS-backed session keyed by `threadKey`. A structural subset of the
1053
- * generated member, so passing `api.agents.&lt;name>Voice` type-checks.
1482
+ * generated member, so passing `api.agents.<name>Voice` type-checks.
1054
1483
  */
1055
1484
  type VoiceReference = FunctionReference<"stream", {
1056
1485
  threadKey: string;
@@ -1078,7 +1507,11 @@ interface UseVoiceAgentOptions {
1078
1507
  * Audio graph stays isolated (and mockable in a non-browser test env).
1079
1508
  */
1080
1509
  createMicrophone?: CreateMicrophone;
1081
- /** Advanced/test seam: open the transport. Defaults to `new WebSocket(url)`. */
1510
+ /**
1511
+ * Advanced/test seam: open the transport. Defaults to the WebSocket
1512
+ * implementation the client was built with (`client.getWebSocketImpl()`),
1513
+ * NOT a raw `globalThis.WebSocket`.
1514
+ */
1082
1515
  createSocket?: CreateSocket;
1083
1516
  /** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
1084
1517
  createSpeaker?: CreateSpeaker;
@@ -1092,7 +1525,7 @@ interface UseVoiceAgentOptions {
1092
1525
  silenceThreshold?: number;
1093
1526
  /** The thread to converse on — shared with the agent's text turns. */
1094
1527
  threadKey: string;
1095
- /** The generated `api.agents.&lt;name>Voice` reference — identifies the voice DO endpoint. */
1528
+ /** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
1096
1529
  voice: VoiceReference;
1097
1530
  }
1098
1531
  interface UseVoiceAgentResult {
@@ -1124,7 +1557,7 @@ interface UseVoiceAgentResult {
1124
1557
  * WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
1125
1558
  * streams the agent's synthesized speech back through the browser's audio output,
1126
1559
  * and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
1127
- * `audioLevel`) to React state. Pass the generated `api.agents.&lt;name>Voice`
1560
+ * `audioLevel`) to React state. Pass the generated `api.agents.<name>Voice`
1128
1561
  * reference (never a string), matching `useAgentChat`'s reference-passing style.
1129
1562
  *
1130
1563
  * v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
@@ -1133,4 +1566,4 @@ interface UseVoiceAgentResult {
1133
1566
  * `createSocket`) so the hook is drivable outside a browser.
1134
1567
  */
1135
1568
  declare const useVoiceAgent: (options: UseVoiceAgentOptions) => UseVoiceAgentResult;
1136
- export { type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, type AuthState, Authenticated, CheckoutButton, type CheckoutButtonProps, CustomerPortalButton, type CustomerPortalButtonProps, type FlagContext, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraProvider, type LunoraProviderProps, type MutationHook, type MutatorHook, type PageItemOf, type PaginatedArgs, type RedirectTarget, type RedirectTrigger, type Subscription, Unauthenticated, type UseAgentApi, type UseAgentChatApi, type UseAgentChatOptions, type UseAgentChatResult, type UseAgentOptions, type UseAgentResult, type UseAgentStateApi, type UseAgentStateOptions, type UseAgentStateResult, type UseAgentToolEventsApi, type UseAgentToolEventsOptions, type UseAgentToolEventsResult, type UseAuthResult, type UseCheckoutResult, type UseHttpStreamOptions, type UseHttpStreamResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseMutationCallOptions, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseStreamOptions, type UseStreamResult, type UseStreamStatus, type UseSubscriptionResult, type UseVoiceAgentOptions, type UseVoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, hydratePreloaded, useAgent, useAgentChat, useAgentState, useAgentToolEvents, useAuth, useAuthState, useCheckout, useClientQuery, useConnectionStatus, useFlag, useFlags, useHttpStream, useInfiniteQuery, useLunora, useMutation, useMutator, usePaginatedQuery, usePreloadedQuery, usePresence, useQuery, useRateLimit, useStream, useSubscription, useVoiceAgent };
1569
+ export { type ActionHook, type AdminAuthListResult, type AgentApprovalGrant, type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, type AuthState, Authenticated, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraProvider, type LunoraProviderProps, type MutationHook, type MutatorHook, type PageItemOf, type PaginatedArgs, type PendingApproval, Unauthenticated, type UseAgentApi, type UseAgentApprovalsApi, type UseAgentApprovalsOptions, type UseAgentApprovalsResult, type UseAgentChatApi, type UseAgentChatOptions, type UseAgentChatResult, type UseAgentOptions, type UseAgentResult, type UseAgentStateApi, type UseAgentStateOptions, type UseAgentStateResult, type UseAgentToolEventsApi, type UseAgentToolEventsOptions, type UseAgentToolEventsResult, type UseAuthResult, type UseAuthSessionsOptions, type UseAuthUsersOptions, type UseHttpStreamOptions, type UseHttpStreamResult, type UseImpersonateResult, type UseInfiniteQueryOptions, type UseInfiniteQueryResult, type UseLiveTopicOptions, type UseLiveTopicResult, type UseMutationCallOptions, type UseOrganizationsOptions, type UsePaginatedQueryOptions, type UsePaginatedQueryResult, type UsePresenceOptions, type UsePresenceResult, type UseQueryOptions, type UseRateLimitOptions, type UseRateLimitResult, type UseSignUpInvitationsOptions, type UseStreamOptions, type UseStreamResult, type UseStreamStatus, type UseSubscriptionResult, type UseVoiceAgentOptions, type UseVoiceAgentResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, hydratePreloaded, useAction, useAgent, useAgentApprovals, useAgentChat, useAgentState, useAgentToolEvents, useAuth, useAuthSessions, useAuthState, useAuthUsers, useClientQuery, useConnectionStatus, useFlag, useFlags, useHttpStream, useImpersonate, useInfiniteQuery, useLiveTopic, useLunora, useMutation, useMutator, useOrganizations, usePaginatedQuery, usePreloadedQuery, usePresence, useQuery, useRateLimit, useSignUpInvitations, useStream, useSubscription, useSuspenseQuery, useVoiceAgent };