@ateam-ai-mobile/ui 0.1.3 → 0.1.4
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 +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +28 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/voice/VoiceCallSheet.tsx +4 -2
- package/src/voice/useVoiceCall.ts +51 -6
package/dist/index.mjs
CHANGED
|
@@ -2072,7 +2072,21 @@ import { AdaOrb as AdaOrb3, SurfaceFullscreen as SurfaceFullscreen2 } from "@ate
|
|
|
2072
2072
|
|
|
2073
2073
|
// src/voice/useVoiceCall.ts
|
|
2074
2074
|
import { useState as useState9, useRef as useRef5, useCallback as useCallback6 } from "react";
|
|
2075
|
-
import { getVoiceApiUrl as getVoiceApiUrl2, getToken as getToken2, getTenant as getTenant5, getUser as getUser2 } from "@ateam-ai-mobile/core";
|
|
2075
|
+
import { getVoiceApiUrl as getVoiceApiUrl2, getToken as getToken2, getTenant as getTenant5, getUser as getUser2, refreshToken } from "@ateam-ai-mobile/core";
|
|
2076
|
+
var TOKEN_REFRESH_SKEW_MS = 9e4;
|
|
2077
|
+
function tokenNeedsRefresh(token) {
|
|
2078
|
+
if (!token) return true;
|
|
2079
|
+
try {
|
|
2080
|
+
const payloadB64 = token.split(".")[1];
|
|
2081
|
+
const padded = payloadB64.replace(/-/g, "+").replace(/_/g, "/");
|
|
2082
|
+
const json = typeof atob === "function" ? atob(padded) : Buffer.from(padded, "base64").toString("utf8");
|
|
2083
|
+
const exp = JSON.parse(json)?.exp;
|
|
2084
|
+
if (typeof exp !== "number") return false;
|
|
2085
|
+
return Date.now() >= exp * 1e3 - TOKEN_REFRESH_SKEW_MS;
|
|
2086
|
+
} catch {
|
|
2087
|
+
return false;
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2076
2090
|
var INJECT_TRACK_HOOK = `
|
|
2077
2091
|
(function() {
|
|
2078
2092
|
if (window._adaTrackHookInstalled) return;
|
|
@@ -2163,7 +2177,7 @@ var buildMuteScript = (muted) => `
|
|
|
2163
2177
|
console.log('[ada-mute]', muted ? 'MUTED' : 'UNMUTED', 'tracks=', n);
|
|
2164
2178
|
})(${muted}); true;
|
|
2165
2179
|
`;
|
|
2166
|
-
function useVoiceCall() {
|
|
2180
|
+
function useVoiceCall({ skillSlug } = {}) {
|
|
2167
2181
|
const [callState, setCallState] = useState9("idle");
|
|
2168
2182
|
const [sessionId, setSessionId] = useState9(null);
|
|
2169
2183
|
const [error, setError] = useState9(null);
|
|
@@ -2204,12 +2218,18 @@ function useVoiceCall() {
|
|
|
2204
2218
|
} catch {
|
|
2205
2219
|
}
|
|
2206
2220
|
}, []);
|
|
2207
|
-
const startCall = useCallback6(() => {
|
|
2208
|
-
setCallState("connecting");
|
|
2221
|
+
const startCall = useCallback6(async () => {
|
|
2209
2222
|
setError(null);
|
|
2210
2223
|
setTranscript([]);
|
|
2211
2224
|
setAiPartial("");
|
|
2212
2225
|
setUserPartial("");
|
|
2226
|
+
try {
|
|
2227
|
+
if (tokenNeedsRefresh(getToken2())) {
|
|
2228
|
+
await refreshToken();
|
|
2229
|
+
}
|
|
2230
|
+
} catch {
|
|
2231
|
+
}
|
|
2232
|
+
setCallState("connecting");
|
|
2213
2233
|
}, []);
|
|
2214
2234
|
const stopCall = useCallback6(() => {
|
|
2215
2235
|
webViewRef.current?.injectJavaScript?.("window.hangUp && window.hangUp(); true;");
|
|
@@ -2229,10 +2249,11 @@ function useVoiceCall() {
|
|
|
2229
2249
|
const token = getToken2();
|
|
2230
2250
|
const tenant = getTenant5();
|
|
2231
2251
|
const actorId = getUser2()?.actorId || "";
|
|
2252
|
+
const skillParam = skillSlug ? `&skillSlug=${encodeURIComponent(skillSlug)}` : "";
|
|
2232
2253
|
return {
|
|
2233
|
-
uri: `${getVoiceApiUrl2()}/app?mode=mini&embedded=rn&authToken=${encodeURIComponent(token || "")}&tenant=${encodeURIComponent(tenant)}&actorId=${encodeURIComponent(actorId)}`
|
|
2254
|
+
uri: `${getVoiceApiUrl2()}/app?mode=mini&embedded=rn&authToken=${encodeURIComponent(token || "")}&tenant=${encodeURIComponent(tenant)}&actorId=${encodeURIComponent(actorId)}${skillParam}`
|
|
2234
2255
|
};
|
|
2235
|
-
}, []);
|
|
2256
|
+
}, [skillSlug]);
|
|
2236
2257
|
return {
|
|
2237
2258
|
callState,
|
|
2238
2259
|
sessionId,
|
|
@@ -2299,7 +2320,7 @@ function HighlightedText({
|
|
|
2299
2320
|
const segments = useMemo5(() => highlightSegments(text), [text]);
|
|
2300
2321
|
return /* @__PURE__ */ jsx15(Text10, { style: baseStyle, children: segments.map((seg, i) => /* @__PURE__ */ jsx15(Text10, { style: seg.important ? importantStyle : void 0, children: seg.text }, i)) });
|
|
2301
2322
|
}
|
|
2302
|
-
function VoiceCallSheet({ visible, onClose }) {
|
|
2323
|
+
function VoiceCallSheet({ visible, onClose, skillSlug }) {
|
|
2303
2324
|
const {
|
|
2304
2325
|
callState,
|
|
2305
2326
|
aiPartial,
|
|
@@ -2314,7 +2335,7 @@ function VoiceCallSheet({ visible, onClose }) {
|
|
|
2314
2335
|
getWebViewSource,
|
|
2315
2336
|
webViewRef,
|
|
2316
2337
|
injectedTrackHook
|
|
2317
|
-
} = useVoiceCall();
|
|
2338
|
+
} = useVoiceCall({ skillSlug });
|
|
2318
2339
|
const scrollRef = useRef6(null);
|
|
2319
2340
|
useEffect8(() => {
|
|
2320
2341
|
if (visible && callState === "idle") startCall();
|