@reactor-team/js-sdk 2.10.0 → 2.10.1

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/dist/index.js CHANGED
@@ -100,6 +100,7 @@ __export(index_exports, {
100
100
  downloadClipAsFile: () => downloadClipAsFile,
101
101
  fetchPlaylist: () => fetchPlaylist,
102
102
  isAbortError: () => isAbortError,
103
+ normalizeJwtSource: () => normalizeJwtSource,
103
104
  parsePlaylist: () => parsePlaylist,
104
105
  rewriteUrlHost: () => rewriteUrlHost,
105
106
  useClipDownload: () => useClipDownload,
@@ -138,15 +139,23 @@ function isAbortError(error) {
138
139
  return error instanceof AbortError || error instanceof Error && error.name === "AbortError";
139
140
  }
140
141
 
142
+ // src/core/auth.ts
143
+ function normalizeJwtSource(source) {
144
+ if (typeof source === "function") {
145
+ return source;
146
+ }
147
+ return () => source;
148
+ }
149
+
141
150
  // src/core/types.ts
142
151
  var import_zod = require("zod");
143
152
 
144
153
  // package.json
145
154
  var package_default = {
146
155
  name: "@reactor-team/js-sdk",
147
- version: "2.10.0",
156
+ version: "2.10.1",
148
157
  description: "Reactor JavaScript frontend SDK \u2014 connect React and TypeScript apps to real-time AI video models on Reactor.",
149
- license: "MIT",
158
+ license: "Apache-2.0",
150
159
  repository: {
151
160
  type: "git",
152
161
  url: "https://github.com/reactor-team/js-sdk.git"
@@ -178,9 +187,13 @@ var package_default = {
178
187
  },
179
188
  files: [
180
189
  "dist",
181
- "README.md"
190
+ "README.md",
191
+ "LICENSE",
192
+ "NOTICE"
182
193
  ],
183
194
  scripts: {
195
+ prepack: "cp ../../LICENSE ../../NOTICE .",
196
+ postpack: "rm -f LICENSE NOTICE",
184
197
  build: "tsup",
185
198
  dev: "tsup --watch",
186
199
  test: "vitest run",
@@ -196,8 +209,9 @@ var package_default = {
196
209
  },
197
210
  packageManager: "pnpm@10.12.1",
198
211
  dependencies: {
212
+ mp4box: "^2.3.0",
199
213
  "sdp-transform": "^3.0.0",
200
- zod: "^4.0.5"
214
+ zod: "^4.4.3"
201
215
  },
202
216
  peerDependencies: {
203
217
  "hls.js": "^1.6.0",
@@ -211,13 +225,13 @@ var package_default = {
211
225
  },
212
226
  devDependencies: {
213
227
  "@roamhq/wrtc": "^0.8.0",
214
- "@types/node": "^20",
215
- "@types/react": "^18.2.8",
228
+ "@types/node": "^25",
229
+ "@types/react": "^19.2.15",
216
230
  "hls.js": "^1.6.0",
217
231
  prettier: "^3.6.2",
218
232
  tsup: "^8.5.0",
219
233
  typescript: "^5.8.3",
220
- vitest: "^3.0.0"
234
+ vitest: "^4.1.7"
221
235
  }
222
236
  };
223
237
 
@@ -320,7 +334,7 @@ var SESSION_POLL_DEFAULT_MAX_ATTEMPTS = 20;
320
334
  var CoordinatorClient = class {
321
335
  constructor(options) {
322
336
  this.baseUrl = options.baseUrl;
323
- this.jwtToken = options.jwtToken;
337
+ this.resolveJwt = normalizeJwtSource(options.jwtToken);
324
338
  this.model = options.model;
325
339
  this.abortController = new AbortController();
326
340
  }
@@ -340,14 +354,22 @@ var CoordinatorClient = class {
340
354
  return this.abortController.signal;
341
355
  }
342
356
  /**
343
- * Returns authorization + versioning headers for all coordinator requests.
357
+ * Returns authorization + versioning headers for all coordinator
358
+ * requests. Async so the JWT resolver can fetch a fresh token if
359
+ * needed; an empty token suppresses the `Authorization` header.
344
360
  */
345
361
  getHeaders() {
346
- return {
347
- Authorization: `Bearer ${this.jwtToken}`,
348
- [API_VERSION_HEADER]: String(REACTOR_API_VERSION),
349
- [API_ACCEPT_VERSION_HEADER]: String(REACTOR_API_VERSION)
350
- };
362
+ return __async(this, null, function* () {
363
+ const headers = {
364
+ [API_VERSION_HEADER]: String(REACTOR_API_VERSION),
365
+ [API_ACCEPT_VERSION_HEADER]: String(REACTOR_API_VERSION)
366
+ };
367
+ const jwt = yield this.resolveJwt();
368
+ if (jwt) {
369
+ headers.Authorization = `Bearer ${jwt}`;
370
+ }
371
+ return headers;
372
+ });
351
373
  }
352
374
  /**
353
375
  * Checks an HTTP response for version mismatch errors (426, 501).
@@ -408,7 +430,7 @@ var CoordinatorClient = class {
408
430
  }, extraArgs ? { extra_args: extraArgs } : {});
409
431
  const response = yield fetch(`${this.baseUrl}/sessions`, {
410
432
  method: "POST",
411
- headers: __spreadProps(__spreadValues({}, this.getHeaders()), {
433
+ headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
412
434
  "Content-Type": "application/json"
413
435
  }),
414
436
  body: JSON.stringify(requestBody),
@@ -463,7 +485,7 @@ var CoordinatorClient = class {
463
485
  `${this.baseUrl}/sessions/${this.currentSessionId}`,
464
486
  {
465
487
  method: "GET",
466
- headers: this.getHeaders(),
488
+ headers: yield this.getHeaders(),
467
489
  signal: this.signal
468
490
  }
469
491
  );
@@ -516,7 +538,7 @@ var CoordinatorClient = class {
516
538
  `${this.baseUrl}/sessions/${this.currentSessionId}`,
517
539
  {
518
540
  method: "GET",
519
- headers: this.getHeaders(),
541
+ headers: yield this.getHeaders(),
520
542
  signal: this.signal
521
543
  }
522
544
  );
@@ -541,7 +563,7 @@ var CoordinatorClient = class {
541
563
  `${this.baseUrl}/sessions/${this.currentSessionId}/info`,
542
564
  {
543
565
  method: "GET",
544
- headers: this.getHeaders(),
566
+ headers: yield this.getHeaders(),
545
567
  signal: this.signal
546
568
  }
547
569
  );
@@ -573,7 +595,7 @@ var CoordinatorClient = class {
573
595
  `${this.baseUrl}/sessions/${this.currentSessionId}`,
574
596
  {
575
597
  method: "PUT",
576
- headers: this.getHeaders(),
598
+ headers: yield this.getHeaders(),
577
599
  signal: this.signal
578
600
  }
579
601
  );
@@ -605,7 +627,7 @@ var CoordinatorClient = class {
605
627
  `${this.baseUrl}/sessions/${this.currentSessionId}`,
606
628
  __spreadProps(__spreadValues({
607
629
  method: "DELETE",
608
- headers: __spreadValues(__spreadValues({}, this.getHeaders()), body ? { "Content-Type": "application/json" } : {})
630
+ headers: __spreadValues(__spreadValues({}, yield this.getHeaders()), body ? { "Content-Type": "application/json" } : {})
609
631
  }, body ? { body: JSON.stringify(body) } : {}), {
610
632
  signal: this.signal
611
633
  })
@@ -644,7 +666,7 @@ var CoordinatorClient = class {
644
666
  `${this.baseUrl}/sessions/${sessionId}/uploads`,
645
667
  {
646
668
  method: "POST",
647
- headers: __spreadProps(__spreadValues({}, this.getHeaders()), {
669
+ headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
648
670
  "Content-Type": "application/json"
649
671
  }),
650
672
  body: JSON.stringify(request),
@@ -676,11 +698,14 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
676
698
  model
677
699
  });
678
700
  }
701
+ // Local runtime endpoints are auth-free; skip the Authorization header.
679
702
  getHeaders() {
680
- return {
681
- [API_VERSION_HEADER]: String(REACTOR_API_VERSION),
682
- [API_ACCEPT_VERSION_HEADER]: String(REACTOR_API_VERSION)
683
- };
703
+ return __async(this, null, function* () {
704
+ return {
705
+ [API_VERSION_HEADER]: String(REACTOR_API_VERSION),
706
+ [API_ACCEPT_VERSION_HEADER]: String(REACTOR_API_VERSION)
707
+ };
708
+ });
684
709
  }
685
710
  /**
686
711
  * Starts a session on the local runtime.
@@ -694,7 +719,7 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
694
719
  console.debug("[LocalCoordinatorClient] Starting session...");
695
720
  const response = yield fetch(`${this.baseUrl}/start_session`, {
696
721
  method: "POST",
697
- headers: __spreadProps(__spreadValues({}, this.getHeaders()), {
722
+ headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
698
723
  "Content-Type": "application/json"
699
724
  }),
700
725
  body: JSON.stringify(__spreadValues({}, extraArgs ? { extra_args: extraArgs } : {})),
@@ -750,7 +775,7 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
750
775
  try {
751
776
  yield fetch(`${this.baseUrl}/stop_session`, {
752
777
  method: "POST",
753
- headers: this.getHeaders(),
778
+ headers: yield this.getHeaders(),
754
779
  signal: this.signal
755
780
  });
756
781
  } catch (error) {
@@ -1330,7 +1355,7 @@ var WebRTCTransportClient = class {
1330
1355
  var _a, _b;
1331
1356
  this.baseUrl = config.baseUrl;
1332
1357
  this.sessionId = config.sessionId;
1333
- this.jwtToken = config.jwtToken;
1358
+ this.resolveJwt = normalizeJwtSource(config.jwtToken);
1334
1359
  this.webrtcVersion = (_a = config.webrtcVersion) != null ? _a : REACTOR_WEBRTC_VERSION;
1335
1360
  this.maxPollAttempts = (_b = config.maxPollAttempts) != null ? _b : DEFAULT_MAX_POLL_ATTEMPTS;
1336
1361
  this.abortController = new AbortController();
@@ -1361,11 +1386,19 @@ var WebRTCTransportClient = class {
1361
1386
  get transportBaseUrl() {
1362
1387
  return `${this.baseUrl}/sessions/${this.sessionId}/transport/webrtc`;
1363
1388
  }
1389
+ // Async so the JWT resolver can fetch a fresh token if needed; an
1390
+ // empty token suppresses the `Authorization` header.
1364
1391
  getHeaders() {
1365
- return {
1366
- Authorization: `Bearer ${this.jwtToken}`,
1367
- [WEBRTC_VERSION_HEADER]: this.webrtcVersion
1368
- };
1392
+ return __async(this, null, function* () {
1393
+ const headers = {
1394
+ [WEBRTC_VERSION_HEADER]: this.webrtcVersion
1395
+ };
1396
+ const jwt = yield this.resolveJwt();
1397
+ if (jwt) {
1398
+ headers.Authorization = `Bearer ${jwt}`;
1399
+ }
1400
+ return headers;
1401
+ });
1369
1402
  }
1370
1403
  checkVersionMismatch(response) {
1371
1404
  return __async(this, null, function* () {
@@ -1407,7 +1440,7 @@ var WebRTCTransportClient = class {
1407
1440
  console.debug("[WebRTCTransport] Fetching ICE servers...");
1408
1441
  const response = yield fetch(`${this.transportBaseUrl}/ice_servers`, {
1409
1442
  method: "GET",
1410
- headers: this.getHeaders(),
1443
+ headers: yield this.getHeaders(),
1411
1444
  signal: this.signal
1412
1445
  });
1413
1446
  yield this.checkVersionMismatch(response);
@@ -1437,7 +1470,7 @@ var WebRTCTransportClient = class {
1437
1470
  };
1438
1471
  const response = yield fetch(`${this.transportBaseUrl}/sdp_params`, {
1439
1472
  method,
1440
- headers: __spreadProps(__spreadValues({}, this.getHeaders()), {
1473
+ headers: __spreadProps(__spreadValues({}, yield this.getHeaders()), {
1441
1474
  "Content-Type": "application/json"
1442
1475
  }),
1443
1476
  body: JSON.stringify(requestBody),
@@ -1474,7 +1507,7 @@ var WebRTCTransportClient = class {
1474
1507
  );
1475
1508
  const response = yield fetch(`${this.transportBaseUrl}/sdp_params`, {
1476
1509
  method: "GET",
1477
- headers: this.getHeaders(),
1510
+ headers: yield this.getHeaders(),
1478
1511
  signal: this.signal
1479
1512
  });
1480
1513
  yield this.checkVersionMismatch(response);
@@ -2128,7 +2161,7 @@ function downloadClipAsFile(_0) {
2128
2161
  `Chunk ${i} returned HTTP ${response.status}`
2129
2162
  );
2130
2163
  }
2131
- const data = yield response.arrayBuffer();
2164
+ const data = new Uint8Array(yield response.arrayBuffer());
2132
2165
  parts.push(data);
2133
2166
  bytes += data.byteLength;
2134
2167
  (_a = options.onProgress) == null ? void 0 : _a.call(options, {
@@ -2137,7 +2170,8 @@ function downloadClipAsFile(_0) {
2137
2170
  bytes
2138
2171
  });
2139
2172
  }
2140
- const blob = new Blob(parts, { type: "video/mp4" });
2173
+ const finalBytes = yield maybeRemux(parts);
2174
+ const blob = new Blob([finalBytes], { type: "video/mp4" });
2141
2175
  if (filename === null) {
2142
2176
  return blob;
2143
2177
  }
@@ -2151,6 +2185,145 @@ function downloadClipAsFile(_0) {
2151
2185
  return blob;
2152
2186
  });
2153
2187
  }
2188
+ function maybeRemux(parts) {
2189
+ return __async(this, null, function* () {
2190
+ const input = concatUint8Arrays(parts);
2191
+ try {
2192
+ const MP4Box = yield loadMp4Box();
2193
+ return yield remuxFragmentedToFlat(input, MP4Box);
2194
+ } catch (error) {
2195
+ console.warn(
2196
+ "[Reactor] Clip remux failed, returning fragmented MP4 instead.",
2197
+ error
2198
+ );
2199
+ return input;
2200
+ }
2201
+ });
2202
+ }
2203
+ var __remuxInternals = {
2204
+ loadMp4Box: () => import("mp4box")
2205
+ };
2206
+ function loadMp4Box() {
2207
+ return __remuxInternals.loadMp4Box();
2208
+ }
2209
+ function remuxFragmentedToFlat(input, MP4Box) {
2210
+ return __async(this, null, function* () {
2211
+ return new Promise((resolve, reject) => {
2212
+ const inFile = MP4Box.createFile();
2213
+ const outFile = MP4Box.createFile();
2214
+ outFile.init({ brands: ["isom", "mp42", "avc1", "iso2"] });
2215
+ const inToOutTrack = /* @__PURE__ */ new Map();
2216
+ const trackBaselineDts = /* @__PURE__ */ new Map();
2217
+ let settled = false;
2218
+ const fail = (err) => {
2219
+ if (settled) return;
2220
+ settled = true;
2221
+ reject(err);
2222
+ };
2223
+ inFile.onError = (_module, message) => {
2224
+ fail(new Error(message));
2225
+ };
2226
+ inFile.onReady = (info) => {
2227
+ if (!info.tracks.length) {
2228
+ fail(new Error("no tracks in input"));
2229
+ return;
2230
+ }
2231
+ for (const track of info.tracks) {
2232
+ inFile.setExtractionOptions(track.id, null, { nbSamples: 1e3 });
2233
+ }
2234
+ inFile.start();
2235
+ };
2236
+ inFile.onSamples = (id, _user, samples) => {
2237
+ if (settled || samples.length === 0) return;
2238
+ let outId = inToOutTrack.get(id);
2239
+ let baseline = trackBaselineDts.get(id);
2240
+ if (outId === void 0) {
2241
+ const firstSample = samples[0];
2242
+ const sampleEntry = firstSample.description;
2243
+ const inputTrack = trackInfoById(inFile, id);
2244
+ outId = outFile.addTrack({
2245
+ type: sampleEntry.type,
2246
+ timescale: firstSample.timescale,
2247
+ width: inputTrack == null ? void 0 : inputTrack.track_width,
2248
+ height: inputTrack == null ? void 0 : inputTrack.track_height,
2249
+ language: inputTrack == null ? void 0 : inputTrack.language,
2250
+ hdlr: (inputTrack == null ? void 0 : inputTrack.video) ? "vide" : (inputTrack == null ? void 0 : inputTrack.audio) ? "soun" : void 0,
2251
+ // `boxes` is typed as `Box[]` but `description_boxes`
2252
+ // wants the narrower `BoxKind[]` union — at runtime they
2253
+ // are the same concrete instances, just typed loosely.
2254
+ description_boxes: sampleEntry.boxes
2255
+ });
2256
+ baseline = firstSample.dts;
2257
+ inToOutTrack.set(id, outId);
2258
+ trackBaselineDts.set(id, baseline);
2259
+ }
2260
+ const dtsShift = baseline;
2261
+ for (const sample of samples) {
2262
+ if (!sample.data) continue;
2263
+ outFile.addSample(outId, sample.data, {
2264
+ duration: sample.duration,
2265
+ dts: sample.dts - dtsShift,
2266
+ cts: sample.cts - dtsShift,
2267
+ is_sync: sample.is_sync
2268
+ });
2269
+ }
2270
+ };
2271
+ let buf;
2272
+ try {
2273
+ buf = MP4Box.MP4BoxBuffer.fromArrayBuffer(
2274
+ input.buffer.slice(
2275
+ input.byteOffset,
2276
+ input.byteOffset + input.byteLength
2277
+ ),
2278
+ 0
2279
+ );
2280
+ } catch (error) {
2281
+ fail(error);
2282
+ return;
2283
+ }
2284
+ try {
2285
+ inFile.appendBuffer(buf);
2286
+ inFile.flush();
2287
+ } catch (error) {
2288
+ fail(error);
2289
+ return;
2290
+ }
2291
+ if (settled) return;
2292
+ if (inToOutTrack.size === 0) {
2293
+ fail(new Error("no samples extracted from input"));
2294
+ return;
2295
+ }
2296
+ let output;
2297
+ try {
2298
+ const stream = outFile.getBuffer();
2299
+ output = new Uint8Array(
2300
+ stream.buffer.slice(0, stream.byteLength)
2301
+ );
2302
+ } catch (error) {
2303
+ fail(error);
2304
+ return;
2305
+ }
2306
+ settled = true;
2307
+ resolve(output);
2308
+ });
2309
+ });
2310
+ }
2311
+ function trackInfoById(file, id) {
2312
+ const info = file.getInfo();
2313
+ return info.tracks.find((t) => t.id === id);
2314
+ }
2315
+ function concatUint8Arrays(parts) {
2316
+ if (parts.length === 1) return parts[0];
2317
+ let total = 0;
2318
+ for (const p of parts) total += p.byteLength;
2319
+ const out = new Uint8Array(total);
2320
+ let offset = 0;
2321
+ for (const p of parts) {
2322
+ out.set(p, offset);
2323
+ offset += p.byteLength;
2324
+ }
2325
+ return out;
2326
+ }
2154
2327
  function resolveAgainst(target, base) {
2155
2328
  try {
2156
2329
  return new URL(target, base).toString();
@@ -2460,6 +2633,15 @@ var Reactor = class {
2460
2633
  getCoordinatorBaseUrl: () => this.coordinatorUrl
2461
2634
  });
2462
2635
  }
2636
+ /**
2637
+ * Returns the JWT resolver supplied to the most recent
2638
+ * {@link connect} call, or `undefined` if none was set (pre-connect
2639
+ * or local mode). Used by clip surfaces as a fallback when their
2640
+ * own `getJwt` prop is omitted.
2641
+ */
2642
+ getJwtResolver() {
2643
+ return this.jwtResolver;
2644
+ }
2463
2645
  on(event, handler) {
2464
2646
  if (!this.eventListeners.has(event)) {
2465
2647
  this.eventListeners.set(event, /* @__PURE__ */ new Set());
@@ -2722,7 +2904,10 @@ var Reactor = class {
2722
2904
  }
2723
2905
  /**
2724
2906
  * Connects to the coordinator, creates a session, then establishes
2725
- * the transport using server-declared capabilities.
2907
+ * the transport using server-declared capabilities. `jwtToken` may
2908
+ * be a static string or a {@link JwtSource} resolver; pass a
2909
+ * resolver when the token is short-lived so each Coordinator HTTP
2910
+ * hop sees a fresh value.
2726
2911
  */
2727
2912
  connect(jwtToken, options) {
2728
2913
  return __async(this, null, function* () {
@@ -2735,6 +2920,9 @@ var Reactor = class {
2735
2920
  }
2736
2921
  this.setStatus("connecting");
2737
2922
  this.connectStartTime = performance.now();
2923
+ if (!this.local && jwtToken !== void 0) {
2924
+ this.jwtResolver = normalizeJwtSource(jwtToken);
2925
+ }
2738
2926
  try {
2739
2927
  this.coordinatorClient = this.local ? new LocalCoordinatorClient(this.coordinatorUrl, this.model) : new CoordinatorClient({
2740
2928
  baseUrl: this.coordinatorUrl,
@@ -3179,12 +3367,27 @@ function ReactorProvider(_a) {
3179
3367
  var _b = _a, {
3180
3368
  children,
3181
3369
  connectOptions,
3182
- jwtToken
3370
+ jwtToken,
3371
+ getJwt
3183
3372
  } = _b, props = __objRest(_b, [
3184
3373
  "children",
3185
3374
  "connectOptions",
3186
- "jwtToken"
3375
+ "jwtToken",
3376
+ "getJwt"
3187
3377
  ]);
3378
+ const getJwtRef = (0, import_react3.useRef)(getJwt);
3379
+ (0, import_react3.useEffect)(() => {
3380
+ getJwtRef.current = getJwt;
3381
+ });
3382
+ const hasGetJwt = getJwt !== void 0;
3383
+ const stableGetJwt = (0, import_react3.useMemo)(() => {
3384
+ if (!hasGetJwt) return void 0;
3385
+ return () => __async(null, null, function* () {
3386
+ const r = getJwtRef.current;
3387
+ return r ? yield r() : "";
3388
+ });
3389
+ }, [hasGetJwt]);
3390
+ const jwtSource = stableGetJwt != null ? stableGetJwt : jwtToken;
3188
3391
  const storeRef = (0, import_react3.useRef)(void 0);
3189
3392
  const firstRender = (0, import_react3.useRef)(true);
3190
3393
  const [_storeVersion, setStoreVersion] = (0, import_react3.useState)(0);
@@ -3192,7 +3395,7 @@ function ReactorProvider(_a) {
3192
3395
  console.debug("[ReactorProvider] Creating new reactor store");
3193
3396
  storeRef.current = createReactorStore(
3194
3397
  initReactorStore(__spreadProps(__spreadValues({}, props), {
3195
- jwtToken
3398
+ jwtToken: jwtSource
3196
3399
  }))
3197
3400
  );
3198
3401
  console.debug("[ReactorProvider] Reactor store created successfully");
@@ -3217,11 +3420,11 @@ function ReactorProvider(_a) {
3217
3420
  if (firstRender.current) {
3218
3421
  firstRender.current = false;
3219
3422
  const current2 = storeRef.current;
3220
- if (autoConnect && current2.getState().status === "disconnected" && jwtToken) {
3423
+ if (autoConnect && current2.getState().status === "disconnected" && jwtSource) {
3221
3424
  console.debug(
3222
3425
  "[ReactorProvider] Starting autoconnect in first render..."
3223
3426
  );
3224
- current2.getState().connect(jwtToken, pollingOptions).then(() => {
3427
+ current2.getState().connect(jwtSource, pollingOptions).then(() => {
3225
3428
  console.debug(
3226
3429
  "[ReactorProvider] Autoconnect successful in first render"
3227
3430
  );
@@ -3254,7 +3457,7 @@ function ReactorProvider(_a) {
3254
3457
  apiUrl,
3255
3458
  modelName,
3256
3459
  local,
3257
- jwtToken
3460
+ jwtToken: jwtSource
3258
3461
  })
3259
3462
  );
3260
3463
  const current = storeRef.current;
@@ -3262,9 +3465,9 @@ function ReactorProvider(_a) {
3262
3465
  console.debug(
3263
3466
  "[ReactorProvider] Reactor store updated successfully, and increased version"
3264
3467
  );
3265
- if (autoConnect && current.getState().status === "disconnected" && jwtToken) {
3468
+ if (autoConnect && current.getState().status === "disconnected" && jwtSource) {
3266
3469
  console.debug("[ReactorProvider] Starting autoconnect...");
3267
- current.getState().connect(jwtToken, pollingOptions).then(() => {
3470
+ current.getState().connect(jwtSource, pollingOptions).then(() => {
3268
3471
  console.debug("[ReactorProvider] Autoconnect successful");
3269
3472
  }).catch((error) => {
3270
3473
  console.error("[ReactorProvider] Failed to autoconnect:", error);
@@ -3280,7 +3483,7 @@ function ReactorProvider(_a) {
3280
3483
  console.error("[ReactorProvider] Failed to disconnect:", error);
3281
3484
  });
3282
3485
  };
3283
- }, [apiUrl, modelName, autoConnect, local, jwtToken, maxAttempts]);
3486
+ }, [apiUrl, modelName, autoConnect, local, jwtSource, maxAttempts]);
3284
3487
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReactorContext.Provider, { value: storeRef.current, children });
3285
3488
  }
3286
3489
  function useReactorStore(selector) {
@@ -4202,13 +4405,16 @@ function ClipPlayer({
4202
4405
  }) {
4203
4406
  const videoRef = (0, import_react8.useRef)(null);
4204
4407
  const [phase, setPhase] = (0, import_react8.useState)({ kind: "waiting" });
4408
+ const store = (0, import_react8.useContext)(ReactorContext);
4205
4409
  const getJwtRef = (0, import_react8.useRef)(getJwt);
4206
4410
  const autoPlayRef = (0, import_react8.useRef)(autoPlay);
4207
4411
  const slackMsRef = (0, import_react8.useRef)(slackMs);
4412
+ const storeRef = (0, import_react8.useRef)(store);
4208
4413
  (0, import_react8.useEffect)(() => {
4209
4414
  getJwtRef.current = getJwt;
4210
4415
  autoPlayRef.current = autoPlay;
4211
4416
  slackMsRef.current = slackMs;
4417
+ storeRef.current = store;
4212
4418
  });
4213
4419
  (0, import_react8.useEffect)(() => {
4214
4420
  const video = videoRef.current;
@@ -4270,9 +4476,13 @@ function ClipPlayer({
4270
4476
  hlsInstance = hls;
4271
4477
  });
4272
4478
  const setup = () => __async(null, null, function* () {
4479
+ var _a;
4273
4480
  try {
4274
4481
  setPhase({ kind: "waiting" });
4275
- const jwt = getJwtRef.current ? yield getJwtRef.current() : void 0;
4482
+ const explicit = getJwtRef.current;
4483
+ const fallback = (_a = storeRef.current) == null ? void 0 : _a.getState().internal.reactor.getJwtResolver();
4484
+ const resolver = explicit != null ? explicit : fallback;
4485
+ const jwt = resolver ? yield resolver() : void 0;
4276
4486
  if (cancelled) return;
4277
4487
  const body = yield fetchPlaylist(clip.playlistUrl, {
4278
4488
  predictedReadyAtMs: clip.predictedReadyAtMs,
@@ -4379,6 +4589,7 @@ var import_react9 = require("react");
4379
4589
  function useClipDownload(clip, options = {}) {
4380
4590
  var _a;
4381
4591
  const [state, setState] = (0, import_react9.useState)({ kind: "idle" });
4592
+ const store = (0, import_react9.useContext)(ReactorContext);
4382
4593
  const clipRef = (0, import_react9.useRef)(clip);
4383
4594
  const filenameRef = (0, import_react9.useRef)(
4384
4595
  (_a = options.filename) != null ? _a : "reactor-clip.mp4"
@@ -4395,7 +4606,10 @@ function useClipDownload(clip, options = {}) {
4395
4606
  inFlightRef.current = true;
4396
4607
  setState({ kind: "downloading", fetched: 0, total: 0 });
4397
4608
  try {
4398
- const jwt = getJwtRef.current ? yield getJwtRef.current() : void 0;
4609
+ const explicit = getJwtRef.current;
4610
+ const fallback = store == null ? void 0 : store.getState().internal.reactor.getJwtResolver();
4611
+ const resolver = explicit != null ? explicit : fallback;
4612
+ const jwt = resolver ? yield resolver() : void 0;
4399
4613
  const blob = yield downloadClipAsFile(
4400
4614
  clipRef.current,
4401
4615
  filenameRef.current,
@@ -4413,7 +4627,7 @@ function useClipDownload(clip, options = {}) {
4413
4627
  } finally {
4414
4628
  inFlightRef.current = false;
4415
4629
  }
4416
- }), []);
4630
+ }), [store]);
4417
4631
  const reset = (0, import_react9.useCallback)(() => setState({ kind: "idle" }), []);
4418
4632
  return { state, download, reset };
4419
4633
  }
@@ -4490,6 +4704,7 @@ function defaultLabel(state) {
4490
4704
  downloadClipAsFile,
4491
4705
  fetchPlaylist,
4492
4706
  isAbortError,
4707
+ normalizeJwtSource,
4493
4708
  parsePlaylist,
4494
4709
  rewriteUrlHost,
4495
4710
  useClipDownload,