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.mjs CHANGED
@@ -16503,6 +16503,10 @@ var FullscreenPreviewModal = ({ url, title, onClose }) => {
16503
16503
  ) })
16504
16504
  ] });
16505
16505
  };
16506
+ function deriveJobStatusUrl(newJobId, pollUrl, regenerateUrl) {
16507
+ const base = pollUrl?.replace(/\/api\/jobs\/[^/]+\/status.*$/, "") ?? regenerateUrl?.replace(/\/api\/reports\/[^/]+\/regenerate.*$/, "") ?? "";
16508
+ return `${base}/api/jobs/${newJobId}/status`;
16509
+ }
16506
16510
  var ResearchReportJobCard = (props) => {
16507
16511
  const {
16508
16512
  job_id,
@@ -16559,6 +16563,7 @@ var ResearchReportJobCard = (props) => {
16559
16563
  const [approving, setApproving] = useState11(false);
16560
16564
  const [regenerating, setRegenerating] = useState11(false);
16561
16565
  const [approveError, setApproveError] = useState11(null);
16566
+ const [regenPollUrl, setRegenPollUrl] = useState11(null);
16562
16567
  const previewRef = useRef7(null);
16563
16568
  const onCompleteRef = useRef7(onComplete);
16564
16569
  const onFailedRef = useRef7(onFailed);
@@ -16682,6 +16687,59 @@ var ResearchReportJobCard = (props) => {
16682
16687
  }
16683
16688
  // Transient fetch errors are ignored — the shared loop retries next tick.
16684
16689
  );
16690
+ const applyRegeneratedOutput = useCallback5(
16691
+ (out) => {
16692
+ if (out.html_url) setHtmlUrl(out.html_url);
16693
+ if (out.template_id) setTemplateId(out.template_id);
16694
+ setReviewStatus("pending_review");
16695
+ setTemplateVersionId("");
16696
+ if (out.section_count !== void 0) setSectionCount(out.section_count);
16697
+ if (out.title) setTitle(out.title);
16698
+ if (out.depth) setDepth(out.depth);
16699
+ if (out.theme) setTheme(out.theme);
16700
+ if (!onCompleteRef.current) return;
16701
+ onCompleteRef.current({
16702
+ title: out.title ?? title,
16703
+ depth: out.depth ?? depth,
16704
+ section_count: out.section_count ?? sectionCount,
16705
+ source_count: out.source_count ?? sourceCount,
16706
+ word_count: out.word_count ?? wordCount,
16707
+ executive_summary: out.executive_summary ?? summary,
16708
+ html_url: out.html_url ?? htmlUrl,
16709
+ generation_mode: "template",
16710
+ template_id: out.template_id ?? templateId,
16711
+ template_version_id: void 0,
16712
+ review_status: "pending_review",
16713
+ theme: out.theme ?? theme
16714
+ });
16715
+ },
16716
+ [title, depth, sectionCount, sourceCount, wordCount, summary, htmlUrl, templateId, theme]
16717
+ );
16718
+ useSharedPoll(
16719
+ {
16720
+ key: regenPollUrl,
16721
+ intervalMs: 3e3,
16722
+ fetcher: async () => {
16723
+ const headers = {};
16724
+ if (authToken) headers["Authorization"] = `Bearer ${authToken}`;
16725
+ const res = await fetch(regenPollUrl, { headers });
16726
+ if (!res.ok) throw new Error(`poll ${res.status}`);
16727
+ return res.json();
16728
+ },
16729
+ shouldContinue: (data) => data.status !== "complete" && data.status !== "failed"
16730
+ },
16731
+ (data) => {
16732
+ if (data.status === "complete") {
16733
+ if (data.output) applyRegeneratedOutput(data.output);
16734
+ setRegenPollUrl(null);
16735
+ setRegenerating(false);
16736
+ } else if (data.status === "failed") {
16737
+ setApproveError(data.error || "Could not switch template");
16738
+ setRegenPollUrl(null);
16739
+ setRegenerating(false);
16740
+ }
16741
+ }
16742
+ );
16685
16743
  const formatWordCount = (count) => {
16686
16744
  if (count >= 1e3) return `${(count / 1e3).toFixed(1)}k`;
16687
16745
  return count.toString();
@@ -16915,32 +16973,14 @@ var ResearchReportJobCard = (props) => {
16915
16973
  throw new Error(err.detail || err.error || `Regenerate failed (${res.status})`);
16916
16974
  }
16917
16975
  const data = await res.json();
16918
- const out = data.output || data;
16919
- if (out.html_url) setHtmlUrl(out.html_url);
16920
- if (data.template_id || out.template_id) setTemplateId(data.template_id || out.template_id);
16921
- setReviewStatus("pending_review");
16922
- setTemplateVersionId("");
16923
- if (out.section_count !== void 0) setSectionCount(out.section_count);
16924
- if (out.title) setTitle(out.title);
16925
- if (onCompleteRef.current) {
16926
- onCompleteRef.current({
16927
- title: out.title || title,
16928
- depth,
16929
- section_count: out.section_count ?? sectionCount,
16930
- source_count: sourceCount,
16931
- word_count: wordCount,
16932
- executive_summary: summary,
16933
- html_url: out.html_url || htmlUrl,
16934
- generation_mode: "template",
16935
- template_id: data.template_id || out.template_id || templateId,
16936
- template_version_id: void 0,
16937
- review_status: "pending_review",
16938
- theme
16939
- });
16976
+ if (typeof data.job_id === "string" && data.job_id !== job_id) {
16977
+ setRegenPollUrl(deriveJobStatusUrl(data.job_id, pollUrl, regenerateUrl));
16978
+ return;
16940
16979
  }
16980
+ applyRegeneratedOutput(data.output || data);
16981
+ setRegenerating(false);
16941
16982
  } catch (e) {
16942
16983
  setApproveError(e instanceof Error ? e.message : "Could not switch template");
16943
- } finally {
16944
16984
  setRegenerating(false);
16945
16985
  }
16946
16986
  };