@reactor-team/js-sdk 2.9.0 → 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.d.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +216 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +219 -82
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -177,6 +177,17 @@ declare const OptionsSchema: z.ZodObject<{
|
|
|
177
177
|
apiUrl: z.ZodDefault<z.ZodString>;
|
|
178
178
|
modelName: z.ZodString;
|
|
179
179
|
local: z.ZodDefault<z.ZodBoolean>;
|
|
180
|
+
modelTracks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
181
|
+
name: z.ZodString;
|
|
182
|
+
kind: z.ZodEnum<{
|
|
183
|
+
video: "video";
|
|
184
|
+
audio: "audio";
|
|
185
|
+
}>;
|
|
186
|
+
direction: z.ZodEnum<{
|
|
187
|
+
recvonly: "recvonly";
|
|
188
|
+
sendonly: "sendonly";
|
|
189
|
+
}>;
|
|
190
|
+
}, z.core.$strip>>>;
|
|
180
191
|
}, z.core.$strip>;
|
|
181
192
|
type Options = z.input<typeof OptionsSchema>;
|
|
182
193
|
|
|
@@ -195,6 +206,7 @@ declare class Reactor {
|
|
|
195
206
|
private connectionTimings?;
|
|
196
207
|
private capabilities?;
|
|
197
208
|
private tracks;
|
|
209
|
+
private presetTracks?;
|
|
198
210
|
private sessionResponse?;
|
|
199
211
|
constructor(options: Options);
|
|
200
212
|
private eventListeners;
|
|
@@ -219,7 +231,9 @@ declare class Reactor {
|
|
|
219
231
|
* (fires `@file_uploaded` on the model if registered)
|
|
220
232
|
* 4. Return a `FileRef` to pass into {@link sendCommand}
|
|
221
233
|
*
|
|
222
|
-
*
|
|
234
|
+
* In local mode, the presigned URL returned by the runtime is rewritten
|
|
235
|
+
* to use the SDK-configured base URL (scheme + host), so port-forwarded
|
|
236
|
+
* setups work correctly (REA-1573).
|
|
223
237
|
*/
|
|
224
238
|
uploadFile(file: File | Blob, options?: {
|
|
225
239
|
name?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -177,6 +177,17 @@ declare const OptionsSchema: z.ZodObject<{
|
|
|
177
177
|
apiUrl: z.ZodDefault<z.ZodString>;
|
|
178
178
|
modelName: z.ZodString;
|
|
179
179
|
local: z.ZodDefault<z.ZodBoolean>;
|
|
180
|
+
modelTracks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
181
|
+
name: z.ZodString;
|
|
182
|
+
kind: z.ZodEnum<{
|
|
183
|
+
video: "video";
|
|
184
|
+
audio: "audio";
|
|
185
|
+
}>;
|
|
186
|
+
direction: z.ZodEnum<{
|
|
187
|
+
recvonly: "recvonly";
|
|
188
|
+
sendonly: "sendonly";
|
|
189
|
+
}>;
|
|
190
|
+
}, z.core.$strip>>>;
|
|
180
191
|
}, z.core.$strip>;
|
|
181
192
|
type Options = z.input<typeof OptionsSchema>;
|
|
182
193
|
|
|
@@ -195,6 +206,7 @@ declare class Reactor {
|
|
|
195
206
|
private connectionTimings?;
|
|
196
207
|
private capabilities?;
|
|
197
208
|
private tracks;
|
|
209
|
+
private presetTracks?;
|
|
198
210
|
private sessionResponse?;
|
|
199
211
|
constructor(options: Options);
|
|
200
212
|
private eventListeners;
|
|
@@ -219,7 +231,9 @@ declare class Reactor {
|
|
|
219
231
|
* (fires `@file_uploaded` on the model if registered)
|
|
220
232
|
* 4. Return a `FileRef` to pass into {@link sendCommand}
|
|
221
233
|
*
|
|
222
|
-
*
|
|
234
|
+
* In local mode, the presigned URL returned by the runtime is rewritten
|
|
235
|
+
* to use the SDK-configured base URL (scheme + host), so port-forwarded
|
|
236
|
+
* setups work correctly (REA-1573).
|
|
223
237
|
*/
|
|
224
238
|
uploadFile(file: File | Blob, options?: {
|
|
225
239
|
name?: string;
|
package/dist/index.js
CHANGED
|
@@ -130,7 +130,7 @@ var import_zod = require("zod");
|
|
|
130
130
|
// package.json
|
|
131
131
|
var package_default = {
|
|
132
132
|
name: "@reactor-team/js-sdk",
|
|
133
|
-
version: "2.9.
|
|
133
|
+
version: "2.9.1",
|
|
134
134
|
description: "Reactor JavaScript frontend SDK",
|
|
135
135
|
main: "dist/index.js",
|
|
136
136
|
module: "dist/index.mjs",
|
|
@@ -1079,45 +1079,20 @@ var WebRTCTransportClient = class {
|
|
|
1079
1079
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1080
1080
|
// Connection Lifecycle
|
|
1081
1081
|
// ─────────────────────────────────────────────────────────────────────────
|
|
1082
|
-
|
|
1082
|
+
warmup() {
|
|
1083
1083
|
return __async(this, null, function* () {
|
|
1084
|
-
this.
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
this.peerConnection = createPeerConnection({ iceServers });
|
|
1088
|
-
this.setupPeerConnectionHandlers();
|
|
1089
|
-
this.dataChannel = createDataChannel(this.peerConnection);
|
|
1090
|
-
this.setupDataChannelHandlers();
|
|
1091
|
-
this.transceiverMap.clear();
|
|
1092
|
-
for (const track of tracks) {
|
|
1093
|
-
const transceiver = this.peerConnection.addTransceiver(track.kind, {
|
|
1094
|
-
direction: track.direction
|
|
1084
|
+
if (!this.cachedIceServers) {
|
|
1085
|
+
this.cachedIceServers = this.fetchIceServers();
|
|
1086
|
+
this.cachedIceServers.catch(() => {
|
|
1095
1087
|
});
|
|
1096
|
-
this.transceiverMap.set(track.name, {
|
|
1097
|
-
name: track.name,
|
|
1098
|
-
kind: track.kind,
|
|
1099
|
-
direction: track.direction,
|
|
1100
|
-
transceiver
|
|
1101
|
-
});
|
|
1102
|
-
console.debug(
|
|
1103
|
-
`[WebRTCTransport] Transceiver added: "${track.name}" (${track.kind}, ${track.direction})`
|
|
1104
|
-
);
|
|
1105
1088
|
}
|
|
1106
|
-
|
|
1107
|
-
const trackMapping = this.buildTrackMapping(tracks);
|
|
1108
|
-
yield this.sendSdpOffer(sdpOffer, trackMapping, "POST");
|
|
1109
|
-
const answerResponse = yield this.pollSdpAnswer();
|
|
1110
|
-
this.iceStartTime = performance.now();
|
|
1111
|
-
yield setRemoteDescription(
|
|
1112
|
-
this.peerConnection,
|
|
1113
|
-
answerResponse.sdp_answer
|
|
1114
|
-
);
|
|
1115
|
-
console.debug("[WebRTCTransport] Remote description set");
|
|
1089
|
+
yield this.cachedIceServers;
|
|
1116
1090
|
});
|
|
1117
1091
|
}
|
|
1118
|
-
|
|
1092
|
+
prepare(tracks) {
|
|
1119
1093
|
return __async(this, null, function* () {
|
|
1120
1094
|
this.setStatus("connecting");
|
|
1095
|
+
this.resetTransportTimings();
|
|
1121
1096
|
this.stopPing();
|
|
1122
1097
|
this.stopStatsPolling();
|
|
1123
1098
|
if (this.dataChannel) {
|
|
@@ -1130,8 +1105,8 @@ var WebRTCTransportClient = class {
|
|
|
1130
1105
|
}
|
|
1131
1106
|
this.peerConnected = false;
|
|
1132
1107
|
this.dataChannelOpen = false;
|
|
1133
|
-
this.
|
|
1134
|
-
|
|
1108
|
+
const iceServers = this.cachedIceServers ? yield this.cachedIceServers : yield this.fetchIceServers();
|
|
1109
|
+
this.cachedIceServers = void 0;
|
|
1135
1110
|
this.peerConnection = createPeerConnection({ iceServers });
|
|
1136
1111
|
this.setupPeerConnectionHandlers();
|
|
1137
1112
|
this.dataChannel = createDataChannel(this.peerConnection);
|
|
@@ -1147,17 +1122,35 @@ var WebRTCTransportClient = class {
|
|
|
1147
1122
|
direction: track.direction,
|
|
1148
1123
|
transceiver
|
|
1149
1124
|
});
|
|
1125
|
+
console.debug(
|
|
1126
|
+
`[WebRTCTransport] Transceiver added: "${track.name}" (${track.kind}, ${track.direction})`
|
|
1127
|
+
);
|
|
1150
1128
|
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1129
|
+
this.pendingSdpOffer = yield createOffer(this.peerConnection);
|
|
1130
|
+
this.pendingTrackMapping = this.buildTrackMapping(tracks);
|
|
1131
|
+
console.debug("[WebRTCTransport] SDP offer prepared");
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
connect(reconnect = false) {
|
|
1135
|
+
return __async(this, null, function* () {
|
|
1136
|
+
if (!this.pendingSdpOffer || !this.pendingTrackMapping) {
|
|
1137
|
+
throw new Error(
|
|
1138
|
+
"[WebRTCTransport] No prepared connection. Call prepare() first."
|
|
1139
|
+
);
|
|
1140
|
+
}
|
|
1141
|
+
const method = reconnect ? "PUT" : "POST";
|
|
1142
|
+
const sdpOffer = this.pendingSdpOffer;
|
|
1143
|
+
const trackMapping = this.pendingTrackMapping;
|
|
1144
|
+
this.pendingSdpOffer = void 0;
|
|
1145
|
+
this.pendingTrackMapping = void 0;
|
|
1146
|
+
yield this.sendSdpOffer(sdpOffer, trackMapping, method);
|
|
1154
1147
|
const answerResponse = yield this.pollSdpAnswer();
|
|
1155
1148
|
this.iceStartTime = performance.now();
|
|
1156
1149
|
yield setRemoteDescription(
|
|
1157
1150
|
this.peerConnection,
|
|
1158
1151
|
answerResponse.sdp_answer
|
|
1159
1152
|
);
|
|
1160
|
-
console.debug("[WebRTCTransport] Remote description set
|
|
1153
|
+
console.debug("[WebRTCTransport] Remote description set");
|
|
1161
1154
|
});
|
|
1162
1155
|
}
|
|
1163
1156
|
disconnect() {
|
|
@@ -1476,10 +1469,16 @@ var WebRTCTransportClient = class {
|
|
|
1476
1469
|
var import_zod2 = require("zod");
|
|
1477
1470
|
var LOCAL_COORDINATOR_URL = "http://localhost:8080";
|
|
1478
1471
|
var DEFAULT_BASE_URL = "https://api.reactor.inc";
|
|
1472
|
+
var TrackHintSchema = import_zod2.z.object({
|
|
1473
|
+
name: import_zod2.z.string(),
|
|
1474
|
+
kind: import_zod2.z.enum(["video", "audio"]),
|
|
1475
|
+
direction: import_zod2.z.enum(["recvonly", "sendonly"])
|
|
1476
|
+
});
|
|
1479
1477
|
var OptionsSchema = import_zod2.z.object({
|
|
1480
1478
|
apiUrl: import_zod2.z.string().default(DEFAULT_BASE_URL),
|
|
1481
1479
|
modelName: import_zod2.z.string(),
|
|
1482
|
-
local: import_zod2.z.boolean().default(false)
|
|
1480
|
+
local: import_zod2.z.boolean().default(false),
|
|
1481
|
+
modelTracks: import_zod2.z.array(TrackHintSchema).optional()
|
|
1483
1482
|
});
|
|
1484
1483
|
var Reactor = class {
|
|
1485
1484
|
constructor(options) {
|
|
@@ -1493,6 +1492,9 @@ var Reactor = class {
|
|
|
1493
1492
|
if (this.local && options.apiUrl === void 0) {
|
|
1494
1493
|
this.coordinatorUrl = LOCAL_COORDINATOR_URL;
|
|
1495
1494
|
}
|
|
1495
|
+
if (validatedOptions.modelTracks) {
|
|
1496
|
+
this.presetTracks = validatedOptions.modelTracks;
|
|
1497
|
+
}
|
|
1496
1498
|
}
|
|
1497
1499
|
on(event, handler) {
|
|
1498
1500
|
if (!this.eventListeners.has(event)) {
|
|
@@ -1567,7 +1569,9 @@ var Reactor = class {
|
|
|
1567
1569
|
* (fires `@file_uploaded` on the model if registered)
|
|
1568
1570
|
* 4. Return a `FileRef` to pass into {@link sendCommand}
|
|
1569
1571
|
*
|
|
1570
|
-
*
|
|
1572
|
+
* In local mode, the presigned URL returned by the runtime is rewritten
|
|
1573
|
+
* to use the SDK-configured base URL (scheme + host), so port-forwarded
|
|
1574
|
+
* setups work correctly (REA-1573).
|
|
1571
1575
|
*/
|
|
1572
1576
|
uploadFile(file, options) {
|
|
1573
1577
|
return __async(this, null, function* () {
|
|
@@ -1591,7 +1595,16 @@ var Reactor = class {
|
|
|
1591
1595
|
size,
|
|
1592
1596
|
mime_type: mimeType
|
|
1593
1597
|
});
|
|
1594
|
-
|
|
1598
|
+
let presignedUrl = slot.presigned_url;
|
|
1599
|
+
if (this.local) {
|
|
1600
|
+
const target = new URL(this.coordinatorUrl);
|
|
1601
|
+
const parsed = new URL(presignedUrl);
|
|
1602
|
+
parsed.protocol = target.protocol;
|
|
1603
|
+
parsed.hostname = target.hostname;
|
|
1604
|
+
parsed.port = target.port;
|
|
1605
|
+
presignedUrl = parsed.toString();
|
|
1606
|
+
}
|
|
1607
|
+
const putResponse = yield fetch(presignedUrl, {
|
|
1595
1608
|
method: "PUT",
|
|
1596
1609
|
body: file,
|
|
1597
1610
|
headers: {
|
|
@@ -1693,7 +1706,8 @@ var Reactor = class {
|
|
|
1693
1706
|
});
|
|
1694
1707
|
this.setupTransportHandlers();
|
|
1695
1708
|
}
|
|
1696
|
-
yield this.transportClient.
|
|
1709
|
+
yield this.transportClient.prepare(this.tracks);
|
|
1710
|
+
yield this.transportClient.connect(true);
|
|
1697
1711
|
} catch (error) {
|
|
1698
1712
|
if (isAbortError(error)) return;
|
|
1699
1713
|
console.error("[Reactor] Failed to reconnect:", error);
|
|
@@ -1739,34 +1753,49 @@ var Reactor = class {
|
|
|
1739
1753
|
initialResponse.state
|
|
1740
1754
|
);
|
|
1741
1755
|
this.setStatus("waiting");
|
|
1742
|
-
const tPoll = performance.now();
|
|
1743
|
-
const sessionResponse = yield this.coordinatorClient.pollSessionReady();
|
|
1744
|
-
const sessionPollingMs = performance.now() - tPoll;
|
|
1745
|
-
this.sessionResponse = sessionResponse;
|
|
1746
|
-
this.capabilities = sessionResponse.capabilities;
|
|
1747
|
-
this.tracks = sessionResponse.capabilities.tracks;
|
|
1748
|
-
this.emit("capabilitiesReceived", this.capabilities);
|
|
1749
|
-
console.debug(
|
|
1750
|
-
"[Reactor] Session ready, transport:",
|
|
1751
|
-
sessionResponse.selected_transport.protocol,
|
|
1752
|
-
"tracks:",
|
|
1753
|
-
this.tracks.length
|
|
1754
|
-
);
|
|
1755
|
-
const protocol = sessionResponse.selected_transport.protocol;
|
|
1756
|
-
if (protocol !== "webrtc") {
|
|
1757
|
-
throw new Error(`Unsupported transport protocol: ${protocol}`);
|
|
1758
|
-
}
|
|
1759
1756
|
this.transportClient = new WebRTCTransportClient({
|
|
1760
1757
|
baseUrl: this.coordinatorUrl,
|
|
1761
|
-
sessionId:
|
|
1758
|
+
sessionId: initialResponse.session_id,
|
|
1762
1759
|
jwtToken: this.local ? "local" : jwtToken,
|
|
1763
1760
|
webrtcVersion: REACTOR_WEBRTC_VERSION,
|
|
1764
1761
|
maxPollAttempts: options == null ? void 0 : options.maxAttempts
|
|
1765
1762
|
});
|
|
1766
1763
|
this.setupTransportHandlers();
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1764
|
+
let sessionPollingMs;
|
|
1765
|
+
let transportConnectingMs;
|
|
1766
|
+
if (this.presetTracks) {
|
|
1767
|
+
const tParallel = performance.now();
|
|
1768
|
+
const [sessionResponse] = yield Promise.all([
|
|
1769
|
+
this.coordinatorClient.pollSessionReady(),
|
|
1770
|
+
this.transportClient.prepare(this.presetTracks)
|
|
1771
|
+
]);
|
|
1772
|
+
sessionPollingMs = performance.now() - tParallel;
|
|
1773
|
+
this.sessionResponse = sessionResponse;
|
|
1774
|
+
this.capabilities = sessionResponse.capabilities;
|
|
1775
|
+
this.tracks = this.presetTracks;
|
|
1776
|
+
this.emit("capabilitiesReceived", this.capabilities);
|
|
1777
|
+
const tConnect = performance.now();
|
|
1778
|
+
yield this.transportClient.connect();
|
|
1779
|
+
transportConnectingMs = performance.now() - tConnect;
|
|
1780
|
+
} else {
|
|
1781
|
+
this.transportClient.warmup();
|
|
1782
|
+
const tPoll = performance.now();
|
|
1783
|
+
const sessionResponse = yield this.coordinatorClient.pollSessionReady();
|
|
1784
|
+
sessionPollingMs = performance.now() - tPoll;
|
|
1785
|
+
this.sessionResponse = sessionResponse;
|
|
1786
|
+
this.capabilities = sessionResponse.capabilities;
|
|
1787
|
+
this.tracks = sessionResponse.capabilities.tracks;
|
|
1788
|
+
this.emit("capabilitiesReceived", this.capabilities);
|
|
1789
|
+
const protocol = sessionResponse.selected_transport.protocol;
|
|
1790
|
+
if (protocol !== "webrtc") {
|
|
1791
|
+
throw new Error(`Unsupported transport protocol: ${protocol}`);
|
|
1792
|
+
}
|
|
1793
|
+
const tTransport = performance.now();
|
|
1794
|
+
yield this.transportClient.prepare(this.tracks);
|
|
1795
|
+
yield this.transportClient.connect();
|
|
1796
|
+
transportConnectingMs = performance.now() - tTransport;
|
|
1797
|
+
}
|
|
1798
|
+
console.debug("[Reactor] Session ready, tracks:", this.tracks.length);
|
|
1770
1799
|
this.connectionTimings = {
|
|
1771
1800
|
sessionCreationMs: sessionCreationMs + sessionPollingMs,
|
|
1772
1801
|
transportConnectingMs,
|
|
@@ -2428,16 +2457,22 @@ function ReactorView({
|
|
|
2428
2457
|
// src/react/ReactorController.tsx
|
|
2429
2458
|
var import_react6 = __toESM(require("react"));
|
|
2430
2459
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
2460
|
+
function isFileParam(ps) {
|
|
2461
|
+
return ps.type === "file" || ps.type === "object" && ps.format === "file-reference";
|
|
2462
|
+
}
|
|
2431
2463
|
function ReactorController({
|
|
2432
2464
|
className,
|
|
2433
2465
|
style
|
|
2434
2466
|
}) {
|
|
2435
|
-
const { sendCommand, status } = useReactor((state) => ({
|
|
2467
|
+
const { sendCommand, uploadFile, status } = useReactor((state) => ({
|
|
2436
2468
|
sendCommand: state.sendCommand,
|
|
2469
|
+
uploadFile: state.uploadFile,
|
|
2437
2470
|
status: state.status
|
|
2438
2471
|
}));
|
|
2439
2472
|
const [commands, setCommands] = (0, import_react6.useState)({});
|
|
2440
2473
|
const [formValues, setFormValues] = (0, import_react6.useState)({});
|
|
2474
|
+
const formRef = (0, import_react6.useRef)(formValues);
|
|
2475
|
+
formRef.current = formValues;
|
|
2441
2476
|
const [expandedCommands, setExpandedCommands] = (0, import_react6.useState)({});
|
|
2442
2477
|
import_react6.default.useEffect(() => {
|
|
2443
2478
|
if (status === "disconnected") {
|
|
@@ -2484,15 +2519,17 @@ function ReactorController({
|
|
|
2484
2519
|
initialExpanded[commandName] = false;
|
|
2485
2520
|
Object.entries(commandSchema.schema).forEach(
|
|
2486
2521
|
([paramName, paramSchema]) => {
|
|
2487
|
-
var _a2
|
|
2488
|
-
if (paramSchema
|
|
2522
|
+
var _a2;
|
|
2523
|
+
if (isFileParam(paramSchema)) {
|
|
2524
|
+
initialValues[commandName][paramName] = null;
|
|
2525
|
+
} else if (paramSchema.default !== void 0) {
|
|
2526
|
+
initialValues[commandName][paramName] = paramSchema.default;
|
|
2527
|
+
} else if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2489
2528
|
initialValues[commandName][paramName] = (_a2 = paramSchema.minimum) != null ? _a2 : 0;
|
|
2490
2529
|
} else if (paramSchema.type === "string") {
|
|
2491
2530
|
initialValues[commandName][paramName] = "";
|
|
2492
2531
|
} else if (paramSchema.type === "boolean") {
|
|
2493
2532
|
initialValues[commandName][paramName] = false;
|
|
2494
|
-
} else if (paramSchema.type === "integer") {
|
|
2495
|
-
initialValues[commandName][paramName] = (_b = paramSchema.minimum) != null ? _b : 0;
|
|
2496
2533
|
}
|
|
2497
2534
|
}
|
|
2498
2535
|
);
|
|
@@ -2519,12 +2556,16 @@ function ReactorController({
|
|
|
2519
2556
|
const handleCommandSubmit = (0, import_react6.useCallback)(
|
|
2520
2557
|
(commandName) => __async(null, null, function* () {
|
|
2521
2558
|
const commandSchema = commands[commandName];
|
|
2522
|
-
const formData =
|
|
2559
|
+
const formData = formRef.current[commandName] || {};
|
|
2523
2560
|
const data = {};
|
|
2524
2561
|
Object.keys(commandSchema.schema).forEach((paramName) => {
|
|
2525
|
-
var _a
|
|
2562
|
+
var _a;
|
|
2526
2563
|
const paramSchema = commandSchema.schema[paramName];
|
|
2527
2564
|
let value = formData[paramName];
|
|
2565
|
+
if (value instanceof FileRef) {
|
|
2566
|
+
data[paramName] = value;
|
|
2567
|
+
return;
|
|
2568
|
+
}
|
|
2528
2569
|
if (paramSchema.type === "number" && typeof value === "string") {
|
|
2529
2570
|
value = parseFloat(value) || 0;
|
|
2530
2571
|
} else if (paramSchema.type === "integer" && typeof value === "string") {
|
|
@@ -2535,10 +2576,8 @@ function ReactorController({
|
|
|
2535
2576
|
if (value !== void 0 && value !== "" && value !== null) {
|
|
2536
2577
|
data[paramName] = value;
|
|
2537
2578
|
} else if (paramSchema.required) {
|
|
2538
|
-
if (paramSchema.type === "number") {
|
|
2579
|
+
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2539
2580
|
data[paramName] = (_a = paramSchema.minimum) != null ? _a : 0;
|
|
2540
|
-
} else if (paramSchema.type === "integer") {
|
|
2541
|
-
data[paramName] = (_b = paramSchema.minimum) != null ? _b : 0;
|
|
2542
2581
|
} else if (paramSchema.type === "string") {
|
|
2543
2582
|
data[paramName] = "";
|
|
2544
2583
|
} else if (paramSchema.type === "boolean") {
|
|
@@ -2546,14 +2585,28 @@ function ReactorController({
|
|
|
2546
2585
|
}
|
|
2547
2586
|
}
|
|
2548
2587
|
});
|
|
2549
|
-
console.log(`Executing command: ${commandName}`, data);
|
|
2550
2588
|
yield sendCommand(commandName, data);
|
|
2551
2589
|
}),
|
|
2552
|
-
[
|
|
2590
|
+
[sendCommand, commands]
|
|
2553
2591
|
);
|
|
2554
2592
|
const renderInput = (commandName, paramName, paramSchema) => {
|
|
2555
2593
|
var _a, _b;
|
|
2556
2594
|
const value = (_b = (_a = formValues[commandName]) == null ? void 0 : _a[paramName]) != null ? _b : "";
|
|
2595
|
+
if (isFileParam(paramSchema)) {
|
|
2596
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2597
|
+
FileParamInput,
|
|
2598
|
+
{
|
|
2599
|
+
commandName,
|
|
2600
|
+
paramName,
|
|
2601
|
+
description: paramSchema.description,
|
|
2602
|
+
value,
|
|
2603
|
+
onChange: handleInputChange,
|
|
2604
|
+
disabled: status !== "ready",
|
|
2605
|
+
uploadFile
|
|
2606
|
+
},
|
|
2607
|
+
`${commandName}-${paramName}`
|
|
2608
|
+
);
|
|
2609
|
+
}
|
|
2557
2610
|
if (paramSchema.type === "number" || paramSchema.type === "integer") {
|
|
2558
2611
|
const isInteger = paramSchema.type === "integer";
|
|
2559
2612
|
const step = isInteger ? 1 : 0.1;
|
|
@@ -2742,10 +2795,11 @@ function ReactorController({
|
|
|
2742
2795
|
const renderCommand = (commandName, commandSchema) => {
|
|
2743
2796
|
const hasParams = Object.keys(commandSchema.schema).length > 0;
|
|
2744
2797
|
const isExpanded = expandedCommands[commandName];
|
|
2745
|
-
const
|
|
2746
|
-
|
|
2798
|
+
const params = Object.values(commandSchema.schema);
|
|
2799
|
+
const allSliders = params.length > 0 && params.every(
|
|
2800
|
+
(ps) => (ps.type === "number" || ps.type === "integer") && typeof ps.minimum === "number" && typeof ps.maximum === "number"
|
|
2747
2801
|
);
|
|
2748
|
-
const showExecuteButton = !
|
|
2802
|
+
const showExecuteButton = !allSliders;
|
|
2749
2803
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
2750
2804
|
"div",
|
|
2751
2805
|
{
|
|
@@ -2883,6 +2937,89 @@ function ReactorController({
|
|
|
2883
2937
|
Object.entries(commands).map(([commandName, commandSchema]) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: renderCommand(commandName, commandSchema) }, commandName))
|
|
2884
2938
|
] }) }) });
|
|
2885
2939
|
}
|
|
2940
|
+
function FileParamInput({
|
|
2941
|
+
commandName,
|
|
2942
|
+
paramName,
|
|
2943
|
+
description,
|
|
2944
|
+
value,
|
|
2945
|
+
onChange,
|
|
2946
|
+
disabled,
|
|
2947
|
+
uploadFile
|
|
2948
|
+
}) {
|
|
2949
|
+
const inputRef = (0, import_react6.useRef)(null);
|
|
2950
|
+
const [uploading, setUploading] = (0, import_react6.useState)(false);
|
|
2951
|
+
const fileRef = value instanceof FileRef ? value : null;
|
|
2952
|
+
const handleFile = (e) => __async(null, null, function* () {
|
|
2953
|
+
var _a;
|
|
2954
|
+
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
2955
|
+
if (!file) return;
|
|
2956
|
+
e.target.value = "";
|
|
2957
|
+
setUploading(true);
|
|
2958
|
+
try {
|
|
2959
|
+
const ref = yield uploadFile(file);
|
|
2960
|
+
onChange(commandName, paramName, ref);
|
|
2961
|
+
} catch (err) {
|
|
2962
|
+
console.error("[FileParamInput] Upload failed:", err);
|
|
2963
|
+
} finally {
|
|
2964
|
+
setUploading(false);
|
|
2965
|
+
}
|
|
2966
|
+
});
|
|
2967
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "8px" }, children: [
|
|
2968
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { style: { fontSize: "12px", color: "#666", display: "block" }, children: [
|
|
2969
|
+
paramName,
|
|
2970
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { color: "#888", fontSize: "11px" }, children: " (file)" }),
|
|
2971
|
+
description && ` - ${description}`
|
|
2972
|
+
] }),
|
|
2973
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
2974
|
+
"div",
|
|
2975
|
+
{
|
|
2976
|
+
style: {
|
|
2977
|
+
display: "flex",
|
|
2978
|
+
alignItems: "center",
|
|
2979
|
+
gap: "8px",
|
|
2980
|
+
marginTop: "4px"
|
|
2981
|
+
},
|
|
2982
|
+
children: [
|
|
2983
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2984
|
+
"input",
|
|
2985
|
+
{
|
|
2986
|
+
ref: inputRef,
|
|
2987
|
+
type: "file",
|
|
2988
|
+
accept: "image/*",
|
|
2989
|
+
onChange: handleFile,
|
|
2990
|
+
style: { display: "none" }
|
|
2991
|
+
}
|
|
2992
|
+
),
|
|
2993
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2994
|
+
"button",
|
|
2995
|
+
{
|
|
2996
|
+
disabled: disabled || uploading,
|
|
2997
|
+
onClick: () => {
|
|
2998
|
+
var _a;
|
|
2999
|
+
return (_a = inputRef.current) == null ? void 0 : _a.click();
|
|
3000
|
+
},
|
|
3001
|
+
style: {
|
|
3002
|
+
padding: "4px 12px",
|
|
3003
|
+
fontSize: "12px",
|
|
3004
|
+
backgroundColor: "#007bff",
|
|
3005
|
+
color: "white",
|
|
3006
|
+
border: "none",
|
|
3007
|
+
borderRadius: "4px",
|
|
3008
|
+
cursor: disabled || uploading ? "default" : "pointer",
|
|
3009
|
+
opacity: disabled || uploading ? 0.5 : 1
|
|
3010
|
+
},
|
|
3011
|
+
children: uploading ? "Uploading\u2026" : fileRef ? "Change" : "Choose File"
|
|
3012
|
+
}
|
|
3013
|
+
),
|
|
3014
|
+
fileRef && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { fontSize: "11px", color: "#28a745" }, children: [
|
|
3015
|
+
"\\u2713 ",
|
|
3016
|
+
fileRef.name
|
|
3017
|
+
] })
|
|
3018
|
+
]
|
|
3019
|
+
}
|
|
3020
|
+
)
|
|
3021
|
+
] });
|
|
3022
|
+
}
|
|
2886
3023
|
|
|
2887
3024
|
// src/react/WebcamStream.tsx
|
|
2888
3025
|
var import_react7 = require("react");
|