@lunora/solid 1.0.0-alpha.25 → 1.0.0-alpha.251
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 +776 -471
- package/dist/index.d.ts +776 -471
- 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-CS3PI19y.mjs +1 -0
- package/dist/packem_shared/createAgentState-BPo1e_ih.mjs +1 -0
- package/dist/packem_shared/createAgentToolEvents-Sjkq8qXp.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-D42ylvG0.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-DQoGdUMB.mjs +0 -78
- package/dist/packem_shared/createInfiniteQuery-DwajCO2G.mjs +0 -314
- 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-DePnevIy.mjs +0 -38
package/dist/index.d.ts
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, OnlineOnlyOption, 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
|
+
}
|
|
24
38
|
/**
|
|
25
|
-
* The
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}
|
|
46
|
+
/**
|
|
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,44 +160,38 @@ 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;
|
|
139
|
-
/** Approval lifecycle marker on a human-in-the-loop tool message. */
|
|
140
|
-
status?: "approved" | "awaiting_approval" | "rejected";
|
|
193
|
+
/** Approval or secret-request lifecycle marker on a human-in-the-loop tool message. */
|
|
194
|
+
status?: "approved" | "awaiting_approval" | "awaiting_secret" | "rejected";
|
|
141
195
|
toolCallId?: string;
|
|
142
196
|
toolCalls?: ReadonlyArray<{
|
|
143
197
|
id: string;
|
|
@@ -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", {
|
|
@@ -191,7 +245,7 @@ type AgentMessagesReference$1 = FunctionReference<"query", {
|
|
|
191
245
|
}, ReadonlyArray<Record<string, unknown>>>;
|
|
192
246
|
/** The `agents:agentResolveApproval` reference — resolves a human-in-the-loop tool approval. */
|
|
193
247
|
type AgentApprovalReference = FunctionReference<"mutation", {
|
|
194
|
-
decision: "approve" | "reject";
|
|
248
|
+
decision: "approve" | "approve_for_thread" | "reject";
|
|
195
249
|
instanceId: string;
|
|
196
250
|
note?: string;
|
|
197
251
|
threadKey: string;
|
|
@@ -199,27 +253,62 @@ type AgentApprovalReference = FunctionReference<"mutation", {
|
|
|
199
253
|
}, {
|
|
200
254
|
resolved: boolean;
|
|
201
255
|
}>;
|
|
256
|
+
/** The `agents:agentSupplySecret` reference — stores a person's value for a paused `requestSecretTool` call. */
|
|
257
|
+
type AgentSupplySecretReference = FunctionReference<"mutation", {
|
|
258
|
+
secret: string;
|
|
259
|
+
threadKey: string;
|
|
260
|
+
toolCallId: string;
|
|
261
|
+
}, {
|
|
262
|
+
resolved: boolean;
|
|
263
|
+
}>;
|
|
264
|
+
/** The `agents:agentDeclineSecret` reference — refuses a paused `requestSecretTool` call. */
|
|
265
|
+
type AgentDeclineSecretReference = FunctionReference<"mutation", {
|
|
266
|
+
threadKey: string;
|
|
267
|
+
toolCallId: string;
|
|
268
|
+
}, {
|
|
269
|
+
resolved: boolean;
|
|
270
|
+
}>;
|
|
202
271
|
/** The `agents:agentThread` reference — live thread status + in-flight `instanceId`. */
|
|
203
272
|
type AgentThreadReference = FunctionReference<"query", {
|
|
204
273
|
key: string;
|
|
205
274
|
}, Record<string, unknown> | undefined>;
|
|
275
|
+
/** A tool approved for the rest of a thread, as `agents:agentApprovalGrants` lists it. */
|
|
276
|
+
interface AgentApprovalGrant {
|
|
277
|
+
createdAt: number;
|
|
278
|
+
toolName: string;
|
|
279
|
+
}
|
|
280
|
+
/** The `agents:agentApprovalGrants` reference — live thread-scoped approval grants. */
|
|
281
|
+
type AgentApprovalGrantsReference = FunctionReference<"query", {
|
|
282
|
+
key: string;
|
|
283
|
+
}, ReadonlyArray<AgentApprovalGrant>>;
|
|
284
|
+
/** The `agents:agentRevokeApprovalGrant` reference — removes a thread-scoped approval grant. */
|
|
285
|
+
type AgentRevokeApprovalGrantReference = FunctionReference<"mutation", {
|
|
286
|
+
threadKey: string;
|
|
287
|
+
toolName: string;
|
|
288
|
+
}, {
|
|
289
|
+
revoked: boolean;
|
|
290
|
+
}>;
|
|
206
291
|
/**
|
|
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
|
-
*/
|
|
292
|
+
* An app stream reference that tees the agent's in-flight live events, keyed by
|
|
293
|
+
* thread. Carries token deltas and — since `ctx.reportProgress` rides the same
|
|
294
|
+
* sink — tool progress events; this primitive consumes only the token arm.
|
|
295
|
+
*/
|
|
211
296
|
type AgentTokenStreamReference = FunctionReference<"stream", {
|
|
212
297
|
key: string;
|
|
213
298
|
}, AgentLiveEvent>;
|
|
214
299
|
/**
|
|
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
|
-
*/
|
|
300
|
+
* The `agents.*` reference surface the chat primitive reads. A structural subset
|
|
301
|
+
* of the generated `api.agents`, so the whole generated `api` object is
|
|
302
|
+
* assignable.
|
|
303
|
+
*/
|
|
219
304
|
interface CreateAgentChatApi {
|
|
220
305
|
agents: {
|
|
306
|
+
agentApprovalGrants: AgentApprovalGrantsReference;
|
|
307
|
+
agentDeclineSecret: AgentDeclineSecretReference;
|
|
221
308
|
agentMessages: AgentMessagesReference$1;
|
|
222
309
|
agentResolveApproval: AgentApprovalReference;
|
|
310
|
+
agentRevokeApprovalGrant: AgentRevokeApprovalGrantReference;
|
|
311
|
+
agentSupplySecret: AgentSupplySecretReference;
|
|
223
312
|
agentThread: AgentThreadReference;
|
|
224
313
|
};
|
|
225
314
|
}
|
|
@@ -227,79 +316,105 @@ interface CreateAgentChatOptions {
|
|
|
227
316
|
/** The generated `api` — its `agents.*` surface provides history, thread state, and approval resolution. */
|
|
228
317
|
api: CreateAgentChatApi;
|
|
229
318
|
/**
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
319
|
+
* Optional app mutation over the agent's cancel path
|
|
320
|
+
* (`ctx.agents.<name>.cancel(id)`). Called with `{ instanceId, threadKey }`.
|
|
321
|
+
* When omitted (or no run is in flight) {@link CreateAgentChatResult.cancel} is
|
|
322
|
+
* a no-op.
|
|
323
|
+
*/
|
|
235
324
|
cancel?: FunctionReference<"mutation">;
|
|
236
325
|
/** History depth forwarded to `agents:agentMessages`. */
|
|
237
326
|
limit?: number;
|
|
238
327
|
/**
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
328
|
+
* Called when the live history, thread, or grants subscription reports an error (a
|
|
329
|
+
* session expiry, an RLS denial). Without it — and without reading `error` —
|
|
330
|
+
* such a failure is invisible and `messages` / `status` are cleared until a later frame arrives.
|
|
331
|
+
*/
|
|
332
|
+
onError?: SubscriptionErrorCallback;
|
|
333
|
+
/**
|
|
334
|
+
* The app mutation that starts (or continues) a run — a thin wrapper over
|
|
335
|
+
* `ctx.agents.<name>.run(...)`. Called with `{ threadKey, input }` merged with
|
|
336
|
+
* {@link CreateAgentChatOptions.sendArgs} and the per-call args.
|
|
337
|
+
*/
|
|
243
338
|
send: FunctionReference<"mutation">;
|
|
244
339
|
/** Extra args merged into every `send` call (e.g. an `owner` or `title`). */
|
|
245
340
|
sendArgs?: Record<string, unknown>;
|
|
246
341
|
/**
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
342
|
+
* Optional live token-delta stream — an app stream function that tees the
|
|
343
|
+
* agent's in-flight deltas. When omitted {@link CreateAgentChatResult.streamingText}
|
|
344
|
+
* stays empty and the UI updates message-by-message from durable history.
|
|
345
|
+
*/
|
|
251
346
|
stream?: AgentTokenStreamReference;
|
|
252
347
|
/** The thread to observe and continue — a plain value or accessor (an accessor re-subscribes on change). */
|
|
253
|
-
threadKey: MaybeAccessor
|
|
348
|
+
threadKey: MaybeAccessor<string>;
|
|
254
349
|
}
|
|
255
350
|
interface CreateAgentChatResult {
|
|
351
|
+
/** The tools approved for the rest of this thread, live. Empty until the grants subscription answers. */
|
|
352
|
+
approvalGrants: Accessor<ReadonlyArray<AgentApprovalGrant>>;
|
|
256
353
|
/** Approve a paused human-in-the-loop tool call (optionally with a note). */
|
|
257
354
|
approve: (toolCallId: string, note?: string) => Promise<void>;
|
|
258
355
|
/**
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
356
|
+
* Approve a paused tool call and grant that tool for the rest of the thread, so
|
|
357
|
+
* later calls to it run without pausing. Undo with {@link CreateAgentChatResult.revokeGrant}.
|
|
358
|
+
*/
|
|
359
|
+
approveForThread: (toolCallId: string, note?: string) => Promise<void>;
|
|
360
|
+
/**
|
|
361
|
+
* Terminate the in-flight run and mark its thread `"cancelled"`. Resolves as a
|
|
362
|
+
* no-op when no `cancel` mutation was supplied or no run is in flight.
|
|
363
|
+
*/
|
|
262
364
|
cancel: () => Promise<void>;
|
|
365
|
+
/** Refuse a paused `requestSecretTool` call: the run resumes with a "declined" result. */
|
|
366
|
+
declineSecret: (toolCallId: string) => Promise<void>;
|
|
367
|
+
/** The history, thread, or grants subscription's last error, or `undefined`. */
|
|
368
|
+
error: Accessor<Error | undefined>;
|
|
263
369
|
/** Durable thread history (oldest first) plus any un-acknowledged optimistic user turns. */
|
|
264
370
|
messages: Accessor<ReadonlyArray<AgentChatMessage>>;
|
|
265
371
|
/** Reject a paused human-in-the-loop tool call (optionally with a reason). */
|
|
266
372
|
reject: (toolCallId: string, note?: string) => Promise<void>;
|
|
373
|
+
/** Remove a thread-scoped approval grant so the tool's gate applies again to later calls. */
|
|
374
|
+
revokeGrant: (toolName: string) => Promise<void>;
|
|
267
375
|
/** Start (or continue) a run with a user message; extra args merge over `sendArgs`. Appends an optimistic user turn. */
|
|
268
376
|
send: (input: string, args?: Record<string, unknown>) => Promise<void>;
|
|
269
377
|
/** The live thread status, or `undefined` before the thread exists. */
|
|
270
378
|
status: Accessor<AgentThreadStatus | undefined>;
|
|
271
379
|
/** The in-flight turn's streamed text — live-only, empty once the turn persists to `messages`. */
|
|
272
380
|
streamingText: Accessor<string>;
|
|
381
|
+
/**
|
|
382
|
+
* Give a paused `requestSecretTool` call its value. Always sent online-only: the
|
|
383
|
+
* value is never queued, persisted or replayed, and the call rejects with
|
|
384
|
+
* `OFFLINE_NOT_QUEUED` while the connection is down. The primitive keeps no copy;
|
|
385
|
+
* a failure rethrows the original error.
|
|
386
|
+
*/
|
|
387
|
+
supplySecret: (toolCallId: string, secret: string) => Promise<void>;
|
|
273
388
|
}
|
|
274
389
|
/**
|
|
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
|
-
*/
|
|
390
|
+
* A first-class agent chat surface: live durable history + in-flight token
|
|
391
|
+
* streaming + the send / approve / reject / secret / cancel writes, keyed by `threadKey` —
|
|
392
|
+
* the Solid counterpart to React's `useAgentChat`, re-expressed with signals.
|
|
393
|
+
*
|
|
394
|
+
* It composes the existing primitives rather than adding transport:
|
|
395
|
+
* `createSubscription(api.agents.agentMessages)` for durable history,
|
|
396
|
+
* `createSubscription(api.agents.agentThread)` for live status + the in-flight
|
|
397
|
+
* `instanceId`, {@link createStream} over an app token stream for in-flight deltas,
|
|
398
|
+
* and `createMutation` for the writes (`api.agents.agentResolveApproval` for
|
|
399
|
+
* approvals; app-defined wrappers for `send`/`cancel`). Only the `agents:*`
|
|
400
|
+
* surface is hard-coded — `send`/`cancel`/`stream` stay generic references.
|
|
401
|
+
*
|
|
402
|
+
* A `send` optimistically appends the user turn so it renders immediately; the
|
|
403
|
+
* optimistic row clears once the durable history carries the acknowledged turn.
|
|
404
|
+
* `streamingText` is live-only: it holds the current turn's streamed text and
|
|
405
|
+
* empties as soon as that turn's assistant message lands in `messages` (the
|
|
406
|
+
* persisted message is the source of truth), consistent with the loop's
|
|
407
|
+
* replay-safe, live-only delta design.
|
|
408
|
+
*/
|
|
294
409
|
declare const createAgentChat: (options: CreateAgentChatOptions) => CreateAgentChatResult;
|
|
295
410
|
/**
|
|
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
|
-
*/
|
|
411
|
+
* The `agents.agentState` reference the primitive subscribes to for the thread's
|
|
412
|
+
* live synced state. A structural subset of the generated `api.agents` surface
|
|
413
|
+
* (like `CreateAgentApi` for `agentThread`), so the whole generated `api` object
|
|
414
|
+
* is assignable. Client-safe: no `@lunora/agent` import — the per-agent state type
|
|
415
|
+
* is mirrored by the primitive's generic `T`, since codegen pins the reference
|
|
416
|
+
* return as an optional record (it never evaluates agent config).
|
|
417
|
+
*/
|
|
303
418
|
interface CreateAgentStateApi {
|
|
304
419
|
agents: {
|
|
305
420
|
agentState: FunctionReference<"query", {
|
|
@@ -311,7 +426,7 @@ interface CreateAgentStateOptions {
|
|
|
311
426
|
/** The generated `api` — its `agents.agentState` query drives live thread state. */
|
|
312
427
|
api: CreateAgentStateApi;
|
|
313
428
|
/** The thread whose synced state to observe — a plain value or accessor (an accessor re-subscribes on change). */
|
|
314
|
-
threadKey: MaybeAccessor
|
|
429
|
+
threadKey: MaybeAccessor<string>;
|
|
315
430
|
}
|
|
316
431
|
interface CreateAgentStateResult<T> {
|
|
317
432
|
/** The subscription error, if the live channel reported one. */
|
|
@@ -320,20 +435,20 @@ interface CreateAgentStateResult<T> {
|
|
|
320
435
|
state: Accessor<T | undefined>;
|
|
321
436
|
}
|
|
322
437
|
/**
|
|
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
|
-
*/
|
|
438
|
+
* Subscribe to an agent thread's synced state — the `setState`-style value a tool
|
|
439
|
+
* writes with `ctx.setState(...)`, seeded by `defineAgent({ initialState })`. A
|
|
440
|
+
* thin wrapper over `createSubscription(api.agents.agentState, { key })`: the
|
|
441
|
+
* server pushes a fresh frame whenever the state changes (the dedicated query's
|
|
442
|
+
* per-socket JSON memo suppresses no-op pushes on unrelated thread writes), so
|
|
443
|
+
* `state` updates only on a real `setState`. The Solid counterpart to React's
|
|
444
|
+
* `useAgentState`, re-expressed with signals.
|
|
445
|
+
*
|
|
446
|
+
* Generic over the app's state shape (`createAgentState` with a `SupportState`
|
|
447
|
+
* type argument, itself a record) — the reference is typed as an optional record
|
|
448
|
+
* because codegen cannot see the per-agent state type; the generic casts to `T`.
|
|
449
|
+
* The `extends` bound (not a bare unbounded type parameter) is required so the
|
|
450
|
+
* reference's optional-record return casts cleanly to `T`.
|
|
451
|
+
*/
|
|
337
452
|
declare const createAgentState: <T extends Record<string, unknown> = Record<string, unknown>>(options: CreateAgentStateOptions) => CreateAgentStateResult<T>;
|
|
338
453
|
/** The `agents:agentMessages` reference — live durable thread history. */
|
|
339
454
|
type AgentMessagesReference = FunctionReference<"query", {
|
|
@@ -341,18 +456,18 @@ type AgentMessagesReference = FunctionReference<"query", {
|
|
|
341
456
|
limit?: number;
|
|
342
457
|
}, ReadonlyArray<Record<string, unknown>>>;
|
|
343
458
|
/**
|
|
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
|
-
*/
|
|
459
|
+
* An app stream reference that tees the agent's in-flight live events, keyed by
|
|
460
|
+
* thread. Carries token deltas and tool progress events; this primitive consumes
|
|
461
|
+
* only the progress arm (`kind === "progress"`).
|
|
462
|
+
*/
|
|
348
463
|
type AgentLiveStreamReference = FunctionReference<"stream", {
|
|
349
464
|
key: string;
|
|
350
465
|
}, AgentLiveEvent>;
|
|
351
466
|
/**
|
|
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
|
-
*/
|
|
467
|
+
* The `agents.*` reference surface the tool-events primitive reads. A structural
|
|
468
|
+
* subset of the generated `api.agents`, so the whole generated `api` object is
|
|
469
|
+
* assignable.
|
|
470
|
+
*/
|
|
356
471
|
interface CreateAgentToolEventsApi {
|
|
357
472
|
agents: {
|
|
358
473
|
agentMessages: AgentMessagesReference;
|
|
@@ -364,21 +479,21 @@ interface CreateAgentToolEventsOptions {
|
|
|
364
479
|
/** History depth forwarded to `agents:agentMessages`. */
|
|
365
480
|
limit?: number;
|
|
366
481
|
/**
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
482
|
+
* Optional live event stream — the same app stream function `createAgentChat`
|
|
483
|
+
* uses. When supplied, ephemeral `ctx.reportProgress(...)` events for the
|
|
484
|
+
* thread are surfaced as `{ type: "progress" }` entries; when omitted only the
|
|
485
|
+
* durable lifecycle (call / result / awaiting-approval / awaiting-secret) is returned.
|
|
486
|
+
*/
|
|
372
487
|
stream?: AgentLiveStreamReference;
|
|
373
488
|
/** The thread whose tool activity to observe — a plain value or accessor (an accessor re-subscribes on change). */
|
|
374
|
-
threadKey: MaybeAccessor
|
|
489
|
+
threadKey: MaybeAccessor<string>;
|
|
375
490
|
}
|
|
376
491
|
/**
|
|
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
|
-
*/
|
|
492
|
+
* A single tool-lifecycle event for a thread. The durable arms
|
|
493
|
+
* (`call`/`result`/`awaiting-approval`/`awaiting-secret`) are derived from `agents:agentMessages`
|
|
494
|
+
* and carry the persisted `seq`; the ephemeral `progress` arm comes live off the
|
|
495
|
+
* stream and has no `seq`. Discriminate on `type`.
|
|
496
|
+
*/
|
|
382
497
|
type AgentToolEvent = {
|
|
383
498
|
data: unknown;
|
|
384
499
|
toolCallId: string;
|
|
@@ -401,159 +516,241 @@ type AgentToolEvent = {
|
|
|
401
516
|
toolCallId?: string;
|
|
402
517
|
toolName?: string;
|
|
403
518
|
type: "awaiting-approval";
|
|
519
|
+
} | {
|
|
520
|
+
seq: number;
|
|
521
|
+
toolCallId?: string;
|
|
522
|
+
toolName?: string;
|
|
523
|
+
type: "awaiting-secret";
|
|
404
524
|
};
|
|
405
525
|
interface CreateAgentToolEventsResult {
|
|
406
526
|
/**
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
527
|
+
* The thread's tool events: the durable lifecycle (oldest first, by `seq`)
|
|
528
|
+
* followed by any in-flight ephemeral progress events, recomputed from the live
|
|
529
|
+
* subscription + stream. Treat as derived, not identity-stable.
|
|
530
|
+
*/
|
|
411
531
|
events: Accessor<ReadonlyArray<AgentToolEvent>>;
|
|
412
532
|
}
|
|
413
533
|
/**
|
|
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
|
-
*/
|
|
534
|
+
* A focused view of a thread's tool activity: tool calls, their results,
|
|
535
|
+
* human-in-the-loop approval pauses, and live `ctx.reportProgress(...)` events —
|
|
536
|
+
* without the full chat message surface. The Solid counterpart to React's
|
|
537
|
+
* `useAgentToolEvents`, re-expressed as a memo.
|
|
538
|
+
*
|
|
539
|
+
* It composes the existing primitives rather than adding transport:
|
|
540
|
+
* `createSubscription(api.agents.agentMessages)` for the durable lifecycle and
|
|
541
|
+
* {@link createStream} over the optional app event stream for ephemeral progress.
|
|
542
|
+
* Progress events are live-only (the durable path never emits them): they ride
|
|
543
|
+
* the same sink as token deltas and are surfaced here, correlated to their tool
|
|
544
|
+
* call by `toolCallId`. For the conversational surface (messages + streaming text
|
|
545
|
+
* + approvals) use `createAgentChat`; this primitive is the tool-observability slice.
|
|
546
|
+
*/
|
|
427
547
|
declare const createAgentToolEvents: (options: CreateAgentToolEventsOptions) => CreateAgentToolEventsResult;
|
|
548
|
+
/**
|
|
549
|
+
* Children accepted by this adapter's components.
|
|
550
|
+
*
|
|
551
|
+
* Structurally identical to Solid 2.0's `Element`, which is in turn a widening
|
|
552
|
+
* of 1.x's `JSX.Element` (a DOM `Node` satisfies `object` with no
|
|
553
|
+
* `call`/`apply`/`bind`). Children are contravariant, so one union that accepts
|
|
554
|
+
* both majors' element types is enough — no `any` required here.
|
|
555
|
+
*/
|
|
556
|
+
type SolidChildren = SolidChildrenArray | boolean | null | number | (object & {
|
|
557
|
+
readonly apply?: never;
|
|
558
|
+
readonly bind?: never;
|
|
559
|
+
readonly call?: never;
|
|
560
|
+
}) | (string & {}) | undefined;
|
|
561
|
+
interface SolidChildrenArray extends Array<SolidChildren> {}
|
|
562
|
+
/**
|
|
563
|
+
* The return type of this adapter's components.
|
|
564
|
+
*
|
|
565
|
+
* Deliberately `any`, and the one place in the package where that is the right
|
|
566
|
+
* answer. TypeScript checks a component's return type against the *renderer's*
|
|
567
|
+
* `JSX.Element`, and the two majors define that incompatibly — 1.x's is rooted
|
|
568
|
+
* in the DOM `Node` interface, 2.0's in an opaque `RenderedElement`. Neither is
|
|
569
|
+
* assignable to the other, so no concrete type satisfies both, and a structural
|
|
570
|
+
* union (as used for {@link SolidChildren}) fails in the return position. `any`
|
|
571
|
+
* is what lets one set of `.d.ts` files type-check inside a 1.x app and a 2.x
|
|
572
|
+
* app alike.
|
|
573
|
+
*/
|
|
574
|
+
type SolidElement = any;
|
|
428
575
|
interface UseAuthResult {
|
|
429
576
|
setToken: (token: string | null) => void;
|
|
577
|
+
/**
|
|
578
|
+
* The resolved auth state. Branch on this, not on `user() === null` — see the
|
|
579
|
+
* contract in `@lunora/client/auth`; `user` is `null` both when signed out
|
|
580
|
+
* and when a held credential's identity could not be resolved.
|
|
581
|
+
*/
|
|
582
|
+
status: Accessor<AuthStatus>;
|
|
430
583
|
token: Accessor<string | null>;
|
|
431
584
|
user: Accessor<User | null>;
|
|
432
585
|
}
|
|
433
586
|
/**
|
|
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
|
-
*/
|
|
587
|
+
* Token + identity plumbing for Solid. Returns `{ token, user, setToken }`
|
|
588
|
+
* where `token` and `user` are fine-grained signals. `setToken(jwt)` after
|
|
589
|
+
* sign-in updates the shared client token; `user` resolves asynchronously via
|
|
590
|
+
* `client.getCurrentUser()` and updates on every token change.
|
|
591
|
+
*/
|
|
439
592
|
declare const createAuth: () => UseAuthResult;
|
|
440
593
|
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
|
-
|
|
594
|
+
children: SolidChildren;
|
|
595
|
+
}
|
|
596
|
+
/** An auth-gate component: renders its children only while the gate's condition holds. */
|
|
597
|
+
type AuthGate = (props: AuthGateProps) => SolidElement;
|
|
598
|
+
/**
|
|
599
|
+
* Render `children` once authentication has settled in the caller's favour — a
|
|
600
|
+
* credential is held and nothing has contradicted it.
|
|
601
|
+
*
|
|
602
|
+
* Gated on the shared `AuthStatus` contract in `@lunora/client/auth`, not on
|
|
603
|
+
* `user() !== null`: an unreachable identity endpoint leaves `user` at `null`
|
|
604
|
+
* while the credential is still perfectly valid.
|
|
605
|
+
*/
|
|
606
|
+
declare const Authenticated: AuthGate;
|
|
607
|
+
/**
|
|
608
|
+
* Render `children` while authentication is still in progress — a credential is
|
|
609
|
+
* held and the first identity resolve has not come back yet.
|
|
610
|
+
*/
|
|
611
|
+
declare const AuthLoading: AuthGate;
|
|
612
|
+
/**
|
|
613
|
+
* Render `children` only when auth has settled and there is no session — no
|
|
614
|
+
* credential, or the server answered that the credential has none.
|
|
615
|
+
*/
|
|
616
|
+
declare const Unauthenticated: AuthGate;
|
|
617
|
+
/**
|
|
618
|
+
* Reactive accessor of the client's aggregate live-socket status across all
|
|
619
|
+
* shard connections. Reads the current status synchronously and updates on
|
|
620
|
+
* every transition (`idle` → `connecting` → `connected` → `offline`) — Solid's
|
|
621
|
+
* fine-grained signals mean only the components that read the accessor
|
|
622
|
+
* re-render. The Solid equivalent of `@lunora/react`'s `useConnectionStatus`.
|
|
623
|
+
*
|
|
624
|
+
* The listener is registered at **mount**, not in the component body, because
|
|
625
|
+
* `onConnectionStatus` invokes it synchronously on subscribe: Solid 2 rejects a
|
|
626
|
+
* signal write inside an owned scope (`REACTIVE_WRITE_IN_OWNED_SCOPE`) and — since
|
|
627
|
+
* the throw escapes render — halts the reactive system for the whole page, not
|
|
628
|
+
* just this component. Nothing is missed by waiting: the initial value comes
|
|
629
|
+
* from `client.connectionStatus()`, and the immediate callback re-syncs at
|
|
630
|
+
* mount. Torn down when the owning scope disposes. Call inside a component /
|
|
631
|
+
* reactive root.
|
|
632
|
+
*/
|
|
468
633
|
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
634
|
/** The value kinds a flag resolves to — OpenFeature's boolean / number / string / structured (JSON) flags. */
|
|
472
635
|
type FlagValue = boolean | number | string | {
|
|
473
636
|
[key: string]: unknown;
|
|
474
637
|
} | 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
638
|
/**
|
|
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
|
-
|
|
639
|
+
* Subscribe to a single feature flag and return a reactive accessor of its value.
|
|
640
|
+
*
|
|
641
|
+
* The accessor reads `defaultValue` until the first evaluation lands, then the
|
|
642
|
+
* server's resolved value — re-pushed whenever the provider re-evaluates (e.g. a
|
|
643
|
+
* flag is toggled in Cloudflare Flagship). The flag's kind is inferred from
|
|
644
|
+
* `defaultValue`'s runtime type, so `createFlag("dark", false)` reads a boolean
|
|
645
|
+
* and `createFlag("hero", "control")` a string.
|
|
646
|
+
*
|
|
647
|
+
* `key` may be a plain value or an accessor; passing an accessor makes the
|
|
648
|
+
* subscription reactive — when it changes the old subscription is torn down (via
|
|
649
|
+
* `onCleanup`) and a fresh one opens.
|
|
650
|
+
*
|
|
651
|
+
* The reactive channel is public, so the server evaluates every flag under the
|
|
652
|
+
* socket's own verified identity — the targeting key your `defineFlags({
|
|
653
|
+
* identify })` derives — and accepts no client-supplied targeting context. For
|
|
654
|
+
* evaluation under a context you compute, call `ctx.flags.*` inside a query,
|
|
655
|
+
* mutation, or action and return the resolved value.
|
|
656
|
+
*
|
|
657
|
+
* Evaluation runs through whatever OpenFeature provider the app wired in
|
|
658
|
+
* `lunora/flags.ts`; the read never throws — a provider error resolves the
|
|
659
|
+
* default (the same fail-open contract as server-side `ctx.flags`).
|
|
660
|
+
*/
|
|
661
|
+
declare const createFlag: <T extends FlagValue>(key: MaybeAccessor<string>, defaultValue: T) => Accessor<T>;
|
|
662
|
+
/**
|
|
663
|
+
* Subscribe to several feature flags at once and return a reactive accessor of
|
|
664
|
+
* the resolved record.
|
|
665
|
+
*
|
|
666
|
+
* Pass a record of `key → defaultValue`; each flag's kind is inferred from its
|
|
667
|
+
* default, and the accessor reads the same-shaped record with resolved values
|
|
668
|
+
* (the defaults until each evaluation lands). This is the batched form of
|
|
669
|
+
* {@link createFlag}, and evaluates under the socket's server-verified identity
|
|
670
|
+
* only. The flag set is fixed for the primitive's lifetime, so nothing here is
|
|
671
|
+
* reactive — the subscriptions open on mount and tear down on cleanup.
|
|
672
|
+
*/
|
|
673
|
+
declare const createFlags: <T extends Record<string, FlagValue>>(flags: T) => Accessor<T>;
|
|
674
|
+
/**
|
|
675
|
+
* `createLiveTopic` — follow one live topic on the connection shared by its URL.
|
|
676
|
+
*
|
|
677
|
+
* A thin lifecycle wrapper over `subscribeLiveTopic` from `@lunora/client`: it
|
|
678
|
+
* subscribes when the owner mounts, unsubscribes on cleanup, and resubscribes when
|
|
679
|
+
* the topic or the connection options change. Callbacks are not part of that
|
|
680
|
+
* identity, so a new `onEvent` / `onError` never reopens the subscription.
|
|
681
|
+
*/
|
|
682
|
+
interface CreateLiveTopicResult<Payload = unknown> {
|
|
683
|
+
/** The shard's refusal of this subscription (403, 409, 429 and similar), or `undefined`. */
|
|
684
|
+
error: Accessor<LiveStreamSubscribeError | undefined>;
|
|
685
|
+
/** The last payload delivered on the topic, or `undefined` until the first event. */
|
|
686
|
+
lastEvent: Accessor<Payload | undefined>;
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Follow the topic `topic` names on the live connection shared by its stream's route. Pass the
|
|
690
|
+
* reference `_generated/live.ts` hands out (`live.posts.post({ postId })`), plain or as an
|
|
691
|
+
* accessor; the route is resolved against the `LunoraClient` from the nearest `LunoraContext`,
|
|
692
|
+
* and `lastEvent` and `onEvent` are typed by the payload the topic declares.
|
|
693
|
+
*
|
|
694
|
+
* `options` may be a plain object or an accessor. The `onEvent` and `onError` callbacks are
|
|
695
|
+
* read at call time, so the latest identity is always the one invoked.
|
|
696
|
+
*/
|
|
697
|
+
declare const createLiveTopic: <Payload>(topic: LiveTopicRef<Payload> | Accessor<LiveTopicRef<Payload>>, options?: LiveTopicOptions<Payload> | Accessor<LiveTopicOptions<Payload>>) => CreateLiveTopicResult<Payload>;
|
|
506
698
|
interface MutationHandle<F extends FunctionReference> {
|
|
507
699
|
/** The latest invocation's resolved value, or `undefined` before the first success. */
|
|
508
700
|
data: Accessor<ReturnOf<F> | undefined>;
|
|
509
701
|
/** The latest invocation's error, or `undefined`. */
|
|
510
702
|
error: Accessor<Error | undefined>;
|
|
511
703
|
/** Invoke the mutation. Resolves with the server result; rejects on failure. */
|
|
512
|
-
mutate: (args: ArgsOf<F>, options?: MutationCallOptions<unknown, unknown, ArgsOf<F>>) => Promise<ReturnOf<F>>;
|
|
704
|
+
mutate: (args: ArgsOf<F>, options?: MutationCallOptions<unknown, unknown, ArgsOf<F>> & OnlineOnlyOption<F>) => Promise<ReturnOf<F>>;
|
|
513
705
|
/** `true` while any invocation from this handle is in flight (ref-counted, so overlapping calls compose). */
|
|
514
706
|
pending: Accessor<boolean>;
|
|
515
707
|
/** Clear `data`/`error` back to idle. */
|
|
516
708
|
reset: () => void;
|
|
517
709
|
}
|
|
518
710
|
/**
|
|
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
|
-
*/
|
|
711
|
+
* The transport surface {@link createMutation} actually needs — just
|
|
712
|
+
* `client.mutation`. Narrowed so the primitive can be exercised against a stub
|
|
713
|
+
* in tests without constructing a full `LunoraClient`.
|
|
714
|
+
*/
|
|
523
715
|
interface MutationClient<F extends FunctionReference> {
|
|
524
|
-
mutation: (function_: F, args: ArgsOf<F>, options?: MutationCallOptions<unknown, unknown, ArgsOf<F>>) => Promise<ReturnOf<F>>;
|
|
716
|
+
mutation: (function_: F, args: ArgsOf<F>, options?: MutationCallOptions<unknown, unknown, ArgsOf<F>> & OnlineOnlyOption<F>) => Promise<ReturnOf<F>>;
|
|
525
717
|
}
|
|
526
718
|
/**
|
|
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
|
-
|
|
719
|
+
* Build a mutation handle bound to an explicit client. Internal seam used by the
|
|
720
|
+
* provider-bound {@link createMutation}; exported for tests that inject a stub.
|
|
721
|
+
* The ref-counted pending + error-normalize orchestration is the shared
|
|
722
|
+
* `createCallRunner` from `@lunora/client`; only the reactive sinks (Solid
|
|
723
|
+
* signals) are adapter-specific.
|
|
724
|
+
*
|
|
725
|
+
* `data`/`error` follow the adapter-wide contract: both track the LATEST
|
|
726
|
+
* invocation (an earlier call settling later cannot clobber a newer one), a
|
|
727
|
+
* success clears `error`, and a failure leaves the previous `data` in place.
|
|
728
|
+
* `reset()` clears both; it does not cancel an in-flight call.
|
|
729
|
+
*/
|
|
533
730
|
declare const createMutationForClient: <F extends FunctionReference>(client: MutationClient<F>, function_: F) => MutationHandle<F>;
|
|
534
731
|
/**
|
|
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
|
-
*/
|
|
732
|
+
* Returns a reactive handle `{ mutate, pending, data, error, reset }` for the
|
|
733
|
+
* given mutation reference, bound to the `LunoraClient` from the nearest
|
|
734
|
+
* `<LunoraProvider>`.
|
|
735
|
+
*
|
|
736
|
+
* Optimistic updates stay client-owned: the `optimistic` / `optimisticUpdate`
|
|
737
|
+
* call options pass straight through to `client.mutation`, which applies and
|
|
738
|
+
* rolls them back against the live Lunora subscription cache — the same
|
|
739
|
+
* machinery `createQuery`/`hydratePreloaded` subscribe to, so an optimistic
|
|
740
|
+
* write reflects in those accessors immediately and reverts on failure.
|
|
741
|
+
*
|
|
742
|
+
* `pending` is ref-counted across overlapping invocations of *this* handle, so
|
|
743
|
+
* it only flips back to `false` once every concurrent call has settled. The
|
|
744
|
+
* mutation also engages `@lunora/client`'s offline queue when the socket is
|
|
745
|
+
* down, so `mutate` stays durable across reconnects.
|
|
746
|
+
*/
|
|
550
747
|
declare const createMutation: <F extends FunctionReference>(function_: F) => MutationHandle<F>;
|
|
551
748
|
/**
|
|
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
|
-
*/
|
|
749
|
+
* The reactive handle returned by {@link createMutator} — the Solid counterpart
|
|
750
|
+
* to `@lunora/react`'s `useMutator`, re-expressed with signals.
|
|
751
|
+
* `error`/`isError`/`pending` are accessors and `mutate` is an awaitable that
|
|
752
|
+
* resolves once the write is persisted (or rejects).
|
|
753
|
+
*/
|
|
557
754
|
interface MutatorHook<TArgs> {
|
|
558
755
|
/** The latest invocation's error, or `undefined`. */
|
|
559
756
|
error: Accessor<Error | undefined>;
|
|
@@ -567,18 +764,18 @@ interface MutatorHook<TArgs> {
|
|
|
567
764
|
reset: () => void;
|
|
568
765
|
}
|
|
569
766
|
/**
|
|
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
|
-
*/
|
|
767
|
+
* Ergonomic `{ mutate, pending, error, isError, reset }` wrapper over a bound
|
|
768
|
+
* custom-mutator handle from `@lunora/db`'s `bindMutators` — the Solid
|
|
769
|
+
* equivalent of `@lunora/react`'s `useMutator`. The optimistic overlay and
|
|
770
|
+
* server-authoritative push are owned by the bound handle (and TanStack DB's
|
|
771
|
+
* optimistic-transaction layer rebases pending overlays on every sync tick);
|
|
772
|
+
* this primitive only surfaces signal state for the in-flight/error lifecycle.
|
|
773
|
+
* Reads stay on the existing TanStack `useLiveQuery`; no new query primitive is
|
|
774
|
+
* needed.
|
|
775
|
+
*
|
|
776
|
+
* `pending` is ref-counted across overlapping invocations of THIS handle, so it
|
|
777
|
+
* clears only once every concurrent call has settled.
|
|
778
|
+
*/
|
|
582
779
|
declare const createMutator: <TArgs = Record<string, unknown>>(handle: MutatorHandle<TArgs>) => MutatorHook<TArgs>;
|
|
583
780
|
/** The args a paginated query exposes minus the framework-supplied page cursor. */
|
|
584
781
|
type PaginatedArgs<F extends FunctionReference> = Omit<ArgsOf<F>, "paginationOpts">;
|
|
@@ -589,9 +786,18 @@ type PageItemOf<F extends FunctionReference> = ReturnOf<F> extends {
|
|
|
589
786
|
interface CreatePaginatedQueryOptions {
|
|
590
787
|
/** Page size for the first page (and the default for `loadMore`). */
|
|
591
788
|
initialNumItems: number;
|
|
789
|
+
/** Called when a page subscription reports an error (also surfaced on the `error` accessor). */
|
|
790
|
+
onError?: SubscriptionErrorCallback;
|
|
592
791
|
shardKey?: string;
|
|
593
792
|
}
|
|
594
793
|
interface CreatePaginatedQueryResult<T> {
|
|
794
|
+
/**
|
|
795
|
+
* The last page subscription error, or `undefined`. A tail page that fails
|
|
796
|
+
* before its first frame is dropped so `status` returns to `"CanLoadMore"`
|
|
797
|
+
* and `loadMore` can retry it; cleared by the next successful frame,
|
|
798
|
+
* `loadMore`, or an args change.
|
|
799
|
+
*/
|
|
800
|
+
error: Accessor<SubscriptionError | undefined>;
|
|
595
801
|
/** `true` while the first page or a `loadMore` page is in flight. */
|
|
596
802
|
isLoading: Accessor<boolean>;
|
|
597
803
|
/** Request the next page. A no-op unless `status === "CanLoadMore"`. */
|
|
@@ -603,9 +809,13 @@ interface CreatePaginatedQueryResult<T> {
|
|
|
603
809
|
interface CreateInfiniteQueryOptions {
|
|
604
810
|
/** Page size for the first page (and the default for `fetchNextPage`). */
|
|
605
811
|
initialNumItems: number;
|
|
812
|
+
/** Called when a page subscription reports an error (also surfaced on the `error` accessor). */
|
|
813
|
+
onError?: SubscriptionErrorCallback;
|
|
606
814
|
shardKey?: string;
|
|
607
815
|
}
|
|
608
816
|
interface CreateInfiniteQueryResult<T> {
|
|
817
|
+
/** The last page subscription error, or `undefined` — see `CreatePaginatedQueryResult.error`. */
|
|
818
|
+
error: Accessor<SubscriptionError | undefined>;
|
|
609
819
|
/** Request the next page. A no-op unless `status === "CanLoadMore"`. */
|
|
610
820
|
fetchNextPage: (numberItems?: number) => void;
|
|
611
821
|
/** `true` when the loaded tail reports it can load another page. */
|
|
@@ -619,46 +829,46 @@ interface CreateInfiniteQueryResult<T> {
|
|
|
619
829
|
status: Accessor<PaginationStatus>;
|
|
620
830
|
}
|
|
621
831
|
/**
|
|
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
|
-
*/
|
|
832
|
+
* Subscribe to a reactively-paginated query and grow the feed page by page.
|
|
833
|
+
*
|
|
834
|
+
* The query function must accept a `paginationOpts: { numItems, cursor,
|
|
835
|
+
* endCursor }` arg and return a `PaginationResult`. `loadMore` appends the next
|
|
836
|
+
* page off the open-ended tail's `continueCursor`; it is a no-op unless
|
|
837
|
+
* `status === "CanLoadMore"`.
|
|
838
|
+
*
|
|
839
|
+
* Call inside a reactive context (component / `createRoot`).
|
|
840
|
+
*/
|
|
631
841
|
declare const createPaginatedQuery: <F extends FunctionReference>(function_: F, args: "skip" | Accessor<"skip" | PaginatedArgs<F>> | PaginatedArgs<F>, options: CreatePaginatedQueryOptions) => CreatePaginatedQueryResult<PageItemOf<F>>;
|
|
632
842
|
/**
|
|
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
|
-
*/
|
|
843
|
+
* Subscribe to a reactively-paginated query and expose its pages discretely.
|
|
844
|
+
*
|
|
845
|
+
* Shares `createPaginatedQuery`'s pagination engine but keeps each page as its
|
|
846
|
+
* own inner array (TanStack-Query-style `fetchNextPage` / `hasNextPage` shape).
|
|
847
|
+
*
|
|
848
|
+
* Call inside a reactive context (component / `createRoot`).
|
|
849
|
+
*/
|
|
640
850
|
declare const createInfiniteQuery: <F extends FunctionReference>(function_: F, args: "skip" | Accessor<"skip" | PaginatedArgs<F>> | PaginatedArgs<F>, options: CreateInfiniteQueryOptions) => CreateInfiniteQueryResult<PageItemOf<F>>;
|
|
641
851
|
/**
|
|
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
|
-
*/
|
|
852
|
+
* `createPresence` — collaborative-awareness primitive, the client half of the
|
|
853
|
+
* `@lunora/server` `definePresence` preset.
|
|
854
|
+
*
|
|
855
|
+
* Drives the heartbeat mutation (on mount, interval, and tab re-focus) and
|
|
856
|
+
* subscribes to the live `listPresent` query for the given room.
|
|
857
|
+
*
|
|
858
|
+
* Call inside a reactive context (component / `createRoot`).
|
|
859
|
+
*/
|
|
860
|
+
/**
|
|
861
|
+
* A heartbeat mutation reference: takes `{ roomId, sessionId, data? }`.
|
|
862
|
+
*/
|
|
653
863
|
type HeartbeatReference = FunctionReference<"mutation", {
|
|
654
864
|
data?: Record<string, unknown>;
|
|
655
865
|
roomId: string;
|
|
656
866
|
sessionId: string;
|
|
657
867
|
}>;
|
|
658
868
|
/**
|
|
659
|
-
* A listPresent query reference: takes `{ roomId }` and returns the array of
|
|
660
|
-
* present members.
|
|
661
|
-
*/
|
|
869
|
+
* A listPresent query reference: takes `{ roomId }` and returns the array of
|
|
870
|
+
* present members.
|
|
871
|
+
*/
|
|
662
872
|
type ListPresentReference = FunctionReference<"query", {
|
|
663
873
|
roomId: string;
|
|
664
874
|
}>;
|
|
@@ -672,14 +882,22 @@ interface CreatePresenceOptions<H extends HeartbeatReference, L extends ListPres
|
|
|
672
882
|
/** The `api.*` reference for the presence listPresent query. */
|
|
673
883
|
listPresent: L;
|
|
674
884
|
/**
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
885
|
+
* Called when the `listPresent` subscription reports an error (a session
|
|
886
|
+
* expiry, an RLS denial). Without it — and without reading `error` — such a
|
|
887
|
+
* failure is invisible and `present` is cleared until a later frame arrives.
|
|
888
|
+
*/
|
|
889
|
+
onError?: SubscriptionErrorCallback;
|
|
890
|
+
/**
|
|
891
|
+
* Stable id for this presence row. Defaults to a fresh per-mount id.
|
|
892
|
+
* Pass a user/connection id to control deduping across tabs.
|
|
893
|
+
*/
|
|
678
894
|
sessionId?: string;
|
|
679
895
|
/** Forwarded to the heartbeat mutation / listPresent subscription when sharding by room. */
|
|
680
896
|
shardKey?: string;
|
|
681
897
|
}
|
|
682
898
|
interface CreatePresenceResult<L extends ListPresentReference> {
|
|
899
|
+
/** The `listPresent` subscription's last error, or `undefined`. */
|
|
900
|
+
error: () => SubscriptionError | undefined;
|
|
683
901
|
/** The present members for the room. `undefined` until the first push. */
|
|
684
902
|
present: () => ReturnOf<L> | undefined;
|
|
685
903
|
/** This mount's session id (generated when not supplied). */
|
|
@@ -689,35 +907,46 @@ interface CreatePresenceResult<L extends ListPresentReference> {
|
|
|
689
907
|
}
|
|
690
908
|
declare const createPresence: <H extends HeartbeatReference, L extends ListPresentReference>(roomId: string, options: CreatePresenceOptions<H, L>) => CreatePresenceResult<L>;
|
|
691
909
|
interface CreateQueryOptions {
|
|
910
|
+
/**
|
|
911
|
+
* Called when the server pushes a subscription-scoped error (an RLS denial, a
|
|
912
|
+
* query that starts failing server-side). Without a handler such an error has
|
|
913
|
+
* nowhere to go and the accessor simply freezes at its last good value.
|
|
914
|
+
*/
|
|
915
|
+
onError?: SubscriptionErrorCallback;
|
|
692
916
|
/** Route to a specific shard when the target function is `.shardBy(...)`-partitioned. */
|
|
693
917
|
shardKey?: string;
|
|
694
918
|
}
|
|
695
919
|
/**
|
|
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
|
-
|
|
920
|
+
* Subscribe to a server query and return a reactive accessor of its value.
|
|
921
|
+
*
|
|
922
|
+
* The accessor reads `undefined` until the first server frame lands, then
|
|
923
|
+
* updates on every delta the WebSocket pushes — Solid's fine-grained signals
|
|
924
|
+
* mean only the components that read the accessor re-render, which maps cleanly
|
|
925
|
+
* onto Lunora's per-subscription delta model.
|
|
926
|
+
*
|
|
927
|
+
* `args` may be a plain value or an accessor; passing an accessor makes the
|
|
928
|
+
* subscription reactive — when the args change the old subscription is torn down
|
|
929
|
+
* (via `onCleanup`), the accessor resets to `undefined`, and a fresh one opens for
|
|
930
|
+
* the new args. Pass `"skip"` (or an
|
|
931
|
+
* accessor returning `"skip"`) to short-circuit: no network call, no socket.
|
|
932
|
+
*
|
|
933
|
+
* ```tsx
|
|
934
|
+
* const messages = createQuery(api.messages.list, () => ({ channelId: channelId() }));
|
|
935
|
+
* return <For each={messages()?.messages}>{(m) => <li>{m.text}</li>}</For>;
|
|
936
|
+
* ```
|
|
937
|
+
*
|
|
938
|
+
* Pass `onError` to surface a subscription-scoped error the server pushes (an RLS
|
|
939
|
+
* denial, a query that starts failing server-side). Without it such an error is
|
|
940
|
+
* dropped and the accessor just freezes at its last good value.
|
|
941
|
+
*/
|
|
713
942
|
declare const createQuery: <F extends FunctionReference>(function_: F, args: (ArgsOf<F> | "skip") | Accessor<ArgsOf<F> | "skip">, options?: CreateQueryOptions) => Accessor<ReturnOf<F> | undefined>;
|
|
714
943
|
interface CreateRateLimitOptions {
|
|
715
944
|
/** Clock injection for tests. Defaults to `Date.now`. */
|
|
716
945
|
now?: () => number;
|
|
717
946
|
/**
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
947
|
+
* Re-evaluation cadence in milliseconds while throttled, so `retryAfter`
|
|
948
|
+
* ticks down and `disabled` flips back automatically. Defaults to `1000`.
|
|
949
|
+
*/
|
|
721
950
|
tickMs?: number;
|
|
722
951
|
}
|
|
723
952
|
interface CreateRateLimitResult {
|
|
@@ -735,14 +964,14 @@ interface CreateRateLimitResult {
|
|
|
735
964
|
retryAfter: () => number;
|
|
736
965
|
}
|
|
737
966
|
/**
|
|
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
|
-
*/
|
|
967
|
+
* Client-side mirror of a rate limit for instant UX — disable a button or show
|
|
968
|
+
* a countdown without a round-trip. It runs the same token-bucket / fixed-window
|
|
969
|
+
* math as `@lunora/ratelimit` on the server, so the prediction agrees with the
|
|
970
|
+
* authoritative check; the server remains the source of truth.
|
|
971
|
+
*
|
|
972
|
+
* `config` is read on every call; pass a stable reference (module constant) so
|
|
973
|
+
* the derived memos stay settled.
|
|
974
|
+
*/
|
|
746
975
|
declare const createRateLimit: (config: RateLimitConfig, options?: CreateRateLimitOptions) => CreateRateLimitResult;
|
|
747
976
|
/** The lifecycle of a stream the primitive is observing. */
|
|
748
977
|
type CreateStreamStatus = "complete" | "error" | "idle" | "streaming";
|
|
@@ -755,47 +984,59 @@ interface CreateStreamResult<T> {
|
|
|
755
984
|
status: Accessor<CreateStreamStatus>;
|
|
756
985
|
}
|
|
757
986
|
interface CreateStreamOptions {
|
|
987
|
+
/**
|
|
988
|
+
* Opt into resume-on-reconnect for a stream the server declared `durable`.
|
|
989
|
+
* The chunks already received are kept and the socket re-attaches to the same
|
|
990
|
+
* run, so a dropped connection mid-generation continues instead of surfacing
|
|
991
|
+
* `STREAM_DISCONNECTED`. Has no effect on an ephemeral stream.
|
|
992
|
+
*/
|
|
993
|
+
durable?: boolean;
|
|
758
994
|
/** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
|
|
759
995
|
maxBuffer?: number;
|
|
760
996
|
shardKey?: string;
|
|
761
997
|
}
|
|
762
998
|
/**
|
|
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
|
-
*/
|
|
999
|
+
* Subscribe to a streaming query. Returns the chunks pushed so far plus a
|
|
1000
|
+
* lifecycle status and a cancel function, all as accessors. Changing the
|
|
1001
|
+
* resolved `args` resets the stream — the previous iterator is cancelled and a
|
|
1002
|
+
* fresh one opens with empty `chunks`.
|
|
1003
|
+
*
|
|
1004
|
+
* `args` may be a plain value or an accessor; resolving it to `"skip"` keeps the
|
|
1005
|
+
* primitive mounted without opening a stream (mirrors `createSubscription`). The
|
|
1006
|
+
* Solid counterpart to React's `useStream`, re-expressed with signals.
|
|
1007
|
+
*/
|
|
772
1008
|
declare const createStream: <F extends FunctionReference<"stream">>(function_: F, args: ArgsOf<F> | "skip" | Accessor<ArgsOf<F> | "skip">, options?: CreateStreamOptions) => CreateStreamResult<ReturnOf<F>>;
|
|
773
1009
|
interface CreateSubscriptionResult<T> {
|
|
774
1010
|
data: Accessor<T | undefined>;
|
|
775
1011
|
error: Accessor<Error | undefined>;
|
|
776
1012
|
}
|
|
777
1013
|
/**
|
|
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
|
-
|
|
1014
|
+
* Subscribe to a reactive server push stream. Returns `{ data, error }`
|
|
1015
|
+
* accessors that update whenever the server emits. Passing `"skip"` as `args`
|
|
1016
|
+
* (or an accessor that resolves to `"skip"`) tears down the subscription.
|
|
1017
|
+
*
|
|
1018
|
+
* `onError` mirrors the other adapters' subscription primitives: it receives the
|
|
1019
|
+
* raw wire-level subscription error (code included) alongside the normalised
|
|
1020
|
+
* `error` accessor.
|
|
1021
|
+
*/
|
|
782
1022
|
declare const createSubscription: <F extends FunctionReference>(function_: F, args: ArgsOf<F> | "skip" | Accessor<ArgsOf<F> | "skip">, options?: {
|
|
1023
|
+
onError?: SubscriptionErrorCallback;
|
|
783
1024
|
shardKey?: string;
|
|
784
1025
|
}) => CreateSubscriptionResult<ReturnOf<F>>;
|
|
785
1026
|
/**
|
|
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
|
-
*/
|
|
1027
|
+
* Browser Web Audio subsystems for `createVoiceAgent` — the default microphone
|
|
1028
|
+
* capture and speaker playback implementations injected into the primitive via
|
|
1029
|
+
* its `createMicrophone` / `createSpeaker` seams. Kept in a sibling module so the
|
|
1030
|
+
* heavy Web Audio graph (and its structural DOM typings) stays isolated from the
|
|
1031
|
+
* primitive's transport + reactive-state logic and remains mockable in a
|
|
1032
|
+
* non-browser test env.
|
|
1033
|
+
*/
|
|
1034
|
+
/**
|
|
1035
|
+
* The negotiated audio format the voice DO streams back. Mirrors
|
|
1036
|
+
* `@lunora/agent`'s `VoiceServerFrame` `ready.audioFormat` — re-declared (not
|
|
1037
|
+
* imported) so this Solid package never pulls in the server-only `@lunora/agent`
|
|
1038
|
+
* module graph.
|
|
1039
|
+
*/
|
|
799
1040
|
type VoiceAudioFormat = "mp3" | "wav";
|
|
800
1041
|
/** Captures microphone audio and reports level / turn boundaries back to the primitive. */
|
|
801
1042
|
interface VoiceMicrophone {
|
|
@@ -819,8 +1060,24 @@ interface MicrophoneConfig {
|
|
|
819
1060
|
interruptChunks: number;
|
|
820
1061
|
/** RMS above which the user is considered to be barging in while the agent speaks. */
|
|
821
1062
|
interruptThreshold: number;
|
|
822
|
-
/**
|
|
823
|
-
|
|
1063
|
+
/**
|
|
1064
|
+
* `true` from the moment a turn is committed until it completes — the whole
|
|
1065
|
+
* `thinking` + `speaking` window, not just the audible half.
|
|
1066
|
+
*
|
|
1067
|
+
* It gates BOTH branches below, and the wider span is the point. Gated only
|
|
1068
|
+
* on "audibly speaking", turn detection kept running through the entire
|
|
1069
|
+
* STT+LLM window after a `commit`: room noise at the (deliberately low)
|
|
1070
|
+
* `silenceThreshold` re-armed `sawSpeech`, another quiet gap fired a SECOND
|
|
1071
|
+
* `commit`, and the DO refused it with "a turn is already in progress" —
|
|
1072
|
+
* a refusal that returns before draining the audio buffer, so the PCM
|
|
1073
|
+
* captured since the first commit leaked into the next utterance.
|
|
1074
|
+
*
|
|
1075
|
+
* A genuine barge-in still works in that window: it routes through the
|
|
1076
|
+
* `onInterrupt` branch, which needs `interruptChunks` consecutive chunks at
|
|
1077
|
+
* `interruptThreshold` — an order of magnitude above `silenceThreshold` —
|
|
1078
|
+
* and `interrupt` is exactly what the DO tells the client to send.
|
|
1079
|
+
*/
|
|
1080
|
+
isTurnActive: () => boolean;
|
|
824
1081
|
/** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
|
|
825
1082
|
onAudio: (pcm: Uint8Array) => void;
|
|
826
1083
|
/** A barge-in was detected (RMS spike while the agent is speaking). */
|
|
@@ -839,15 +1096,10 @@ type CreateSpeaker = (config: {
|
|
|
839
1096
|
audioFormat: VoiceAudioFormat;
|
|
840
1097
|
}) => VoiceSpeaker;
|
|
841
1098
|
/**
|
|
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
|
-
*/
|
|
1099
|
+
* The `agents.<name>Voice` reference codegen emits for a voice-enabled agent — a
|
|
1100
|
+
* live, WS-backed session keyed by `threadKey`. A structural subset of the
|
|
1101
|
+
* generated member, so passing `api.agents.<name>Voice` type-checks.
|
|
1102
|
+
*/
|
|
851
1103
|
type VoiceReference = FunctionReference<"stream", {
|
|
852
1104
|
threadKey: string;
|
|
853
1105
|
}, Record<string, unknown>>;
|
|
@@ -869,12 +1121,16 @@ interface VoiceSocket {
|
|
|
869
1121
|
type CreateSocket = (url: string) => VoiceSocket;
|
|
870
1122
|
interface CreateVoiceAgentOptions {
|
|
871
1123
|
/**
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
1124
|
+
* Advanced/test seam: build the microphone capture subsystem. Defaults to a
|
|
1125
|
+
* `getUserMedia` + Web Audio implementation. Injected wholesale so the Web
|
|
1126
|
+
* Audio graph stays isolated (and mockable in a non-browser test env).
|
|
1127
|
+
*/
|
|
876
1128
|
createMicrophone?: CreateMicrophone;
|
|
877
|
-
/**
|
|
1129
|
+
/**
|
|
1130
|
+
* Advanced/test seam: open the transport. Defaults to the WebSocket
|
|
1131
|
+
* implementation the client was built with (`client.getWebSocketImpl()`),
|
|
1132
|
+
* NOT a raw `globalThis.WebSocket`.
|
|
1133
|
+
*/
|
|
878
1134
|
createSocket?: CreateSocket;
|
|
879
1135
|
/** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
|
|
880
1136
|
createSpeaker?: CreateSpeaker;
|
|
@@ -887,8 +1143,8 @@ interface CreateVoiceAgentOptions {
|
|
|
887
1143
|
/** Input RMS below which audio counts as silence. Default `0.01`. */
|
|
888
1144
|
silenceThreshold?: number;
|
|
889
1145
|
/** 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
|
|
1146
|
+
threadKey: MaybeAccessor<string>;
|
|
1147
|
+
/** The generated `api.agents.<name>Voice` reference — identifies the voice DO endpoint. */
|
|
892
1148
|
voice: VoiceReference;
|
|
893
1149
|
}
|
|
894
1150
|
interface CreateVoiceAgentResult {
|
|
@@ -916,73 +1172,122 @@ interface CreateVoiceAgentResult {
|
|
|
916
1172
|
transcript: Accessor<string>;
|
|
917
1173
|
}
|
|
918
1174
|
/**
|
|
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
|
-
*/
|
|
1175
|
+
* A first-class voice-call surface for a voice-enabled agent: it opens a
|
|
1176
|
+
* WebSocket to the agent's `VoiceSessionDO`, captures mic audio as 16 kHz PCM,
|
|
1177
|
+
* streams the agent's synthesized speech back through the browser's audio output,
|
|
1178
|
+
* and mirrors the call lifecycle (`status`, `transcript`, `interimTranscript`,
|
|
1179
|
+
* `audioLevel`) to Solid signals. Pass the generated `api.agents.<name>Voice`
|
|
1180
|
+
* reference (never a string), matching `createAgentChat`'s reference-passing style.
|
|
1181
|
+
* The Solid counterpart to React's `useVoiceAgent`, re-expressed with signals; the
|
|
1182
|
+
* per-call connection lives in a closure variable (a primitive runs once per
|
|
1183
|
+
* component, so no signal-of-signal indirection is needed).
|
|
1184
|
+
*
|
|
1185
|
+
* v1 transport is plain binary WebSocket frames with push-to-talk / silence-timer
|
|
1186
|
+
* turn detection and client-side RMS barge-in. The heavy Web Audio capture and
|
|
1187
|
+
* playback subsystems are injectable (`createMicrophone` / `createSpeaker` /
|
|
1188
|
+
* `createSocket`) so the primitive is drivable outside a browser.
|
|
1189
|
+
*/
|
|
934
1190
|
declare const createVoiceAgent: (options: CreateVoiceAgentOptions) => CreateVoiceAgentResult;
|
|
935
1191
|
/**
|
|
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
|
-
|
|
1192
|
+
* Hydrate a query from a {@link Preloaded} token produced by `preloadQuery`
|
|
1193
|
+
* during SSR, then keep it live.
|
|
1194
|
+
*
|
|
1195
|
+
* This is the client half of PLAN4's "your loaders are live" handoff. The
|
|
1196
|
+
* returned accessor is seeded **synchronously** from `preloaded.value`, so the
|
|
1197
|
+
* very first read — during hydration — returns the server-rendered value with
|
|
1198
|
+
* no loading flash and no `Suspense` fallback (unlike `createResource`, which
|
|
1199
|
+
* always starts pending). Once the component mounts, a WebSocket subscription
|
|
1200
|
+
* attaches and every subsequent server delta flows into the same signal, so the
|
|
1201
|
+
* UI goes live with zero refetch.
|
|
1202
|
+
*
|
|
1203
|
+
* ```tsx
|
|
1204
|
+
* // route loader (server): const preloaded = await preloadQuery(client, api.messages.list, args);
|
|
1205
|
+
* const messages = hydratePreloaded(preloaded); // seeded from SSR, then live
|
|
1206
|
+
* return <pre>{JSON.stringify(messages())}</pre>;
|
|
1207
|
+
* ```
|
|
1208
|
+
*
|
|
1209
|
+
* Mount callbacks do not run on the server during SSR (both Solid majors defer
|
|
1210
|
+
* them until after hydration), so the subscription is strictly client-side —
|
|
1211
|
+
* the seed is the only value the server render ever sees.
|
|
1212
|
+
*
|
|
1213
|
+
* Pass `onError` to surface a subscription-scoped error the server pushes (a
|
|
1214
|
+
* session expiry, an RLS denial). Without it such an error is dropped and the
|
|
1215
|
+
* accessor keeps rendering the SSR snapshot as if it were live.
|
|
1216
|
+
*
|
|
1217
|
+
* The preloaded value was read for whoever was signed in when the page loaded.
|
|
1218
|
+
* After a sign-out or user switch retires that identity
|
|
1219
|
+
* (`client.identityEpoch() > 0`), every `hydratePreloaded` on the client (mounted
|
|
1220
|
+
* then or later) stops using it and returns `undefined` until the live value
|
|
1221
|
+
* arrives — matching `@lunora/react`'s `usePreloadedQuery`, hence the
|
|
1222
|
+
* `Accessor<T | undefined>` type. The same holds under a `LunoraProvider` whose
|
|
1223
|
+
* `client` was swapped: the value was preloaded for the first client.
|
|
1224
|
+
*/
|
|
1225
|
+
declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, options?: {
|
|
1226
|
+
onError?: SubscriptionErrorCallback;
|
|
1227
|
+
}) => Accessor<T | undefined>;
|
|
958
1228
|
interface LunoraProviderProps {
|
|
959
|
-
children:
|
|
1229
|
+
children: SolidChildren;
|
|
960
1230
|
/**
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1231
|
+
* The framework-neutral transport. Build it once at the app root with
|
|
1232
|
+
* `new LunoraClient({ url })` (or `createServerClient` during SSR) and pass
|
|
1233
|
+
* it here — the provider does not own its lifecycle, so the same instance
|
|
1234
|
+
* survives across route navigations.
|
|
1235
|
+
*/
|
|
966
1236
|
client: LunoraClient;
|
|
967
1237
|
}
|
|
968
1238
|
/**
|
|
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
|
-
|
|
1239
|
+
* Provides a {@link LunoraClient} to the Solid tree via {@link LunoraContext}.
|
|
1240
|
+
*
|
|
1241
|
+
* Solid's context is reactive-graph scoped rather than render scoped, so unlike
|
|
1242
|
+
* the React provider there is no QueryClient to detect or lazily create — the
|
|
1243
|
+
* adapter's reactive primitives (`createQuery`, `createMutation`,
|
|
1244
|
+
* `hydratePreloaded`) own their own signals and read the client straight from
|
|
1245
|
+
* context. Drop one of these at the root of your app:
|
|
1246
|
+
*
|
|
1247
|
+
* ```tsx
|
|
1248
|
+
* const client = new LunoraClient({ url: window.location.origin });
|
|
1249
|
+
*
|
|
1250
|
+
* render(() => (
|
|
1251
|
+
* <LunoraProvider client={client}>
|
|
1252
|
+
* <App />
|
|
1253
|
+
* </LunoraProvider>
|
|
1254
|
+
* ), root);
|
|
1255
|
+
* ```
|
|
1256
|
+
*
|
|
1257
|
+
* Swapping the `client` prop for a different instance **remounts the subtree**
|
|
1258
|
+
* under the provider. Solid's providers read their value once, so the swap
|
|
1259
|
+
* cannot be pushed into primitives that already resolved the client; instead
|
|
1260
|
+
* every primitive below is disposed (its subscriptions on the old client torn
|
|
1261
|
+
* down) and recreated against the new client, starting from `undefined` — no
|
|
1262
|
+
* rows from the old client survive, and `hydratePreloaded` does not seed a value
|
|
1263
|
+
* preloaded for the client the provider first rendered with (not even after
|
|
1264
|
+
* swapping back to it). Local component state under the provider resets with
|
|
1265
|
+
* it. Re-reading the same instance is a no-op.
|
|
1266
|
+
*
|
|
1267
|
+
* Written with `createComponent` rather than JSX on purpose. Solid 1.x and 2.0
|
|
1268
|
+
* compile JSX against different runtimes (`solid-js/web` vs `@solidjs/web`), so
|
|
1269
|
+
* a JSX source file would force this package to ship two builds; `createComponent`
|
|
1270
|
+
* is exported from the `solid-js` root in both majors, and the provider component
|
|
1271
|
+
* itself is resolved per-major by {@link providerOf}.
|
|
1272
|
+
*/
|
|
1273
|
+
declare const LunoraProvider: (props: LunoraProviderProps) => SolidElement;
|
|
1274
|
+
export { type ActionClient, type ActionHandle, type AgentApprovalGrant, 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,
|
|
1275
|
+
/**
|
|
1276
|
+
* SolidJS adapter for Lunora.
|
|
1277
|
+
*
|
|
1278
|
+
* Thin, idiomatic glue over the framework-neutral `@lunora/client`. Solid's
|
|
1279
|
+
* fine-grained signals map directly onto Lunora's per-subscription deltas, so a
|
|
1280
|
+
* live query is just a signal the WebSocket writes to. The adapter exposes
|
|
1281
|
+
* `LunoraProvider` / `useLunora` (context carrying the `LunoraClient`),
|
|
1282
|
+
* `createQuery` (a live query accessor that opens a subscription and updates on
|
|
1283
|
+
* every delta), `createMutation` (an optimistic mutation handle), and
|
|
1284
|
+
* `hydratePreloaded` (seed a query from an SSR `Preloaded` token synchronously —
|
|
1285
|
+
* no loading flash — then attach the live subscription; the client half of
|
|
1286
|
+
* PLAN4's "your loaders are live" reactive-loader handoff).
|
|
1287
|
+
*
|
|
1288
|
+
* Server-side preloading (`createServerClient`, `preloadQuery`) lives in the
|
|
1289
|
+
* socket-free `@lunora/solid/server` entry (a re-export of `@lunora/client/ssr`, the
|
|
1290
|
+
* framework-neutral server contract) — call it from your SolidStart route loader
|
|
1291
|
+
* and hand the resulting `Preloaded` token to `hydratePreloaded`.
|
|
1292
|
+
*/
|
|
1293
|
+
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 };
|