@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.js +11 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/chat/store.ts +17 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ateam-ai-mobile/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
4
4
|
"description": "Headless ADAS SDK core — auth bridge, API client, chat/job streaming, MCP calls, theme tokens. No UI, no Expo dependencies.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/chat/store.ts
CHANGED
|
@@ -952,10 +952,26 @@ async function fetchTurnResult(jobId: string, jobSnap: any) {
|
|
|
952
952
|
// Polling fallback (when WS is unavailable)
|
|
953
953
|
// ---------------------------------------------------------------------------
|
|
954
954
|
|
|
955
|
+
/** Is this job's bubble still on screen waiting for its answer? (A chat cleared or a job that ended another way stops the poll.) */
|
|
956
|
+
function isWaitingOnScreen(jobId: string): boolean {
|
|
957
|
+
return useChatStore.getState().messages.some(m => {
|
|
958
|
+
const p = m.jobProgress;
|
|
959
|
+
return p?.jobId === jobId && p.status !== 'done' && p.status !== 'error' && p.status !== 'paused';
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/** Wait between two reads: 1.5 s, then 5 s once the job has run a few minutes. */
|
|
964
|
+
function pollDelayMs(attempt: number): number {
|
|
965
|
+
return attempt < 120 ? 1500 : 5000;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// No give-up time: a long job is still running, and saying "timed out" on a job that then finishes is a wrong statement. The poll ends
|
|
969
|
+
// when the job ends, when Core no longer knows it (404), or when its bubble is no longer waiting on screen.
|
|
955
970
|
async function pollJob(jobId: string, token: string | null) {
|
|
956
971
|
const { updateJobProgress } = useChatStore.getState();
|
|
957
972
|
|
|
958
|
-
for (let i = 0;
|
|
973
|
+
for (let i = 0; isWaitingOnScreen(jobId); i++) {
|
|
974
|
+
if (i > 0) await new Promise(r => setTimeout(r, pollDelayMs(i)));
|
|
959
975
|
try {
|
|
960
976
|
const res = await fetch(`${getCoreApiUrl()}/api/job/${jobId}/status`, {
|
|
961
977
|
headers: {
|
|
@@ -984,13 +1000,5 @@ async function pollJob(jobId: string, token: string | null) {
|
|
|
984
1000
|
return;
|
|
985
1001
|
}
|
|
986
1002
|
} catch {}
|
|
987
|
-
|
|
988
|
-
await new Promise(r => setTimeout(r, 1500));
|
|
989
1003
|
}
|
|
990
|
-
|
|
991
|
-
// Timeout
|
|
992
|
-
updateJobProgress(jobId, {
|
|
993
|
-
status: 'error',
|
|
994
|
-
resultMessage: 'Job timed out. Please try again.',
|
|
995
|
-
});
|
|
996
1004
|
}
|