@runhuman/sensor 0.2.1 → 0.2.3
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 +131 -5
- package/dist/index.d.ts +131 -5
- package/dist/index.js +281 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +278 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -7
- package/dist/overlay/index.d.mts +0 -34
- package/dist/overlay/index.d.ts +0 -34
- package/dist/overlay/index.js +0 -1445
- package/dist/overlay/index.js.map +0 -1
- package/dist/overlay/index.mjs +0 -1424
- package/dist/overlay/index.mjs.map +0 -1
- package/dist/session-manager-B6tiwEQm.d.mts +0 -99
- package/dist/session-manager-B6tiwEQm.d.ts +0 -99
package/dist/index.mjs
CHANGED
|
@@ -1054,7 +1054,14 @@ var DeepLinkHandler = class {
|
|
|
1054
1054
|
// src/runhuman.ts
|
|
1055
1055
|
var PRODUCTION_BASE_URL = "https://qa-experiment.fly.dev";
|
|
1056
1056
|
var SDK_VERSION = "0.1.0";
|
|
1057
|
-
var
|
|
1057
|
+
var INSTANCE_KEY = "__runhuman_sensor_instance__";
|
|
1058
|
+
var Runhuman = class _Runhuman {
|
|
1059
|
+
static get instance() {
|
|
1060
|
+
return globalThis[INSTANCE_KEY] ?? null;
|
|
1061
|
+
}
|
|
1062
|
+
static set instance(value) {
|
|
1063
|
+
globalThis[INSTANCE_KEY] = value;
|
|
1064
|
+
}
|
|
1058
1065
|
constructor(config) {
|
|
1059
1066
|
this.debug = config.debug === true;
|
|
1060
1067
|
this.apiClient = new ApiClient(
|
|
@@ -1147,9 +1154,276 @@ var _Runhuman = class _Runhuman {
|
|
|
1147
1154
|
}
|
|
1148
1155
|
}
|
|
1149
1156
|
};
|
|
1150
|
-
|
|
1151
|
-
|
|
1157
|
+
|
|
1158
|
+
// src/overlay/RunhumanOverlay.tsx
|
|
1159
|
+
import { View as View2, StyleSheet as StyleSheet2 } from "react-native";
|
|
1160
|
+
|
|
1161
|
+
// src/overlay/use-sensor-state.ts
|
|
1162
|
+
import { useCallback } from "react";
|
|
1163
|
+
import { useSyncExternalStore } from "react";
|
|
1164
|
+
var IDLE_STATE = { state: "idle", activeJobId: null, sessionId: null };
|
|
1165
|
+
function tryGetInstance() {
|
|
1166
|
+
try {
|
|
1167
|
+
return Runhuman.getInstance();
|
|
1168
|
+
} catch {
|
|
1169
|
+
return null;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
function useSensorState() {
|
|
1173
|
+
const subscribe = useCallback((onStoreChange) => {
|
|
1174
|
+
const instance = tryGetInstance();
|
|
1175
|
+
if (!instance) {
|
|
1176
|
+
const interval = setInterval(() => {
|
|
1177
|
+
if (tryGetInstance()) {
|
|
1178
|
+
clearInterval(interval);
|
|
1179
|
+
onStoreChange();
|
|
1180
|
+
}
|
|
1181
|
+
}, 100);
|
|
1182
|
+
return () => clearInterval(interval);
|
|
1183
|
+
}
|
|
1184
|
+
return instance.getSessionManager().subscribe(onStoreChange);
|
|
1185
|
+
}, []);
|
|
1186
|
+
const getSnapshot = useCallback(() => {
|
|
1187
|
+
const instance = tryGetInstance();
|
|
1188
|
+
if (!instance) return IDLE_STATE;
|
|
1189
|
+
const sm = instance.getSessionManager();
|
|
1190
|
+
return {
|
|
1191
|
+
state: sm.getSnapshot(),
|
|
1192
|
+
activeJobId: sm.getActiveJobId(),
|
|
1193
|
+
sessionId: sm.getSessionId()
|
|
1194
|
+
};
|
|
1195
|
+
}, []);
|
|
1196
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// src/overlay/CodeEntryPanel.tsx
|
|
1200
|
+
import { useState } from "react";
|
|
1201
|
+
import { View, Text, TextInput, Pressable } from "react-native";
|
|
1202
|
+
|
|
1203
|
+
// src/overlay/overlay-styles.ts
|
|
1204
|
+
import { StyleSheet } from "react-native";
|
|
1205
|
+
var BRAND_GREEN = "#22c55e";
|
|
1206
|
+
var BRAND_AMBER = "#f59e0b";
|
|
1207
|
+
var BRAND_RED = "#ef4444";
|
|
1208
|
+
var BRAND_BLUE = "#3b82f6";
|
|
1209
|
+
var OVERLAY_BG = "rgba(0, 0, 0, 0.85)";
|
|
1210
|
+
var OVERLAY_BORDER = "rgba(255, 255, 255, 0.15)";
|
|
1211
|
+
var overlayStyles = StyleSheet.create({
|
|
1212
|
+
// Positioning containers
|
|
1213
|
+
topLeft: { top: 60, left: 16 },
|
|
1214
|
+
topRight: { top: 60, right: 16 },
|
|
1215
|
+
bottomLeft: { bottom: 40, left: 16 },
|
|
1216
|
+
bottomRight: { bottom: 40, right: 16 },
|
|
1217
|
+
// Code entry panel
|
|
1218
|
+
panel: {
|
|
1219
|
+
position: "absolute",
|
|
1220
|
+
zIndex: 99999,
|
|
1221
|
+
backgroundColor: OVERLAY_BG,
|
|
1222
|
+
borderRadius: 12,
|
|
1223
|
+
borderWidth: 1,
|
|
1224
|
+
borderColor: OVERLAY_BORDER,
|
|
1225
|
+
padding: 16,
|
|
1226
|
+
width: 220
|
|
1227
|
+
},
|
|
1228
|
+
panelTitle: {
|
|
1229
|
+
color: "#ffffff",
|
|
1230
|
+
fontSize: 13,
|
|
1231
|
+
fontWeight: "600",
|
|
1232
|
+
marginBottom: 8
|
|
1233
|
+
},
|
|
1234
|
+
input: {
|
|
1235
|
+
backgroundColor: "rgba(255, 255, 255, 0.1)",
|
|
1236
|
+
borderRadius: 8,
|
|
1237
|
+
borderWidth: 1,
|
|
1238
|
+
borderColor: OVERLAY_BORDER,
|
|
1239
|
+
color: "#ffffff",
|
|
1240
|
+
fontSize: 18,
|
|
1241
|
+
fontFamily: "monospace",
|
|
1242
|
+
fontWeight: "bold",
|
|
1243
|
+
letterSpacing: 2,
|
|
1244
|
+
padding: 10,
|
|
1245
|
+
textAlign: "center"
|
|
1246
|
+
},
|
|
1247
|
+
inputError: {
|
|
1248
|
+
borderColor: BRAND_RED
|
|
1249
|
+
},
|
|
1250
|
+
submitButton: {
|
|
1251
|
+
backgroundColor: BRAND_BLUE,
|
|
1252
|
+
borderRadius: 8,
|
|
1253
|
+
paddingVertical: 8,
|
|
1254
|
+
marginTop: 8,
|
|
1255
|
+
alignItems: "center"
|
|
1256
|
+
},
|
|
1257
|
+
submitButtonDisabled: {
|
|
1258
|
+
opacity: 0.5
|
|
1259
|
+
},
|
|
1260
|
+
submitButtonText: {
|
|
1261
|
+
color: "#ffffff",
|
|
1262
|
+
fontSize: 13,
|
|
1263
|
+
fontWeight: "600"
|
|
1264
|
+
},
|
|
1265
|
+
errorText: {
|
|
1266
|
+
color: BRAND_RED,
|
|
1267
|
+
fontSize: 11,
|
|
1268
|
+
marginTop: 4,
|
|
1269
|
+
textAlign: "center"
|
|
1270
|
+
},
|
|
1271
|
+
minimizeButton: {
|
|
1272
|
+
position: "absolute",
|
|
1273
|
+
top: 8,
|
|
1274
|
+
right: 8
|
|
1275
|
+
},
|
|
1276
|
+
minimizeText: {
|
|
1277
|
+
color: "rgba(255, 255, 255, 0.5)",
|
|
1278
|
+
fontSize: 16
|
|
1279
|
+
},
|
|
1280
|
+
// Minimized fab (floating action button)
|
|
1281
|
+
fab: {
|
|
1282
|
+
position: "absolute",
|
|
1283
|
+
zIndex: 99999,
|
|
1284
|
+
width: 40,
|
|
1285
|
+
height: 40,
|
|
1286
|
+
borderRadius: 20,
|
|
1287
|
+
backgroundColor: OVERLAY_BG,
|
|
1288
|
+
borderWidth: 1,
|
|
1289
|
+
borderColor: OVERLAY_BORDER,
|
|
1290
|
+
alignItems: "center",
|
|
1291
|
+
justifyContent: "center"
|
|
1292
|
+
},
|
|
1293
|
+
fabText: {
|
|
1294
|
+
color: "#ffffff",
|
|
1295
|
+
fontSize: 16
|
|
1296
|
+
},
|
|
1297
|
+
// Active indicator dot
|
|
1298
|
+
indicator: {
|
|
1299
|
+
position: "absolute",
|
|
1300
|
+
zIndex: 99999,
|
|
1301
|
+
width: 12,
|
|
1302
|
+
height: 12,
|
|
1303
|
+
borderRadius: 6
|
|
1304
|
+
},
|
|
1305
|
+
indicatorActive: {
|
|
1306
|
+
backgroundColor: BRAND_GREEN
|
|
1307
|
+
},
|
|
1308
|
+
indicatorEnding: {
|
|
1309
|
+
backgroundColor: BRAND_AMBER
|
|
1310
|
+
},
|
|
1311
|
+
indicatorPolling: {
|
|
1312
|
+
backgroundColor: BRAND_BLUE
|
|
1313
|
+
}
|
|
1314
|
+
});
|
|
1315
|
+
|
|
1316
|
+
// src/overlay/CodeEntryPanel.tsx
|
|
1317
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1318
|
+
function CodeEntryPanel({ position }) {
|
|
1319
|
+
const [code, setCode] = useState("");
|
|
1320
|
+
const [error, setError] = useState(null);
|
|
1321
|
+
const [resolving, setResolving] = useState(false);
|
|
1322
|
+
const [minimized, setMinimized] = useState(false);
|
|
1323
|
+
const handleSubmit = async () => {
|
|
1324
|
+
const trimmed = code.trim();
|
|
1325
|
+
if (!trimmed) return;
|
|
1326
|
+
setResolving(true);
|
|
1327
|
+
setError(null);
|
|
1328
|
+
const instance = Runhuman.getInstance();
|
|
1329
|
+
const result = await instance.getApiClient().resolveShortCode(trimmed);
|
|
1330
|
+
if (result) {
|
|
1331
|
+
instance.activate(result.jobId);
|
|
1332
|
+
} else {
|
|
1333
|
+
setError("Invalid or expired code");
|
|
1334
|
+
setResolving(false);
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
if (minimized) {
|
|
1338
|
+
return /* @__PURE__ */ jsx(Pressable, { style: [overlayStyles.fab, overlayStyles[position]], onPress: () => setMinimized(false), children: /* @__PURE__ */ jsx(Text, { style: overlayStyles.fabText, children: "RH" }) });
|
|
1339
|
+
}
|
|
1340
|
+
return /* @__PURE__ */ jsxs(View, { style: [overlayStyles.panel, overlayStyles[position]], children: [
|
|
1341
|
+
/* @__PURE__ */ jsx(Pressable, { style: overlayStyles.minimizeButton, onPress: () => setMinimized(true), children: /* @__PURE__ */ jsx(Text, { style: overlayStyles.minimizeText, children: "-" }) }),
|
|
1342
|
+
/* @__PURE__ */ jsx(Text, { style: overlayStyles.panelTitle, children: "Runhuman Sensor" }),
|
|
1343
|
+
/* @__PURE__ */ jsx(
|
|
1344
|
+
TextInput,
|
|
1345
|
+
{
|
|
1346
|
+
style: error ? { ...overlayStyles.input, ...overlayStyles.inputError } : overlayStyles.input,
|
|
1347
|
+
value: code,
|
|
1348
|
+
onChangeText: (text) => {
|
|
1349
|
+
setCode(text.toUpperCase());
|
|
1350
|
+
setError(null);
|
|
1351
|
+
},
|
|
1352
|
+
placeholder: "RH-XXXX",
|
|
1353
|
+
placeholderTextColor: "rgba(255,255,255,0.3)",
|
|
1354
|
+
autoCapitalize: "characters",
|
|
1355
|
+
maxLength: 10,
|
|
1356
|
+
editable: !resolving,
|
|
1357
|
+
onSubmitEditing: handleSubmit
|
|
1358
|
+
}
|
|
1359
|
+
),
|
|
1360
|
+
error ? /* @__PURE__ */ jsx(Text, { style: overlayStyles.errorText, children: error }) : null,
|
|
1361
|
+
/* @__PURE__ */ jsx(
|
|
1362
|
+
Pressable,
|
|
1363
|
+
{
|
|
1364
|
+
style: resolving ? { ...overlayStyles.submitButton, ...overlayStyles.submitButtonDisabled } : overlayStyles.submitButton,
|
|
1365
|
+
onPress: handleSubmit,
|
|
1366
|
+
disabled: resolving || !code.trim(),
|
|
1367
|
+
children: /* @__PURE__ */ jsx(Text, { style: overlayStyles.submitButtonText, children: resolving ? "Activating..." : "Activate" })
|
|
1368
|
+
}
|
|
1369
|
+
)
|
|
1370
|
+
] });
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
// src/overlay/ActiveIndicator.tsx
|
|
1374
|
+
import { useEffect, useRef } from "react";
|
|
1375
|
+
import { Animated } from "react-native";
|
|
1376
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
1377
|
+
var stateStyle = {
|
|
1378
|
+
active: overlayStyles.indicatorActive,
|
|
1379
|
+
ending: overlayStyles.indicatorEnding,
|
|
1380
|
+
polling: overlayStyles.indicatorPolling
|
|
1381
|
+
};
|
|
1382
|
+
function ActiveIndicator({ state, position }) {
|
|
1383
|
+
const pulse = useRef(new Animated.Value(1)).current;
|
|
1384
|
+
useEffect(() => {
|
|
1385
|
+
if (state === "active") {
|
|
1386
|
+
const animation = Animated.loop(
|
|
1387
|
+
Animated.sequence([
|
|
1388
|
+
Animated.timing(pulse, { toValue: 0.3, duration: 800, useNativeDriver: true }),
|
|
1389
|
+
Animated.timing(pulse, { toValue: 1, duration: 800, useNativeDriver: true })
|
|
1390
|
+
])
|
|
1391
|
+
);
|
|
1392
|
+
animation.start();
|
|
1393
|
+
return () => animation.stop();
|
|
1394
|
+
}
|
|
1395
|
+
pulse.setValue(1);
|
|
1396
|
+
}, [state, pulse]);
|
|
1397
|
+
const colorStyle = stateStyle[state];
|
|
1398
|
+
if (!colorStyle) return null;
|
|
1399
|
+
return /* @__PURE__ */ jsx2(Animated.View, { style: [overlayStyles.indicator, overlayStyles[position], colorStyle, { opacity: pulse }] });
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
// src/overlay/RunhumanOverlay.tsx
|
|
1403
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1404
|
+
var positionMap = {
|
|
1405
|
+
"top-left": "topLeft",
|
|
1406
|
+
"top-right": "topRight",
|
|
1407
|
+
"bottom-left": "bottomLeft",
|
|
1408
|
+
"bottom-right": "bottomRight"
|
|
1409
|
+
};
|
|
1410
|
+
function RunhumanOverlay({ children, position = "bottom-right" }) {
|
|
1411
|
+
const { state, activeJobId } = useSensorState();
|
|
1412
|
+
const posKey = positionMap[position];
|
|
1413
|
+
return /* @__PURE__ */ jsxs2(View2, { style: styles.container, children: [
|
|
1414
|
+
children,
|
|
1415
|
+
state === "idle" && !activeJobId ? /* @__PURE__ */ jsx3(CodeEntryPanel, { position: posKey }) : null,
|
|
1416
|
+
state !== "idle" ? /* @__PURE__ */ jsx3(ActiveIndicator, { state, position: posKey }) : null
|
|
1417
|
+
] });
|
|
1418
|
+
}
|
|
1419
|
+
var styles = StyleSheet2.create({
|
|
1420
|
+
container: {
|
|
1421
|
+
flex: 1
|
|
1422
|
+
}
|
|
1423
|
+
});
|
|
1152
1424
|
export {
|
|
1153
|
-
Runhuman
|
|
1425
|
+
Runhuman,
|
|
1426
|
+
RunhumanOverlay,
|
|
1427
|
+
useSensorState
|
|
1154
1428
|
};
|
|
1155
1429
|
//# sourceMappingURL=index.mjs.map
|