@creaditor/business-ai 1.0.52 → 1.0.54

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.
@@ -23691,6 +23691,7 @@ async function IT(e) {
23691
23691
  return t.json();
23692
23692
  }
23693
23693
  async function xT(e) {
23694
+ var o;
23694
23695
  if (!e.prompt)
23695
23696
  throw new Error("generateNewsletterV3: prompt is required");
23696
23697
  const t = await fetch(Xn.STUDIO_NEWSLETTER_V3, {
@@ -23699,10 +23700,41 @@ async function xT(e) {
23699
23700
  body: JSON.stringify(AE(e))
23700
23701
  });
23701
23702
  if (!t.ok) {
23702
- const n = await t.text();
23703
- throw new Error(`studio newsletter v3 failed: ${t.status} ${n}`);
23704
- }
23705
- return t.json();
23703
+ const s = await t.text();
23704
+ throw new Error(`studio newsletter v3 failed: ${t.status} ${s}`);
23705
+ }
23706
+ console.log("[v3-sse] response status:", t.status, "content-type:", t.headers.get("content-type"));
23707
+ const n = t.body.getReader(), a = new TextDecoder();
23708
+ let r = "", l = null, i = 0;
23709
+ for (; ; ) {
23710
+ const { done: s, value: p } = await n.read();
23711
+ if (s) {
23712
+ console.log("[v3-sse] stream ended. total chunks:", i, "remaining buffer:", r.slice(0, 200));
23713
+ break;
23714
+ }
23715
+ const u = a.decode(p, { stream: !0 });
23716
+ console.log(`[v3-sse] chunk #${i}:`, u.slice(0, 300)), i++, r += u;
23717
+ const c = r.split(`
23718
+
23719
+ `);
23720
+ r = c.pop();
23721
+ for (const d of c) {
23722
+ const f = d.split(`
23723
+ `)[0];
23724
+ if (console.log("[v3-sse] event:", f), d.startsWith("event: done")) {
23725
+ const W = d.split(`
23726
+ data: `)[1];
23727
+ console.log("[v3-sse] done payload length:", W == null ? void 0 : W.length), l = JSON.parse(W);
23728
+ } else if (d.startsWith("event: error")) {
23729
+ const W = d.split(`
23730
+ data: `)[1];
23731
+ throw console.error("[v3-sse] error event:", W), new Error(JSON.parse(W).reason);
23732
+ }
23733
+ }
23734
+ }
23735
+ if (!l)
23736
+ throw console.error("[v3-sse] no done event received. buffer was:", r.slice(0, 500)), new Error("studio newsletter v3: stream ended without a done event");
23737
+ return console.log("[v3-sse] success, nodes count:", (o = l.nodes) == null ? void 0 : o.length), l;
23706
23738
  }
23707
23739
  function ET(e, t) {
23708
23740
  const n = e ?? {}, a = n.accountId || n.domain || n.websiteUrl || n.website || "", r = n.theme && typeof n.theme == "object" ? n.theme : { primary: "#1b65a0", secondary: "#841d94", colors: ["#1b65a0", "#ffffff"] }, l = {