From d175b3b9263bbd4ad91714b6c7ea80cd2fa09afb Mon Sep 17 00:00:00 2001 From: gator Date: Mon, 7 Sep 2026 21:25:52 +0000 Subject: [PATCH] Poll for the placement suggestion instead of waiting on it Matching pictures to the script is a model call and cannot answer inside the few seconds the API gateway allows, so it returned "Function timed out". It now starts in the background and this waits for it, the same way frames and joins already do. --- script.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/script.html b/script.html index c066ee0..6f90f17 100644 --- a/script.html +++ b/script.html @@ -366,6 +366,21 @@ function bindPics() { if (!PICS.length) { showMsg("msg", "Add a picture first."); return; } sg.disabled = true; sg.textContent = "Reading the script…"; var r = await api("suggest_image_placements", { email: email, project_id: pid }); + if (!r.ok) { sg.disabled = false; sg.textContent = "Suggest where they fit"; showMsg("msg", r.error || "Could not suggest."); return; } + // Reading the script is a model call, far too slow to answer inside one + // request, so it runs in the background and we wait for it here. + if (r.pending) { + document.getElementById("sugnote").textContent = r.status_text || "Reading the script…"; + var waited = 0; + r = await new Promise(function (done) { + var t = setInterval(async function () { + waited += 4; + var g = await api("suggest_image_placements", { email: email, project_id: pid }); + if (g.ok && !g.pending) { clearInterval(t); done(g); return; } + if (waited > 150) { clearInterval(t); done({ ok: false, error: "That is taking unusually long." }); } + }, 4000); + }); + } sg.disabled = false; sg.textContent = "Suggest where they fit"; document.getElementById("sugnote").textContent = r.status_text || ""; if (!r.ok) { showMsg("msg", r.error || "Could not suggest."); return; }