@reactor-team/js-sdk 2.7.0 → 2.8.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/dist/index.js CHANGED
@@ -86,9 +86,7 @@ __export(index_exports, {
86
86
  ReactorController: () => ReactorController,
87
87
  ReactorProvider: () => ReactorProvider,
88
88
  ReactorView: () => ReactorView,
89
- WebRTCTransportClient: () => WebRTCTransportClient,
90
89
  WebcamStream: () => WebcamStream,
91
- fetchInsecureToken: () => fetchInsecureToken,
92
90
  isAbortError: () => isAbortError,
93
91
  useReactor: () => useReactor,
94
92
  useReactorInternalMessage: () => useReactorInternalMessage,
@@ -119,7 +117,7 @@ var import_zod = require("zod");
119
117
  // package.json
120
118
  var package_default = {
121
119
  name: "@reactor-team/js-sdk",
122
- version: "2.7.0",
120
+ version: "2.8.0",
123
121
  description: "Reactor JavaScript frontend SDK",
124
122
  main: "dist/index.js",
125
123
  module: "dist/index.mjs",
@@ -220,13 +218,6 @@ var CreateSessionRequestSchema = import_zod.z.object({
220
218
  supported_transports: import_zod.z.array(TransportDeclarationSchema),
221
219
  extra_args: import_zod.z.record(import_zod.z.string(), import_zod.z.any()).optional()
222
220
  });
223
- var InitialSessionResponseSchema = import_zod.z.object({
224
- session_id: import_zod.z.string(),
225
- model: import_zod.z.object({ name: import_zod.z.string() }),
226
- server_info: import_zod.z.object({ server_version: import_zod.z.string() }).optional(),
227
- state: import_zod.z.string(),
228
- cluster: import_zod.z.string().optional()
229
- });
230
221
  var CommandCapabilitySchema = import_zod.z.object({
231
222
  name: import_zod.z.string(),
232
223
  description: import_zod.z.string(),
@@ -238,23 +229,18 @@ var CapabilitiesSchema = import_zod.z.object({
238
229
  commands: import_zod.z.array(CommandCapabilitySchema).optional(),
239
230
  emission_fps: import_zod.z.number().nullable().optional()
240
231
  });
241
- var SessionResponseSchema = import_zod.z.object({
232
+ var SessionInfoResponseSchema = import_zod.z.object({
242
233
  session_id: import_zod.z.string(),
243
- server_info: import_zod.z.object({ server_version: import_zod.z.string() }).optional(),
244
- selected_transport: TransportDeclarationSchema.optional(),
245
- model: import_zod.z.object({ name: import_zod.z.string(), version: import_zod.z.string().optional() }),
246
- capabilities: CapabilitiesSchema.optional(),
247
234
  state: import_zod.z.string(),
248
- cluster: import_zod.z.string().optional()
235
+ cluster: import_zod.z.string()
249
236
  });
250
- var CreateSessionResponseSchema = SessionResponseSchema.extend({
251
- selected_transport: TransportDeclarationSchema,
252
- capabilities: CapabilitiesSchema
237
+ var CreateSessionResponseSchema = SessionInfoResponseSchema.extend({
238
+ model: import_zod.z.object({ name: import_zod.z.string(), version: import_zod.z.string().optional() }),
239
+ server_info: import_zod.z.object({ server_version: import_zod.z.string() })
253
240
  });
254
- var SessionInfoResponseSchema = import_zod.z.object({
255
- session_id: import_zod.z.string(),
256
- cluster: import_zod.z.string().optional(),
257
- state: import_zod.z.string()
241
+ var SessionResponseSchema = CreateSessionResponseSchema.extend({
242
+ selected_transport: TransportDeclarationSchema.optional(),
243
+ capabilities: CapabilitiesSchema.optional()
258
244
  });
259
245
  var TerminateSessionRequestSchema = import_zod.z.object({
260
246
  reason: import_zod.z.string().optional()
@@ -389,7 +375,7 @@ var CoordinatorClient = class {
389
375
  );
390
376
  }
391
377
  const data = yield response.json();
392
- const parsed = InitialSessionResponseSchema.parse(data);
378
+ const parsed = CreateSessionResponseSchema.parse(data);
393
379
  this.currentSessionId = parsed.session_id;
394
380
  console.debug(
395
381
  "[CoordinatorClient] Session created:",
@@ -453,11 +439,10 @@ var CoordinatorClient = class {
453
439
  );
454
440
  }
455
441
  if (partial.capabilities && partial.selected_transport) {
456
- const full = CreateSessionResponseSchema.parse(data);
457
442
  console.debug(
458
- `[CoordinatorClient] Session ready after ${attempt} poll(s), transport: ${full.selected_transport.protocol}, tracks: ${full.capabilities.tracks.length}`
443
+ `[CoordinatorClient] Session ready after ${attempt} poll(s), transport: ${partial.selected_transport.protocol}, tracks: ${partial.capabilities.tracks.length}`
459
444
  );
460
- return full;
445
+ return partial;
461
446
  }
462
447
  console.debug(
463
448
  `[CoordinatorClient] Session poll ${attempt}/${maxAttempts} \u2014 state: ${partial.state}, waiting ${backoffMs}ms...`
@@ -471,8 +456,9 @@ var CoordinatorClient = class {
471
456
  });
472
457
  }
473
458
  /**
474
- * Gets full session details from the coordinator.
475
- * Returns the same shape as the creation response but with updated state.
459
+ * Gets session details from the coordinator.
460
+ * Fields like selected_transport and capabilities are only present
461
+ * after the Runtime accepts the session.
476
462
  */
477
463
  getSession() {
478
464
  return __async(this, null, function* () {
@@ -493,7 +479,7 @@ var CoordinatorClient = class {
493
479
  throw new Error(`Failed to get session: ${response.status} ${errorText}`);
494
480
  }
495
481
  const data = yield response.json();
496
- return CreateSessionResponseSchema.parse(data);
482
+ return SessionResponseSchema.parse(data);
497
483
  });
498
484
  }
499
485
  /**
@@ -623,6 +609,7 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
623
609
  */
624
610
  createSession(extraArgs) {
625
611
  return __async(this, null, function* () {
612
+ var _a, _b;
626
613
  console.debug("[LocalCoordinatorClient] Starting session...");
627
614
  const response = yield fetch(`${this.baseUrl}/start_session`, {
628
615
  method: "POST",
@@ -639,17 +626,18 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
639
626
  );
640
627
  }
641
628
  const data = yield response.json();
642
- this.cachedSessionResponse = CreateSessionResponseSchema.parse(data);
643
- this.currentSessionId = this.cachedSessionResponse.session_id;
629
+ const session = SessionResponseSchema.parse(data);
630
+ this.cachedSessionResponse = session;
631
+ this.currentSessionId = session.session_id;
644
632
  console.debug(
645
633
  "[LocalCoordinatorClient] Session started:",
646
634
  this.currentSessionId,
647
635
  "transport:",
648
- this.cachedSessionResponse.selected_transport.protocol,
636
+ (_a = session.selected_transport) == null ? void 0 : _a.protocol,
649
637
  "tracks:",
650
- this.cachedSessionResponse.capabilities.tracks.length
638
+ (_b = session.capabilities) == null ? void 0 : _b.tracks.length
651
639
  );
652
- return InitialSessionResponseSchema.parse(data);
640
+ return CreateSessionResponseSchema.parse(data);
653
641
  });
654
642
  }
655
643
  /**
@@ -1574,7 +1562,7 @@ var Reactor = class {
1574
1562
  */
1575
1563
  connect(jwtToken, options) {
1576
1564
  return __async(this, null, function* () {
1577
- var _a;
1565
+ var _a, _b;
1578
1566
  console.debug("[Reactor] Connecting, status:", this.status);
1579
1567
  if (jwtToken == void 0 && !this.local) {
1580
1568
  throw new Error("No authentication provided and not in local mode");
@@ -1622,7 +1610,7 @@ var Reactor = class {
1622
1610
  baseUrl: this.coordinatorUrl,
1623
1611
  sessionId: sessionResponse.session_id,
1624
1612
  jwtToken: this.local ? "local" : jwtToken,
1625
- webrtcVersion: (_a = sessionResponse.selected_transport.version) != null ? _a : REACTOR_WEBRTC_VERSION,
1613
+ webrtcVersion: (_b = (_a = sessionResponse.selected_transport) == null ? void 0 : _a.version) != null ? _b : REACTOR_WEBRTC_VERSION,
1626
1614
  maxPollAttempts: options == null ? void 0 : options.maxAttempts
1627
1615
  });
1628
1616
  this.setupTransportHandlers();
@@ -2928,27 +2916,6 @@ function WebcamStream({
2928
2916
  }
2929
2917
  );
2930
2918
  }
2931
-
2932
- // src/utils/tokens.ts
2933
- function fetchInsecureToken(_0) {
2934
- return __async(this, arguments, function* (apiKey, apiUrl = DEFAULT_BASE_URL) {
2935
- console.warn(
2936
- "[Reactor] \u26A0\uFE0F SECURITY WARNING: fetchInsecureToken() exposes your API key in client-side code. This should ONLY be used for local development or testing. In production, fetch tokens from your server instead."
2937
- );
2938
- const response = yield fetch(`${apiUrl}/tokens`, {
2939
- method: "GET",
2940
- headers: {
2941
- "Reactor-API-Key": apiKey
2942
- }
2943
- });
2944
- if (!response.ok) {
2945
- const error = yield response.text();
2946
- throw new Error(`Failed to create token: ${response.status} ${error}`);
2947
- }
2948
- const { jwt } = yield response.json();
2949
- return jwt;
2950
- });
2951
- }
2952
2919
  // Annotate the CommonJS export names for ESM import in node:
2953
2920
  0 && (module.exports = {
2954
2921
  AbortError,
@@ -2958,9 +2925,7 @@ function fetchInsecureToken(_0) {
2958
2925
  ReactorController,
2959
2926
  ReactorProvider,
2960
2927
  ReactorView,
2961
- WebRTCTransportClient,
2962
2928
  WebcamStream,
2963
- fetchInsecureToken,
2964
2929
  isAbortError,
2965
2930
  useReactor,
2966
2931
  useReactorInternalMessage,