system-prompts-and-models-o.../dealix/api/routers/service_excellence.py
Dealix Builder e106a9a0d2 feat(targeting+service+excellence): Saudi Targeting OS + Service Tower + Service Excellence — 38 modules + 62 endpoints + 105 tests
Targeting & Acquisition OS (16 modules) — نظام الاستهداف الذكي
- account_finder: account-first targeting; 12 buying signals; deterministic 10-25 accounts per (sector, city)
- buyer_role_mapper: 14 buyer roles + sector-specific buying-committee maps + role-based Arabic angles
- contact_source_policy: 12 sources (crm_customer→opt_out) with risk_score, channels-allowed, retention guidance, lawful_basis
- contactability_matrix: 5 action modes (suggest_only/draft_only/approval_required/approved_execute/blocked); opt-out always blocked
- linkedin_strategy: Lead Forms + Ads + manual ONLY; linkedin_do_not_do() locks scrape/auto-DM/auto-connect/extensions
- email_strategy: drafts + unsubscribe footer + domain-pacing (fresh/warmed/trusted/damaged) + spam-trigger risk
- whatsapp_strategy: opt-in only; rejects cold + risky phrases; opt-in template requires explicit purpose+company+unsubscribe
- social_strategy: official APIs only; listening + drafts; no auto-publish
- outreach_scheduler: day-by-day plans + daily limits + opt-out enforcement
- reputation_guard: bounce/complaint/opt-out thresholds → healthy/watch/pause + recovery actions per channel
- daily_autopilot: Arabic brief + 7 today actions + EOD report
- acquisition_scorecard: pipeline + meetings + risks + productivity_score
- self_growth_mode: 5 ICP focuses for Dealix; daily brief + monthly targets
- free_diagnostic: Free Growth Diagnostic (3 ops + msg + risk + plan) → paid pilot recommendation
- contract_drafts: Pilot/DPA/Referral/Agency/SOW outlines (legal_review_required, PDPL-aware)
- service_offers: 7 targeting-tier offers + recommend by customer-type

Service Tower (8 modules) — برج الخدمات الذاتية (12 productized services)
- service_catalog: 12 services with target_customer/outcome/inputs/workflow/deliverables/pricing/risk/proof/upgrade
- service_wizard: deterministic recommend (agency→partner; list→list_intelligence; founder→self_growth; CEO→exec_brief; budget≥2999→growth_os; default→first_10)
- mission_templates: workflow steps with approval gates + linked growth missions
- pricing_engine: SAR quotes scaled by company_size×urgency×channels_count + setup_fee + monthly_offer
- deliverables: client report outline + proof pack template + operator checklist (no live actions)
- service_scorecard: 0..100 score from drafts/replies/meetings/pipeline/CSAT
- whatsapp_ceo_control: daily brief, approval cards (≤3 buttons), risk alerts, EOD reports
- upgrade_paths: deterministic next-service recommendation + Arabic upsell messages

Service Excellence OS (8 modules) — مصنع الخدمات الممتازة
- feature_matrix: 12 must-have features per service + advanced/premium/future tiers
- service_scoring: 10-dimension excellence score (clarity, speed_to_value, automation, compliance, proof, upsell, uniqueness, scalability, ops_daily, proof_data) → launch_ready/beta_only/needs_work
- quality_review: 4 gates (proof / approval / pricing / channels) + status verdict; review_service_before_launch and review/all
- competitor_gap: 7 competitor categories (CRM, WhatsApp tools, email assistants, LinkedIn tools, agencies, revenue intelligence, generic AI) + Dealix advantages + do-not-copy
- proof_metrics: required metrics + ROI estimate (pipeline_x + closed_won_x) + Arabic summary
- research_lab: monthly brief + feature hypotheses + top-3 experiments + monthly review
- service_improvement_backlog: feedback→backlog conversion + impact/effort prioritization + weekly improvements
- launch_package: landing outline + sales script + 12-min demo script + 5-day onboarding checklist

Routers (3 new) — 62 endpoints
- /api/v1/targeting/* — 20 endpoints (accounts, buying-committee, contacts, uploaded-list, outreach, daily-autopilot, self-growth, reputation, linkedin, drafts, free-diagnostic, services, contracts)
- /api/v1/services/* — 20 endpoints (catalog, recommend, intake, start, workflow, deliverables, proof-pack, quote, setup-fee, monthly-offer, scorecard, upgrade-path, ceo daily-brief/approval-card/risk-alert/EOD)
- /api/v1/service-excellence/* — 22 endpoints (feature-matrix, score, quality-review, review/all, proof-metrics, roi-estimate, gap-analysis, research-brief, hypotheses, experiments, monthly-review, backlog, weekly-improvements, launch-package, landing/sales/demo/onboarding)

Tests (3 new files, 105 tests)
- test_targeting_os: 47 tests (Arabic accounts, buying committees, opt-out blocked, cold WA blocked, LinkedIn no-scraping, email unsubscribe, WA risk, outreach plan, reputation guard, self-growth, contracts, scorecard)
- test_service_tower: 38 tests (12+ services, all have pricing/proof/deliverables/approval, wizard recommendations, workflow includes approval, quote scales, CEO cards ≤3 buttons, no live send)
- test_service_excellence: 33 tests (feature matrix, score returns status, ALL services pass quality gates, ROI x-multiples, 7 competitor categories, hypotheses+experiments, backlog conversion, launch package complete, demo=12min)

Docs (3 new + 1 updated)
- TARGETING_ACQUISITION_OS.md (Arabic)
- SERVICE_TOWER_STRATEGY.md (Arabic)
- SERVICE_EXCELLENCE_OS.md (Arabic)
- DEALIX_100_PERCENT_LAUNCH_PLAN.md — added §36 Targeting OS + §37 Service Tower + §38 Service Excellence + §39 Landing Pages

Landing pages (4 new, RTL Arabic)
- services.html — 3 doors + 12 productized services
- free-diagnostic.html — free growth diagnostic
- first-10-opportunities.html — kill feature
- agency-partner.html — agency partner program

Test results
- 105/105 new tests pass
- Full suite: 768 passed, 2 skipped
- 0 existing tests broken

Safety + integration with previous layers
- Targeting OS uses contactability_matrix → ALL contacts gated before any send
- Service Tower's workflow includes approval gate; ALL services live_send_allowed=False
- Service Excellence quality_review BLOCKS launch on missing proof/approval/pricing/unsafe channels
- linkedin_do_not_do() encodes 8 explicit prohibitions (scraping/auto-DM/auto-connect/extensions)
- whatsapp_do_not_do() blocks cold sends + group scraping
- Contracts always: legal_review_required=True, not_legal_advice=True, PDPL sections present
- Self-Growth Mode lets Dealix target its OWN ICP using the same approval-first pipeline

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 17:11:00 +03:00

180 lines
6.4 KiB
Python

"""Service Excellence OS router — feature matrix + score + gates + research."""
from __future__ import annotations
from typing import Any
from fastapi import APIRouter, Body
from auto_client_acquisition.service_excellence import (
build_backlog,
build_demo_script,
build_feature_matrix,
build_landing_page_outline,
build_monthly_service_review,
build_onboarding_checklist,
build_proof_pack_template_excellence,
build_sales_script,
build_service_launch_package,
build_service_research_brief,
calculate_service_excellence_score,
calculate_service_roi_estimate,
classify_features,
compare_against_categories,
convert_feedback_to_backlog,
generate_feature_hypotheses,
prioritize_backlog_items,
recommend_missing_features,
recommend_next_experiments,
recommend_weekly_improvements,
required_proof_metrics,
review_service_before_launch,
summarize_proof_ar,
)
from auto_client_acquisition.service_tower import ALL_SERVICES
router = APIRouter(prefix="/api/v1/service-excellence", tags=["service-excellence"])
# ── Feature matrix ───────────────────────────────────────────
@router.get("/{service_id}/feature-matrix")
async def feature_matrix(service_id: str) -> dict[str, Any]:
return build_feature_matrix(service_id)
@router.get("/{service_id}/feature-classification")
async def feature_classification(service_id: str) -> dict[str, Any]:
return classify_features(service_id)
@router.get("/{service_id}/missing-features")
async def missing_features(service_id: str) -> dict[str, Any]:
return {"recommendations": recommend_missing_features(service_id)}
# ── Scoring ──────────────────────────────────────────────────
@router.get("/{service_id}/score")
async def score(service_id: str) -> dict[str, Any]:
return calculate_service_excellence_score(service_id)
# ── Gates / quality review ──────────────────────────────────
@router.get("/{service_id}/quality-review")
async def quality_review(service_id: str) -> dict[str, Any]:
return review_service_before_launch(service_id)
@router.get("/review/all")
async def review_all() -> dict[str, Any]:
"""Review every catalogued service."""
out = [review_service_before_launch(s.id) for s in ALL_SERVICES]
counts: dict[str, int] = {}
for r in out:
v = str(r.get("verdict", "?"))
counts[v] = counts.get(v, 0) + 1
return {"total": len(out), "by_verdict": counts, "results": out}
# ── Proof metrics ────────────────────────────────────────────
@router.get("/{service_id}/proof-metrics")
async def proof_metrics(service_id: str) -> dict[str, Any]:
return {
"service_id": service_id,
"metrics": required_proof_metrics(service_id),
"template": build_proof_pack_template_excellence(service_id),
}
@router.post("/{service_id}/roi-estimate")
async def roi_estimate(
service_id: str,
metrics: dict[str, Any] = Body(default_factory=dict),
) -> dict[str, Any]:
out = calculate_service_roi_estimate(service_id, metrics)
if "error" not in out:
out["proof_summary_ar"] = summarize_proof_ar(service_id, metrics)
return out
# ── Competitor gap ───────────────────────────────────────────
@router.get("/{service_id}/gap-analysis")
async def gap_analysis(service_id: str) -> dict[str, Any]:
return compare_against_categories(service_id)
# ── Research lab ─────────────────────────────────────────────
@router.get("/{service_id}/research-brief")
async def research_brief(service_id: str) -> dict[str, Any]:
return build_service_research_brief(service_id)
@router.get("/{service_id}/feature-hypotheses")
async def feature_hypotheses(service_id: str) -> dict[str, Any]:
return {"hypotheses": generate_feature_hypotheses(service_id)}
@router.get("/{service_id}/experiments")
async def experiments(service_id: str) -> dict[str, Any]:
return recommend_next_experiments(service_id)
@router.get("/{service_id}/monthly-review")
async def monthly_review(service_id: str) -> dict[str, Any]:
return build_monthly_service_review(service_id)
# ── Backlog ──────────────────────────────────────────────────
@router.get("/{service_id}/backlog")
async def backlog(service_id: str) -> dict[str, Any]:
return build_backlog(service_id)
@router.post("/{service_id}/backlog/from-feedback")
async def backlog_from_feedback(
service_id: str,
feedback: list[dict[str, Any]] = Body(..., embed=True),
) -> dict[str, Any]:
return {
"service_id": service_id,
"items": convert_feedback_to_backlog(feedback),
}
@router.post("/{service_id}/backlog/prioritize")
async def backlog_prioritize(
service_id: str,
items: list[dict[str, Any]] = Body(..., embed=True),
) -> dict[str, Any]:
return {"items": prioritize_backlog_items(items)}
@router.get("/{service_id}/weekly-improvements")
async def weekly_improvements(service_id: str) -> dict[str, Any]:
return recommend_weekly_improvements(service_id)
# ── Launch package ───────────────────────────────────────────
@router.get("/{service_id}/launch-package")
async def launch_package(service_id: str) -> dict[str, Any]:
return build_service_launch_package(service_id)
@router.get("/{service_id}/landing-outline")
async def landing_outline(service_id: str) -> dict[str, Any]:
return build_landing_page_outline(service_id)
@router.get("/{service_id}/sales-script")
async def sales_script(service_id: str) -> dict[str, Any]:
return build_sales_script(service_id)
@router.get("/{service_id}/demo-script")
async def demo_script(service_id: str) -> dict[str, Any]:
return build_demo_script(service_id)
@router.get("/{service_id}/onboarding-checklist")
async def onboarding_checklist(service_id: str) -> dict[str, Any]:
return build_onboarding_checklist(service_id)