pxengine 0.1.112 → 0.1.113

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.cjs CHANGED
@@ -16835,6 +16835,10 @@ var FullscreenPreviewModal = ({ url, title, onClose }) => {
16835
16835
  ) })
16836
16836
  ] });
16837
16837
  };
16838
+ function deriveJobStatusUrl(newJobId, pollUrl, regenerateUrl) {
16839
+ const base = pollUrl?.replace(/\/api\/jobs\/[^/]+\/status.*$/, "") ?? regenerateUrl?.replace(/\/api\/reports\/[^/]+\/regenerate.*$/, "") ?? "";
16840
+ return `${base}/api/jobs/${newJobId}/status`;
16841
+ }
16838
16842
  var ResearchReportJobCard = (props) => {
16839
16843
  const {
16840
16844
  job_id,
@@ -16891,6 +16895,7 @@ var ResearchReportJobCard = (props) => {
16891
16895
  const [approving, setApproving] = (0, import_react79.useState)(false);
16892
16896
  const [regenerating, setRegenerating] = (0, import_react79.useState)(false);
16893
16897
  const [approveError, setApproveError] = (0, import_react79.useState)(null);
16898
+ const [regenPollUrl, setRegenPollUrl] = (0, import_react79.useState)(null);
16894
16899
  const previewRef = (0, import_react79.useRef)(null);
16895
16900
  const onCompleteRef = (0, import_react79.useRef)(onComplete);
16896
16901
  const onFailedRef = (0, import_react79.useRef)(onFailed);
@@ -17014,6 +17019,59 @@ var ResearchReportJobCard = (props) => {
17014
17019
  }
17015
17020
  // Transient fetch errors are ignored — the shared loop retries next tick.
17016
17021
  );
17022
+ const applyRegeneratedOutput = (0, import_react79.useCallback)(
17023
+ (out) => {
17024
+ if (out.html_url) setHtmlUrl(out.html_url);
17025
+ if (out.template_id) setTemplateId(out.template_id);
17026
+ setReviewStatus("pending_review");
17027
+ setTemplateVersionId("");
17028
+ if (out.section_count !== void 0) setSectionCount(out.section_count);
17029
+ if (out.title) setTitle(out.title);
17030
+ if (out.depth) setDepth(out.depth);
17031
+ if (out.theme) setTheme(out.theme);
17032
+ if (!onCompleteRef.current) return;
17033
+ onCompleteRef.current({
17034
+ title: out.title ?? title,
17035
+ depth: out.depth ?? depth,
17036
+ section_count: out.section_count ?? sectionCount,
17037
+ source_count: out.source_count ?? sourceCount,
17038
+ word_count: out.word_count ?? wordCount,
17039
+ executive_summary: out.executive_summary ?? summary,
17040
+ html_url: out.html_url ?? htmlUrl,
17041
+ generation_mode: "template",
17042
+ template_id: out.template_id ?? templateId,
17043
+ template_version_id: void 0,
17044
+ review_status: "pending_review",
17045
+ theme: out.theme ?? theme
17046
+ });
17047
+ },
17048
+ [title, depth, sectionCount, sourceCount, wordCount, summary, htmlUrl, templateId, theme]
17049
+ );
17050
+ useSharedPoll(
17051
+ {
17052
+ key: regenPollUrl,
17053
+ intervalMs: 3e3,
17054
+ fetcher: async () => {
17055
+ const headers = {};
17056
+ if (authToken) headers["Authorization"] = `Bearer ${authToken}`;
17057
+ const res = await fetch(regenPollUrl, { headers });
17058
+ if (!res.ok) throw new Error(`poll ${res.status}`);
17059
+ return res.json();
17060
+ },
17061
+ shouldContinue: (data) => data.status !== "complete" && data.status !== "failed"
17062
+ },
17063
+ (data) => {
17064
+ if (data.status === "complete") {
17065
+ if (data.output) applyRegeneratedOutput(data.output);
17066
+ setRegenPollUrl(null);
17067
+ setRegenerating(false);
17068
+ } else if (data.status === "failed") {
17069
+ setApproveError(data.error || "Could not switch template");
17070
+ setRegenPollUrl(null);
17071
+ setRegenerating(false);
17072
+ }
17073
+ }
17074
+ );
17017
17075
  const formatWordCount = (count) => {
17018
17076
  if (count >= 1e3) return `${(count / 1e3).toFixed(1)}k`;
17019
17077
  return count.toString();
@@ -17247,32 +17305,14 @@ var ResearchReportJobCard = (props) => {
17247
17305
  throw new Error(err.detail || err.error || `Regenerate failed (${res.status})`);
17248
17306
  }
17249
17307
  const data = await res.json();
17250
- const out = data.output || data;
17251
- if (out.html_url) setHtmlUrl(out.html_url);
17252
- if (data.template_id || out.template_id) setTemplateId(data.template_id || out.template_id);
17253
- setReviewStatus("pending_review");
17254
- setTemplateVersionId("");
17255
- if (out.section_count !== void 0) setSectionCount(out.section_count);
17256
- if (out.title) setTitle(out.title);
17257
- if (onCompleteRef.current) {
17258
- onCompleteRef.current({
17259
- title: out.title || title,
17260
- depth,
17261
- section_count: out.section_count ?? sectionCount,
17262
- source_count: sourceCount,
17263
- word_count: wordCount,
17264
- executive_summary: summary,
17265
- html_url: out.html_url || htmlUrl,
17266
- generation_mode: "template",
17267
- template_id: data.template_id || out.template_id || templateId,
17268
- template_version_id: void 0,
17269
- review_status: "pending_review",
17270
- theme
17271
- });
17308
+ if (typeof data.job_id === "string" && data.job_id !== job_id) {
17309
+ setRegenPollUrl(deriveJobStatusUrl(data.job_id, pollUrl, regenerateUrl));
17310
+ return;
17272
17311
  }
17312
+ applyRegeneratedOutput(data.output || data);
17313
+ setRegenerating(false);
17273
17314
  } catch (e) {
17274
17315
  setApproveError(e instanceof Error ? e.message : "Could not switch template");
17275
- } finally {
17276
17316
  setRegenerating(false);
17277
17317
  }
17278
17318
  };