@reactor-team/js-sdk 2.8.1 → 2.9.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
@@ -50,6 +50,18 @@ var __async = (__this, __arguments, generator) => {
50
50
  });
51
51
  };
52
52
 
53
+ // src/core/FileRef.ts
54
+ var FileRef = class {
55
+ constructor(uploadId, name, mimeType, size) {
56
+ this.uploadId = uploadId;
57
+ this.name = name;
58
+ this.mimeType = mimeType;
59
+ this.size = size;
60
+ /** @internal Marker so sendCommand can detect FileRef values. */
61
+ this.__isFileRef = true;
62
+ }
63
+ };
64
+
53
65
  // src/types.ts
54
66
  var ConflictError = class extends Error {
55
67
  constructor(message) {
@@ -71,7 +83,7 @@ import { z } from "zod";
71
83
  // package.json
72
84
  var package_default = {
73
85
  name: "@reactor-team/js-sdk",
74
- version: "2.8.1",
86
+ version: "2.9.1",
75
87
  description: "Reactor JavaScript frontend SDK",
76
88
  main: "dist/index.js",
77
89
  module: "dist/index.mjs",
@@ -110,7 +122,7 @@ var package_default = {
110
122
  license: "MIT",
111
123
  repository: {
112
124
  type: "git",
113
- url: "https://github.com/reactor-team/js-sdk"
125
+ url: "https://github.com/reactor-team/js-sdk.git"
114
126
  },
115
127
  packageManager: "pnpm@10.12.1",
116
128
  devDependencies: {
@@ -199,6 +211,16 @@ var SessionResponseSchema = CreateSessionResponseSchema.extend({
199
211
  var TerminateSessionRequestSchema = z.object({
200
212
  reason: z.string().optional()
201
213
  });
214
+ var CreateUploadRequestSchema = z.object({
215
+ name: z.string(),
216
+ size: z.number().int().positive(),
217
+ mime_type: z.string()
218
+ });
219
+ var CreateUploadResponseSchema = z.object({
220
+ presigned_id: z.string(),
221
+ presigned_url: z.string(),
222
+ path: z.string()
223
+ });
202
224
  var IceServerCredentialsSchema = z.object({
203
225
  username: z.string(),
204
226
  password: z.string()
@@ -535,6 +557,40 @@ var CoordinatorClient = class {
535
557
  );
536
558
  });
537
559
  }
560
+ /**
561
+ * Allocates an upload slot for a file.
562
+ * Returns a presigned PUT URL the caller can use to upload the file
563
+ * directly to the object store (production) or local runtime (local dev).
564
+ */
565
+ createUpload(sessionId, request) {
566
+ return __async(this, null, function* () {
567
+ console.debug("[CoordinatorClient] Creating upload slot...", {
568
+ sessionId,
569
+ name: request.name,
570
+ size: request.size
571
+ });
572
+ const response = yield fetch(
573
+ `${this.baseUrl}/sessions/${sessionId}/uploads`,
574
+ {
575
+ method: "POST",
576
+ headers: __spreadProps(__spreadValues({}, this.getHeaders()), {
577
+ "Content-Type": "application/json"
578
+ }),
579
+ body: JSON.stringify(request),
580
+ signal: this.signal
581
+ }
582
+ );
583
+ yield this.checkVersionMismatch(response);
584
+ if (!response.ok) {
585
+ const errorText = yield response.text();
586
+ throw new Error(
587
+ `Failed to create upload slot: ${response.status} ${errorText}`
588
+ );
589
+ }
590
+ const data = yield response.json();
591
+ return CreateUploadResponseSchema.parse(data);
592
+ });
593
+ }
538
594
  getSessionId() {
539
595
  return this.currentSessionId;
540
596
  }
@@ -703,12 +759,15 @@ function waitForIceGathering(pc, timeoutMs = 5e3) {
703
759
  }, timeoutMs);
704
760
  });
705
761
  }
706
- function sendMessage(channel, command, data, scope = "application", maxBytes = DEFAULT_MAX_MESSAGE_BYTES) {
762
+ function sendMessage(channel, command, data, scope = "application", maxBytes = DEFAULT_MAX_MESSAGE_BYTES, uploads) {
707
763
  if (channel.readyState !== "open") {
708
764
  throw new Error(`Data channel not open: ${channel.readyState}`);
709
765
  }
710
766
  const jsonData = typeof data === "string" ? JSON.parse(data) : data;
711
767
  const inner = { type: command, data: jsonData };
768
+ if (uploads && Object.keys(uploads).length > 0) {
769
+ inner.uploads = uploads;
770
+ }
712
771
  const payload = { scope, data: inner };
713
772
  const serialized = JSON.stringify(payload);
714
773
  const byteLength = new TextEncoder().encode(serialized).byteLength;
@@ -973,45 +1032,20 @@ var WebRTCTransportClient = class {
973
1032
  // ─────────────────────────────────────────────────────────────────────────
974
1033
  // Connection Lifecycle
975
1034
  // ─────────────────────────────────────────────────────────────────────────
976
- connect(tracks) {
1035
+ warmup() {
977
1036
  return __async(this, null, function* () {
978
- this.setStatus("connecting");
979
- this.resetTransportTimings();
980
- const iceServers = yield this.fetchIceServers();
981
- this.peerConnection = createPeerConnection({ iceServers });
982
- this.setupPeerConnectionHandlers();
983
- this.dataChannel = createDataChannel(this.peerConnection);
984
- this.setupDataChannelHandlers();
985
- this.transceiverMap.clear();
986
- for (const track of tracks) {
987
- const transceiver = this.peerConnection.addTransceiver(track.kind, {
988
- direction: track.direction
1037
+ if (!this.cachedIceServers) {
1038
+ this.cachedIceServers = this.fetchIceServers();
1039
+ this.cachedIceServers.catch(() => {
989
1040
  });
990
- this.transceiverMap.set(track.name, {
991
- name: track.name,
992
- kind: track.kind,
993
- direction: track.direction,
994
- transceiver
995
- });
996
- console.debug(
997
- `[WebRTCTransport] Transceiver added: "${track.name}" (${track.kind}, ${track.direction})`
998
- );
999
1041
  }
1000
- const sdpOffer = yield createOffer(this.peerConnection);
1001
- const trackMapping = this.buildTrackMapping(tracks);
1002
- yield this.sendSdpOffer(sdpOffer, trackMapping, "POST");
1003
- const answerResponse = yield this.pollSdpAnswer();
1004
- this.iceStartTime = performance.now();
1005
- yield setRemoteDescription(
1006
- this.peerConnection,
1007
- answerResponse.sdp_answer
1008
- );
1009
- console.debug("[WebRTCTransport] Remote description set");
1042
+ yield this.cachedIceServers;
1010
1043
  });
1011
1044
  }
1012
- reconnect(tracks) {
1045
+ prepare(tracks) {
1013
1046
  return __async(this, null, function* () {
1014
1047
  this.setStatus("connecting");
1048
+ this.resetTransportTimings();
1015
1049
  this.stopPing();
1016
1050
  this.stopStatsPolling();
1017
1051
  if (this.dataChannel) {
@@ -1024,8 +1058,8 @@ var WebRTCTransportClient = class {
1024
1058
  }
1025
1059
  this.peerConnected = false;
1026
1060
  this.dataChannelOpen = false;
1027
- this.resetTransportTimings();
1028
- const iceServers = yield this.fetchIceServers();
1061
+ const iceServers = this.cachedIceServers ? yield this.cachedIceServers : yield this.fetchIceServers();
1062
+ this.cachedIceServers = void 0;
1029
1063
  this.peerConnection = createPeerConnection({ iceServers });
1030
1064
  this.setupPeerConnectionHandlers();
1031
1065
  this.dataChannel = createDataChannel(this.peerConnection);
@@ -1041,17 +1075,35 @@ var WebRTCTransportClient = class {
1041
1075
  direction: track.direction,
1042
1076
  transceiver
1043
1077
  });
1078
+ console.debug(
1079
+ `[WebRTCTransport] Transceiver added: "${track.name}" (${track.kind}, ${track.direction})`
1080
+ );
1081
+ }
1082
+ this.pendingSdpOffer = yield createOffer(this.peerConnection);
1083
+ this.pendingTrackMapping = this.buildTrackMapping(tracks);
1084
+ console.debug("[WebRTCTransport] SDP offer prepared");
1085
+ });
1086
+ }
1087
+ connect(reconnect = false) {
1088
+ return __async(this, null, function* () {
1089
+ if (!this.pendingSdpOffer || !this.pendingTrackMapping) {
1090
+ throw new Error(
1091
+ "[WebRTCTransport] No prepared connection. Call prepare() first."
1092
+ );
1044
1093
  }
1045
- const sdpOffer = yield createOffer(this.peerConnection);
1046
- const trackMapping = this.buildTrackMapping(tracks);
1047
- yield this.sendSdpOffer(sdpOffer, trackMapping, "PUT");
1094
+ const method = reconnect ? "PUT" : "POST";
1095
+ const sdpOffer = this.pendingSdpOffer;
1096
+ const trackMapping = this.pendingTrackMapping;
1097
+ this.pendingSdpOffer = void 0;
1098
+ this.pendingTrackMapping = void 0;
1099
+ yield this.sendSdpOffer(sdpOffer, trackMapping, method);
1048
1100
  const answerResponse = yield this.pollSdpAnswer();
1049
1101
  this.iceStartTime = performance.now();
1050
1102
  yield setRemoteDescription(
1051
1103
  this.peerConnection,
1052
1104
  answerResponse.sdp_answer
1053
1105
  );
1054
- console.debug("[WebRTCTransport] Remote description set (reconnect)");
1106
+ console.debug("[WebRTCTransport] Remote description set");
1055
1107
  });
1056
1108
  }
1057
1109
  disconnect() {
@@ -1117,7 +1169,7 @@ var WebRTCTransportClient = class {
1117
1169
  var _a, _b, _c;
1118
1170
  return (_c = (_b = (_a = this.peerConnection) == null ? void 0 : _a.sctp) == null ? void 0 : _b.maxMessageSize) != null ? _c : void 0;
1119
1171
  }
1120
- sendCommand(command, data, scope = "application") {
1172
+ sendCommand(command, data, scope = "application", uploads) {
1121
1173
  if (!this.dataChannel) {
1122
1174
  throw new Error("[WebRTCTransport] Data channel not available");
1123
1175
  }
@@ -1127,7 +1179,8 @@ var WebRTCTransportClient = class {
1127
1179
  command,
1128
1180
  data,
1129
1181
  scope,
1130
- this.maxMessageBytes
1182
+ this.maxMessageBytes,
1183
+ uploads
1131
1184
  );
1132
1185
  } catch (error) {
1133
1186
  console.warn("[WebRTCTransport] Failed to send message:", error);
@@ -1369,10 +1422,16 @@ var WebRTCTransportClient = class {
1369
1422
  import { z as z2 } from "zod";
1370
1423
  var LOCAL_COORDINATOR_URL = "http://localhost:8080";
1371
1424
  var DEFAULT_BASE_URL = "https://api.reactor.inc";
1425
+ var TrackHintSchema = z2.object({
1426
+ name: z2.string(),
1427
+ kind: z2.enum(["video", "audio"]),
1428
+ direction: z2.enum(["recvonly", "sendonly"])
1429
+ });
1372
1430
  var OptionsSchema = z2.object({
1373
1431
  apiUrl: z2.string().default(DEFAULT_BASE_URL),
1374
1432
  modelName: z2.string(),
1375
- local: z2.boolean().default(false)
1433
+ local: z2.boolean().default(false),
1434
+ modelTracks: z2.array(TrackHintSchema).optional()
1376
1435
  });
1377
1436
  var Reactor = class {
1378
1437
  constructor(options) {
@@ -1386,6 +1445,9 @@ var Reactor = class {
1386
1445
  if (this.local && options.apiUrl === void 0) {
1387
1446
  this.coordinatorUrl = LOCAL_COORDINATOR_URL;
1388
1447
  }
1448
+ if (validatedOptions.modelTracks) {
1449
+ this.presetTracks = validatedOptions.modelTracks;
1450
+ }
1389
1451
  }
1390
1452
  on(event, handler) {
1391
1453
  if (!this.eventListeners.has(event)) {
@@ -1403,6 +1465,10 @@ var Reactor = class {
1403
1465
  }
1404
1466
  /**
1405
1467
  * Sends a command to the model via the data channel.
1468
+ *
1469
+ * When any value in `data` is a {@link FileRef}, it is automatically
1470
+ * extracted and serialized into a separate `uploads` section on the
1471
+ * wire, keyed by the parameter name. Scalar values remain in `data`.
1406
1472
  */
1407
1473
  sendCommand(command, data, scope = "application") {
1408
1474
  return __async(this, null, function* () {
@@ -1413,7 +1479,28 @@ var Reactor = class {
1413
1479
  return;
1414
1480
  }
1415
1481
  try {
1416
- (_a = this.transportClient) == null ? void 0 : _a.sendCommand(command, data, scope);
1482
+ let uploads;
1483
+ if (data && typeof data === "object" && !Array.isArray(data)) {
1484
+ const scalarData = {};
1485
+ const extractedUploads = {};
1486
+ for (const [key, value] of Object.entries(data)) {
1487
+ if (value instanceof FileRef) {
1488
+ extractedUploads[key] = {
1489
+ upload_id: value.uploadId,
1490
+ name: value.name,
1491
+ mime_type: value.mimeType,
1492
+ size: value.size
1493
+ };
1494
+ } else {
1495
+ scalarData[key] = value;
1496
+ }
1497
+ }
1498
+ if (Object.keys(extractedUploads).length > 0) {
1499
+ uploads = extractedUploads;
1500
+ data = scalarData;
1501
+ }
1502
+ }
1503
+ (_a = this.transportClient) == null ? void 0 : _a.sendCommand(command, data, scope, uploads);
1417
1504
  } catch (error) {
1418
1505
  console.error("[Reactor] Failed to send message:", error);
1419
1506
  this.createError(
@@ -1425,6 +1512,82 @@ var Reactor = class {
1425
1512
  }
1426
1513
  });
1427
1514
  }
1515
+ /**
1516
+ * Uploads a file to the session's object store and returns a {@link FileRef}.
1517
+ *
1518
+ * Flow:
1519
+ * 1. POST /sessions/{id}/uploads → allocate presigned PUT URL
1520
+ * 2. PUT file bytes to the presigned URL
1521
+ * 3. Send `fileUploaded` notification on the runtime data channel
1522
+ * (fires `@file_uploaded` on the model if registered)
1523
+ * 4. Return a `FileRef` to pass into {@link sendCommand}
1524
+ *
1525
+ * In local mode, the presigned URL returned by the runtime is rewritten
1526
+ * to use the SDK-configured base URL (scheme + host), so port-forwarded
1527
+ * setups work correctly (REA-1573).
1528
+ */
1529
+ uploadFile(file, options) {
1530
+ return __async(this, null, function* () {
1531
+ var _a;
1532
+ if (this.status !== "ready") {
1533
+ throw new Error(
1534
+ `Cannot upload file, status is "${this.status}". Must be "ready".`
1535
+ );
1536
+ }
1537
+ if (!this.coordinatorClient || !this.sessionId) {
1538
+ throw new Error("No active session. Call connect() first.");
1539
+ }
1540
+ const name = (_a = options == null ? void 0 : options.name) != null ? _a : file instanceof File ? file.name : "upload";
1541
+ const mimeType = file.type || "application/octet-stream";
1542
+ const size = file.size;
1543
+ if (size <= 0) {
1544
+ throw new Error("File is empty");
1545
+ }
1546
+ const slot = yield this.coordinatorClient.createUpload(this.sessionId, {
1547
+ name,
1548
+ size,
1549
+ mime_type: mimeType
1550
+ });
1551
+ let presignedUrl = slot.presigned_url;
1552
+ if (this.local) {
1553
+ const target = new URL(this.coordinatorUrl);
1554
+ const parsed = new URL(presignedUrl);
1555
+ parsed.protocol = target.protocol;
1556
+ parsed.hostname = target.hostname;
1557
+ parsed.port = target.port;
1558
+ presignedUrl = parsed.toString();
1559
+ }
1560
+ const putResponse = yield fetch(presignedUrl, {
1561
+ method: "PUT",
1562
+ body: file,
1563
+ headers: {
1564
+ "Content-Length": String(size)
1565
+ }
1566
+ });
1567
+ if (!putResponse.ok) {
1568
+ throw new Error(
1569
+ `File upload failed: ${putResponse.status} ${putResponse.statusText}`
1570
+ );
1571
+ }
1572
+ yield this.sendCommand(
1573
+ "fileUploaded",
1574
+ {
1575
+ upload_id: slot.presigned_id,
1576
+ name,
1577
+ mime_type: mimeType,
1578
+ size
1579
+ },
1580
+ "runtime"
1581
+ );
1582
+ console.debug("[Reactor] File uploaded:", {
1583
+ uploadId: slot.presigned_id,
1584
+ name,
1585
+ mimeType,
1586
+ size
1587
+ });
1588
+ return new FileRef(slot.presigned_id, name, mimeType, size);
1589
+ });
1590
+ }
1428
1591
  /**
1429
1592
  * Publishes a MediaStreamTrack to a named sendonly track.
1430
1593
  * The transceiver is already set up from capabilities — this just
@@ -1496,7 +1659,8 @@ var Reactor = class {
1496
1659
  });
1497
1660
  this.setupTransportHandlers();
1498
1661
  }
1499
- yield this.transportClient.reconnect(this.tracks);
1662
+ yield this.transportClient.prepare(this.tracks);
1663
+ yield this.transportClient.connect(true);
1500
1664
  } catch (error) {
1501
1665
  if (isAbortError(error)) return;
1502
1666
  console.error("[Reactor] Failed to reconnect:", error);
@@ -1542,34 +1706,49 @@ var Reactor = class {
1542
1706
  initialResponse.state
1543
1707
  );
1544
1708
  this.setStatus("waiting");
1545
- const tPoll = performance.now();
1546
- const sessionResponse = yield this.coordinatorClient.pollSessionReady();
1547
- const sessionPollingMs = performance.now() - tPoll;
1548
- this.sessionResponse = sessionResponse;
1549
- this.capabilities = sessionResponse.capabilities;
1550
- this.tracks = sessionResponse.capabilities.tracks;
1551
- this.emit("capabilitiesReceived", this.capabilities);
1552
- console.debug(
1553
- "[Reactor] Session ready, transport:",
1554
- sessionResponse.selected_transport.protocol,
1555
- "tracks:",
1556
- this.tracks.length
1557
- );
1558
- const protocol = sessionResponse.selected_transport.protocol;
1559
- if (protocol !== "webrtc") {
1560
- throw new Error(`Unsupported transport protocol: ${protocol}`);
1561
- }
1562
1709
  this.transportClient = new WebRTCTransportClient({
1563
1710
  baseUrl: this.coordinatorUrl,
1564
- sessionId: sessionResponse.session_id,
1711
+ sessionId: initialResponse.session_id,
1565
1712
  jwtToken: this.local ? "local" : jwtToken,
1566
1713
  webrtcVersion: REACTOR_WEBRTC_VERSION,
1567
1714
  maxPollAttempts: options == null ? void 0 : options.maxAttempts
1568
1715
  });
1569
1716
  this.setupTransportHandlers();
1570
- const tTransport = performance.now();
1571
- yield this.transportClient.connect(this.tracks);
1572
- const transportConnectingMs = performance.now() - tTransport;
1717
+ let sessionPollingMs;
1718
+ let transportConnectingMs;
1719
+ if (this.presetTracks) {
1720
+ const tParallel = performance.now();
1721
+ const [sessionResponse] = yield Promise.all([
1722
+ this.coordinatorClient.pollSessionReady(),
1723
+ this.transportClient.prepare(this.presetTracks)
1724
+ ]);
1725
+ sessionPollingMs = performance.now() - tParallel;
1726
+ this.sessionResponse = sessionResponse;
1727
+ this.capabilities = sessionResponse.capabilities;
1728
+ this.tracks = this.presetTracks;
1729
+ this.emit("capabilitiesReceived", this.capabilities);
1730
+ const tConnect = performance.now();
1731
+ yield this.transportClient.connect();
1732
+ transportConnectingMs = performance.now() - tConnect;
1733
+ } else {
1734
+ this.transportClient.warmup();
1735
+ const tPoll = performance.now();
1736
+ const sessionResponse = yield this.coordinatorClient.pollSessionReady();
1737
+ sessionPollingMs = performance.now() - tPoll;
1738
+ this.sessionResponse = sessionResponse;
1739
+ this.capabilities = sessionResponse.capabilities;
1740
+ this.tracks = sessionResponse.capabilities.tracks;
1741
+ this.emit("capabilitiesReceived", this.capabilities);
1742
+ const protocol = sessionResponse.selected_transport.protocol;
1743
+ if (protocol !== "webrtc") {
1744
+ throw new Error(`Unsupported transport protocol: ${protocol}`);
1745
+ }
1746
+ const tTransport = performance.now();
1747
+ yield this.transportClient.prepare(this.tracks);
1748
+ yield this.transportClient.connect();
1749
+ transportConnectingMs = performance.now() - tTransport;
1750
+ }
1751
+ console.debug("[Reactor] Session ready, tracks:", this.tracks.length);
1573
1752
  this.connectionTimings = {
1574
1753
  sessionCreationMs: sessionCreationMs + sessionPollingMs,
1575
1754
  transportConnectingMs,
@@ -1931,6 +2110,17 @@ var createReactorStore = (initProps, publicState = defaultInitState) => {
1931
2110
  console.error("[ReactorStore] Failed to reconnect:", error);
1932
2111
  throw error;
1933
2112
  }
2113
+ }),
2114
+ uploadFile: (file, options) => __async(null, null, function* () {
2115
+ console.debug("[ReactorStore] Uploading file");
2116
+ try {
2117
+ const result = yield get().internal.reactor.uploadFile(file, options);
2118
+ console.debug("[ReactorStore] File uploaded successfully", result);
2119
+ return result;
2120
+ } catch (error) {
2121
+ console.error("[ReactorStore] Failed to upload file:", error);
2122
+ throw error;
2123
+ }
1934
2124
  })
1935
2125
  });
1936
2126
  });
@@ -2218,18 +2408,24 @@ function ReactorView({
2218
2408
  }
2219
2409
 
2220
2410
  // src/react/ReactorController.tsx
2221
- import React, { useState as useState3, useCallback } from "react";
2411
+ import React, { useState as useState3, useCallback, useRef as useRef4 } from "react";
2222
2412
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
2413
+ function isFileParam(ps) {
2414
+ return ps.type === "file" || ps.type === "object" && ps.format === "file-reference";
2415
+ }
2223
2416
  function ReactorController({
2224
2417
  className,
2225
2418
  style
2226
2419
  }) {
2227
- const { sendCommand, status } = useReactor((state) => ({
2420
+ const { sendCommand, uploadFile, status } = useReactor((state) => ({
2228
2421
  sendCommand: state.sendCommand,
2422
+ uploadFile: state.uploadFile,
2229
2423
  status: state.status
2230
2424
  }));
2231
2425
  const [commands, setCommands] = useState3({});
2232
2426
  const [formValues, setFormValues] = useState3({});
2427
+ const formRef = useRef4(formValues);
2428
+ formRef.current = formValues;
2233
2429
  const [expandedCommands, setExpandedCommands] = useState3({});
2234
2430
  React.useEffect(() => {
2235
2431
  if (status === "disconnected") {
@@ -2276,15 +2472,17 @@ function ReactorController({
2276
2472
  initialExpanded[commandName] = false;
2277
2473
  Object.entries(commandSchema.schema).forEach(
2278
2474
  ([paramName, paramSchema]) => {
2279
- var _a2, _b;
2280
- if (paramSchema.type === "number") {
2475
+ var _a2;
2476
+ if (isFileParam(paramSchema)) {
2477
+ initialValues[commandName][paramName] = null;
2478
+ } else if (paramSchema.default !== void 0) {
2479
+ initialValues[commandName][paramName] = paramSchema.default;
2480
+ } else if (paramSchema.type === "number" || paramSchema.type === "integer") {
2281
2481
  initialValues[commandName][paramName] = (_a2 = paramSchema.minimum) != null ? _a2 : 0;
2282
2482
  } else if (paramSchema.type === "string") {
2283
2483
  initialValues[commandName][paramName] = "";
2284
2484
  } else if (paramSchema.type === "boolean") {
2285
2485
  initialValues[commandName][paramName] = false;
2286
- } else if (paramSchema.type === "integer") {
2287
- initialValues[commandName][paramName] = (_b = paramSchema.minimum) != null ? _b : 0;
2288
2486
  }
2289
2487
  }
2290
2488
  );
@@ -2311,12 +2509,16 @@ function ReactorController({
2311
2509
  const handleCommandSubmit = useCallback(
2312
2510
  (commandName) => __async(null, null, function* () {
2313
2511
  const commandSchema = commands[commandName];
2314
- const formData = formValues[commandName] || {};
2512
+ const formData = formRef.current[commandName] || {};
2315
2513
  const data = {};
2316
2514
  Object.keys(commandSchema.schema).forEach((paramName) => {
2317
- var _a, _b;
2515
+ var _a;
2318
2516
  const paramSchema = commandSchema.schema[paramName];
2319
2517
  let value = formData[paramName];
2518
+ if (value instanceof FileRef) {
2519
+ data[paramName] = value;
2520
+ return;
2521
+ }
2320
2522
  if (paramSchema.type === "number" && typeof value === "string") {
2321
2523
  value = parseFloat(value) || 0;
2322
2524
  } else if (paramSchema.type === "integer" && typeof value === "string") {
@@ -2327,10 +2529,8 @@ function ReactorController({
2327
2529
  if (value !== void 0 && value !== "" && value !== null) {
2328
2530
  data[paramName] = value;
2329
2531
  } else if (paramSchema.required) {
2330
- if (paramSchema.type === "number") {
2532
+ if (paramSchema.type === "number" || paramSchema.type === "integer") {
2331
2533
  data[paramName] = (_a = paramSchema.minimum) != null ? _a : 0;
2332
- } else if (paramSchema.type === "integer") {
2333
- data[paramName] = (_b = paramSchema.minimum) != null ? _b : 0;
2334
2534
  } else if (paramSchema.type === "string") {
2335
2535
  data[paramName] = "";
2336
2536
  } else if (paramSchema.type === "boolean") {
@@ -2338,14 +2538,28 @@ function ReactorController({
2338
2538
  }
2339
2539
  }
2340
2540
  });
2341
- console.log(`Executing command: ${commandName}`, data);
2342
2541
  yield sendCommand(commandName, data);
2343
2542
  }),
2344
- [formValues, sendCommand, commands]
2543
+ [sendCommand, commands]
2345
2544
  );
2346
2545
  const renderInput = (commandName, paramName, paramSchema) => {
2347
2546
  var _a, _b;
2348
2547
  const value = (_b = (_a = formValues[commandName]) == null ? void 0 : _a[paramName]) != null ? _b : "";
2548
+ if (isFileParam(paramSchema)) {
2549
+ return /* @__PURE__ */ jsx3(
2550
+ FileParamInput,
2551
+ {
2552
+ commandName,
2553
+ paramName,
2554
+ description: paramSchema.description,
2555
+ value,
2556
+ onChange: handleInputChange,
2557
+ disabled: status !== "ready",
2558
+ uploadFile
2559
+ },
2560
+ `${commandName}-${paramName}`
2561
+ );
2562
+ }
2349
2563
  if (paramSchema.type === "number" || paramSchema.type === "integer") {
2350
2564
  const isInteger = paramSchema.type === "integer";
2351
2565
  const step = isInteger ? 1 : 0.1;
@@ -2534,10 +2748,11 @@ function ReactorController({
2534
2748
  const renderCommand = (commandName, commandSchema) => {
2535
2749
  const hasParams = Object.keys(commandSchema.schema).length > 0;
2536
2750
  const isExpanded = expandedCommands[commandName];
2537
- const hasSliderInputs = Object.values(commandSchema.schema).some(
2538
- (paramSchema) => (paramSchema.type === "number" || paramSchema.type === "integer") && typeof paramSchema.minimum === "number" && typeof paramSchema.maximum === "number"
2751
+ const params = Object.values(commandSchema.schema);
2752
+ const allSliders = params.length > 0 && params.every(
2753
+ (ps) => (ps.type === "number" || ps.type === "integer") && typeof ps.minimum === "number" && typeof ps.maximum === "number"
2539
2754
  );
2540
- const showExecuteButton = !hasSliderInputs;
2755
+ const showExecuteButton = !allSliders;
2541
2756
  return /* @__PURE__ */ jsxs2(
2542
2757
  "div",
2543
2758
  {
@@ -2675,9 +2890,92 @@ function ReactorController({
2675
2890
  Object.entries(commands).map(([commandName, commandSchema]) => /* @__PURE__ */ jsx3("div", { children: renderCommand(commandName, commandSchema) }, commandName))
2676
2891
  ] }) }) });
2677
2892
  }
2893
+ function FileParamInput({
2894
+ commandName,
2895
+ paramName,
2896
+ description,
2897
+ value,
2898
+ onChange,
2899
+ disabled,
2900
+ uploadFile
2901
+ }) {
2902
+ const inputRef = useRef4(null);
2903
+ const [uploading, setUploading] = useState3(false);
2904
+ const fileRef = value instanceof FileRef ? value : null;
2905
+ const handleFile = (e) => __async(null, null, function* () {
2906
+ var _a;
2907
+ const file = (_a = e.target.files) == null ? void 0 : _a[0];
2908
+ if (!file) return;
2909
+ e.target.value = "";
2910
+ setUploading(true);
2911
+ try {
2912
+ const ref = yield uploadFile(file);
2913
+ onChange(commandName, paramName, ref);
2914
+ } catch (err) {
2915
+ console.error("[FileParamInput] Upload failed:", err);
2916
+ } finally {
2917
+ setUploading(false);
2918
+ }
2919
+ });
2920
+ return /* @__PURE__ */ jsxs2("div", { style: { marginBottom: "8px" }, children: [
2921
+ /* @__PURE__ */ jsxs2("label", { style: { fontSize: "12px", color: "#666", display: "block" }, children: [
2922
+ paramName,
2923
+ /* @__PURE__ */ jsx3("span", { style: { color: "#888", fontSize: "11px" }, children: " (file)" }),
2924
+ description && ` - ${description}`
2925
+ ] }),
2926
+ /* @__PURE__ */ jsxs2(
2927
+ "div",
2928
+ {
2929
+ style: {
2930
+ display: "flex",
2931
+ alignItems: "center",
2932
+ gap: "8px",
2933
+ marginTop: "4px"
2934
+ },
2935
+ children: [
2936
+ /* @__PURE__ */ jsx3(
2937
+ "input",
2938
+ {
2939
+ ref: inputRef,
2940
+ type: "file",
2941
+ accept: "image/*",
2942
+ onChange: handleFile,
2943
+ style: { display: "none" }
2944
+ }
2945
+ ),
2946
+ /* @__PURE__ */ jsx3(
2947
+ "button",
2948
+ {
2949
+ disabled: disabled || uploading,
2950
+ onClick: () => {
2951
+ var _a;
2952
+ return (_a = inputRef.current) == null ? void 0 : _a.click();
2953
+ },
2954
+ style: {
2955
+ padding: "4px 12px",
2956
+ fontSize: "12px",
2957
+ backgroundColor: "#007bff",
2958
+ color: "white",
2959
+ border: "none",
2960
+ borderRadius: "4px",
2961
+ cursor: disabled || uploading ? "default" : "pointer",
2962
+ opacity: disabled || uploading ? 0.5 : 1
2963
+ },
2964
+ children: uploading ? "Uploading\u2026" : fileRef ? "Change" : "Choose File"
2965
+ }
2966
+ ),
2967
+ fileRef && /* @__PURE__ */ jsxs2("span", { style: { fontSize: "11px", color: "#28a745" }, children: [
2968
+ "\\u2713 ",
2969
+ fileRef.name
2970
+ ] })
2971
+ ]
2972
+ }
2973
+ )
2974
+ ] });
2975
+ }
2678
2976
 
2679
2977
  // src/react/WebcamStream.tsx
2680
- import { useEffect as useEffect4, useRef as useRef4, useState as useState4 } from "react";
2978
+ import { useEffect as useEffect4, useRef as useRef5, useState as useState4 } from "react";
2681
2979
  import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
2682
2980
  function WebcamStream({
2683
2981
  track,
@@ -2699,7 +2997,7 @@ function WebcamStream({
2699
2997
  unpublish: state.unpublish,
2700
2998
  reactor: state.internal.reactor
2701
2999
  }));
2702
- const videoRef = useRef4(null);
3000
+ const videoRef = useRef5(null);
2703
3001
  const startWebcam = () => __async(null, null, function* () {
2704
3002
  console.debug("[WebcamPublisher] Starting webcam");
2705
3003
  try {
@@ -2873,6 +3171,7 @@ export {
2873
3171
  AbortError,
2874
3172
  ConflictError,
2875
3173
  DEFAULT_BASE_URL,
3174
+ FileRef,
2876
3175
  Reactor,
2877
3176
  ReactorController,
2878
3177
  ReactorProvider,