@reactor-team/js-sdk 2.7.0 → 2.8.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.mjs CHANGED
@@ -71,7 +71,7 @@ import { z } from "zod";
71
71
  // package.json
72
72
  var package_default = {
73
73
  name: "@reactor-team/js-sdk",
74
- version: "2.7.0",
74
+ version: "2.8.1",
75
75
  description: "Reactor JavaScript frontend SDK",
76
76
  main: "dist/index.js",
77
77
  module: "dist/index.mjs",
@@ -172,13 +172,6 @@ var CreateSessionRequestSchema = z.object({
172
172
  supported_transports: z.array(TransportDeclarationSchema),
173
173
  extra_args: z.record(z.string(), z.any()).optional()
174
174
  });
175
- var InitialSessionResponseSchema = z.object({
176
- session_id: z.string(),
177
- model: z.object({ name: z.string() }),
178
- server_info: z.object({ server_version: z.string() }).optional(),
179
- state: z.string(),
180
- cluster: z.string().optional()
181
- });
182
175
  var CommandCapabilitySchema = z.object({
183
176
  name: z.string(),
184
177
  description: z.string(),
@@ -190,23 +183,18 @@ var CapabilitiesSchema = z.object({
190
183
  commands: z.array(CommandCapabilitySchema).optional(),
191
184
  emission_fps: z.number().nullable().optional()
192
185
  });
193
- var SessionResponseSchema = z.object({
186
+ var SessionInfoResponseSchema = z.object({
194
187
  session_id: z.string(),
195
- server_info: z.object({ server_version: z.string() }).optional(),
196
- selected_transport: TransportDeclarationSchema.optional(),
197
- model: z.object({ name: z.string(), version: z.string().optional() }),
198
- capabilities: CapabilitiesSchema.optional(),
199
188
  state: z.string(),
200
- cluster: z.string().optional()
189
+ cluster: z.string()
201
190
  });
202
- var CreateSessionResponseSchema = SessionResponseSchema.extend({
203
- selected_transport: TransportDeclarationSchema,
204
- capabilities: CapabilitiesSchema
191
+ var CreateSessionResponseSchema = SessionInfoResponseSchema.extend({
192
+ model: z.object({ name: z.string(), version: z.string().optional() }),
193
+ server_info: z.object({ server_version: z.string() })
205
194
  });
206
- var SessionInfoResponseSchema = z.object({
207
- session_id: z.string(),
208
- cluster: z.string().optional(),
209
- state: z.string()
195
+ var SessionResponseSchema = CreateSessionResponseSchema.extend({
196
+ selected_transport: TransportDeclarationSchema.optional(),
197
+ capabilities: CapabilitiesSchema.optional()
210
198
  });
211
199
  var TerminateSessionRequestSchema = z.object({
212
200
  reason: z.string().optional()
@@ -341,7 +329,7 @@ var CoordinatorClient = class {
341
329
  );
342
330
  }
343
331
  const data = yield response.json();
344
- const parsed = InitialSessionResponseSchema.parse(data);
332
+ const parsed = CreateSessionResponseSchema.parse(data);
345
333
  this.currentSessionId = parsed.session_id;
346
334
  console.debug(
347
335
  "[CoordinatorClient] Session created:",
@@ -405,11 +393,10 @@ var CoordinatorClient = class {
405
393
  );
406
394
  }
407
395
  if (partial.capabilities && partial.selected_transport) {
408
- const full = CreateSessionResponseSchema.parse(data);
409
396
  console.debug(
410
- `[CoordinatorClient] Session ready after ${attempt} poll(s), transport: ${full.selected_transport.protocol}, tracks: ${full.capabilities.tracks.length}`
397
+ `[CoordinatorClient] Session ready after ${attempt} poll(s), transport: ${partial.selected_transport.protocol}, tracks: ${partial.capabilities.tracks.length}`
411
398
  );
412
- return full;
399
+ return partial;
413
400
  }
414
401
  console.debug(
415
402
  `[CoordinatorClient] Session poll ${attempt}/${maxAttempts} \u2014 state: ${partial.state}, waiting ${backoffMs}ms...`
@@ -423,8 +410,9 @@ var CoordinatorClient = class {
423
410
  });
424
411
  }
425
412
  /**
426
- * Gets full session details from the coordinator.
427
- * Returns the same shape as the creation response but with updated state.
413
+ * Gets session details from the coordinator.
414
+ * Fields like selected_transport and capabilities are only present
415
+ * after the Runtime accepts the session.
428
416
  */
429
417
  getSession() {
430
418
  return __async(this, null, function* () {
@@ -445,7 +433,7 @@ var CoordinatorClient = class {
445
433
  throw new Error(`Failed to get session: ${response.status} ${errorText}`);
446
434
  }
447
435
  const data = yield response.json();
448
- return CreateSessionResponseSchema.parse(data);
436
+ return SessionResponseSchema.parse(data);
449
437
  });
450
438
  }
451
439
  /**
@@ -575,6 +563,7 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
575
563
  */
576
564
  createSession(extraArgs) {
577
565
  return __async(this, null, function* () {
566
+ var _a, _b;
578
567
  console.debug("[LocalCoordinatorClient] Starting session...");
579
568
  const response = yield fetch(`${this.baseUrl}/start_session`, {
580
569
  method: "POST",
@@ -591,17 +580,18 @@ var LocalCoordinatorClient = class extends CoordinatorClient {
591
580
  );
592
581
  }
593
582
  const data = yield response.json();
594
- this.cachedSessionResponse = CreateSessionResponseSchema.parse(data);
595
- this.currentSessionId = this.cachedSessionResponse.session_id;
583
+ const session = SessionResponseSchema.parse(data);
584
+ this.cachedSessionResponse = session;
585
+ this.currentSessionId = session.session_id;
596
586
  console.debug(
597
587
  "[LocalCoordinatorClient] Session started:",
598
588
  this.currentSessionId,
599
589
  "transport:",
600
- this.cachedSessionResponse.selected_transport.protocol,
590
+ (_a = session.selected_transport) == null ? void 0 : _a.protocol,
601
591
  "tracks:",
602
- this.cachedSessionResponse.capabilities.tracks.length
592
+ (_b = session.capabilities) == null ? void 0 : _b.tracks.length
603
593
  );
604
- return InitialSessionResponseSchema.parse(data);
594
+ return CreateSessionResponseSchema.parse(data);
605
595
  });
606
596
  }
607
597
  /**
@@ -1526,7 +1516,6 @@ var Reactor = class {
1526
1516
  */
1527
1517
  connect(jwtToken, options) {
1528
1518
  return __async(this, null, function* () {
1529
- var _a;
1530
1519
  console.debug("[Reactor] Connecting, status:", this.status);
1531
1520
  if (jwtToken == void 0 && !this.local) {
1532
1521
  throw new Error("No authentication provided and not in local mode");
@@ -1574,7 +1563,7 @@ var Reactor = class {
1574
1563
  baseUrl: this.coordinatorUrl,
1575
1564
  sessionId: sessionResponse.session_id,
1576
1565
  jwtToken: this.local ? "local" : jwtToken,
1577
- webrtcVersion: (_a = sessionResponse.selected_transport.version) != null ? _a : REACTOR_WEBRTC_VERSION,
1566
+ webrtcVersion: REACTOR_WEBRTC_VERSION,
1578
1567
  maxPollAttempts: options == null ? void 0 : options.maxAttempts
1579
1568
  });
1580
1569
  this.setupTransportHandlers();
@@ -2880,27 +2869,6 @@ function WebcamStream({
2880
2869
  }
2881
2870
  );
2882
2871
  }
2883
-
2884
- // src/utils/tokens.ts
2885
- function fetchInsecureToken(_0) {
2886
- return __async(this, arguments, function* (apiKey, apiUrl = DEFAULT_BASE_URL) {
2887
- console.warn(
2888
- "[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."
2889
- );
2890
- const response = yield fetch(`${apiUrl}/tokens`, {
2891
- method: "GET",
2892
- headers: {
2893
- "Reactor-API-Key": apiKey
2894
- }
2895
- });
2896
- if (!response.ok) {
2897
- const error = yield response.text();
2898
- throw new Error(`Failed to create token: ${response.status} ${error}`);
2899
- }
2900
- const { jwt } = yield response.json();
2901
- return jwt;
2902
- });
2903
- }
2904
2872
  export {
2905
2873
  AbortError,
2906
2874
  ConflictError,
@@ -2909,9 +2877,7 @@ export {
2909
2877
  ReactorController,
2910
2878
  ReactorProvider,
2911
2879
  ReactorView,
2912
- WebRTCTransportClient,
2913
2880
  WebcamStream,
2914
- fetchInsecureToken,
2915
2881
  isAbortError,
2916
2882
  useReactor,
2917
2883
  useReactorInternalMessage,