(gen, ctxId)
| 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; |
nothing calls this directly
no test coverage detected