MCPcopy Index your code
hub / github.com/agent0ai/agent-zero / _pollLoop

Function _pollLoop

plugins/_plugin_scan/webui/plugin-scan-store.js:213–247  ·  view source on GitHub ↗

@param {number} gen @param {string} ctxId

(gen, ctxId)

Source from the content-addressed store, hash-verified

211
212 /** @param {number} gen @param {string} ctxId */
213 async _pollLoop(gen, ctxId) {
214 let started = false;
215 const deadline = Date.now() + MAX_POLL_MS;
216 while (true) {
217 if (Date.now() >= deadline) {
218 if (gen === _pollGen) {
219 this.scanning = false;
220 void toastFrontendError("Scan timed out while waiting for the agent response", SCAN_TITLE);
221 console.error(`Scan poll timed out for context ${ctxId}`);
222 }
223 return;
224 }
225 await new Promise((r) => setTimeout(r, POLL_INTERVAL));
226 try {
227 const snap = await api.callJsonApi("/poll", {
228 context: ctxId, log_from: 0, notifications_from: 0,
229 timezone: getUserTimezone(),
230 });
231
232 if (gen === _pollGen && snap.logs?.length) {
233 const last = snap.logs.filter((/** @type {any} */ l) => l.type === "response" && l.no > 0).pop();
234 if (last) this.output = last.content || "";
235 }
236
237 if (snap.log_progress_active) started = true;
238 if (started && !snap.log_progress_active) {
239 if (gen === _pollGen) this.scanning = false;
240 return;
241 }
242 if (snap.deselect_chat) return;
243 } catch (/** @type {any} */ e) {
244 if (gen === _pollGen) console.error("Poll error:", e);
245 }
246 }
247 },
248
249 openChatInNewWindow() {
250 if (!this.scanCtxId) return;

Callers

nothing calls this directly

Calls 4

getUserTimezoneFunction · 0.90
popMethod · 0.80
nowMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected