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

Function _pollLoop

plugins/_plugin_validator/webui/plugin-validator-store.js:426–466  ·  view source on GitHub ↗
(gen, ctxId)

Source from the content-addressed store, hash-verified

424 },
425
426 async _pollLoop(gen, ctxId) {
427 let started = false;
428 const deadline = Date.now() + MAX_POLL_MS;
429 while (true) {
430 if (Date.now() >= deadline) {
431 if (gen === _pollGen) {
432 this.validating = false;
433 void toastFrontendError("Validation timed out while waiting for the agent response", "Plugin Validator");
434 console.error(`Validation poll timed out for context ${ctxId}`);
435 }
436 return;
437 }
438 await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
439 try {
440 const snapshot = await api.callJsonApi("/poll", {
441 context: ctxId,
442 log_from: 0,
443 notifications_from: 0,
444 timezone: getUserTimezone(),
445 });
446
447 if (gen === _pollGen && snapshot.logs?.length) {
448 const last = snapshot.logs
449 .filter((log) => log.type === "response" && log.no > 0)
450 .pop();
451 if (last) this.output = last.content || "";
452 }
453
454 if (snapshot.log_progress_active) started = true;
455 if (started && !snapshot.log_progress_active) {
456 if (gen === _pollGen) this.validating = false;
457 return;
458 }
459 if (snapshot.deselect_chat) return;
460 } catch (e) {
461 if (gen === _pollGen) {
462 console.error("Validation poll error:", e);
463 }
464 }
465 }
466 },
467
468 openChatInNewWindow() {
469 if (!this.validationCtxId) 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