@ateam-ai-mobile/core 0.1.26 → 0.1.28

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
@@ -40,6 +40,14 @@ function getCoreApiUrl() {
40
40
  function getCoreWsUrl() {
41
41
  return getCoreApiUrl().replace(/^http/, "ws");
42
42
  }
43
+ var CORE_WS_PROTOCOL = "adas.v1";
44
+ var CORE_WS_BEARER_PREFIX = "adas.bearer.";
45
+ function openCoreWs(tenant, token) {
46
+ const url = `${getCoreWsUrl()}/ws?tenant=${encodeURIComponent(tenant)}`;
47
+ const protocols = [CORE_WS_PROTOCOL];
48
+ if (token) protocols.push(CORE_WS_BEARER_PREFIX + token);
49
+ return new WebSocket(url, protocols);
50
+ }
43
51
  function getVoiceApiUrl() {
44
52
  const url = getConfig().voiceUrl;
45
53
  if (!url) throw new Error("[adas] voiceUrl not configured");
@@ -976,9 +984,8 @@ function handleEvent(msg) {
976
984
  function openSocket() {
977
985
  if (_ws) return;
978
986
  if (!_token || !_tenant) return;
979
- const url = `${getCoreWsUrl()}/ws?token=${encodeURIComponent(_token)}&tenant=${encodeURIComponent(_tenant)}`;
980
987
  console.log(`[acsWs] opening`);
981
- const ws = new WebSocket(url);
988
+ const ws = openCoreWs(_tenant, _token);
982
989
  _ws = ws;
983
990
  const isCurrent = () => ws === _ws;
984
991
  ws.onopen = () => {
@@ -1838,8 +1845,7 @@ function setClientDeclarationProvider(fn) {
1838
1845
  var _currentJobId = null;
1839
1846
  function ensureWs(tenant, token) {
1840
1847
  if (_ws2 && _wsReady) return _ws2;
1841
- const wsUrl = `${getCoreWsUrl()}/ws?token=${encodeURIComponent(token || "")}&tenant=${encodeURIComponent(tenant)}`;
1842
- const ws = new WebSocket(wsUrl);
1848
+ const ws = openCoreWs(tenant, token);
1843
1849
  _ws2 = ws;
1844
1850
  _wsReady = false;
1845
1851
  ws.onopen = () => {
@@ -1990,9 +1996,19 @@ async function fetchTurnResult(jobId, jobSnap) {
1990
1996
  const fallback = jobSnap.result?.message || jobSnap.state?.finalReply || (status === "error" ? "Something went wrong. Please try again." : "Done.");
1991
1997
  updateJobProgress(jobId, { status, resultMessage: fallback });
1992
1998
  }
1999
+ function isWaitingOnScreen(jobId) {
2000
+ return useChatStore.getState().messages.some((m) => {
2001
+ const p = m.jobProgress;
2002
+ return p?.jobId === jobId && p.status !== "done" && p.status !== "error" && p.status !== "paused";
2003
+ });
2004
+ }
2005
+ function pollDelayMs(attempt) {
2006
+ return attempt < 120 ? 1500 : 5e3;
2007
+ }
1993
2008
  async function pollJob(jobId, token) {
1994
2009
  const { updateJobProgress } = useChatStore.getState();
1995
- for (let i = 0; i < 120; i++) {
2010
+ for (let i = 0; isWaitingOnScreen(jobId); i++) {
2011
+ if (i > 0) await new Promise((r) => setTimeout(r, pollDelayMs(i)));
1996
2012
  try {
1997
2013
  const res = await fetch(`${getCoreApiUrl()}/api/job/${jobId}/status`, {
1998
2014
  headers: {
@@ -2016,12 +2032,7 @@ async function pollJob(jobId, token) {
2016
2032
  }
2017
2033
  } catch {
2018
2034
  }
2019
- await new Promise((r) => setTimeout(r, 1500));
2020
2035
  }
2021
- updateJobProgress(jobId, {
2022
- status: "error",
2023
- resultMessage: "Job timed out. Please try again."
2024
- });
2025
2036
  }
2026
2037
 
2027
2038
  // src/api/tenants.ts