@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.js CHANGED
@@ -151,6 +151,14 @@ function getCoreApiUrl() {
151
151
  function getCoreWsUrl() {
152
152
  return getCoreApiUrl().replace(/^http/, "ws");
153
153
  }
154
+ var CORE_WS_PROTOCOL = "adas.v1";
155
+ var CORE_WS_BEARER_PREFIX = "adas.bearer.";
156
+ function openCoreWs(tenant, token) {
157
+ const url = `${getCoreWsUrl()}/ws?tenant=${encodeURIComponent(tenant)}`;
158
+ const protocols = [CORE_WS_PROTOCOL];
159
+ if (token) protocols.push(CORE_WS_BEARER_PREFIX + token);
160
+ return new WebSocket(url, protocols);
161
+ }
154
162
  function getVoiceApiUrl() {
155
163
  const url = getConfig().voiceUrl;
156
164
  if (!url) throw new Error("[adas] voiceUrl not configured");
@@ -1087,9 +1095,8 @@ function handleEvent(msg) {
1087
1095
  function openSocket() {
1088
1096
  if (_ws) return;
1089
1097
  if (!_token || !_tenant) return;
1090
- const url = `${getCoreWsUrl()}/ws?token=${encodeURIComponent(_token)}&tenant=${encodeURIComponent(_tenant)}`;
1091
1098
  console.log(`[acsWs] opening`);
1092
- const ws = new WebSocket(url);
1099
+ const ws = openCoreWs(_tenant, _token);
1093
1100
  _ws = ws;
1094
1101
  const isCurrent = () => ws === _ws;
1095
1102
  ws.onopen = () => {
@@ -1949,8 +1956,7 @@ function setClientDeclarationProvider(fn) {
1949
1956
  var _currentJobId = null;
1950
1957
  function ensureWs(tenant, token) {
1951
1958
  if (_ws2 && _wsReady) return _ws2;
1952
- const wsUrl = `${getCoreWsUrl()}/ws?token=${encodeURIComponent(token || "")}&tenant=${encodeURIComponent(tenant)}`;
1953
- const ws = new WebSocket(wsUrl);
1959
+ const ws = openCoreWs(tenant, token);
1954
1960
  _ws2 = ws;
1955
1961
  _wsReady = false;
1956
1962
  ws.onopen = () => {
@@ -2101,9 +2107,19 @@ async function fetchTurnResult(jobId, jobSnap) {
2101
2107
  const fallback = jobSnap.result?.message || jobSnap.state?.finalReply || (status === "error" ? "Something went wrong. Please try again." : "Done.");
2102
2108
  updateJobProgress(jobId, { status, resultMessage: fallback });
2103
2109
  }
2110
+ function isWaitingOnScreen(jobId) {
2111
+ return useChatStore.getState().messages.some((m) => {
2112
+ const p = m.jobProgress;
2113
+ return p?.jobId === jobId && p.status !== "done" && p.status !== "error" && p.status !== "paused";
2114
+ });
2115
+ }
2116
+ function pollDelayMs(attempt) {
2117
+ return attempt < 120 ? 1500 : 5e3;
2118
+ }
2104
2119
  async function pollJob(jobId, token) {
2105
2120
  const { updateJobProgress } = useChatStore.getState();
2106
- for (let i = 0; i < 120; i++) {
2121
+ for (let i = 0; isWaitingOnScreen(jobId); i++) {
2122
+ if (i > 0) await new Promise((r) => setTimeout(r, pollDelayMs(i)));
2107
2123
  try {
2108
2124
  const res = await fetch(`${getCoreApiUrl()}/api/job/${jobId}/status`, {
2109
2125
  headers: {
@@ -2127,12 +2143,7 @@ async function pollJob(jobId, token) {
2127
2143
  }
2128
2144
  } catch {
2129
2145
  }
2130
- await new Promise((r) => setTimeout(r, 1500));
2131
2146
  }
2132
- updateJobProgress(jobId, {
2133
- status: "error",
2134
- resultMessage: "Job timed out. Please try again."
2135
- });
2136
2147
  }
2137
2148
 
2138
2149
  // src/api/tenants.ts