@lunora/solid 1.0.0-alpha.24 → 1.0.0-alpha.240
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -17
- package/dist/index.d.mts +713 -466
- package/dist/index.d.ts +713 -466
- package/dist/index.mjs +1 -19
- package/dist/packem_shared/AuthLoading-DjUnIaP5.mjs +1 -0
- package/dist/packem_shared/LunoraContext-BWsj_3CK.mjs +1 -0
- package/dist/packem_shared/LunoraProvider-DMhpuxvx.mjs +1 -0
- package/dist/packem_shared/createAction-BZkayM2R.mjs +1 -0
- package/dist/packem_shared/createAgent-CWckPY7u.mjs +1 -0
- package/dist/packem_shared/createAgentChat-jPhnwbdQ.mjs +1 -0
- package/dist/packem_shared/createAgentState-BPo1e_ih.mjs +1 -0
- package/dist/packem_shared/createAgentToolEvents-WUQRSY8o.mjs +1 -0
- package/dist/packem_shared/createConnectionStatus-D8bC05Jn.mjs +1 -0
- package/dist/packem_shared/createFlag-BwBkDAcT.mjs +1 -0
- package/dist/packem_shared/createInfiniteQuery-CwGPFeuc.mjs +1 -0
- package/dist/packem_shared/createLiveTopic-CgkjI8l8.mjs +1 -0
- package/dist/packem_shared/createMutation-DM2mXpq3.mjs +1 -0
- package/dist/packem_shared/createMutator-q9cMjGKv.mjs +1 -0
- package/dist/packem_shared/createPresence-DkTotieP.mjs +1 -0
- package/dist/packem_shared/createQuery-oNQqVGjE.mjs +1 -0
- package/dist/packem_shared/createRateLimit-CIVWrD5H.mjs +1 -0
- package/dist/packem_shared/createStream-CCAOb9q1.mjs +1 -0
- package/dist/packem_shared/createSubscription-CF_00S2O.mjs +1 -0
- package/dist/packem_shared/createVoiceAgent-CEuW4ux5.mjs +1 -0
- package/dist/packem_shared/hydratePreloaded-DCi296oW.mjs +1 -0
- package/dist/packem_shared/reactive-args-qKMBsFpd.mjs +1 -0
- package/dist/packem_shared/solid-compat-ByG5HD_F.mjs +1 -0
- package/dist/server.mjs +1 -1
- package/dist/upload.d.mts +2 -0
- package/dist/upload.d.ts +2 -0
- package/dist/upload.mjs +1 -0
- package/package.json +11 -5
- package/dist/packem_shared/AuthLoading-u5QJoV-J.mjs +0 -73
- package/dist/packem_shared/LunoraContext-C59PzHhN.mjs +0 -13
- package/dist/packem_shared/LunoraProvider-CzB3zGhy.mjs +0 -17
- package/dist/packem_shared/createAgent-D7EZBeql.mjs +0 -55
- package/dist/packem_shared/createAgentChat-CsoyE3RE.mjs +0 -150
- package/dist/packem_shared/createAgentState-DckYu3G8.mjs +0 -21
- package/dist/packem_shared/createAgentToolEvents-UavTO16u.mjs +0 -99
- package/dist/packem_shared/createConnectionStatus-1poqwqR9.mjs +0 -14
- package/dist/packem_shared/createFlag-Bu9YfzcJ.mjs +0 -78
- package/dist/packem_shared/createInfiniteQuery-Dy9k7Px2.mjs +0 -216
- package/dist/packem_shared/createMutation-LkrbhItI.mjs +0 -36
- package/dist/packem_shared/createMutator-foSnPJPt.mjs +0 -24
- package/dist/packem_shared/createPresence-DM2cVkiG.mjs +0 -85
- package/dist/packem_shared/createQuery-BUldvZXj.mjs +0 -28
- package/dist/packem_shared/createRateLimit-BA2f8XyF.mjs +0 -76
- package/dist/packem_shared/createStream-D9ONbGAw.mjs +0 -70
- package/dist/packem_shared/createSubscription-D3HbChGe.mjs +0 -41
- package/dist/packem_shared/createVoiceAgent-hu59SaDl.mjs +0 -418
- package/dist/packem_shared/hydratePreloaded-CWny5-2J.mjs +0 -25
- package/dist/packem_shared/stable-key-CGp4e2Ux.mjs +0 -38
package/dist/index.d.mts
CHANGED
|
@@ -1,44 +1,96 @@
|
|
|
1
|
-
import { LunoraClient, FunctionReference, User, ConnectionStatus,
|
|
2
|
-
export type { ArgsOf, FunctionReference, MutatorHandle, MutatorTransaction, OptimisticUpdate, Preloaded, ReturnOf, Unsubscribe } from '@lunora/client';
|
|
3
|
-
import { Context, Accessor
|
|
1
|
+
import { LunoraClient, FunctionReference, ArgsOf, ActionCallOptions, ReturnOf, SubscriptionErrorCallback, User, ConnectionStatus, LiveStreamSubscribeError, LiveTopicRef, LiveTopicOptions, MutationCallOptions, MutatorHandle, SubscriptionError, Preloaded } from '@lunora/client';
|
|
2
|
+
export type { ArgsOf, FunctionReference, MutatorHandle, MutatorTransaction, OptimisticUpdate, Preloaded, ReturnOf, SubscriptionError, SubscriptionErrorCallback, Unsubscribe } from '@lunora/client';
|
|
3
|
+
import { Context, Accessor } from 'solid-js';
|
|
4
|
+
import { AuthStatus } from '@lunora/client/auth';
|
|
4
5
|
import { PaginationStatus } from '@lunora/client/pagination';
|
|
5
6
|
import { RateLimitStatus, RateLimitConfig } from '@lunora/ratelimit';
|
|
6
7
|
/**
|
|
7
|
-
* Solid context carrying the framework-neutral {@link LunoraClient}. Every
|
|
8
|
-
* reactive primitive in this adapter (`createQuery`, `createMutation`,
|
|
9
|
-
* `hydratePreloaded`) reads the client from here, so a single
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Defaults to `undefined` so {@link useLunora} can throw a helpful error when a
|
|
13
|
-
* primitive is used outside a provider rather than dereferencing it.
|
|
14
|
-
|
|
8
|
+
* Solid context carrying the framework-neutral {@link LunoraClient}. Every
|
|
9
|
+
* reactive primitive in this adapter (`createQuery`, `createMutation`,
|
|
10
|
+
* `hydratePreloaded`) reads the client from here, so a single
|
|
11
|
+
* `<LunoraProvider client={…}>` at the root of the tree wires the whole app.
|
|
12
|
+
*
|
|
13
|
+
* Defaults to `undefined` so {@link useLunora} can throw a helpful error when a
|
|
14
|
+
* primitive is used outside a provider rather than dereferencing it. Solid 2
|
|
15
|
+
* refuses to hand back an `undefined` default at all — see {@link useLunora}.
|
|
16
|
+
*/
|
|
15
17
|
declare const LunoraContext: Context<LunoraClient | undefined>;
|
|
16
18
|
/**
|
|
17
|
-
* Read the {@link LunoraClient} from the nearest
|
|
18
|
-
*
|
|
19
|
-
* Throws when called outside a provider — the client is required to open the
|
|
20
|
-
* HTTP/WS transport, so there is no sensible fallback. The React adapter's
|
|
21
|
-
* `useLunora` has the same contract.
|
|
22
|
-
*/
|
|
19
|
+
* Read the {@link LunoraClient} from the nearest `<LunoraProvider>`.
|
|
20
|
+
*
|
|
21
|
+
* Throws when called outside a provider — the client is required to open the
|
|
22
|
+
* HTTP/WS transport, so there is no sensible fallback. The React adapter's
|
|
23
|
+
* `useLunora` has the same contract.
|
|
24
|
+
*/
|
|
23
25
|
declare const useLunora: () => LunoraClient;
|
|
26
|
+
interface ActionHandle<F extends FunctionReference> {
|
|
27
|
+
/** Invoke the action. Resolves with the server result; rejects on failure. */
|
|
28
|
+
call: (args: ArgsOf<F>, options?: ActionCallOptions) => Promise<ReturnOf<F>>;
|
|
29
|
+
/** The latest invocation's resolved value, or `undefined` before the first success. */
|
|
30
|
+
data: Accessor<ReturnOf<F> | undefined>;
|
|
31
|
+
/** The latest invocation's error, or `undefined`. */
|
|
32
|
+
error: Accessor<Error | undefined>;
|
|
33
|
+
/** `true` while any invocation from this handle is in flight (ref-counted, so overlapping calls compose). */
|
|
34
|
+
pending: Accessor<boolean>;
|
|
35
|
+
/** Clear `data`/`error` back to idle. */
|
|
36
|
+
reset: () => void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The transport surface {@link createAction} actually needs — just
|
|
40
|
+
* `client.action`. Narrowed so the primitive can be exercised against a stub in
|
|
41
|
+
* tests without constructing a full `LunoraClient`.
|
|
42
|
+
*/
|
|
43
|
+
interface ActionClient<F extends FunctionReference> {
|
|
44
|
+
action: (function_: F, args: ArgsOf<F>, options?: ActionCallOptions) => Promise<ReturnOf<F>>;
|
|
45
|
+
}
|
|
24
46
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
47
|
+
* Build an action handle bound to an explicit client. Internal seam used by the
|
|
48
|
+
* provider-bound {@link createAction}; exported for tests that inject a stub.
|
|
49
|
+
* The ref-counted pending + error-normalize orchestration is the shared
|
|
50
|
+
* `createCallRunner` from `@lunora/client`; only the reactive sinks (Solid
|
|
51
|
+
* signals) are adapter-specific.
|
|
52
|
+
*
|
|
53
|
+
* `data`/`error` follow the adapter-wide contract: both track the LATEST
|
|
54
|
+
* invocation (an earlier call settling later cannot clobber a newer one), a
|
|
55
|
+
* success clears `error`, and a failure leaves the previous `data` in place.
|
|
56
|
+
* `reset()` clears both; it does not cancel an in-flight call.
|
|
57
|
+
*/
|
|
58
|
+
declare const createActionForClient: <F extends FunctionReference>(client: ActionClient<F>, function_: F) => ActionHandle<F>;
|
|
59
|
+
/**
|
|
60
|
+
* Returns a reactive handle `{ call, pending, data, error, reset }` for the
|
|
61
|
+
* given action reference, bound to the `LunoraClient` from the nearest
|
|
62
|
+
* `<LunoraProvider>`.
|
|
63
|
+
*
|
|
64
|
+
* **Narrower than `createMutation` on purpose:** no `optimistic` /
|
|
65
|
+
* `optimisticUpdate` call options. An optimistic update patches the subscription
|
|
66
|
+
* cache on the assumption a write will land; an action is not a write — it runs
|
|
67
|
+
* in the Worker, may call a third party, and has no declared effect on any
|
|
68
|
+
* query. Offering the option would imply a rollback guarantee nothing can
|
|
69
|
+
* honour.
|
|
70
|
+
*/
|
|
71
|
+
declare const createAction: <F extends FunctionReference>(function_: F) => ActionHandle<F>;
|
|
72
|
+
/**
|
|
73
|
+
* The lifecycle status stored on an agent thread. Client-safe mirror of
|
|
74
|
+
* `@lunora/agent`'s `AgentThreadStatus` — re-declared here (rather than imported)
|
|
75
|
+
* so this Solid entry never pulls in the server-only `@lunora/agent` module graph
|
|
76
|
+
* (the adapter stays Solid + `@lunora/client` only). Keep in sync with
|
|
77
|
+
* `packages/agent/src/types.ts`.
|
|
78
|
+
*/
|
|
31
79
|
type AgentThreadStatus = "awaiting_input" | "cancelled" | "error" | "idle" | "running";
|
|
32
80
|
/**
|
|
33
|
-
* The live thread record surfaced by the `agents:agentThread` query. A structural
|
|
34
|
-
* subset of the persisted thread row — every field beyond `status` is optional so
|
|
35
|
-
* the shape stays forgiving as the server schema grows. Keep in sync with the
|
|
36
|
-
* `agent_threads` table in `packages/agent/src/component.ts`.
|
|
37
|
-
*/
|
|
81
|
+
* The live thread record surfaced by the `agents:agentThread` query. A structural
|
|
82
|
+
* subset of the persisted thread row — every field beyond `status` is optional so
|
|
83
|
+
* the shape stays forgiving as the server schema grows. Keep in sync with the
|
|
84
|
+
* `agent_threads` table in `packages/agent/src/component.ts`.
|
|
85
|
+
*/
|
|
38
86
|
interface AgentThreadRecord {
|
|
39
87
|
createdAt?: number;
|
|
40
|
-
/**
|
|
41
|
-
|
|
88
|
+
/**
|
|
89
|
+
* The failure message when `status === "error"`, `null` once a later run
|
|
90
|
+
* cleared it, absent on a thread that has never failed. Read it for
|
|
91
|
+
* truthiness — `null` and absent both mean "no error".
|
|
92
|
+
*/
|
|
93
|
+
error?: null | string;
|
|
42
94
|
/** The workflow instance id of the in-flight run — the handle `cancel` targets. */
|
|
43
95
|
instanceId?: string;
|
|
44
96
|
messageCount?: number;
|
|
@@ -49,13 +101,13 @@ interface AgentThreadRecord {
|
|
|
49
101
|
updatedAt?: number;
|
|
50
102
|
}
|
|
51
103
|
/** A plain value or a Solid accessor of it — matching `createQuery`'s reactive-args contract. */
|
|
52
|
-
type MaybeAccessor
|
|
104
|
+
type MaybeAccessor<T> = Accessor<T> | T;
|
|
53
105
|
/**
|
|
54
|
-
* The `agents.agentThread` reference the primitive subscribes to for live thread
|
|
55
|
-
* state (status + the in-flight `instanceId`). A structural subset of the
|
|
56
|
-
* generated `api.agents` surface, so the whole generated `api` object is
|
|
57
|
-
* assignable.
|
|
58
|
-
*/
|
|
106
|
+
* The `agents.agentThread` reference the primitive subscribes to for live thread
|
|
107
|
+
* state (status + the in-flight `instanceId`). A structural subset of the
|
|
108
|
+
* generated `api.agents` surface, so the whole generated `api` object is
|
|
109
|
+
* assignable.
|
|
110
|
+
*/
|
|
59
111
|
interface CreateAgentApi {
|
|
60
112
|
agents: {
|
|
61
113
|
agentThread: FunctionReference<"query", {
|
|
@@ -67,29 +119,37 @@ interface CreateAgentOptions {
|
|
|
67
119
|
/** The generated `api` — its `agents.agentThread` query drives live thread state. */
|
|
68
120
|
api: CreateAgentApi;
|
|
69
121
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
122
|
+
* Optional app mutation over the agent's cancel path
|
|
123
|
+
* (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
|
|
124
|
+
* When omitted (or no run is in flight) {@link CreateAgentResult.cancel} is a
|
|
125
|
+
* no-op.
|
|
126
|
+
*/
|
|
75
127
|
cancel?: FunctionReference<"mutation">;
|
|
76
128
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
129
|
+
* Called when the live thread subscription reports an error (a session
|
|
130
|
+
* expiry, an RLS denial). Without it — and without reading `error` — such a
|
|
131
|
+
* failure is invisible and `thread` / `status` are cleared until a later frame arrives.
|
|
132
|
+
*/
|
|
133
|
+
onError?: SubscriptionErrorCallback;
|
|
134
|
+
/**
|
|
135
|
+
* The app mutation that starts (or continues) a run — a thin wrapper over
|
|
136
|
+
* `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
|
|
137
|
+
* {@link CreateAgentOptions.runArgs} and the per-call args.
|
|
138
|
+
*/
|
|
81
139
|
run: FunctionReference<"mutation">;
|
|
82
140
|
/** Extra args merged into every `run` call (e.g. an `owner` or `title`). */
|
|
83
141
|
runArgs?: Record<string, unknown>;
|
|
84
142
|
/** The thread to observe and drive — a plain value or accessor (an accessor re-subscribes on change). */
|
|
85
|
-
threadKey: MaybeAccessor
|
|
143
|
+
threadKey: MaybeAccessor<string>;
|
|
86
144
|
}
|
|
87
145
|
interface CreateAgentResult {
|
|
88
146
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
147
|
+
* Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
|
|
148
|
+
* no-op when no `cancel` mutation was supplied or no run is in flight.
|
|
149
|
+
*/
|
|
92
150
|
cancel: () => Promise<void>;
|
|
151
|
+
/** The live thread subscription's last error, or `undefined`. */
|
|
152
|
+
error: Accessor<Error | undefined>;
|
|
93
153
|
/** `true` while a `run` invocation is in flight. */
|
|
94
154
|
pending: Accessor<boolean>;
|
|
95
155
|
/** Start (or continue) a run with a user message; extra args merge over `runArgs`. */
|
|
@@ -100,39 +160,33 @@ interface CreateAgentResult {
|
|
|
100
160
|
thread: Accessor<AgentThreadRecord | undefined>;
|
|
101
161
|
}
|
|
102
162
|
/**
|
|
103
|
-
* A
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
|
|
115
|
-
*
|
|
116
|
-
* `run` and `cancel` stay generic over the app-defined mutations that wrap
|
|
117
|
-
* `ctx.agents.<name>.run` / `.cancel`, so the primitive hard-codes no function
|
|
118
|
-
* names beyond the `agents:*` surface. `threadKey` may be an accessor — a changing
|
|
119
|
-
* key re-subscribes to the new thread.
|
|
120
|
-
*/
|
|
163
|
+
* A thin agent handle: live thread `status` plus `run` / `cancel`, without the
|
|
164
|
+
* chat message surface. Composes `createSubscription(api.agents.agentThread)` for
|
|
165
|
+
* live state and `createMutation` for the run/cancel writes — the Solid
|
|
166
|
+
* counterpart to React's `useAgent`, re-expressed with signals. For the full
|
|
167
|
+
* conversation surface (durable history + streaming + approvals) use
|
|
168
|
+
* `createAgentChat`.
|
|
169
|
+
*
|
|
170
|
+
* `run` and `cancel` stay generic over the app-defined mutations that wrap
|
|
171
|
+
* `ctx.agents.<name>.run` / `.cancel`, so the primitive hard-codes no function
|
|
172
|
+
* names beyond the `agents:*` surface. `threadKey` may be an accessor — a changing
|
|
173
|
+
* key re-subscribes to the new thread.
|
|
174
|
+
*/
|
|
121
175
|
declare const createAgent: (options: CreateAgentOptions) => CreateAgentResult;
|
|
122
176
|
/**
|
|
123
|
-
* One persisted (or optimistic) thread message, as `agents:agentMessages`
|
|
124
|
-
* surfaces it. Client-safe mirror of `@lunora/agent`'s `AgentMessageRow` —
|
|
125
|
-
* re-declared here (rather than imported) so this Solid entry never pulls in the
|
|
126
|
-
* server-only `@lunora/agent` module graph. Keep in sync with the
|
|
127
|
-
* `agent_messages` table in `packages/agent/src/component.ts`.
|
|
128
|
-
*/
|
|
177
|
+
* One persisted (or optimistic) thread message, as `agents:agentMessages`
|
|
178
|
+
* surfaces it. Client-safe mirror of `@lunora/agent`'s `AgentMessageRow` —
|
|
179
|
+
* re-declared here (rather than imported) so this Solid entry never pulls in the
|
|
180
|
+
* server-only `@lunora/agent` module graph. Keep in sync with the
|
|
181
|
+
* `agent_messages` table in `packages/agent/src/component.ts`.
|
|
182
|
+
*/
|
|
129
183
|
interface AgentChatMessage {
|
|
130
184
|
content: string;
|
|
131
185
|
createdAt?: number;
|
|
132
186
|
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
187
|
+
* `true` for a client-side optimistic user message not yet acknowledged by
|
|
188
|
+
* the server. Cleared once the durable history carries the matching user turn.
|
|
189
|
+
*/
|
|
136
190
|
optimistic?: boolean;
|
|
137
191
|
role: "assistant" | "system" | "tool" | "user";
|
|
138
192
|
seq: number;
|
|
@@ -147,11 +201,11 @@ interface AgentChatMessage {
|
|
|
147
201
|
toolName?: string;
|
|
148
202
|
}
|
|
149
203
|
/**
|
|
150
|
-
* A live token delta streamed while a turn is generating. Client-safe mirror of
|
|
151
|
-
* `@lunora/agent`'s `AgentTokenDelta`. Ephemeral — deltas feed
|
|
152
|
-
* {@link CreateAgentChatResult.streamingText} live and are never replayed; the
|
|
153
|
-
* persisted assistant message stays the single source of truth.
|
|
154
|
-
*/
|
|
204
|
+
* A live token delta streamed while a turn is generating. Client-safe mirror of
|
|
205
|
+
* `@lunora/agent`'s `AgentTokenDelta`. Ephemeral — deltas feed
|
|
206
|
+
* {@link CreateAgentChatResult.streamingText} live and are never replayed; the
|
|
207
|
+
* persisted assistant message stays the single source of truth.
|
|
208
|
+
*/
|
|
155
209
|
interface AgentTokenDelta {
|
|
156
210
|
/** Discriminates the token arm of {@link AgentLiveEvent}; unset on the wire (token is the default). */
|
|
157
211
|
kind?: "token";
|
|
@@ -163,10 +217,10 @@ interface AgentTokenDelta {
|
|
|
163
217
|
turn: number;
|
|
164
218
|
}
|
|
165
219
|
/**
|
|
166
|
-
* A live tool-progress event streamed via `ctx.reportProgress(...)`. Client-safe
|
|
167
|
-
* mirror of `@lunora/agent`'s `AgentProgressEvent`. Ephemeral and `toolCallId`-keyed;
|
|
168
|
-
* surfaced by `createAgentToolEvents`, ignored by {@link CreateAgentChatResult.streamingText}.
|
|
169
|
-
*/
|
|
220
|
+
* A live tool-progress event streamed via `ctx.reportProgress(...)`. Client-safe
|
|
221
|
+
* mirror of `@lunora/agent`'s `AgentProgressEvent`. Ephemeral and `toolCallId`-keyed;
|
|
222
|
+
* surfaced by `createAgentToolEvents`, ignored by {@link CreateAgentChatResult.streamingText}.
|
|
223
|
+
*/
|
|
170
224
|
interface AgentProgressEvent {
|
|
171
225
|
/** The arbitrary, JSON-serializable payload the tool reported. */
|
|
172
226
|
data: unknown;
|
|
@@ -178,11 +232,11 @@ interface AgentProgressEvent {
|
|
|
178
232
|
toolCallId: string;
|
|
179
233
|
}
|
|
180
234
|
/**
|
|
181
|
-
* A single event on the agent's live-only channel — a streamed token delta or a
|
|
182
|
-
* tool progress event. Client-safe mirror of `@lunora/agent`'s `AgentLiveEvent`.
|
|
183
|
-
* Discriminate on `kind` (`"progress"` for the progress arm; token deltas leave
|
|
184
|
-
* it unset).
|
|
185
|
-
*/
|
|
235
|
+
* A single event on the agent's live-only channel — a streamed token delta or a
|
|
236
|
+
* tool progress event. Client-safe mirror of `@lunora/agent`'s `AgentLiveEvent`.
|
|
237
|
+
* Discriminate on `kind` (`"progress"` for the progress arm; token deltas leave
|
|
238
|
+
* it unset).
|
|
239
|
+
*/
|
|
186
240
|
type AgentLiveEvent = AgentProgressEvent | AgentTokenDelta;
|
|
187
241
|
/** The `agents:agentMessages` reference — live durable thread history. */
|
|
188
242
|
type AgentMessagesReference$1 = FunctionReference<"query", {
|
|
@@ -204,18 +258,18 @@ type AgentThreadReference = FunctionReference<"query", {
|
|
|
204
258
|
key: string;
|
|
205
259
|
}, Record<string, unknown> | undefined>;
|
|
206
260
|
/**
|
|
207
|
-
* An app stream reference that tees the agent's in-flight live events, keyed by
|
|
208
|
-
* thread. Carries token deltas and — since `ctx.reportProgress` rides the same
|
|
209
|
-
* sink — tool progress events; this primitive consumes only the token arm.
|
|
210
|
-
*/
|
|
261
|
+
* An app stream reference that tees the agent's in-flight live events, keyed by
|
|
262
|
+
* thread. Carries token deltas and — since `ctx.reportProgress` rides the same
|
|
263
|
+
* sink — tool progress events; this primitive consumes only the token arm.
|
|
264
|
+
*/
|
|
211
265
|
type AgentTokenStreamReference = FunctionReference<"stream", {
|
|
212
266
|
key: string;
|
|
213
267
|
}, AgentLiveEvent>;
|
|
214
268
|
/**
|
|
215
|
-
* The `agents.*` reference surface the chat primitive reads. A structural subset
|
|
216
|
-
* of the generated `api.agents`, so the whole generated `api` object is
|
|
217
|
-
* assignable.
|
|
218
|
-
*/
|
|
269
|
+
* The `agents.*` reference surface the chat primitive reads. A structural subset
|
|
270
|
+
* of the generated `api.agents`, so the whole generated `api` object is
|
|
271
|
+
* assignable.
|
|
272
|
+
*/
|
|
219
273
|
interface CreateAgentChatApi {
|
|
220
274
|
agents: {
|
|
221
275
|
agentMessages: AgentMessagesReference$1;
|
|
@@ -227,39 +281,47 @@ interface CreateAgentChatOptions {
|
|
|
227
281
|
/** The generated `api` — its `agents.*` surface provides history, thread state, and approval resolution. */
|
|
228
282
|
api: CreateAgentChatApi;
|
|
229
283
|
/**
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
284
|
+
* Optional app mutation over the agent's cancel path
|
|
285
|
+
* (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
|
|
286
|
+
* When omitted (or no run is in flight) {@link CreateAgentChatResult.cancel} is
|
|
287
|
+
* a no-op.
|
|
288
|
+
*/
|
|
235
289
|
cancel?: FunctionReference<"mutation">;
|
|
236
290
|
/** History depth forwarded to `agents:agentMessages`. */
|
|
237
291
|
limit?: number;
|
|
238
292
|
/**
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
293
|
+
* Called when the live history or thread subscription reports an error (a
|
|
294
|
+
* session expiry, an RLS denial). Without it — and without reading `error` —
|
|
295
|
+
* such a failure is invisible and `messages` / `status` are cleared until a later frame arrives.
|
|
296
|
+
*/
|
|
297
|
+
onError?: SubscriptionErrorCallback;
|
|
298
|
+
/**
|
|
299
|
+
* The app mutation that starts (or continues) a run — a thin wrapper over
|
|
300
|
+
* `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
|
|
301
|
+
* {@link CreateAgentChatOptions.sendArgs} and the per-call args.
|
|
302
|
+
*/
|
|
243
303
|
send: FunctionReference<"mutation">;
|
|
244
304
|
/** Extra args merged into every `send` call (e.g. an `owner` or `title`). */
|
|
245
305
|
sendArgs?: Record<string, unknown>;
|
|
246
306
|
/**
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
307
|
+
* Optional live token-delta stream — an app stream function that tees the
|
|
308
|
+
* agent's in-flight deltas. When omitted {@link CreateAgentChatResult.streamingText}
|
|
309
|
+
* stays empty and the UI updates message-by-message from durable history.
|
|
310
|
+
*/
|
|
251
311
|
stream?: AgentTokenStreamReference;
|
|
252
312
|
/** The thread to observe and continue — a plain value or accessor (an accessor re-subscribes on change). */
|
|
253
|
-
threadKey: MaybeAccessor
|
|
313
|
+
threadKey: MaybeAccessor<string>;
|
|
254
314
|
}
|
|
255
315
|
interface CreateAgentChatResult {
|
|
256
316
|
/** Approve a paused human-in-the-loop tool call (optionally with a note). */
|
|
257
317
|
approve: (toolCallId: string, note?: string) => Promise<void>;
|
|
258
318
|
/**
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
319
|
+
* Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
|
|
320
|
+
* no-op when no `cancel` mutation was supplied or no run is in flight.
|
|
321
|
+
*/
|
|
262
322
|
cancel: () => Promise<void>;
|
|
323
|
+
/** The history or thread subscription's last error, or `undefined`. */
|
|
324
|
+
error: Accessor<Error | undefined>;
|
|
263
325
|
/** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. */
|
|
264
326
|
messages: Accessor<ReadonlyArray<AgentChatMessage>>;
|
|
265
327
|
/** Reject a paused human-in-the-loop tool call (optionally with a reason). */
|
|
@@ -272,34 +334,34 @@ interface CreateAgentChatResult {
|
|
|
272
334
|
streamingText: Accessor<string>;
|
|
273
335
|
}
|
|
274
336
|
/**
|
|
275
|
-
* A first-class agent chat surface: live durable history + in-flight token
|
|
276
|
-
* streaming + the send / approve / reject / cancel writes, keyed by `threadKey` —
|
|
277
|
-
* the Solid counterpart to React's `useAgentChat`, re-expressed with signals.
|
|
278
|
-
*
|
|
279
|
-
* It composes the existing primitives rather than adding transport:
|
|
280
|
-
* `createSubscription(api.agents.agentMessages)` for durable history,
|
|
281
|
-
* `createSubscription(api.agents.agentThread)` for live status + the in-flight
|
|
282
|
-
* `instanceId`, {@link createStream} over an app token stream for in-flight deltas,
|
|
283
|
-
* and `createMutation` for the writes (`api.agents.agentResolveApproval` for
|
|
284
|
-
* approvals; app-defined wrappers for `send`/`cancel`). Only the `agents:*`
|
|
285
|
-
* surface is hard-coded — `send`/`cancel`/`stream` stay generic references.
|
|
286
|
-
*
|
|
287
|
-
* A `send` optimistically appends the user turn so it renders immediately; the
|
|
288
|
-
* optimistic row clears once the durable history carries the acknowledged turn.
|
|
289
|
-
* `streamingText` is live-only: it holds the current turn's streamed text and
|
|
290
|
-
* empties as soon as that turn's assistant message lands in `messages` (the
|
|
291
|
-
* persisted message is the source of truth), consistent with the loop's
|
|
292
|
-
* replay-safe, live-only delta design.
|
|
293
|
-
*/
|
|
337
|
+
* A first-class agent chat surface: live durable history + in-flight token
|
|
338
|
+
* streaming + the send / approve / reject / cancel writes, keyed by `threadKey` —
|
|
339
|
+
* the Solid counterpart to React's `useAgentChat`, re-expressed with signals.
|
|
340
|
+
*
|
|
341
|
+
* It composes the existing primitives rather than adding transport:
|
|
342
|
+
* `createSubscription(api.agents.agentMessages)` for durable history,
|
|
343
|
+
* `createSubscription(api.agents.agentThread)` for live status + the in-flight
|
|
344
|
+
* `instanceId`, {@link createStream} over an app token stream for in-flight deltas,
|
|
345
|
+
* and `createMutation` for the writes (`api.agents.agentResolveApproval` for
|
|
346
|
+
* approvals; app-defined wrappers for `send`/`cancel`). Only the `agents:*`
|
|
347
|
+
* surface is hard-coded — `send`/`cancel`/`stream` stay generic references.
|
|
348
|
+
*
|
|
349
|
+
* A `send` optimistically appends the user turn so it renders immediately; the
|
|
350
|
+
* optimistic row clears once the durable history carries the acknowledged turn.
|
|
351
|
+
* `streamingText` is live-only: it holds the current turn's streamed text and
|
|
352
|
+
* empties as soon as that turn's assistant message lands in `messages` (the
|
|
353
|
+
* persisted message is the source of truth), consistent with the loop's
|
|
354
|
+
* replay-safe, live-only delta design.
|
|
355
|
+
*/
|
|
294
356
|
declare const createAgentChat: (options: CreateAgentChatOptions) => CreateAgentChatResult;
|
|
295
357
|
/**
|
|
296
|
-
* The `agents.agentState` reference the primitive subscribes to for the thread's
|
|
297
|
-
* live synced state. A structural subset of the generated `api.agents` surface
|
|
298
|
-
* (like `CreateAgentApi` for `agentThread`), so the whole generated `api` object
|
|
299
|
-
* is assignable. Client-safe: no `@lunora/agent` import — the per-agent state type
|
|
300
|
-
* is mirrored by the primitive's generic `T`, since codegen pins the reference
|
|
301
|
-
* return as an optional record (it never evaluates agent config).
|
|
302
|
-
*/
|
|
358
|
+
* The `agents.agentState` reference the primitive subscribes to for the thread's
|
|
359
|
+
* live synced state. A structural subset of the generated `api.agents` surface
|
|
360
|
+
* (like `CreateAgentApi` for `agentThread`), so the whole generated `api` object
|
|
361
|
+
* is assignable. Client-safe: no `@lunora/agent` import — the per-agent state type
|
|
362
|
+
* is mirrored by the primitive's generic `T`, since codegen pins the reference
|
|
363
|
+
* return as an optional record (it never evaluates agent config).
|
|
364
|
+
*/
|
|
303
365
|
interface CreateAgentStateApi {
|
|
304
366
|
agents: {
|
|
305
367
|
agentState: FunctionReference<"query", {
|
|
@@ -311,7 +373,7 @@ interface CreateAgentStateOptions {
|
|
|
311
373
|
/** The generated `api` — its `agents.agentState` query drives live thread state. */
|
|
312
374
|
api: CreateAgentStateApi;
|
|
313
375
|
/** The thread whose synced state to observe — a plain value or accessor (an accessor re-subscribes on change). */
|
|
314
|
-
threadKey: MaybeAccessor
|
|
376
|
+
threadKey: MaybeAccessor<string>;
|
|
315
377
|
}
|
|
316
378
|
interface CreateAgentStateResult<T> {
|
|
317
379
|
/** The subscription error, if the live channel reported one. */
|
|
@@ -320,20 +382,20 @@ interface CreateAgentStateResult<T> {
|
|
|
320
382
|
state: Accessor<T | undefined>;
|
|
321
383
|
}
|
|
322
384
|
/**
|
|
323
|
-
* Subscribe to an agent thread's synced state — the `setState`-style value a tool
|
|
324
|
-
* writes with `ctx.setState(...)`, seeded by `defineAgent({ initialState })`. A
|
|
325
|
-
* thin wrapper over `createSubscription(api.agents.agentState, { key })`: the
|
|
326
|
-
* server pushes a fresh frame whenever the state changes (the dedicated query's
|
|
327
|
-
* per-socket JSON memo suppresses no-op pushes on unrelated thread writes), so
|
|
328
|
-
* `state` updates only on a real `setState`. The Solid counterpart to React's
|
|
329
|
-
* `useAgentState`, re-expressed with signals.
|
|
330
|
-
*
|
|
331
|
-
* Generic over the app's state shape (`createAgentState` with a `SupportState`
|
|
332
|
-
* type argument, itself a record) — the reference is typed as an optional record
|
|
333
|
-
* because codegen cannot see the per-agent state type; the generic casts to `T`.
|
|
334
|
-
* The `extends` bound (not a bare unbounded type parameter) is required so the
|
|
335
|
-
* reference's optional-record return casts cleanly to `T`.
|
|
336
|
-
*/
|
|
385
|
+
* Subscribe to an agent thread's synced state — the `setState`-style value a tool
|
|
386
|
+
* writes with `ctx.setState(...)`, seeded by `defineAgent({ initialState })`. A
|
|
387
|
+
* thin wrapper over `createSubscription(api.agents.agentState, { key })`: the
|
|
388
|
+
* server pushes a fresh frame whenever the state changes (the dedicated query's
|
|
389
|
+
* per-socket JSON memo suppresses no-op pushes on unrelated thread writes), so
|
|
390
|
+
* `state` updates only on a real `setState`. The Solid counterpart to React's
|
|
391
|
+
* `useAgentState`, re-expressed with signals.
|
|
392
|
+
*
|
|
393
|
+
* Generic over the app's state shape (`createAgentState` with a `SupportState`
|
|
394
|
+
* type argument, itself a record) — the reference is typed as an optional record
|
|
395
|
+
* because codegen cannot see the per-agent state type; the generic casts to `T`.
|
|
396
|
+
* The `extends` bound (not a bare unbounded type parameter) is required so the
|
|
397
|
+
* reference's optional-record return casts cleanly to `T`.
|
|
398
|
+
*/
|
|
337
399
|
declare const createAgentState: <T extends Record<string, unknown> = Record<string, unknown>>(options: CreateAgentStateOptions) => CreateAgentStateResult<T>;
|
|
338
400
|
/** The `agents:agentMessages` reference — live durable thread history. */
|
|
339
401
|
type AgentMessagesReference = FunctionReference<"query", {
|
|
@@ -341,18 +403,18 @@ type AgentMessagesReference = FunctionReference<"query", {
|
|
|
341
403
|
limit?: number;
|
|
342
404
|
}, ReadonlyArray<Record<string, unknown>>>;
|
|
343
405
|
/**
|
|
344
|
-
* An app stream reference that tees the agent's in-flight live events, keyed by
|
|
345
|
-
* thread. Carries token deltas and tool progress events; this primitive consumes
|
|
346
|
-
* only the progress arm (`kind === "progress"`).
|
|
347
|
-
*/
|
|
406
|
+
* An app stream reference that tees the agent's in-flight live events, keyed by
|
|
407
|
+
* thread. Carries token deltas and tool progress events; this primitive consumes
|
|
408
|
+
* only the progress arm (`kind === "progress"`).
|
|
409
|
+
*/
|
|
348
410
|
type AgentLiveStreamReference = FunctionReference<"stream", {
|
|
349
411
|
key: string;
|
|
350
412
|
}, AgentLiveEvent>;
|
|
351
413
|
/**
|
|
352
|
-
* The `agents.*` reference surface the tool-events primitive reads. A structural
|
|
353
|
-
* subset of the generated `api.agents`, so the whole generated `api` object is
|
|
354
|
-
* assignable.
|
|
355
|
-
*/
|
|
414
|
+
* The `agents.*` reference surface the tool-events primitive reads. A structural
|
|
415
|
+
* subset of the generated `api.agents`, so the whole generated `api` object is
|
|
416
|
+
* assignable.
|
|
417
|
+
*/
|
|
356
418
|
interface CreateAgentToolEventsApi {
|
|
357
419
|
agents: {
|
|
358
420
|
agentMessages: AgentMessagesReference;
|
|
@@ -364,21 +426,21 @@ interface CreateAgentToolEventsOptions {
|
|
|
364
426
|
/** History depth forwarded to `agents:agentMessages`. */
|
|
365
427
|
limit?: number;
|
|
366
428
|
/**
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
429
|
+
* Optional live event stream — the same app stream function `createAgentChat`
|
|
430
|
+
* uses. When supplied, ephemeral `ctx.reportProgress(...)` events for the
|
|
431
|
+
* thread are surfaced as `{ type: "progress" }` entries; when omitted only the
|
|
432
|
+
* durable lifecycle (call / result / awaiting-approval) is returned.
|
|
433
|
+
*/
|
|
372
434
|
stream?: AgentLiveStreamReference;
|
|
373
435
|
/** The thread whose tool activity to observe — a plain value or accessor (an accessor re-subscribes on change). */
|
|
374
|
-
threadKey: MaybeAccessor
|
|
436
|
+
threadKey: MaybeAccessor<string>;
|
|
375
437
|
}
|
|
376
438
|
/**
|
|
377
|
-
* A single tool-lifecycle event for a thread. The durable arms
|
|
378
|
-
* (`call`/`result`/`awaiting-approval`) are derived from `agents:agentMessages`
|
|
379
|
-
* and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
|
|
380
|
-
* stream and has no `seq`. Discriminate on `type`.
|
|
381
|
-
*/
|
|
439
|
+
* A single tool-lifecycle event for a thread. The durable arms
|
|
440
|
+
* (`call`/`result`/`awaiting-approval`) are derived from `agents:agentMessages`
|
|
441
|
+
* and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
|
|
442
|
+
* stream and has no `seq`. Discriminate on `type`.
|
|
443
|
+
*/
|
|
382
444
|
type AgentToolEvent = {
|
|
383
445
|
data: unknown;
|
|
384
446
|
toolCallId: string;
|
|
@@ -404,105 +466,177 @@ type AgentToolEvent = {
|
|
|
404
466
|
};
|
|
405
467
|
interface CreateAgentToolEventsResult {
|
|
406
468
|
/**
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
469
|
+
* The thread's tool events: the durable lifecycle (oldest first, by `seq`)
|
|
470
|
+
* followed by any in-flight ephemeral progress events, recomputed from the live
|
|
471
|
+
* subscription + stream. Treat as derived, not identity-stable.
|
|
472
|
+
*/
|
|
411
473
|
events: Accessor<ReadonlyArray<AgentToolEvent>>;
|
|
412
474
|
}
|
|
413
475
|
/**
|
|
414
|
-
* A focused view of a thread's tool activity: tool calls, their results,
|
|
415
|
-
* human-in-the-loop approval pauses, and live `ctx.reportProgress(...)` events —
|
|
416
|
-
* without the full chat message surface. The Solid counterpart to React's
|
|
417
|
-
* `useAgentToolEvents`, re-expressed as a memo.
|
|
418
|
-
*
|
|
419
|
-
* It composes the existing primitives rather than adding transport:
|
|
420
|
-
* `createSubscription(api.agents.agentMessages)` for the durable lifecycle and
|
|
421
|
-
* {@link createStream} over the optional app event stream for ephemeral progress.
|
|
422
|
-
* Progress events are live-only (the durable path never emits them): they ride
|
|
423
|
-
* the same sink as token deltas and are surfaced here, correlated to their tool
|
|
424
|
-
* call by `toolCallId`. For the conversational surface (messages + streaming text
|
|
425
|
-
* + approvals) use `createAgentChat`; this primitive is the tool-observability slice.
|
|
426
|
-
*/
|
|
476
|
+
* A focused view of a thread's tool activity: tool calls, their results,
|
|
477
|
+
* human-in-the-loop approval pauses, and live `ctx.reportProgress(...)` events —
|
|
478
|
+
* without the full chat message surface. The Solid counterpart to React's
|
|
479
|
+
* `useAgentToolEvents`, re-expressed as a memo.
|
|
480
|
+
*
|
|
481
|
+
* It composes the existing primitives rather than adding transport:
|
|
482
|
+
* `createSubscription(api.agents.agentMessages)` for the durable lifecycle and
|
|
483
|
+
* {@link createStream} over the optional app event stream for ephemeral progress.
|
|
484
|
+
* Progress events are live-only (the durable path never emits them): they ride
|
|
485
|
+
* the same sink as token deltas and are surfaced here, correlated to their tool
|
|
486
|
+
* call by `toolCallId`. For the conversational surface (messages + streaming text
|
|
487
|
+
* + approvals) use `createAgentChat`; this primitive is the tool-observability slice.
|
|
488
|
+
*/
|
|
427
489
|
declare const createAgentToolEvents: (options: CreateAgentToolEventsOptions) => CreateAgentToolEventsResult;
|
|
490
|
+
/**
|
|
491
|
+
* Children accepted by this adapter's components.
|
|
492
|
+
*
|
|
493
|
+
* Structurally identical to Solid 2.0's `Element`, which is in turn a widening
|
|
494
|
+
* of 1.x's `JSX.Element` (a DOM `Node` satisfies `object` with no
|
|
495
|
+
* `call`/`apply`/`bind`). Children are contravariant, so one union that accepts
|
|
496
|
+
* both majors' element types is enough — no `any` required here.
|
|
497
|
+
*/
|
|
498
|
+
type SolidChildren = SolidChildrenArray | boolean | null | number | (object & {
|
|
499
|
+
readonly apply?: never;
|
|
500
|
+
readonly bind?: never;
|
|
501
|
+
readonly call?: never;
|
|
502
|
+
}) | (string & {}) | undefined;
|
|
503
|
+
interface SolidChildrenArray extends Array<SolidChildren> {}
|
|
504
|
+
/**
|
|
505
|
+
* The return type of this adapter's components.
|
|
506
|
+
*
|
|
507
|
+
* Deliberately `any`, and the one place in the package where that is the right
|
|
508
|
+
* answer. TypeScript checks a component's return type against the *renderer's*
|
|
509
|
+
* `JSX.Element`, and the two majors define that incompatibly — 1.x's is rooted
|
|
510
|
+
* in the DOM `Node` interface, 2.0's in an opaque `RenderedElement`. Neither is
|
|
511
|
+
* assignable to the other, so no concrete type satisfies both, and a structural
|
|
512
|
+
* union (as used for {@link SolidChildren}) fails in the return position. `any`
|
|
513
|
+
* is what lets one set of `.d.ts` files type-check inside a 1.x app and a 2.x
|
|
514
|
+
* app alike.
|
|
515
|
+
*/
|
|
516
|
+
type SolidElement = any;
|
|
428
517
|
interface UseAuthResult {
|
|
429
518
|
setToken: (token: string | null) => void;
|
|
519
|
+
/**
|
|
520
|
+
* The resolved auth state. Branch on this, not on `user() === null` — see the
|
|
521
|
+
* contract in `@lunora/client/auth`; `user` is `null` both when signed out
|
|
522
|
+
* and when a held credential's identity could not be resolved.
|
|
523
|
+
*/
|
|
524
|
+
status: Accessor<AuthStatus>;
|
|
430
525
|
token: Accessor<string | null>;
|
|
431
526
|
user: Accessor<User | null>;
|
|
432
527
|
}
|
|
433
528
|
/**
|
|
434
|
-
* Token + identity plumbing for Solid. Returns `{ token, user, setToken }`
|
|
435
|
-
* where `token` and `user` are fine-grained signals. `setToken(jwt)` after
|
|
436
|
-
* sign-in updates the shared client token; `user` resolves asynchronously via
|
|
437
|
-
* `client.getCurrentUser()` and updates on every token change.
|
|
438
|
-
*/
|
|
529
|
+
* Token + identity plumbing for Solid. Returns `{ token, user, setToken }`
|
|
530
|
+
* where `token` and `user` are fine-grained signals. `setToken(jwt)` after
|
|
531
|
+
* sign-in updates the shared client token; `user` resolves asynchronously via
|
|
532
|
+
* `client.getCurrentUser()` and updates on every token change.
|
|
533
|
+
*/
|
|
439
534
|
declare const createAuth: () => UseAuthResult;
|
|
440
535
|
interface AuthGateProps {
|
|
441
|
-
children:
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
*
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
|
|
536
|
+
children: SolidChildren;
|
|
537
|
+
}
|
|
538
|
+
/** An auth-gate component: renders its children only while the gate's condition holds. */
|
|
539
|
+
type AuthGate = (props: AuthGateProps) => SolidElement;
|
|
540
|
+
/**
|
|
541
|
+
* Render `children` once authentication has settled in the caller's favour — a
|
|
542
|
+
* credential is held and nothing has contradicted it.
|
|
543
|
+
*
|
|
544
|
+
* Gated on the shared `AuthStatus` contract in `@lunora/client/auth`, not on
|
|
545
|
+
* `user() !== null`: an unreachable identity endpoint leaves `user` at `null`
|
|
546
|
+
* while the credential is still perfectly valid.
|
|
547
|
+
*/
|
|
548
|
+
declare const Authenticated: AuthGate;
|
|
549
|
+
/**
|
|
550
|
+
* Render `children` while authentication is still in progress — a credential is
|
|
551
|
+
* held and the first identity resolve has not come back yet.
|
|
552
|
+
*/
|
|
553
|
+
declare const AuthLoading: AuthGate;
|
|
554
|
+
/**
|
|
555
|
+
* Render `children` only when auth has settled and there is no session — no
|
|
556
|
+
* credential, or the server answered that the credential has none.
|
|
557
|
+
*/
|
|
558
|
+
declare const Unauthenticated: AuthGate;
|
|
559
|
+
/**
|
|
560
|
+
* Reactive accessor of the client's aggregate live-socket status across all
|
|
561
|
+
* shard connections. Reads the current status synchronously and updates on
|
|
562
|
+
* every transition (`idle` → `connecting` → `connected` → `offline`) — Solid's
|
|
563
|
+
* fine-grained signals mean only the components that read the accessor
|
|
564
|
+
* re-render. The Solid equivalent of `@lunora/react`'s `useConnectionStatus`.
|
|
565
|
+
*
|
|
566
|
+
* The listener is registered at **mount**, not in the component body, because
|
|
567
|
+
* `onConnectionStatus` invokes it synchronously on subscribe: Solid 2 rejects a
|
|
568
|
+
* signal write inside an owned scope (`REACTIVE_WRITE_IN_OWNED_SCOPE`) and — since
|
|
569
|
+
* the throw escapes render — halts the reactive system for the whole page, not
|
|
570
|
+
* just this component. Nothing is missed by waiting: the initial value comes
|
|
571
|
+
* from `client.connectionStatus()`, and the immediate callback re-syncs at
|
|
572
|
+
* mount. Torn down when the owning scope disposes. Call inside a component /
|
|
573
|
+
* reactive root.
|
|
574
|
+
*/
|
|
468
575
|
declare const createConnectionStatus: () => Accessor<ConnectionStatus>;
|
|
469
|
-
/** A targeting context merged on top of the app's default (`defineFlags({ identify })`). */
|
|
470
|
-
type FlagContext = Record<string, unknown>;
|
|
471
576
|
/** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
|
|
472
577
|
type FlagValue = boolean | number | string | {
|
|
473
578
|
[key: string]: unknown;
|
|
474
579
|
} | unknown[] | null;
|
|
475
|
-
/** A plain value or a Solid accessor of it — matching `createQuery`'s reactive-args contract. */
|
|
476
|
-
type MaybeAccessor<T> = Accessor<T> | T;
|
|
477
580
|
/**
|
|
478
|
-
* Subscribe to a single feature flag and return a reactive accessor of its value.
|
|
479
|
-
*
|
|
480
|
-
* The accessor reads `defaultValue` until the first evaluation lands, then the
|
|
481
|
-
* server's resolved value — re-pushed whenever the provider re-evaluates (e.g. a
|
|
482
|
-
* flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
|
|
483
|
-
* `defaultValue`'s runtime type, so `createFlag("dark", false)` reads a boolean
|
|
484
|
-
* and `createFlag("hero", "control")` a string.
|
|
485
|
-
*
|
|
486
|
-
* `key`
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
* `
|
|
493
|
-
*
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
*
|
|
498
|
-
* the
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
|
|
505
|
-
|
|
581
|
+
* Subscribe to a single feature flag and return a reactive accessor of its value.
|
|
582
|
+
*
|
|
583
|
+
* The accessor reads `defaultValue` until the first evaluation lands, then the
|
|
584
|
+
* server's resolved value — re-pushed whenever the provider re-evaluates (e.g. a
|
|
585
|
+
* flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
|
|
586
|
+
* `defaultValue`'s runtime type, so `createFlag("dark", false)` reads a boolean
|
|
587
|
+
* and `createFlag("hero", "control")` a string.
|
|
588
|
+
*
|
|
589
|
+
* `key` may be a plain value or an accessor; passing an accessor makes the
|
|
590
|
+
* subscription reactive — when it changes the old subscription is torn down (via
|
|
591
|
+
* `onCleanup`) and a fresh one opens.
|
|
592
|
+
*
|
|
593
|
+
* The reactive channel is public, so the server evaluates every flag under the
|
|
594
|
+
* socket's own verified identity — the targeting key your `defineFlags({
|
|
595
|
+
* identify })` derives — and accepts no client-supplied targeting context. For
|
|
596
|
+
* evaluation under a context you compute, call `ctx.flags.*` inside a query,
|
|
597
|
+
* mutation, or action and return the resolved value.
|
|
598
|
+
*
|
|
599
|
+
* Evaluation runs through whatever OpenFeature provider the app wired in
|
|
600
|
+
* `lunora/flags.ts`; the read never throws — a provider error resolves the
|
|
601
|
+
* default (the same fail-open contract as server-side `ctx.flags`).
|
|
602
|
+
*/
|
|
603
|
+
declare const createFlag: <T extends FlagValue>(key: MaybeAccessor<string>, defaultValue: T) => Accessor<T>;
|
|
604
|
+
/**
|
|
605
|
+
* Subscribe to several feature flags at once and return a reactive accessor of
|
|
606
|
+
* the resolved record.
|
|
607
|
+
*
|
|
608
|
+
* Pass a record of `key → defaultValue`; each flag's kind is inferred from its
|
|
609
|
+
* default, and the accessor reads the same-shaped record with resolved values
|
|
610
|
+
* (the defaults until each evaluation lands). This is the batched form of
|
|
611
|
+
* {@link createFlag}, and evaluates under the socket's server-verified identity
|
|
612
|
+
* only. The flag set is fixed for the primitive's lifetime, so nothing here is
|
|
613
|
+
* reactive — the subscriptions open on mount and tear down on cleanup.
|
|
614
|
+
*/
|
|
615
|
+
declare const createFlags: <T extends Record<string, FlagValue>>(flags: T) => Accessor<T>;
|
|
616
|
+
/**
|
|
617
|
+
* `createLiveTopic` — follow one live topic on the connection shared by its URL.
|
|
618
|
+
*
|
|
619
|
+
* A thin lifecycle wrapper over `subscribeLiveTopic` from `@lunora/client`: it
|
|
620
|
+
* subscribes when the owner mounts, unsubscribes on cleanup, and resubscribes when
|
|
621
|
+
* the topic or the connection options change. Callbacks are not part of that
|
|
622
|
+
* identity, so a new `onEvent` / `onError` never reopens the subscription.
|
|
623
|
+
*/
|
|
624
|
+
interface CreateLiveTopicResult<Payload = unknown> {
|
|
625
|
+
/** The shard's refusal of this subscription (403, 409, 429 and similar), or `undefined`. */
|
|
626
|
+
error: Accessor<LiveStreamSubscribeError | undefined>;
|
|
627
|
+
/** The last payload delivered on the topic, or `undefined` until the first event. */
|
|
628
|
+
lastEvent: Accessor<Payload | undefined>;
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Follow the topic `topic` names on the live connection shared by its stream's route. Pass the
|
|
632
|
+
* reference `_generated/live.ts` hands out (`live.posts.post({ postId })`), plain or as an
|
|
633
|
+
* accessor; the route is resolved against the `LunoraClient` from the nearest `LunoraContext`,
|
|
634
|
+
* and `lastEvent` and `onEvent` are typed by the payload the topic declares.
|
|
635
|
+
*
|
|
636
|
+
* `options` may be a plain object or an accessor. The `onEvent` and `onError` callbacks are
|
|
637
|
+
* read at call time, so the latest identity is always the one invoked.
|
|
638
|
+
*/
|
|
639
|
+
declare const createLiveTopic: <Payload>(topic: LiveTopicRef<Payload> | Accessor<LiveTopicRef<Payload>>, options?: LiveTopicOptions<Payload> | Accessor<LiveTopicOptions<Payload>>) => CreateLiveTopicResult<Payload>;
|
|
506
640
|
interface MutationHandle<F extends FunctionReference> {
|
|
507
641
|
/** The latest invocation's resolved value, or `undefined` before the first success. */
|
|
508
642
|
data: Accessor<ReturnOf<F> | undefined>;
|
|
@@ -516,44 +650,49 @@ interface MutationHandle<F extends FunctionReference> {
|
|
|
516
650
|
reset: () => void;
|
|
517
651
|
}
|
|
518
652
|
/**
|
|
519
|
-
* The transport surface {@link createMutation} actually needs — just
|
|
520
|
-
* `client.mutation`. Narrowed so the primitive can be exercised against a stub
|
|
521
|
-
* in tests without constructing a full `LunoraClient`.
|
|
522
|
-
*/
|
|
653
|
+
* The transport surface {@link createMutation} actually needs — just
|
|
654
|
+
* `client.mutation`. Narrowed so the primitive can be exercised against a stub
|
|
655
|
+
* in tests without constructing a full `LunoraClient`.
|
|
656
|
+
*/
|
|
523
657
|
interface MutationClient<F extends FunctionReference> {
|
|
524
658
|
mutation: (function_: F, args: ArgsOf<F>, options?: MutationCallOptions<unknown, unknown, ArgsOf<F>>) => Promise<ReturnOf<F>>;
|
|
525
659
|
}
|
|
526
660
|
/**
|
|
527
|
-
* Build a mutation handle bound to an explicit client. Internal seam used by the
|
|
528
|
-
* provider-bound {@link createMutation}; exported for tests that inject a stub.
|
|
529
|
-
* The ref-counted pending + error-normalize orchestration is the shared
|
|
530
|
-
* `
|
|
531
|
-
* signals) are adapter-specific.
|
|
532
|
-
|
|
661
|
+
* Build a mutation handle bound to an explicit client. Internal seam used by the
|
|
662
|
+
* provider-bound {@link createMutation}; exported for tests that inject a stub.
|
|
663
|
+
* The ref-counted pending + error-normalize orchestration is the shared
|
|
664
|
+
* `createCallRunner` from `@lunora/client`; only the reactive sinks (Solid
|
|
665
|
+
* signals) are adapter-specific.
|
|
666
|
+
*
|
|
667
|
+
* `data`/`error` follow the adapter-wide contract: both track the LATEST
|
|
668
|
+
* invocation (an earlier call settling later cannot clobber a newer one), a
|
|
669
|
+
* success clears `error`, and a failure leaves the previous `data` in place.
|
|
670
|
+
* `reset()` clears both; it does not cancel an in-flight call.
|
|
671
|
+
*/
|
|
533
672
|
declare const createMutationForClient: <F extends FunctionReference>(client: MutationClient<F>, function_: F) => MutationHandle<F>;
|
|
534
673
|
/**
|
|
535
|
-
* Returns a reactive handle `{ mutate, pending, data, error, reset }` for the
|
|
536
|
-
* given mutation reference, bound to the `LunoraClient` from the nearest
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
* Optimistic updates stay client-owned: the `optimistic` / `optimisticUpdate`
|
|
540
|
-
* call options pass straight through to `client.mutation`, which applies and
|
|
541
|
-
* rolls them back against the live Lunora subscription cache — the same
|
|
542
|
-
* machinery `createQuery`/`hydratePreloaded` subscribe to, so an optimistic
|
|
543
|
-
* write reflects in those accessors immediately and reverts on failure.
|
|
544
|
-
*
|
|
545
|
-
* `pending` is ref-counted across overlapping invocations of *this* handle, so
|
|
546
|
-
* it only flips back to `false` once every concurrent call has settled. The
|
|
547
|
-
* mutation also engages `@lunora/client`'s offline queue when the socket is
|
|
548
|
-
* down, so `mutate` stays durable across reconnects.
|
|
549
|
-
*/
|
|
674
|
+
* Returns a reactive handle `{ mutate, pending, data, error, reset }` for the
|
|
675
|
+
* given mutation reference, bound to the `LunoraClient` from the nearest
|
|
676
|
+
* `<LunoraProvider>`.
|
|
677
|
+
*
|
|
678
|
+
* Optimistic updates stay client-owned: the `optimistic` / `optimisticUpdate`
|
|
679
|
+
* call options pass straight through to `client.mutation`, which applies and
|
|
680
|
+
* rolls them back against the live Lunora subscription cache — the same
|
|
681
|
+
* machinery `createQuery`/`hydratePreloaded` subscribe to, so an optimistic
|
|
682
|
+
* write reflects in those accessors immediately and reverts on failure.
|
|
683
|
+
*
|
|
684
|
+
* `pending` is ref-counted across overlapping invocations of *this* handle, so
|
|
685
|
+
* it only flips back to `false` once every concurrent call has settled. The
|
|
686
|
+
* mutation also engages `@lunora/client`'s offline queue when the socket is
|
|
687
|
+
* down, so `mutate` stays durable across reconnects.
|
|
688
|
+
*/
|
|
550
689
|
declare const createMutation: <F extends FunctionReference>(function_: F) => MutationHandle<F>;
|
|
551
690
|
/**
|
|
552
|
-
* The reactive handle returned by {@link createMutator} — the Solid counterpart
|
|
553
|
-
* to `@lunora/react`'s `useMutator`, re-expressed with signals.
|
|
554
|
-
* `error`/`isError`/`pending` are accessors and `mutate` is an awaitable that
|
|
555
|
-
* resolves once the write is persisted (or rejects).
|
|
556
|
-
*/
|
|
691
|
+
* The reactive handle returned by {@link createMutator} — the Solid counterpart
|
|
692
|
+
* to `@lunora/react`'s `useMutator`, re-expressed with signals.
|
|
693
|
+
* `error`/`isError`/`pending` are accessors and `mutate` is an awaitable that
|
|
694
|
+
* resolves once the write is persisted (or rejects).
|
|
695
|
+
*/
|
|
557
696
|
interface MutatorHook<TArgs> {
|
|
558
697
|
/** The latest invocation's error, or `undefined`. */
|
|
559
698
|
error: Accessor<Error | undefined>;
|
|
@@ -567,18 +706,18 @@ interface MutatorHook<TArgs> {
|
|
|
567
706
|
reset: () => void;
|
|
568
707
|
}
|
|
569
708
|
/**
|
|
570
|
-
* Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
|
|
571
|
-
* custom-mutator handle from `@lunora/db`'s `bindMutators` — the Solid
|
|
572
|
-
* equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
|
|
573
|
-
* server-authoritative push are owned by the bound handle (and TanStack DB's
|
|
574
|
-
* optimistic-transaction layer rebases pending overlays on every sync tick);
|
|
575
|
-
* this primitive only surfaces signal state for the in-flight/error lifecycle.
|
|
576
|
-
* Reads stay on the existing TanStack `useLiveQuery`; no new query primitive is
|
|
577
|
-
* needed.
|
|
578
|
-
*
|
|
579
|
-
* `pending` is ref-counted across overlapping invocations of THIS handle, so it
|
|
580
|
-
* clears only once every concurrent call has settled.
|
|
581
|
-
*/
|
|
709
|
+
* Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
|
|
710
|
+
* custom-mutator handle from `@lunora/db`'s `bindMutators` — the Solid
|
|
711
|
+
* equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
|
|
712
|
+
* server-authoritative push are owned by the bound handle (and TanStack DB's
|
|
713
|
+
* optimistic-transaction layer rebases pending overlays on every sync tick);
|
|
714
|
+
* this primitive only surfaces signal state for the in-flight/error lifecycle.
|
|
715
|
+
* Reads stay on the existing TanStack `useLiveQuery`; no new query primitive is
|
|
716
|
+
* needed.
|
|
717
|
+
*
|
|
718
|
+
* `pending` is ref-counted across overlapping invocations of THIS handle, so it
|
|
719
|
+
* clears only once every concurrent call has settled.
|
|
720
|
+
*/
|
|
582
721
|
declare const createMutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorHook<TArgs>;
|
|
583
722
|
/** The args a paginated query exposes minus the framework-supplied page cursor. */
|
|
584
723
|
type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOf<F>, "paginationOpts">;
|
|
@@ -589,9 +728,18 @@ type PageItemOf<F extends FunctionReference> = ReturnOf<F> extends {
|
|
|
589
728
|
interface CreatePaginatedQueryOptions {
|
|
590
729
|
/** Page size for the first page (and the default for `loadMore`). */
|
|
591
730
|
initialNumItems: number;
|
|
731
|
+
/** Called when a page subscription reports an error (also surfaced on the `error` accessor). */
|
|
732
|
+
onError?: SubscriptionErrorCallback;
|
|
592
733
|
shardKey?: string;
|
|
593
734
|
}
|
|
594
735
|
interface CreatePaginatedQueryResult<T> {
|
|
736
|
+
/**
|
|
737
|
+
* The last page subscription error, or `undefined`. A tail page that fails
|
|
738
|
+
* before its first frame is dropped so `status` returns to `"CanLoadMore"`
|
|
739
|
+
* and `loadMore` can retry it; cleared by the next successful frame,
|
|
740
|
+
* `loadMore`, or an args change.
|
|
741
|
+
*/
|
|
742
|
+
error: Accessor<SubscriptionError | undefined>;
|
|
595
743
|
/** `true` while the first page or a `loadMore` page is in flight. */
|
|
596
744
|
isLoading: Accessor<boolean>;
|
|
597
745
|
/** Request the next page. A no-op unless `status === "CanLoadMore"`. */
|
|
@@ -603,9 +751,13 @@ interface CreatePaginatedQueryResult<T> {
|
|
|
603
751
|
interface CreateInfiniteQueryOptions {
|
|
604
752
|
/** Page size for the first page (and the default for `fetchNextPage`). */
|
|
605
753
|
initialNumItems: number;
|
|
754
|
+
/** Called when a page subscription reports an error (also surfaced on the `error` accessor). */
|
|
755
|
+
onError?: SubscriptionErrorCallback;
|
|
606
756
|
shardKey?: string;
|
|
607
757
|
}
|
|
608
758
|
interface CreateInfiniteQueryResult<T> {
|
|
759
|
+
/** The last page subscription error, or `undefined` — see `CreatePaginatedQueryResult.error`. */
|
|
760
|
+
error: Accessor<SubscriptionError | undefined>;
|
|
609
761
|
/** Request the next page. A no-op unless `status === "CanLoadMore"`. */
|
|
610
762
|
fetchNextPage: (numberItems?: number) => void;
|
|
611
763
|
/** `true` when the loaded tail reports it can load another page. */
|
|
@@ -619,46 +771,46 @@ interface CreateInfiniteQueryResult<T> {
|
|
|
619
771
|
status: Accessor<PaginationStatus>;
|
|
620
772
|
}
|
|
621
773
|
/**
|
|
622
|
-
* Subscribe to a reactively-paginated query and grow the feed page by page.
|
|
623
|
-
*
|
|
624
|
-
* The query function must accept a `paginationOpts: { numItems, cursor,
|
|
625
|
-
* endCursor }` arg and return a `PaginationResult`. `loadMore` appends the next
|
|
626
|
-
* page off the open-ended tail's `continueCursor`; it is a no-op unless
|
|
627
|
-
* `status === "CanLoadMore"`.
|
|
628
|
-
*
|
|
629
|
-
* Call inside a reactive context (component / `createRoot`).
|
|
630
|
-
*/
|
|
774
|
+
* Subscribe to a reactively-paginated query and grow the feed page by page.
|
|
775
|
+
*
|
|
776
|
+
* The query function must accept a `paginationOpts: { numItems, cursor,
|
|
777
|
+
* endCursor }` arg and return a `PaginationResult`. `loadMore` appends the next
|
|
778
|
+
* page off the open-ended tail's `continueCursor`; it is a no-op unless
|
|
779
|
+
* `status === "CanLoadMore"`.
|
|
780
|
+
*
|
|
781
|
+
* Call inside a reactive context (component / `createRoot`).
|
|
782
|
+
*/
|
|
631
783
|
declare const createPaginatedQuery: <F extends FunctionReference>(function_: F, args: "skip" | Accessor<"skip" | PaginatedArgs<F>> | PaginatedArgs<F>, options: CreatePaginatedQueryOptions) => CreatePaginatedQueryResult<PageItemOf<F>>;
|
|
632
784
|
/**
|
|
633
|
-
* Subscribe to a reactively-paginated query and expose its pages discretely.
|
|
634
|
-
*
|
|
635
|
-
* Shares `createPaginatedQuery`'s pagination engine but keeps each page as its
|
|
636
|
-
* own inner array (TanStack-Query-style `fetchNextPage` / `hasNextPage` shape).
|
|
637
|
-
*
|
|
638
|
-
* Call inside a reactive context (component / `createRoot`).
|
|
639
|
-
*/
|
|
785
|
+
* Subscribe to a reactively-paginated query and expose its pages discretely.
|
|
786
|
+
*
|
|
787
|
+
* Shares `createPaginatedQuery`'s pagination engine but keeps each page as its
|
|
788
|
+
* own inner array (TanStack-Query-style `fetchNextPage` / `hasNextPage` shape).
|
|
789
|
+
*
|
|
790
|
+
* Call inside a reactive context (component / `createRoot`).
|
|
791
|
+
*/
|
|
640
792
|
declare const createInfiniteQuery: <F extends FunctionReference>(function_: F, args: "skip" | Accessor<"skip" | PaginatedArgs<F>> | PaginatedArgs<F>, options: CreateInfiniteQueryOptions) => CreateInfiniteQueryResult<PageItemOf<F>>;
|
|
641
793
|
/**
|
|
642
|
-
* `createPresence` — collaborative-awareness primitive, the client half of the
|
|
643
|
-
* `@lunora/server` `definePresence` preset.
|
|
644
|
-
*
|
|
645
|
-
* Drives the heartbeat mutation (on mount, interval, and tab re-focus) and
|
|
646
|
-
* subscribes to the live `listPresent` query for the given room.
|
|
647
|
-
*
|
|
648
|
-
* Call inside a reactive context (component / `createRoot`).
|
|
649
|
-
*/
|
|
650
|
-
/**
|
|
651
|
-
* A heartbeat mutation reference: takes `{ roomId, sessionId, data? }`.
|
|
652
|
-
*/
|
|
794
|
+
* `createPresence` — collaborative-awareness primitive, the client half of the
|
|
795
|
+
* `@lunora/server` `definePresence` preset.
|
|
796
|
+
*
|
|
797
|
+
* Drives the heartbeat mutation (on mount, interval, and tab re-focus) and
|
|
798
|
+
* subscribes to the live `listPresent` query for the given room.
|
|
799
|
+
*
|
|
800
|
+
* Call inside a reactive context (component / `createRoot`).
|
|
801
|
+
*/
|
|
802
|
+
/**
|
|
803
|
+
* A heartbeat mutation reference: takes `{ roomId, sessionId, data? }`.
|
|
804
|
+
*/
|
|
653
805
|
type HeartbeatReference = FunctionReference<"mutation", {
|
|
654
806
|
data?: Record<string, unknown>;
|
|
655
807
|
roomId: string;
|
|
656
808
|
sessionId: string;
|
|
657
809
|
}>;
|
|
658
810
|
/**
|
|
659
|
-
* A listPresent query reference: takes `{ roomId }` and returns the array of
|
|
660
|
-
* present members.
|
|
661
|
-
*/
|
|
811
|
+
* A listPresent query reference: takes `{ roomId }` and returns the array of
|
|
812
|
+
* present members.
|
|
813
|
+
*/
|
|
662
814
|
type ListPresentReference = FunctionReference<"query", {
|
|
663
815
|
roomId: string;
|
|
664
816
|
}>;
|
|
@@ -672,14 +824,22 @@ interface CreatePresenceOptions<H extends HeartbeatReference, L extends ListPres
|
|
|
672
824
|
/** The `api.*` reference for the presence listPresent query. */
|
|
673
825
|
listPresent: L;
|
|
674
826
|
/**
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
827
|
+
* Called when the `listPresent` subscription reports an error (a session
|
|
828
|
+
* expiry, an RLS denial). Without it — and without reading `error` — such a
|
|
829
|
+
* failure is invisible and `present` is cleared until a later frame arrives.
|
|
830
|
+
*/
|
|
831
|
+
onError?: SubscriptionErrorCallback;
|
|
832
|
+
/**
|
|
833
|
+
* Stable id for this presence row. Defaults to a fresh per-mount id.
|
|
834
|
+
* Pass a user/connection id to control deduping across tabs.
|
|
835
|
+
*/
|
|
678
836
|
sessionId?: string;
|
|
679
837
|
/** Forwarded to the heartbeat mutation / listPresent subscription when sharding by room. */
|
|
680
838
|
shardKey?: string;
|
|
681
839
|
}
|
|
682
840
|
interface CreatePresenceResult<L extends ListPresentReference> {
|
|
841
|
+
/** The `listPresent` subscription's last error, or `undefined`. */
|
|
842
|
+
error: () => SubscriptionError | undefined;
|
|
683
843
|
/** The present members for the room. `undefined` until the first push. */
|
|
684
844
|
present: () => ReturnOf<L> | undefined;
|
|
685
845
|
/** This mount's session id (generated when not supplied). */
|
|
@@ -689,35 +849,46 @@ interface CreatePresenceResult<L extends ListPresentReference> {
|
|
|
689
849
|
}
|
|
690
850
|
declare const createPresence: <H extends HeartbeatReference, L extends ListPresentReference>(roomId: string, options: CreatePresenceOptions<H, L>) => CreatePresenceResult<L>;
|
|
691
851
|
interface CreateQueryOptions {
|
|
852
|
+
/**
|
|
853
|
+
* Called when the server pushes a subscription-scoped error (an RLS denial, a
|
|
854
|
+
* query that starts failing server-side). Without a handler such an error has
|
|
855
|
+
* nowhere to go and the accessor simply freezes at its last good value.
|
|
856
|
+
*/
|
|
857
|
+
onError?: SubscriptionErrorCallback;
|
|
692
858
|
/** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
|
|
693
859
|
shardKey?: string;
|
|
694
860
|
}
|
|
695
861
|
/**
|
|
696
|
-
* Subscribe to a server query and return a reactive accessor of its value.
|
|
697
|
-
*
|
|
698
|
-
* The accessor reads `undefined` until the first server frame lands, then
|
|
699
|
-
* updates on every delta the WebSocket pushes — Solid's fine-grained signals
|
|
700
|
-
* mean only the components that read the accessor re-render, which maps cleanly
|
|
701
|
-
* onto Lunora's per-subscription delta model.
|
|
702
|
-
*
|
|
703
|
-
* `args` may be a plain value or an accessor; passing an accessor makes the
|
|
704
|
-
* subscription reactive — when the args change the old subscription is torn down
|
|
705
|
-
* (via `onCleanup`) and a fresh one opens for
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
|
|
862
|
+
* Subscribe to a server query and return a reactive accessor of its value.
|
|
863
|
+
*
|
|
864
|
+
* The accessor reads `undefined` until the first server frame lands, then
|
|
865
|
+
* updates on every delta the WebSocket pushes — Solid's fine-grained signals
|
|
866
|
+
* mean only the components that read the accessor re-render, which maps cleanly
|
|
867
|
+
* onto Lunora's per-subscription delta model.
|
|
868
|
+
*
|
|
869
|
+
* `args` may be a plain value or an accessor; passing an accessor makes the
|
|
870
|
+
* subscription reactive — when the args change the old subscription is torn down
|
|
871
|
+
* (via `onCleanup`), the accessor resets to `undefined`, and a fresh one opens for
|
|
872
|
+
* the new args. Pass `"skip"` (or an
|
|
873
|
+
* accessor returning `"skip"`) to short-circuit: no network call, no socket.
|
|
874
|
+
*
|
|
875
|
+
* ```tsx
|
|
876
|
+
* const messages = createQuery(api.messages.list, () => ({ channelId: channelId() }));
|
|
877
|
+
* return <For each={messages()?.messages}>{(m) => <li>{m.text}</li>}</For>;
|
|
878
|
+
* ```
|
|
879
|
+
*
|
|
880
|
+
* Pass `onError` to surface a subscription-scoped error the server pushes (an RLS
|
|
881
|
+
* denial, a query that starts failing server-side). Without it such an error is
|
|
882
|
+
* dropped and the accessor just freezes at its last good value.
|
|
883
|
+
*/
|
|
713
884
|
declare const createQuery: <F extends FunctionReference>(function_: F, args: (ArgsOf<F> | "skip") | Accessor<ArgsOf<F> | "skip">, options?: CreateQueryOptions) => Accessor<ReturnOf<F> | undefined>;
|
|
714
885
|
interface CreateRateLimitOptions {
|
|
715
886
|
/** Clock injection for tests. Defaults to `Date.now`. */
|
|
716
887
|
now?: () => number;
|
|
717
888
|
/**
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
889
|
+
* Re-evaluation cadence in milliseconds while throttled, so `retryAfter`
|
|
890
|
+
* ticks down and `disabled` flips back automatically. Defaults to `1000`.
|
|
891
|
+
*/
|
|
721
892
|
tickMs?: number;
|
|
722
893
|
}
|
|
723
894
|
interface CreateRateLimitResult {
|
|
@@ -735,14 +906,14 @@ interface CreateRateLimitResult {
|
|
|
735
906
|
retryAfter: () => number;
|
|
736
907
|
}
|
|
737
908
|
/**
|
|
738
|
-
* Client-side mirror of a rate limit for instant UX — disable a button or show
|
|
739
|
-
* a countdown without a round-trip. It runs the same token-bucket / fixed-window
|
|
740
|
-
* math as `@lunora/ratelimit` on the server, so the prediction agrees with the
|
|
741
|
-
* authoritative check; the server remains the source of truth.
|
|
742
|
-
*
|
|
743
|
-
* `config` is read on every call; pass a stable reference (module constant) so
|
|
744
|
-
* the derived memos stay settled.
|
|
745
|
-
*/
|
|
909
|
+
* Client-side mirror of a rate limit for instant UX — disable a button or show
|
|
910
|
+
* a countdown without a round-trip. It runs the same token-bucket / fixed-window
|
|
911
|
+
* math as `@lunora/ratelimit` on the server, so the prediction agrees with the
|
|
912
|
+
* authoritative check; the server remains the source of truth.
|
|
913
|
+
*
|
|
914
|
+
* `config` is read on every call; pass a stable reference (module constant) so
|
|
915
|
+
* the derived memos stay settled.
|
|
916
|
+
*/
|
|
746
917
|
declare const createRateLimit: (config: RateLimitConfig, options?: CreateRateLimitOptions) => CreateRateLimitResult;
|
|
747
918
|
/** The lifecycle of a stream the primitive is observing. */
|
|
748
919
|
type CreateStreamStatus = "complete" | "error" | "idle" | "streaming";
|
|
@@ -755,47 +926,59 @@ interface CreateStreamResult<T> {
|
|
|
755
926
|
status: Accessor<CreateStreamStatus>;
|
|
756
927
|
}
|
|
757
928
|
interface CreateStreamOptions {
|
|
929
|
+
/**
|
|
930
|
+
* Opt into resume-on-reconnect for a stream the server declared `durable`.
|
|
931
|
+
* The chunks already received are kept and the socket re-attaches to the same
|
|
932
|
+
* run, so a dropped connection mid-generation continues instead of surfacing
|
|
933
|
+
* `STREAM_DISCONNECTED`. Has no effect on an ephemeral stream.
|
|
934
|
+
*/
|
|
935
|
+
durable?: boolean;
|
|
758
936
|
/** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
|
|
759
937
|
maxBuffer?: number;
|
|
760
938
|
shardKey?: string;
|
|
761
939
|
}
|
|
762
940
|
/**
|
|
763
|
-
* Subscribe to a streaming query. Returns the chunks pushed so far plus a
|
|
764
|
-
* lifecycle status and a cancel function, all as accessors. Changing the
|
|
765
|
-
* resolved `args` resets the stream — the previous iterator is cancelled and a
|
|
766
|
-
* fresh one opens with empty `chunks`.
|
|
767
|
-
*
|
|
768
|
-
* `args` may be a plain value or an accessor; resolving it to `"skip"` keeps the
|
|
769
|
-
* primitive mounted without opening a stream (mirrors `createSubscription`). The
|
|
770
|
-
* Solid counterpart to React's `useStream`, re-expressed with signals.
|
|
771
|
-
*/
|
|
941
|
+
* Subscribe to a streaming query. Returns the chunks pushed so far plus a
|
|
942
|
+
* lifecycle status and a cancel function, all as accessors. Changing the
|
|
943
|
+
* resolved `args` resets the stream — the previous iterator is cancelled and a
|
|
944
|
+
* fresh one opens with empty `chunks`.
|
|
945
|
+
*
|
|
946
|
+
* `args` may be a plain value or an accessor; resolving it to `"skip"` keeps the
|
|
947
|
+
* primitive mounted without opening a stream (mirrors `createSubscription`). The
|
|
948
|
+
* Solid counterpart to React's `useStream`, re-expressed with signals.
|
|
949
|
+
*/
|
|
772
950
|
declare const createStream: <F extends FunctionReference<"stream">>(function_: F, args: ArgsOf<F> | "skip" | Accessor<ArgsOf<F> | "skip">, options?: CreateStreamOptions) => CreateStreamResult<ReturnOf<F>>;
|
|
773
951
|
interface CreateSubscriptionResult<T> {
|
|
774
952
|
data: Accessor<T | undefined>;
|
|
775
953
|
error: Accessor<Error | undefined>;
|
|
776
954
|
}
|
|
777
955
|
/**
|
|
778
|
-
* Subscribe to a reactive server push stream. Returns `{ data, error }`
|
|
779
|
-
* accessors that update whenever the server emits. Passing `"skip"` as `args`
|
|
780
|
-
* (or an accessor that resolves to `"skip"`) tears down the subscription.
|
|
781
|
-
|
|
956
|
+
* Subscribe to a reactive server push stream. Returns `{ data, error }`
|
|
957
|
+
* accessors that update whenever the server emits. Passing `"skip"` as `args`
|
|
958
|
+
* (or an accessor that resolves to `"skip"`) tears down the subscription.
|
|
959
|
+
*
|
|
960
|
+
* `onError` mirrors the other adapters' subscription primitives: it receives the
|
|
961
|
+
* raw wire-level subscription error (code included) alongside the normalised
|
|
962
|
+
* `error` accessor.
|
|
963
|
+
*/
|
|
782
964
|
declare const createSubscription: <F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip" | Accessor<ArgsOf<F> | "skip">, options?: {
|
|
965
|
+
onError?: SubscriptionErrorCallback;
|
|
783
966
|
shardKey?: string;
|
|
784
967
|
}) => CreateSubscriptionResult<ReturnOf<F>>;
|
|
785
968
|
/**
|
|
786
|
-
* Browser Web Audio subsystems for `createVoiceAgent` — the default microphone
|
|
787
|
-
* capture and speaker playback implementations injected into the primitive via
|
|
788
|
-
* its `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
|
|
789
|
-
* heavy Web Audio graph (and its structural DOM typings) stays isolated from the
|
|
790
|
-
* primitive's transport + reactive-state logic and remains mockable in a
|
|
791
|
-
* non-browser test env.
|
|
792
|
-
*/
|
|
793
|
-
/**
|
|
794
|
-
* The negotiated audio format the voice DO streams back. Mirrors
|
|
795
|
-
* `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` — re-declared (not
|
|
796
|
-
* imported) so this Solid package never pulls in the server-only `@lunora/agent`
|
|
797
|
-
* module graph.
|
|
798
|
-
*/
|
|
969
|
+
* Browser Web Audio subsystems for `createVoiceAgent` — the default microphone
|
|
970
|
+
* capture and speaker playback implementations injected into the primitive via
|
|
971
|
+
* its `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
|
|
972
|
+
* heavy Web Audio graph (and its structural DOM typings) stays isolated from the
|
|
973
|
+
* primitive's transport + reactive-state logic and remains mockable in a
|
|
974
|
+
* non-browser test env.
|
|
975
|
+
*/
|
|
976
|
+
/**
|
|
977
|
+
* The negotiated audio format the voice DO streams back. Mirrors
|
|
978
|
+
* `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` — re-declared (not
|
|
979
|
+
* imported) so this Solid package never pulls in the server-only `@lunora/agent`
|
|
980
|
+
* module graph.
|
|
981
|
+
*/
|
|
799
982
|
type VoiceAudioFormat = "mp3" | "wav";
|
|
800
983
|
/** Captures microphone audio and reports level / turn boundaries back to the primitive. */
|
|
801
984
|
interface VoiceMicrophone {
|
|
@@ -819,8 +1002,24 @@ interface MicrophoneConfig {
|
|
|
819
1002
|
interruptChunks: number;
|
|
820
1003
|
/** RMS above which the user is considered to be barging in while the agent speaks. */
|
|
821
1004
|
interruptThreshold: number;
|
|
822
|
-
/**
|
|
823
|
-
|
|
1005
|
+
/**
|
|
1006
|
+
* `true` from the moment a turn is committed until it completes — the whole
|
|
1007
|
+
* `thinking` + `speaking` window, not just the audible half.
|
|
1008
|
+
*
|
|
1009
|
+
* It gates BOTH branches below, and the wider span is the point. Gated only
|
|
1010
|
+
* on "audibly speaking", turn detection kept running through the entire
|
|
1011
|
+
* STT+LLM window after a `commit`: room noise at the (deliberately low)
|
|
1012
|
+
* `silenceThreshold` re-armed `sawSpeech`, another quiet gap fired a SECOND
|
|
1013
|
+
* `commit`, and the DO refused it with "a turn is already in progress" —
|
|
1014
|
+
* a refusal that returns before draining the audio buffer, so the PCM
|
|
1015
|
+
* captured since the first commit leaked into the next utterance.
|
|
1016
|
+
*
|
|
1017
|
+
* A genuine barge-in still works in that window: it routes through the
|
|
1018
|
+
* `onInterrupt` branch, which needs `interruptChunks` consecutive chunks at
|
|
1019
|
+
* `interruptThreshold` — an order of magnitude above `silenceThreshold` —
|
|
1020
|
+
* and `interrupt` is exactly what the DO tells the client to send.
|
|
1021
|
+
*/
|
|
1022
|
+
isTurnActive: () => boolean;
|
|
824
1023
|
/** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
|
|
825
1024
|
onAudio: (pcm: Uint8Array) => void;
|
|
826
1025
|
/** A barge-in was detected (RMS spike while the agent is speaking). */
|
|
@@ -839,15 +1038,10 @@ type CreateSpeaker = (config: {
|
|
|
839
1038
|
audioFormat: VoiceAudioFormat;
|
|
840
1039
|
}) => VoiceSpeaker;
|
|
841
1040
|
/**
|
|
842
|
-
* The
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
*/
|
|
846
|
-
/**
|
|
847
|
-
* The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
|
|
848
|
-
* live, WS-backed session keyed by `threadKey`. A structural subset of the
|
|
849
|
-
* generated member, so passing `api.agents.<name>Voice` type-checks.
|
|
850
|
-
*/
|
|
1041
|
+
* The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
|
|
1042
|
+
* live, WS-backed session keyed by `threadKey`. A structural subset of the
|
|
1043
|
+
* generated member, so passing `api.agents.<name>Voice` type-checks.
|
|
1044
|
+
*/
|
|
851
1045
|
type VoiceReference = FunctionReference<"stream", {
|
|
852
1046
|
threadKey: string;
|
|
853
1047
|
}, Record<string, unknown>>;
|
|
@@ -869,12 +1063,16 @@ interface VoiceSocket {
|
|
|
869
1063
|
type CreateSocket = (url: string) => VoiceSocket;
|
|
870
1064
|
interface CreateVoiceAgentOptions {
|
|
871
1065
|
/**
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
1066
|
+
* Advanced/test seam: build the microphone capture subsystem. Defaults to a
|
|
1067
|
+
* `getUserMedia` + Web Audio implementation. Injected wholesale so the Web
|
|
1068
|
+
* Audio graph stays isolated (and mockable in a non-browser test env).
|
|
1069
|
+
*/
|
|
876
1070
|
createMicrophone?: CreateMicrophone;
|
|
877
|
-
/**
|
|
1071
|
+
/**
|
|
1072
|
+
* Advanced/test seam: open the transport. Defaults to the WebSocket
|
|
1073
|
+
* implementation the client was built with (`client.getWebSocketImpl()`),
|
|
1074
|
+
* NOT a raw `globalThis.WebSocket`.
|
|
1075
|
+
*/
|
|
878
1076
|
createSocket?: CreateSocket;
|
|
879
1077
|
/** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
|
|
880
1078
|
createSpeaker?: CreateSpeaker;
|
|
@@ -887,8 +1085,8 @@ interface CreateVoiceAgentOptions {
|
|
|
887
1085
|
/** Input RMS below which audio counts as silence. Default `0.01`. */
|
|
888
1086
|
silenceThreshold?: number;
|
|
889
1087
|
/** The thread to converse on — shared with the agent's text turns. May be a plain value or accessor (resolved when the call opens). */
|
|
890
|
-
threadKey: MaybeAccessor
|
|
891
|
-
/** The generated `api.agents
|
|
1088
|
+
threadKey: MaybeAccessor<string>;
|
|
1089
|
+
/** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
|
|
892
1090
|
voice: VoiceReference;
|
|
893
1091
|
}
|
|
894
1092
|
interface CreateVoiceAgentResult {
|
|
@@ -916,73 +1114,122 @@ interface CreateVoiceAgentResult {
|
|
|
916
1114
|
transcript: Accessor<string>;
|
|
917
1115
|
}
|
|
918
1116
|
/**
|
|
919
|
-
* A first-class voice-call surface for a voice-enabled agent: it opens a
|
|
920
|
-
* WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
|
|
921
|
-
* streams the agent's synthesized speech back through the browser's audio output,
|
|
922
|
-
* and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
|
|
923
|
-
* `audioLevel`) to Solid signals. Pass the generated `api.agents
|
|
924
|
-
* reference (never a string), matching `createAgentChat`'s reference-passing style.
|
|
925
|
-
* The Solid counterpart to React's `useVoiceAgent`, re-expressed with signals; the
|
|
926
|
-
* per-call connection lives in a closure variable (a primitive runs once per
|
|
927
|
-
* component, so no signal-of-signal indirection is needed).
|
|
928
|
-
*
|
|
929
|
-
* v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
|
|
930
|
-
* turn detection and client-side RMS barge-in. The heavy Web Audio capture and
|
|
931
|
-
* playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
|
|
932
|
-
* `createSocket`) so the primitive is drivable outside a browser.
|
|
933
|
-
*/
|
|
1117
|
+
* A first-class voice-call surface for a voice-enabled agent: it opens a
|
|
1118
|
+
* WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
|
|
1119
|
+
* streams the agent's synthesized speech back through the browser's audio output,
|
|
1120
|
+
* and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
|
|
1121
|
+
* `audioLevel`) to Solid signals. Pass the generated `api.agents.<name>Voice`
|
|
1122
|
+
* reference (never a string), matching `createAgentChat`'s reference-passing style.
|
|
1123
|
+
* The Solid counterpart to React's `useVoiceAgent`, re-expressed with signals; the
|
|
1124
|
+
* per-call connection lives in a closure variable (a primitive runs once per
|
|
1125
|
+
* component, so no signal-of-signal indirection is needed).
|
|
1126
|
+
*
|
|
1127
|
+
* v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
|
|
1128
|
+
* turn detection and client-side RMS barge-in. The heavy Web Audio capture and
|
|
1129
|
+
* playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
|
|
1130
|
+
* `createSocket`) so the primitive is drivable outside a browser.
|
|
1131
|
+
*/
|
|
934
1132
|
declare const createVoiceAgent: (options: CreateVoiceAgentOptions) => CreateVoiceAgentResult;
|
|
935
1133
|
/**
|
|
936
|
-
* Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
|
|
937
|
-
* during SSR, then keep it live.
|
|
938
|
-
*
|
|
939
|
-
* This is the client half of PLAN4's "your loaders are live" handoff. The
|
|
940
|
-
* returned accessor is seeded **synchronously** from `preloaded.value`, so the
|
|
941
|
-
* very first read — during hydration — returns the server-rendered value with
|
|
942
|
-
* no loading flash and no `Suspense` fallback (unlike `createResource`, which
|
|
943
|
-
* always starts pending).
|
|
944
|
-
* attaches
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
* ```tsx
|
|
948
|
-
* // route loader (server): const preloaded = await preloadQuery(client, api.messages.list, args);
|
|
949
|
-
* const messages = hydratePreloaded(preloaded); // seeded from SSR, then live
|
|
950
|
-
* return
|
|
951
|
-
* ```
|
|
952
|
-
*
|
|
953
|
-
*
|
|
954
|
-
* hydration), so the subscription is strictly client-side —
|
|
955
|
-
* only value the server render ever sees.
|
|
956
|
-
|
|
957
|
-
|
|
1134
|
+
* Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
|
|
1135
|
+
* during SSR, then keep it live.
|
|
1136
|
+
*
|
|
1137
|
+
* This is the client half of PLAN4's "your loaders are live" handoff. The
|
|
1138
|
+
* returned accessor is seeded **synchronously** from `preloaded.value`, so the
|
|
1139
|
+
* very first read — during hydration — returns the server-rendered value with
|
|
1140
|
+
* no loading flash and no `Suspense` fallback (unlike `createResource`, which
|
|
1141
|
+
* always starts pending). Once the component mounts, a WebSocket subscription
|
|
1142
|
+
* attaches and every subsequent server delta flows into the same signal, so the
|
|
1143
|
+
* UI goes live with zero refetch.
|
|
1144
|
+
*
|
|
1145
|
+
* ```tsx
|
|
1146
|
+
* // route loader (server): const preloaded = await preloadQuery(client, api.messages.list, args);
|
|
1147
|
+
* const messages = hydratePreloaded(preloaded); // seeded from SSR, then live
|
|
1148
|
+
* return <pre>{JSON.stringify(messages())}</pre>;
|
|
1149
|
+
* ```
|
|
1150
|
+
*
|
|
1151
|
+
* Mount callbacks do not run on the server during SSR (both Solid majors defer
|
|
1152
|
+
* them until after hydration), so the subscription is strictly client-side —
|
|
1153
|
+
* the seed is the only value the server render ever sees.
|
|
1154
|
+
*
|
|
1155
|
+
* Pass `onError` to surface a subscription-scoped error the server pushes (a
|
|
1156
|
+
* session expiry, an RLS denial). Without it such an error is dropped and the
|
|
1157
|
+
* accessor keeps rendering the SSR snapshot as if it were live.
|
|
1158
|
+
*
|
|
1159
|
+
* The preloaded value was read for whoever was signed in when the page loaded.
|
|
1160
|
+
* After a sign-out or user switch retires that identity
|
|
1161
|
+
* (`client.identityEpoch() > 0`), every `hydratePreloaded` on the client (mounted
|
|
1162
|
+
* then or later) stops using it and returns `undefined` until the live value
|
|
1163
|
+
* arrives — matching `@lunora/react`'s `usePreloadedQuery`, hence the
|
|
1164
|
+
* `Accessor<T | undefined>` type. The same holds under a `LunoraProvider` whose
|
|
1165
|
+
* `client` was swapped: the value was preloaded for the first client.
|
|
1166
|
+
*/
|
|
1167
|
+
declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, options?: {
|
|
1168
|
+
onError?: SubscriptionErrorCallback;
|
|
1169
|
+
}) => Accessor<T | undefined>;
|
|
958
1170
|
interface LunoraProviderProps {
|
|
959
|
-
children:
|
|
1171
|
+
children: SolidChildren;
|
|
960
1172
|
/**
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1173
|
+
* The framework-neutral transport. Build it once at the app root with
|
|
1174
|
+
* `new LunoraClient({ url })` (or `createServerClient` during SSR) and pass
|
|
1175
|
+
* it here — the provider does not own its lifecycle, so the same instance
|
|
1176
|
+
* survives across route navigations.
|
|
1177
|
+
*/
|
|
966
1178
|
client: LunoraClient;
|
|
967
1179
|
}
|
|
968
1180
|
/**
|
|
969
|
-
* Provides a {@link LunoraClient} to the Solid tree via {@link LunoraContext}.
|
|
970
|
-
*
|
|
971
|
-
* Solid's context is reactive-graph scoped rather than render scoped, so unlike
|
|
972
|
-
* the React provider there is no QueryClient to detect or lazily create — the
|
|
973
|
-
* adapter's reactive primitives (`createQuery`, `createMutation`,
|
|
974
|
-
* `hydratePreloaded`) own their own signals and read the client straight from
|
|
975
|
-
* context. Drop one of these at the root of your app:
|
|
976
|
-
*
|
|
977
|
-
* ```tsx
|
|
978
|
-
* const client = new LunoraClient({ url: window.location.origin });
|
|
979
|
-
*
|
|
980
|
-
* render(() => (
|
|
981
|
-
*
|
|
982
|
-
*
|
|
983
|
-
*
|
|
984
|
-
* ), root);
|
|
985
|
-
* ```
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1181
|
+
* Provides a {@link LunoraClient} to the Solid tree via {@link LunoraContext}.
|
|
1182
|
+
*
|
|
1183
|
+
* Solid's context is reactive-graph scoped rather than render scoped, so unlike
|
|
1184
|
+
* the React provider there is no QueryClient to detect or lazily create — the
|
|
1185
|
+
* adapter's reactive primitives (`createQuery`, `createMutation`,
|
|
1186
|
+
* `hydratePreloaded`) own their own signals and read the client straight from
|
|
1187
|
+
* context. Drop one of these at the root of your app:
|
|
1188
|
+
*
|
|
1189
|
+
* ```tsx
|
|
1190
|
+
* const client = new LunoraClient({ url: window.location.origin });
|
|
1191
|
+
*
|
|
1192
|
+
* render(() => (
|
|
1193
|
+
* <LunoraProvider client={client}>
|
|
1194
|
+
* <App />
|
|
1195
|
+
* </LunoraProvider>
|
|
1196
|
+
* ), root);
|
|
1197
|
+
* ```
|
|
1198
|
+
*
|
|
1199
|
+
* Swapping the `client` prop for a different instance **remounts the subtree**
|
|
1200
|
+
* under the provider. Solid's providers read their value once, so the swap
|
|
1201
|
+
* cannot be pushed into primitives that already resolved the client; instead
|
|
1202
|
+
* every primitive below is disposed (its subscriptions on the old client torn
|
|
1203
|
+
* down) and recreated against the new client, starting from `undefined` — no
|
|
1204
|
+
* rows from the old client survive, and `hydratePreloaded` does not seed a value
|
|
1205
|
+
* preloaded for the client the provider first rendered with (not even after
|
|
1206
|
+
* swapping back to it). Local component state under the provider resets with
|
|
1207
|
+
* it. Re-reading the same instance is a no-op.
|
|
1208
|
+
*
|
|
1209
|
+
* Written with `createComponent` rather than JSX on purpose. Solid 1.x and 2.0
|
|
1210
|
+
* compile JSX against different runtimes (`solid-js/web` vs `@solidjs/web`), so
|
|
1211
|
+
* a JSX source file would force this package to ship two builds; `createComponent`
|
|
1212
|
+
* is exported from the `solid-js` root in both majors, and the provider component
|
|
1213
|
+
* itself is resolved per-major by {@link providerOf}.
|
|
1214
|
+
*/
|
|
1215
|
+
declare const LunoraProvider: (props: LunoraProviderProps) => SolidElement;
|
|
1216
|
+
export { type ActionClient, type ActionHandle, type AgentChatMessage, type AgentLiveEvent, type AgentProgressEvent, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, AuthLoading, Authenticated, type CreateAgentApi, type CreateAgentChatApi, type CreateAgentChatOptions, type CreateAgentChatResult, type CreateAgentOptions, type CreateAgentResult, type CreateAgentStateApi, type CreateAgentStateOptions, type CreateAgentStateResult, type CreateAgentToolEventsApi, type CreateAgentToolEventsOptions, type CreateAgentToolEventsResult, type CreateInfiniteQueryOptions, type CreateInfiniteQueryResult, type CreateLiveTopicResult, type CreatePaginatedQueryOptions, type CreatePaginatedQueryResult, type CreatePresenceOptions, type CreatePresenceResult, type CreateQueryOptions, type CreateRateLimitOptions, type CreateRateLimitResult, type CreateStreamOptions, type CreateStreamResult, type CreateStreamStatus, type CreateSubscriptionResult, type CreateVoiceAgentOptions, type CreateVoiceAgentResult, type FlagValue, type HeartbeatReference, type ListPresentReference, LunoraContext, LunoraProvider,
|
|
1217
|
+
/**
|
|
1218
|
+
* SolidJS adapter for Lunora.
|
|
1219
|
+
*
|
|
1220
|
+
* Thin, idiomatic glue over the framework-neutral `@lunora/client`. Solid's
|
|
1221
|
+
* fine-grained signals map directly onto Lunora's per-subscription deltas, so a
|
|
1222
|
+
* live query is just a signal the WebSocket writes to. The adapter exposes
|
|
1223
|
+
* `LunoraProvider` / `useLunora` (context carrying the `LunoraClient`),
|
|
1224
|
+
* `createQuery` (a live query accessor that opens a subscription and updates on
|
|
1225
|
+
* every delta), `createMutation` (an optimistic mutation handle), and
|
|
1226
|
+
* `hydratePreloaded` (seed a query from an SSR `Preloaded` token synchronously —
|
|
1227
|
+
* no loading flash — then attach the live subscription; the client half of
|
|
1228
|
+
* PLAN4's "your loaders are live" reactive-loader handoff).
|
|
1229
|
+
*
|
|
1230
|
+
* Server-side preloading (`createServerClient`, `preloadQuery`) lives in the
|
|
1231
|
+
* socket-free `@lunora/solid/server` entry (a re-export of `@lunora/client/ssr`, the
|
|
1232
|
+
* framework-neutral server contract) — call it from your SolidStart route loader
|
|
1233
|
+
* and hand the resulting `Preloaded` token to `hydratePreloaded`.
|
|
1234
|
+
*/
|
|
1235
|
+
type LunoraProviderProps, type MutationClient, type MutationHandle, type MutatorHook, type PageItemOf, type PaginatedArgs, type SolidChildren, Unauthenticated, type UseAuthResult, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, createAction, createActionForClient, createAgent, createAgentChat, createAgentState, createAgentToolEvents, createAuth, createConnectionStatus, createFlag, createFlags, createInfiniteQuery, createLiveTopic, createMutation, createMutationForClient, createMutator, createPaginatedQuery, createPresence, createQuery, createRateLimit, createStream, createSubscription, createVoiceAgent, hydratePreloaded, useLunora };
|