@voltro/client 0.90.0 → 0.91.0
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/CHANGELOG.md +121 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/apiRuntime.js +50 -50
- package/dist/apiSupervisor.js +25 -25
- package/dist/awaitResolvedApi.js +17 -17
- package/dist/bootstrap.js +8 -8
- package/dist/connectionPrerequisite.js +18 -18
- package/dist/connectionSetupController.js +97 -97
- package/dist/createHooks.js +11 -11
- package/dist/form.js +7 -7
- package/dist/index.js +82 -82
- package/dist/outbox.js +133 -133
- package/dist/platform.js +10 -10
- package/dist/rpcCallOnce.js +10 -10
- package/dist/runtime.js +16 -16
- package/dist/runtimeContext.js +1 -1
- package/dist/serviceClient.js +23 -23
- package/dist/store.js +3 -3
- package/dist/subscriptionCache.js +1 -1
- package/dist/uploadClient.js +35 -35
- package/dist/useAction.js +59 -59
- package/dist/useAgentChat.js +3 -3
- package/dist/useCapabilityManifest.js +7 -7
- package/dist/useConnectionStatus.js +5 -5
- package/dist/useDataTable.js +4 -4
- package/dist/useEvent.js +22 -22
- package/dist/useFormBinding.js +10 -10
- package/dist/useMutation.js +89 -89
- package/dist/useOnRpcError.js +5 -5
- package/dist/usePreloadedSubscription.js +6 -6
- package/dist/useRpcCaller.js +21 -21
- package/dist/useRpcInvocationOwner.js +6 -6
- package/dist/useTranscription.js +27 -27
- package/dist/useWorkflow.js +22 -22
- package/dist/workflowClient.js +33 -33
- package/package.json +3 -3
package/dist/useMutation.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { bindMutationConnectionSetup as g, captureMutationConnectionSetup as te, connectionSetupOwner as _ } from "./mutationConnectionSetup.js";
|
|
1
|
+
import { useFrameworkApi as e } from "./runtimeContext.js";
|
|
2
|
+
import { deferRpcMethod as t, runRpcPromise as n } from "./runRpc.js";
|
|
3
|
+
import { resolveByTag as r } from "./tagWalk.js";
|
|
4
|
+
import { omitMutationInputs as i, omitMutationOutputs as a, startMutation as o } from "./mutationsBus.js";
|
|
5
|
+
import { publishClientTrace as s, publishClientTraceRefusal as c } from "./traceBus.js";
|
|
6
|
+
import { awaitResolvedApi as l, bindResolvedRpcInvocationOwner as u } from "./awaitResolvedApi.js";
|
|
7
|
+
import { useRpcInvocationOwner as d } from "./useRpcInvocationOwner.js";
|
|
8
|
+
import { ConnectionPrerequisiteInvalidated as f } from "./connectionPrerequisite.js";
|
|
9
|
+
import { rpcErrorKind as p } from "./rpcErrorKind.js";
|
|
10
|
+
import { reportUnknownRpcTag as m } from "./unknownRpcTag.js";
|
|
11
|
+
import { recoveryCoordinatorFor as h } from "./recoveryCoordinator.js";
|
|
12
|
+
import { bindMutationConnectionSetup as g, captureMutationConnectionSetup as ee, connectionSetupOwner as _ } from "./mutationConnectionSetup.js";
|
|
14
13
|
import { freshIdempotencyKey as v, withIdempotencyKey as y } from "./mutationIdentity.js";
|
|
14
|
+
import { connectionScopeForRuntime as te } from "./connectionScope.js";
|
|
15
15
|
import { MutationSerialExecutionError as b, makeMutationSerialExecution as x } from "./mutationSerialExecution.js";
|
|
16
16
|
import { useCallback as S, useEffect as C, useMemo as w, useRef as T, useState as E } from "react";
|
|
17
17
|
import { Effect as D } from "effect";
|
|
@@ -42,11 +42,11 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
|
|
|
42
42
|
},
|
|
43
43
|
forTag: (n, r) => e.forTag(n, r, t)
|
|
44
44
|
}), F = (b, x) => {
|
|
45
|
-
let O =
|
|
45
|
+
let O = e(b), { descriptors: j } = O, M = T(O);
|
|
46
46
|
M.current = O;
|
|
47
|
-
let { owner: P, current: F, assertCurrent: I, assertOwnerCurrent: L } =
|
|
47
|
+
let { owner: P, current: F, assertCurrent: I, assertOwnerCurrent: L } = d(M, b, x), R = j[x], z = R?.outputRetention === "none", B = R?.clientHistory?.input === "omit", V = R?.targets;
|
|
48
48
|
if (process.env.NODE_ENV !== "production") {
|
|
49
|
-
|
|
49
|
+
m("useMutation", b, x, j);
|
|
50
50
|
let e = R?.kind;
|
|
51
51
|
e !== void 0 && e !== "mutation" && console.error(`[@voltro/client] useMutation('${b}', '${x}') targets a ${e}, not a mutation. Use ${e === "action" ? "useAction" : e === "workflow" ? "useWorkflow" : `the ${e} hook`} instead.`);
|
|
52
52
|
}
|
|
@@ -60,13 +60,13 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
|
|
|
60
60
|
z && (U((e) => e.data === void 0 ? e : {
|
|
61
61
|
...e,
|
|
62
62
|
data: void 0
|
|
63
|
-
}),
|
|
63
|
+
}), a(b, x));
|
|
64
64
|
}, [
|
|
65
65
|
z,
|
|
66
66
|
b,
|
|
67
67
|
x
|
|
68
68
|
]), C(() => {
|
|
69
|
-
B &&
|
|
69
|
+
B && i(b, x);
|
|
70
70
|
}, [
|
|
71
71
|
B,
|
|
72
72
|
b,
|
|
@@ -80,18 +80,18 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
|
|
|
80
80
|
owner: P,
|
|
81
81
|
count: 0
|
|
82
82
|
}, W.current = null, G.current = !1);
|
|
83
|
-
let q = S(async (
|
|
83
|
+
let q = S(async (e, i) => {
|
|
84
84
|
I();
|
|
85
|
-
let
|
|
86
|
-
I(),
|
|
87
|
-
let
|
|
88
|
-
I(),
|
|
85
|
+
let a = P.subject, d = K.current, m = i?.onError !== void 0 || i?.notify?.error !== void 0, g = (t) => {
|
|
86
|
+
I(), i?.onError?.(t, e), I();
|
|
87
|
+
let n = N(i?.notify?.error, t, e);
|
|
88
|
+
I(), n !== void 0 && A?.error(n);
|
|
89
89
|
};
|
|
90
|
-
|
|
90
|
+
d.count += 1;
|
|
91
91
|
let _ = () => {
|
|
92
|
-
--
|
|
92
|
+
--d.count, F() && U((e) => e.owner === P ? {
|
|
93
93
|
...e,
|
|
94
|
-
pending:
|
|
94
|
+
pending: d.count > 0
|
|
95
95
|
} : e);
|
|
96
96
|
};
|
|
97
97
|
U((e) => ({
|
|
@@ -102,17 +102,17 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
|
|
|
102
102
|
}));
|
|
103
103
|
let S, C, w, T, E;
|
|
104
104
|
try {
|
|
105
|
-
T =
|
|
106
|
-
let
|
|
107
|
-
if (
|
|
108
|
-
let
|
|
109
|
-
E = ne(
|
|
105
|
+
T = ee(q);
|
|
106
|
+
let t = M.current.descriptors[x]?.serialize;
|
|
107
|
+
if (t !== void 0) {
|
|
108
|
+
let n = M.current, r = n.recovery ?? h(n.errorBus, b);
|
|
109
|
+
E = ne(n.descriptors, x, t.maxPending ?? 32).reserve(t.key(e), r.subjectSignal);
|
|
110
110
|
}
|
|
111
|
-
let
|
|
112
|
-
if (
|
|
113
|
-
|
|
111
|
+
let n = await l(M, b, x);
|
|
112
|
+
if (a.aborted) throw new f("inactive");
|
|
113
|
+
u(P, n), I(), {runtime: S, cache: C, client: w} = n;
|
|
114
114
|
} catch (e) {
|
|
115
|
-
if (E?.release(), _(), !F()) throw new
|
|
115
|
+
if (E?.release(), _(), !F()) throw new f("inactive");
|
|
116
116
|
if (U((t) => t.owner === P ? {
|
|
117
117
|
...t,
|
|
118
118
|
error: e
|
|
@@ -125,21 +125,21 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
|
|
|
125
125
|
}), m) return g(e);
|
|
126
126
|
throw e;
|
|
127
127
|
}
|
|
128
|
-
let O = ie(), j =
|
|
128
|
+
let O = ie(), j = i?.idempotencyKey ?? v(), L = M.current.descriptors[x]?.outputRetention === "none", R = !M.current.descriptors[x] || M.current.descriptors[x]?.clientHistory?.input === "omit", z = o({
|
|
129
129
|
id: O,
|
|
130
130
|
apiName: b,
|
|
131
131
|
tag: x,
|
|
132
|
-
input: R ? void 0 :
|
|
132
|
+
input: R ? void 0 : e,
|
|
133
133
|
...R ? { inputOmitted: !0 } : {},
|
|
134
134
|
...L ? { outputOmitted: !0 } : {}
|
|
135
135
|
}, P.subject), B = W.current, H = G.current;
|
|
136
136
|
try {
|
|
137
|
-
I(), B ? B(ae(C, O),
|
|
137
|
+
I(), B ? B(ae(C, O), e) : !H && V && V.length > 0 && C.autoApply(V, e, O);
|
|
138
138
|
} catch (e) {
|
|
139
139
|
if (E?.release(), _(), C.revertByMutation(O), z.settle({
|
|
140
140
|
status: "error",
|
|
141
141
|
error: e
|
|
142
|
-
}), !F()) throw new
|
|
142
|
+
}), !F()) throw new f("inactive");
|
|
143
143
|
if (U((t) => t.owner === P ? {
|
|
144
144
|
...t,
|
|
145
145
|
error: e
|
|
@@ -150,117 +150,117 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
|
|
|
150
150
|
try {
|
|
151
151
|
if (E) {
|
|
152
152
|
await E.ready, I(), E.assertActive();
|
|
153
|
-
let e = await
|
|
153
|
+
let e = await l(M, b, x);
|
|
154
154
|
I(), S = e.runtime, w = e.client;
|
|
155
155
|
}
|
|
156
|
-
let
|
|
156
|
+
let a = async (i, a, o, c) => {
|
|
157
157
|
I();
|
|
158
|
-
let l =
|
|
159
|
-
Z = l === void 0 ? void 0 : () => M.current.runtime ===
|
|
160
|
-
let d = T === void 0 ? void 0 : await T.prepare(
|
|
161
|
-
u = l?.getSnapshot(), I(),
|
|
162
|
-
let f =
|
|
163
|
-
I(),
|
|
164
|
-
let
|
|
165
|
-
return Y = !0,
|
|
166
|
-
}), j), m = D.currentSpan.pipe(D.tap((
|
|
167
|
-
J =
|
|
168
|
-
traceId:
|
|
169
|
-
spanId:
|
|
158
|
+
let l = te(i), u = l?.getSnapshot();
|
|
159
|
+
Z = l === void 0 ? void 0 : () => M.current.runtime === i && u !== void 0 && l.getSnapshot() === u, c?.(), E?.assertActive();
|
|
160
|
+
let d = T === void 0 ? void 0 : await T.prepare(i, a);
|
|
161
|
+
u = l?.getSnapshot(), I(), c?.();
|
|
162
|
+
let f = r(a, x), p = y(t(() => {
|
|
163
|
+
I(), c?.(), E?.assertActive();
|
|
164
|
+
let t = f(e);
|
|
165
|
+
return Y = !0, t;
|
|
166
|
+
}), j), m = D.currentSpan.pipe(D.tap((e) => D.sync(() => {
|
|
167
|
+
J = e.traceId, s({
|
|
168
|
+
traceId: e.traceId,
|
|
169
|
+
spanId: e.spanId,
|
|
170
170
|
source: "mutation",
|
|
171
171
|
tag: x
|
|
172
172
|
});
|
|
173
173
|
})), D.catch(() => D.void), D.andThen(D.try({
|
|
174
174
|
try: () => {
|
|
175
|
-
I(),
|
|
175
|
+
I(), c?.(), E?.assertActive();
|
|
176
176
|
},
|
|
177
177
|
catch: (e) => e
|
|
178
178
|
})), D.andThen(p)).pipe(D.withSpan(`client.mutation.${x}`, { attributes: {
|
|
179
179
|
"voltro.api": b,
|
|
180
180
|
"voltro.mutationId": O,
|
|
181
181
|
"rpc.tag": x,
|
|
182
|
-
"voltro.replay":
|
|
182
|
+
"voltro.replay": o
|
|
183
183
|
} }));
|
|
184
|
-
return d === void 0 ?
|
|
185
|
-
},
|
|
184
|
+
return d === void 0 ? n(i, m) : d.run(m);
|
|
185
|
+
}, o;
|
|
186
186
|
try {
|
|
187
|
-
|
|
187
|
+
o = await a(S, w, !1);
|
|
188
188
|
} catch (e) {
|
|
189
189
|
I();
|
|
190
|
-
let
|
|
191
|
-
|
|
190
|
+
let t = p(e, Y ? "handler" : "client"), n = k(e, J);
|
|
191
|
+
t === "transport" && (M.current.errorBus.emit({
|
|
192
192
|
source: "mutation",
|
|
193
193
|
tag: x,
|
|
194
|
-
error:
|
|
195
|
-
kind:
|
|
194
|
+
error: n,
|
|
195
|
+
kind: t,
|
|
196
196
|
...Z === void 0 ? {} : { affectsTransport: Z() },
|
|
197
197
|
outcome: Y ? "unknown" : "not-started",
|
|
198
198
|
...J === void 0 ? {} : { traceId: J }
|
|
199
|
-
}), X =
|
|
200
|
-
let
|
|
201
|
-
if (
|
|
199
|
+
}), X = n), I();
|
|
200
|
+
let r = M.current, i = r.recovery ?? h(r.errorBus, b), s = t === "transport" ? i.reserveMutationReplay($) : void 0;
|
|
201
|
+
if (s === void 0) throw n;
|
|
202
202
|
try {
|
|
203
|
-
if (!await
|
|
203
|
+
if (!await i.waitForMutationReplaySupport($) || !await i.waitForProtocolReady($) || !s.isValid()) throw n;
|
|
204
204
|
let e = () => {
|
|
205
|
-
if (I(), !
|
|
205
|
+
if (I(), !s.isValid()) throw n;
|
|
206
206
|
};
|
|
207
207
|
for (;;) {
|
|
208
208
|
e();
|
|
209
|
-
let
|
|
209
|
+
let t = await l(M, b, x);
|
|
210
210
|
try {
|
|
211
|
-
|
|
211
|
+
o = await a(t.runtime, t.client, !0, e);
|
|
212
212
|
break;
|
|
213
213
|
} catch (t) {
|
|
214
214
|
let n = t;
|
|
215
215
|
if (n?._tag !== "MutationInFlight") throw t;
|
|
216
216
|
let r = typeof n.retryAfterMs == "number" && Number.isFinite(n.retryAfterMs) && n.retryAfterMs > 0 ? n.retryAfterMs : 1e3;
|
|
217
|
-
if (r >=
|
|
217
|
+
if (r >= i.replayWindowRemaining($)) throw t;
|
|
218
218
|
await new Promise((e) => setTimeout(e, r)), e();
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
} finally {
|
|
222
|
-
|
|
222
|
+
s.release();
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
I();
|
|
226
|
-
let
|
|
226
|
+
let c = L || M.current.descriptors[x]?.outputRetention === "none";
|
|
227
227
|
U((e) => e.owner === P ? {
|
|
228
228
|
...e,
|
|
229
|
-
data:
|
|
229
|
+
data: c ? void 0 : o,
|
|
230
230
|
error: void 0
|
|
231
231
|
} : e), I(), z.settle({
|
|
232
232
|
status: "success",
|
|
233
|
-
output:
|
|
234
|
-
...
|
|
233
|
+
output: c ? void 0 : o,
|
|
234
|
+
...c ? { outputOmitted: !0 } : {}
|
|
235
235
|
}), I(), M.current.errorBus.emitSuccess({
|
|
236
236
|
source: "mutation",
|
|
237
237
|
tag: x
|
|
238
|
-
}), I(), C.confirmByMutation(O), I(),
|
|
239
|
-
let
|
|
240
|
-
return I(),
|
|
238
|
+
}), I(), C.confirmByMutation(O), I(), i?.onSuccess?.(o, e), I();
|
|
239
|
+
let u = N(i?.notify?.success, o, e);
|
|
240
|
+
return I(), u !== void 0 && A?.success(u), o;
|
|
241
241
|
} catch (e) {
|
|
242
|
-
let
|
|
243
|
-
!Y || re(e) ||
|
|
244
|
-
let
|
|
242
|
+
let t = F();
|
|
243
|
+
!Y || re(e) || t && X === void 0 && p(e, "handler") !== "transport" || (Q = "unknown");
|
|
244
|
+
let n = k(t ? e : new f("inactive"), J);
|
|
245
245
|
if (z.settle({
|
|
246
246
|
status: "error",
|
|
247
|
-
error:
|
|
247
|
+
error: n
|
|
248
248
|
}), C.revertByMutation(O), I(), U((e) => e.owner === P ? {
|
|
249
249
|
...e,
|
|
250
|
-
error:
|
|
251
|
-
} : e), I(), Object.is(X,
|
|
250
|
+
error: n
|
|
251
|
+
} : e), I(), Object.is(X, n) || (Y && J !== void 0 && p(e, "handler") === "handler" && c({
|
|
252
252
|
traceId: J,
|
|
253
253
|
tag: x
|
|
254
254
|
}), M.current.errorBus.emit({
|
|
255
255
|
source: "mutation",
|
|
256
256
|
tag: x,
|
|
257
|
-
error:
|
|
258
|
-
kind: Y ?
|
|
257
|
+
error: n,
|
|
258
|
+
kind: Y ? p(e, "handler") : "client",
|
|
259
259
|
...Z === void 0 ? {} : { affectsTransport: Z() },
|
|
260
|
-
outcome: Y &&
|
|
260
|
+
outcome: Y && p(e, "handler") === "transport" ? "unknown" : Y ? "known" : "not-started",
|
|
261
261
|
...J === void 0 ? {} : { traceId: J }
|
|
262
|
-
})), I(), m) return g(
|
|
263
|
-
throw
|
|
262
|
+
})), I(), m) return g(n);
|
|
263
|
+
throw n;
|
|
264
264
|
} finally {
|
|
265
265
|
E?.release(Q), _();
|
|
266
266
|
}
|
package/dist/useOnRpcError.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useFrameworkApi as e } from "./runtimeContext.js";
|
|
2
|
+
import { recoveryCoordinatorFor as t } from "./recoveryCoordinator.js";
|
|
3
3
|
import { useEffect as n, useRef as r } from "react";
|
|
4
4
|
// src/useOnRpcError.ts
|
|
5
5
|
var i = (i, a) => {
|
|
6
|
-
let o =
|
|
6
|
+
let o = e(i), s = o.recovery ?? t(o.errorBus, i), c = r(a);
|
|
7
7
|
c.current = a, n(() => s.onVisibleError((e) => c.current(e)), [s]);
|
|
8
|
-
}, a = (
|
|
9
|
-
let { errorBus: a } = t
|
|
8
|
+
}, a = (t, i) => {
|
|
9
|
+
let { errorBus: a } = e(t), o = r(i);
|
|
10
10
|
o.current = i, n(() => a.on((e) => o.current(e)), [a]);
|
|
11
11
|
};
|
|
12
12
|
export { a as useOnRawRpcError, i as useOnRpcError };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { readPreloadedSeedOutcome as e, readPreloadedSnapshot as t } from "./preloadSeed.js";
|
|
2
|
+
import { useFrameworkApi as n } from "./runtimeContext.js";
|
|
3
|
+
import { useSubscription as r } from "./useSubscription.js";
|
|
4
4
|
import { useSyncExternalStore as i } from "react";
|
|
5
5
|
// src/usePreloadedSubscription.ts
|
|
6
6
|
var a = () => !0, o = (e) => () => {};
|
|
7
7
|
function s(s, c, l = {}, u = {}) {
|
|
8
|
-
let { recovery: d } =
|
|
8
|
+
let { recovery: d } = n(s), f = i(d?.subscribe ?? o, d?.getPreloadSeedPermission ?? a, a), p = f ? t(s, c, l) : void 0, m = p === void 0 ? u : {
|
|
9
9
|
...u,
|
|
10
10
|
initialSnapshot: p
|
|
11
|
-
}, h =
|
|
12
|
-
return f &&
|
|
11
|
+
}, h = r(s, c, l, m);
|
|
12
|
+
return f && e(s, c, l) === "failed" ? {
|
|
13
13
|
...h,
|
|
14
14
|
preloadFailed: !0
|
|
15
15
|
} : h;
|
package/dist/useRpcCaller.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useFrameworkApi as e } from "./runtimeContext.js";
|
|
2
|
-
import {
|
|
3
|
-
import { ConnectionPrerequisiteInvalidated as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { awaitResolvedApi as t, bindResolvedRpcInvocationOwner as n, captureRpcInvocationOwner as r, rpcInvocationOwnerCurrent as i } from "./awaitResolvedApi.js";
|
|
3
|
+
import { ConnectionPrerequisiteInvalidated as a } from "./connectionPrerequisite.js";
|
|
4
|
+
import { rpcCallOnce as o } from "./rpcCallOnce.js";
|
|
5
|
+
import { resolveByTag as s } from "./tagWalk.js";
|
|
6
6
|
import { useEffect as c, useMemo as l, useRef as u, useState as d } from "react";
|
|
7
7
|
// src/useRpcCaller.ts
|
|
8
8
|
var f = (f) => {
|
|
@@ -18,7 +18,7 @@ var f = (f) => {
|
|
|
18
18
|
});
|
|
19
19
|
let h = m.current.handleRef;
|
|
20
20
|
h.current = p;
|
|
21
|
-
let g =
|
|
21
|
+
let g = r(p, f, "rpc.caller", m.current.owner);
|
|
22
22
|
m.current.owner = g;
|
|
23
23
|
let _ = g.subject, [, v] = d(0);
|
|
24
24
|
c(() => {
|
|
@@ -27,46 +27,46 @@ var f = (f) => {
|
|
|
27
27
|
return _.addEventListener("abort", e, { once: !0 }), () => _.removeEventListener("abort", e);
|
|
28
28
|
}, [_]);
|
|
29
29
|
let y = () => {
|
|
30
|
-
if (!
|
|
30
|
+
if (!i(g, h.current)) throw new a("inactive");
|
|
31
31
|
};
|
|
32
32
|
return l(() => Object.freeze({
|
|
33
|
-
call: (e, t, n) =>
|
|
34
|
-
query: async (e,
|
|
33
|
+
call: (e, t, n) => o(h, f, e, t, n?.signal, "[rpc.call]", g),
|
|
34
|
+
query: async (e, n, r) => {
|
|
35
35
|
y();
|
|
36
|
-
let i = await
|
|
36
|
+
let i = await t(h, f, e, r?.signal);
|
|
37
37
|
if (i.descriptors[e]?.kind !== "query") throw Error(`Voltro: query '${e}' is not a registered query on api '${f}'.`);
|
|
38
|
-
let a = await
|
|
38
|
+
let a = await o({ current: i }, f, e, n ?? {}, r?.signal, "[rpc.query]", g);
|
|
39
39
|
return y(), a;
|
|
40
40
|
},
|
|
41
|
-
subscribe: (e,
|
|
41
|
+
subscribe: (e, r, a) => {
|
|
42
42
|
y();
|
|
43
|
-
let
|
|
44
|
-
l || (l = !0,
|
|
43
|
+
let o = new AbortController(), c = g.subject, l = !1, u, d = c, p = () => {
|
|
44
|
+
l || (l = !0, o.abort(), d.removeEventListener("abort", p), u?.());
|
|
45
45
|
};
|
|
46
|
-
return d.addEventListener("abort", p, { once: !0 }),
|
|
46
|
+
return d.addEventListener("abort", p, { once: !0 }), t(h, f, e, o.signal).then((t) => {
|
|
47
47
|
if (l) return;
|
|
48
48
|
if (c.aborted) {
|
|
49
49
|
p();
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
if (
|
|
52
|
+
if (n(g, t), y(), t.descriptors[e]?.kind !== "query") throw Error(`[rpc.subscribe] ${e}: only queries can be subscribed to`);
|
|
53
53
|
if (d.removeEventListener("abort", p), d = g.subject, d.aborted) {
|
|
54
54
|
p();
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
d.addEventListener("abort", p, { once: !0 });
|
|
58
|
-
let
|
|
59
|
-
if (l || !
|
|
60
|
-
if (!
|
|
58
|
+
let o, f = -2, m, _, v = () => {
|
|
59
|
+
if (l || !o) return;
|
|
60
|
+
if (!i(g, h.current)) {
|
|
61
61
|
p();
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
let e =
|
|
64
|
+
let e = o.getSnapshot();
|
|
65
65
|
e.error !== void 0 && e.error !== m && (m = e.error, a.onError?.(e.error)), !l && e.revision >= 0 && e.data !== void 0 && (e.revision !== f || e.data !== _) && (f = e.revision, _ = e.data, a.onValue(e.data));
|
|
66
66
|
};
|
|
67
|
-
|
|
67
|
+
o = t.cache.subscribe([e, r], () => s(t.client, e)(r), t.runtime, v), u = o.unsubscribe, l ? u() : v();
|
|
68
68
|
}).catch((e) => {
|
|
69
|
-
!l &&
|
|
69
|
+
!l && i(g, h.current) && a.onError?.(e);
|
|
70
70
|
}), Object.freeze({ unsubscribe: p });
|
|
71
71
|
}
|
|
72
72
|
}), [
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { captureRpcInvocationOwner as e, rpcInvocationOwnerCurrent as t } from "./awaitResolvedApi.js";
|
|
2
|
+
import { ConnectionPrerequisiteInvalidated as n } from "./connectionPrerequisite.js";
|
|
3
3
|
import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
|
|
4
4
|
// src/useRpcInvocationOwner.ts
|
|
5
5
|
var s = (s, c, l) => {
|
|
6
|
-
let u = a(void 0), d =
|
|
6
|
+
let u = a(void 0), d = e(s.current, c, l, u.current);
|
|
7
7
|
u.current = d;
|
|
8
8
|
let f = d.subject, p = a(!0), [, m] = o(0);
|
|
9
9
|
i(() => (p.current = !0, () => {
|
|
@@ -14,15 +14,15 @@ var s = (s, c, l) => {
|
|
|
14
14
|
let t = () => m((e) => e + 1);
|
|
15
15
|
return e.addEventListener("abort", t, { once: !0 }), () => e.removeEventListener("abort", t);
|
|
16
16
|
}, [d, f]);
|
|
17
|
-
let h = r(() => u.current === d &&
|
|
17
|
+
let h = r(() => u.current === d && t(d, s.current), [d, s]), g = r(() => p.current && h(), [h]);
|
|
18
18
|
return {
|
|
19
19
|
owner: d,
|
|
20
20
|
current: g,
|
|
21
21
|
assertCurrent: r(() => {
|
|
22
|
-
if (!g()) throw new
|
|
22
|
+
if (!g()) throw new n("inactive");
|
|
23
23
|
}, [g]),
|
|
24
24
|
assertOwnerCurrent: r(() => {
|
|
25
|
-
if (!h()) throw new
|
|
25
|
+
if (!h()) throw new n("inactive");
|
|
26
26
|
}, [h])
|
|
27
27
|
};
|
|
28
28
|
};
|
package/dist/useTranscription.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { useAction as e } from "./useAction.js";
|
|
2
|
+
import { useUpload as t } from "./useUpload.js";
|
|
3
|
+
import { useFrameworkApi as n } from "./runtimeContext.js";
|
|
4
4
|
import { useRpcInvocationOwner as r } from "./useRpcInvocationOwner.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { bindResolvedRpcInvocationOwner as i } from "./awaitResolvedApi.js";
|
|
6
|
+
import { ConnectionPrerequisiteInvalidated as a } from "./connectionPrerequisite.js";
|
|
7
|
+
import { waitForInvocation as o } from "./invocationWait.js";
|
|
8
8
|
import { useCallback as s, useEffect as c, useMemo as l, useRef as u, useState as d } from "react";
|
|
9
9
|
// src/useTranscription.ts
|
|
10
10
|
var f = (f, p) => {
|
|
11
|
-
let m =
|
|
11
|
+
let m = n(f), h = u(m);
|
|
12
12
|
h.current = m;
|
|
13
|
-
let { owner: g, current: _, assertCurrent: v } = r(h, f, p.action), y =
|
|
13
|
+
let { owner: g, current: _, assertCurrent: v } = r(h, f, p.action), y = t(f), b = e(f, p.action), x = l(() => ({ active: void 0 }), [g]), S = u(void 0), [C, w] = d(() => ({
|
|
14
14
|
owner: g,
|
|
15
15
|
phase: "idle",
|
|
16
16
|
result: void 0,
|
|
@@ -27,54 +27,54 @@ var f = (f, p) => {
|
|
|
27
27
|
}, [x, g]);
|
|
28
28
|
let E = s(async (e) => {
|
|
29
29
|
if (v(), x.active) throw Error("useTranscription: another transcription is in progress; await it, cancel or reset before starting another.");
|
|
30
|
-
let
|
|
31
|
-
if (Object.hasOwn(
|
|
32
|
-
let
|
|
30
|
+
let t = T.current ?? {};
|
|
31
|
+
if (Object.hasOwn(t, "storageRef")) throw TypeError("useTranscription: extra.storageRef is reserved for the uploaded file.");
|
|
32
|
+
let n = { ...t }, r = {
|
|
33
33
|
controller: new AbortController(),
|
|
34
34
|
resetUpload: y.reset
|
|
35
35
|
}, s = S.current;
|
|
36
|
-
s && (s.controller.abort(), s.resetUpload()), x.active =
|
|
36
|
+
s && (s.controller.abort(), s.resetUpload()), x.active = r, S.current = r, w({
|
|
37
37
|
owner: g,
|
|
38
38
|
phase: "uploading",
|
|
39
39
|
result: void 0,
|
|
40
40
|
error: void 0
|
|
41
41
|
});
|
|
42
|
-
let c, l = () =>
|
|
42
|
+
let c, l = () => r.controller.abort(), u = () => {
|
|
43
43
|
c !== g.subject && (c?.removeEventListener("abort", l), c = g.subject, c.addEventListener("abort", l, { once: !0 })), c.aborted && l();
|
|
44
44
|
}, d = () => {
|
|
45
|
-
if (v(), x.active !==
|
|
46
|
-
}, f = () => _() && x.active ===
|
|
45
|
+
if (v(), x.active !== r || r.controller.signal.aborted) throw new DOMException("transcription aborted", "AbortError");
|
|
46
|
+
}, f = () => _() && x.active === r && !r.controller.signal.aborted;
|
|
47
47
|
u();
|
|
48
48
|
try {
|
|
49
49
|
d();
|
|
50
|
-
let t = await
|
|
51
|
-
d(),
|
|
50
|
+
let t = await o(y.upload(e), r.controller.signal, d);
|
|
51
|
+
d(), i(g, h.current), u(), d(), S.current === r && (S.current = void 0), w({
|
|
52
52
|
owner: g,
|
|
53
53
|
phase: "transcribing",
|
|
54
54
|
result: void 0,
|
|
55
55
|
error: void 0
|
|
56
56
|
});
|
|
57
|
-
let
|
|
58
|
-
...
|
|
57
|
+
let a = await o(b.run({
|
|
58
|
+
...n,
|
|
59
59
|
storageRef: t.id
|
|
60
|
-
}, { signal:
|
|
61
|
-
if (
|
|
60
|
+
}, { signal: r.controller.signal }), r.controller.signal, d);
|
|
61
|
+
if (a == null) throw TypeError("useTranscription: the declared action returned no transcript.");
|
|
62
62
|
return d(), w({
|
|
63
63
|
owner: g,
|
|
64
64
|
phase: "done",
|
|
65
|
-
result:
|
|
65
|
+
result: a,
|
|
66
66
|
error: void 0
|
|
67
|
-
}),
|
|
67
|
+
}), a;
|
|
68
68
|
} catch (e) {
|
|
69
|
-
let
|
|
69
|
+
let t = _() ? r.controller.signal.aborted || x.active !== r ? new DOMException("transcription aborted", "AbortError") : e : new a("inactive");
|
|
70
70
|
throw f() && w({
|
|
71
71
|
owner: g,
|
|
72
72
|
phase: "error",
|
|
73
73
|
result: void 0,
|
|
74
|
-
error:
|
|
75
|
-
}),
|
|
74
|
+
error: t
|
|
75
|
+
}), t;
|
|
76
76
|
} finally {
|
|
77
|
-
c?.removeEventListener("abort", l), x.active ===
|
|
77
|
+
c?.removeEventListener("abort", l), x.active === r && (x.active = void 0), S.current === r && (S.current = void 0);
|
|
78
78
|
}
|
|
79
79
|
}, [
|
|
80
80
|
v,
|