@ateam-ai-mobile/core 0.1.27 → 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
@@ -1996,9 +1996,19 @@ async function fetchTurnResult(jobId, jobSnap) {
1996
1996
  const fallback = jobSnap.result?.message || jobSnap.state?.finalReply || (status === "error" ? "Something went wrong. Please try again." : "Done.");
1997
1997
  updateJobProgress(jobId, { status, resultMessage: fallback });
1998
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
+ }
1999
2008
  async function pollJob(jobId, token) {
2000
2009
  const { updateJobProgress } = useChatStore.getState();
2001
- 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)));
2002
2012
  try {
2003
2013
  const res = await fetch(`${getCoreApiUrl()}/api/job/${jobId}/status`, {
2004
2014
  headers: {
@@ -2022,12 +2032,7 @@ async function pollJob(jobId, token) {
2022
2032
  }
2023
2033
  } catch {
2024
2034
  }
2025
- await new Promise((r) => setTimeout(r, 1500));
2026
2035
  }
2027
- updateJobProgress(jobId, {
2028
- status: "error",
2029
- resultMessage: "Job timed out. Please try again."
2030
- });
2031
2036
  }
2032
2037
 
2033
2038
  // src/api/tenants.ts