@danhachuel/prodmaker 0.1.12 → 0.1.13

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/CHANGELOG.md CHANGED
@@ -3,6 +3,23 @@
3
3
  Todas as versões seguem a etiqueta visual `MAJOR.MINOR.PATCH` com patch de dois dígitos
4
4
  (o registry NPM normaliza `0.1.00` → `0.1.0`).
5
5
 
6
+ ## 0.1.13 — 2026-10-31
7
+
8
+ - **Fase 10 — Product Builder Wizard (motor de criação de ofertas).**
9
+ - Studio substituído pelo **Wizard de 3 passos**: (1) mineração de **5 ofertas validadas**
10
+ a partir do nicho (promessa, dores, entregáveis, bônus, preço R$27–97) + registro do
11
+ **Parceiro 50/50**; (2) **estrutura** (módulos com aulas, e-books, ferramentas, **Quiz
12
+ com IA** e **3 Order Bumps** — checkout +R$21,90, upsell +R$197, parceiro 50/50) +
13
+ precificação com trava de faixa; (3) **12 anúncios** (Prova social/material/lógica,
14
+ Desafio-garantia, Comparação isso-vs-aquilo) com cópia por anúncio + **exportação de PDF**
15
+ (Markdown → HTML A4 → PDF) e **prompts de imagem** para Gamma/Canva.
16
+ - Backend: `services/builder.py` + `api/builder.py` (`POST /api/builder/generate-offers`,
17
+ `/generate-structure`, `/generate-ads`, `/generate-pdf`, `/salvar`). Tudo é salvo em
18
+ `infoprodutos` (novas colunas `oferta_json`, `estrutura_json`, `anuncios_json`, `preco`,
19
+ `parceiro` com migração automática) para AdsPages/AdsCreator consumirem.
20
+ - Novos prompts no seed: `builder-ofertas.md`, `builder-estrutura.md`, `builder-anuncios.md`.
21
+ - Rota `/studio` agora abre o Wizard; barra de progresso com "passo X de 3".
22
+
6
23
  ## 0.1.12 — 2026-10-31
7
24
 
8
25
  - **Parte 10 — Polish E2E + OAuth Google 1 clique + radar Supabase + ROAS real.**
@@ -0,0 +1,81 @@
1
+ """Product Builder Wizard — 4 rotas de LLM + geração de PDF (Fase 10)."""
2
+ from fastapi import APIRouter, HTTPException
3
+ from pydantic import BaseModel
4
+
5
+ from ..services import builder
6
+ from ..services.llm import LLMError
7
+
8
+ router = APIRouter(prefix="/api/builder", tags=["builder"])
9
+
10
+
11
+ class OfertasBody(BaseModel):
12
+ nicho: str
13
+ avatar: str = ""
14
+
15
+
16
+ class EstruturaBody(BaseModel):
17
+ oferta: dict
18
+
19
+
20
+ class AnunciosBody(BaseModel):
21
+ produto: str
22
+ promessa: str = ""
23
+ nicho: str = ""
24
+ link: str = ""
25
+
26
+
27
+ class PdfBody(BaseModel):
28
+ oferta: dict
29
+ estrutura: dict
30
+ preco: float
31
+ parceiro: str = ""
32
+ modo: str = "rapido"
33
+
34
+
35
+ class SalvarBody(BaseModel):
36
+ record_id: int
37
+ anuncios: list
38
+
39
+
40
+ def _erro(exc: LLMError) -> HTTPException:
41
+ return HTTPException(status_code=400, detail=str(exc))
42
+
43
+
44
+ @router.post("/generate-offers")
45
+ def generate_offers(body: OfertasBody):
46
+ try:
47
+ return builder.gerar_ofertas(body.nicho, body.avatar)
48
+ except LLMError as exc:
49
+ raise _erro(exc)
50
+
51
+
52
+ @router.post("/generate-structure")
53
+ def generate_structure(body: EstruturaBody):
54
+ try:
55
+ return builder.gerar_estrutura(body.oferta)
56
+ except LLMError as exc:
57
+ raise _erro(exc)
58
+
59
+
60
+ @router.post("/generate-ads")
61
+ def generate_ads(body: AnunciosBody):
62
+ try:
63
+ return builder.gerar_anuncios(body.produto, body.promessa, body.nicho, body.link)
64
+ except LLMError as exc:
65
+ raise _erro(exc)
66
+
67
+
68
+ @router.post("/generate-pdf")
69
+ def generate_pdf(body: PdfBody):
70
+ try:
71
+ return builder.gerar_pdf(body.oferta, body.estrutura, body.preco, body.parceiro, body.modo)
72
+ except LLMError as exc:
73
+ raise _erro(exc)
74
+
75
+
76
+ @router.post("/salvar")
77
+ def salvar(body: SalvarBody):
78
+ try:
79
+ return builder.salvar(body.anuncios, body.record_id)
80
+ except (LLMError, ValueError) as exc:
81
+ raise HTTPException(status_code=400, detail=str(exc))
package/app/main.py CHANGED
@@ -15,7 +15,7 @@ from .services.database import ensure_db, get_db, now_str, row_to_dict
15
15
  from .services.llm import LLMError, analyze_product, list_providers
16
16
  from .services.store import PRODMAKER_HOME, STORAGE, STATE, ensure_state_dir, get_master_code, get_settings, save_settings
17
17
 
18
- APP_VERSION = "0.1.12"
18
+ APP_VERSION = "0.1.13"
19
19
  COOKIE_NAME = "prodmaker_session"
20
20
  SESSION_DAYS = 30
21
21
  MASTER_ALIAS = "admin"
@@ -40,6 +40,7 @@ from .api import logs as logs_router # noqa: E402
40
40
  from .api import guias as guias_router # noqa: E402
41
41
  from .api import contas as contas_router # noqa: E402
42
42
  from .api import invest as invest_router # noqa: E402
43
+ from .api import builder as builder_router # noqa: E402
43
44
 
44
45
  app.include_router(llm_router.router)
45
46
  app.include_router(infoprodutos_router.router)
@@ -56,6 +57,7 @@ app.include_router(logs_router.router)
56
57
  app.include_router(guias_router.router)
57
58
  app.include_router(contas_router.router)
58
59
  app.include_router(invest_router.router)
60
+ app.include_router(builder_router.router)
59
61
 
60
62
  ensure_db()
61
63
 
@@ -262,7 +264,7 @@ def health():
262
264
 
263
265
  @app.get("/api/version")
264
266
  def version():
265
- return {"version": APP_VERSION, "canonical": "0.1.12"}
267
+ return {"version": APP_VERSION, "canonical": "0.1.13"}
266
268
 
267
269
 
268
270
  @app.get("/api/settings")
@@ -0,0 +1,217 @@
1
+ """Product Builder Wizard — motor de criação de ofertas (Fase 10).
2
+
3
+ Fluxo: 5 ofertas (nicho) -> estrutura + quiz + 3 order bumps -> 12 anuncios ->
4
+ PDF (Markdown -> HTML -> PDF) -> salva em infoprodutos + produto (AdsPages/AdsCreator
5
+ consomem automaticamente).
6
+ """
7
+ import json
8
+ import re
9
+ from pathlib import Path
10
+
11
+ from .database import get_db, now_str, row_to_dict
12
+ from .llm import LLMError, generate
13
+ from .pdf import markdown_para_pdf
14
+ from .store import STORAGE
15
+
16
+ SEED_DIR = Path(__file__).resolve().parent.parent.parent / "seed"
17
+
18
+
19
+ def _template(nome: str, fallback: str) -> str:
20
+ path = SEED_DIR / "prompts" / nome
21
+ return path.read_text(encoding="utf-8") if path.exists() else fallback
22
+
23
+
24
+ def _fill(template: str, values: dict) -> str:
25
+ for key, value in values.items():
26
+ template = template.replace("{" + key + "}", str(value or ""))
27
+ return template
28
+
29
+
30
+ def _parse_json(text: str) -> dict:
31
+ cleaned = re.sub(r"```(?:json)?", "", text).strip()
32
+ match = re.search(r"\{.*\}", cleaned, re.DOTALL)
33
+ if not match:
34
+ raise LLMError("A resposta do LLM não contém JSON válido.")
35
+ return json.loads(match.group(0))
36
+
37
+
38
+ def _limit_ofertas(ofertas: list) -> list:
39
+ normalizadas = []
40
+ for item in ofertas[:5]:
41
+ if not isinstance(item, dict) or not (item.get("promessa") or "").strip():
42
+ continue
43
+ normalizadas.append({
44
+ "nome": (item.get("nome") or "Oferta").strip()[:80],
45
+ "promessa": (item.get("promessa") or "").strip(),
46
+ "dores": [str(item) for item in (item.get("dores") or [])][:6],
47
+ "entregaveis": [str(item) for item in (item.get("entregaveis") or [])][:8],
48
+ "bonus": [str(item) for item in (item.get("bonus") or [])][:4],
49
+ "preco_sugerido": float(item.get("preco_sugerido") or 47),
50
+ "formato": (item.get("formato") or "E-book").strip(),
51
+ "publico": (item.get("publico") or "").strip(),
52
+ })
53
+ return normalizadas
54
+
55
+
56
+ def gerar_ofertas(nicho: str, avatar: str = "") -> dict:
57
+ nicho = (nicho or "").strip()
58
+ if not nicho:
59
+ raise LLMError("Informe o nicho para gerar as ofertas.")
60
+ prompt = _fill(
61
+ _template("builder-ofertas.md", "Gere 5 ofertas low-ticket para o nicho {NICHO} em JSON com chave 'ofertas'."),
62
+ {"NICHO": nicho, "AVATAR": avatar or "empreendedores e afiliados do nicho"},
63
+ )
64
+ result = generate(prompt, system="Você é um estrategista de ofertas low-ticket. Responda SOMENTE JSON válido.", max_tokens=4000)
65
+ try:
66
+ parsed = _parse_json(result["text"])
67
+ except json.JSONDecodeError as exc:
68
+ raise LLMError(f"JSON do LLM inválido: {exc}") from exc
69
+ ofertas = _limit_ofertas(parsed.get("ofertas") or [])
70
+ if not ofertas:
71
+ raise LLMError("O LLM não retornou ofertas utilizáveis — tente novamente.")
72
+ return {"ofertas": ofertas, "provider": result["provider"]}
73
+
74
+
75
+ def gerar_estrutura(oferta: dict) -> dict:
76
+ if not oferta or not (oferta.get("promessa") or "").strip():
77
+ raise LLMError("Selecione uma oferta antes de gerar a estrutura.")
78
+ prompt = _fill(
79
+ _template("builder-estrutura.md", "Gere a estrutura do produto para {OFERTA} em JSON."),
80
+ {
81
+ "OFERTA": oferta.get("nome") or "",
82
+ "PROMESSA": oferta.get("promessa") or "",
83
+ "NICHO": oferta.get("publico") or (oferta.get("dores") or [""])[0],
84
+ "AVATAR": oferta.get("publico") or "",
85
+ },
86
+ )
87
+ result = generate(prompt, system="Você é um especialista em produtos digitais. Responda SOMENTE JSON válido.", max_tokens=6000)
88
+ try:
89
+ estrutura = _parse_json(result["text"])
90
+ except json.JSONDecodeError as exc:
91
+ raise LLMError(f"JSON do LLM inválido: {exc}") from exc
92
+ if not estrutura.get("modulos"):
93
+ raise LLMError("O LLM não retornou módulos — tente novamente.")
94
+ return {"estrutura": estrutura, "provider": result["provider"]}
95
+
96
+
97
+ def gerar_anuncios(produto: str, promessa: str, nicho: str = "", link: str = "") -> dict:
98
+ if not produto.strip():
99
+ raise LLMError("Informe o nome do produto para gerar os anúncios.")
100
+ prompt = _fill(
101
+ _template("builder-anuncios.md", "Gere 12 anuncios para {PRODUTO} em JSON com chave 'anuncios'."),
102
+ {"PRODUTO": produto, "PROMESSA": promessa, "NICHO": nicho, "LINK": link},
103
+ )
104
+ result = generate(prompt, system="Você é um copywriter de direct response. Responda SOMENTE JSON válido.", max_tokens=5000)
105
+ try:
106
+ parsed = _parse_json(result["text"])
107
+ except json.JSONDecodeError as exc:
108
+ raise LLMError(f"JSON do LLM inválido: {exc}") from exc
109
+ anuncios = [item for item in (parsed.get("anuncios") or []) if isinstance(item, dict)]
110
+ if len(anuncios) < 12:
111
+ raise LLMError(f"O LLM retornou {len(anuncios)} anúncios (esperado 12) — tente novamente.")
112
+ return {"anuncios": anuncios[:12], "provider": result["provider"]}
113
+
114
+
115
+ def _imagem_prompts(oferta: dict, estrutura: dict) -> list[str]:
116
+ prompts = [
117
+ f"Capa de e-book high-conversion para '{oferta.get('nome')}' ({oferta.get('formato')}), promessa: {oferta.get('promessa')}",
118
+ f"Mockup 3D do produto '{oferta.get('nome')}' para página de vendas, fundo claro, estilo premium",
119
+ ]
120
+ for bonus in (oferta.get("bonus") or [])[:2]:
121
+ prompts.append(f"Capa do bônus '{bonus}', estilo coeso com a capa principal")
122
+ for modulo in (estrutura.get("modulos") or [])[:3]:
123
+ prompts.append(f"Imagem de módulo: {modulo.get('titulo')}")
124
+ return prompts
125
+
126
+
127
+ def _markdown_produto(oferta: dict, estrutura: dict, preco: float, parceiro: str) -> str:
128
+ linhas = [f"# {oferta.get('nome') or 'Produto'}", "", f"**Promessa:** {oferta.get('promessa')}", ""]
129
+ if oferta.get("publico"):
130
+ linhas += [f"**Público:** {oferta['publico']}", ""]
131
+ linhas += ["## Módulos", ""]
132
+ for modulo in estrutura.get("modulos") or []:
133
+ linhas.append(f"### {modulo.get('titulo')}")
134
+ for aula in modulo.get("aulas") or []:
135
+ linhas.append(f"- {aula}")
136
+ linhas.append("")
137
+ if estrutura.get("ebooks"):
138
+ linhas += ["## E-books inclusos", ""] + [f"- {item}" for item in estrutura["ebooks"]] + [""]
139
+ if estrutura.get("ferramentas"):
140
+ linhas += ["## Ferramentas e planilhas", ""] + [f"- {item}" for item in estrutura["ferramentas"]] + [""]
141
+ linhas += ["## Order Bumps", ""]
142
+ for bump in estrutura.get("order_bumps") or []:
143
+ linhas.append(f"- **{bump.get('tipo')}**: {bump.get('nome')} — {bump.get('descricao')}")
144
+ linhas += ["", f"## Preço", "", f"**R$ {preco:.2f}**", ""]
145
+ if parceiro:
146
+ linhas += [f"## Parceiro 50/50", "", parceiro, ""]
147
+ return "\n".join(linhas)
148
+
149
+
150
+ def _ensure_columns() -> None:
151
+ from .dbengine import add_column_if_missing
152
+
153
+ with get_db() as conn:
154
+ add_column_if_missing(conn, "infoprodutos", "oferta_json TEXT NOT NULL DEFAULT ''", "oferta_json")
155
+ add_column_if_missing(conn, "infoprodutos", "estrutura_json TEXT NOT NULL DEFAULT ''", "estrutura_json")
156
+ add_column_if_missing(conn, "infoprodutos", "anuncios_json TEXT NOT NULL DEFAULT ''", "anuncios_json")
157
+ add_column_if_missing(conn, "infoprodutos", "preco REAL NOT NULL DEFAULT 0", "preco")
158
+ add_column_if_missing(conn, "infoprodutos", "parceiro TEXT NOT NULL DEFAULT ''", "parceiro")
159
+
160
+
161
+ def gerar_pdf(oferta: dict, estrutura: dict, preco: float, parceiro: str = "", modo: str = "rapido") -> dict:
162
+ """Gera o PDF do produto + prompts de imagem (Gamma/Canva). Salva em infoprodutos."""
163
+ _ensure_columns()
164
+ md_text = _markdown_produto(oferta, estrutura, preco, parceiro)
165
+ prompt_imagens = _imagem_prompts(oferta, estrutura)
166
+ timestamp = now_str()
167
+ with get_db() as conn:
168
+ cursor = conn.execute(
169
+ "INSERT INTO infoprodutos (titulo, formato, nicho, modo, provider, created_at) VALUES (?, ?, ?, '', 'builder', ?)",
170
+ ((oferta.get("nome") or "Produto")[:120], oferta.get("formato") or "E-book", (oferta.get("publico") or "")[:80], timestamp),
171
+ )
172
+ record_id = cursor.lastrowid
173
+
174
+ pasta = STORAGE / "produtos" / str(record_id)
175
+ pasta.mkdir(parents=True, exist_ok=True)
176
+ md_path = pasta / "infoproduto.md"
177
+ md_path.write_text(md_text, encoding="utf-8")
178
+ pdf_path = None
179
+ erro_pdf = ""
180
+ if modo != "somente_markdown":
181
+ try:
182
+ pdf_path = markdown_para_pdf(md_text, pasta / "infoproduto.pdf")
183
+ except RuntimeError as exc:
184
+ erro_pdf = str(exc)
185
+
186
+ with get_db() as conn:
187
+ conn.execute(
188
+ "UPDATE infoprodutos SET oferta_json = ?, estrutura_json = ?, preco = ?, parceiro = ?, md_path = ?, pdf_path = ? WHERE id = ?",
189
+ (
190
+ json.dumps(oferta, ensure_ascii=False),
191
+ json.dumps(estrutura, ensure_ascii=False),
192
+ float(preco or 0),
193
+ parceiro or "",
194
+ md_path.relative_to(STORAGE).as_posix(),
195
+ pdf_path.relative_to(STORAGE).as_posix() if pdf_path else "",
196
+ record_id,
197
+ ),
198
+ )
199
+ row = conn.execute("SELECT * FROM infoprodutos WHERE id = ?", (record_id,)).fetchone()
200
+ record = row_to_dict(row)
201
+ record["markdown"] = md_text
202
+ record["imagem_prompts"] = prompt_imagens
203
+ record["erro_pdf"] = erro_pdf
204
+ return record
205
+
206
+
207
+ def salvar(anuncios: list, record_id: int) -> dict:
208
+ _ensure_columns()
209
+ with get_db() as conn:
210
+ conn.execute(
211
+ "UPDATE infoprodutos SET anuncios_json = ? WHERE id = ?",
212
+ (json.dumps(anuncios[:12], ensure_ascii=False), record_id),
213
+ )
214
+ row = conn.execute("SELECT * FROM infoprodutos WHERE id = ?", (record_id,)).fetchone()
215
+ record = row_to_dict(row)
216
+ oferta = json.loads(record.get("oferta_json") or "{}")
217
+ return {**record, "oferta": oferta}