mirror of
https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools.git
synced 2026-06-17 23:09:35 +00:00
Security Curator (4 modules) — جدار الحماية الأول
- secret_redactor: 11 patterns (GitHub PAT, OpenAI/Anthropic/Supabase/WhatsApp/Moyasar/Sentry/Google/AWS/private keys); never returns raw secret
- patch_firewall: blocks .env / credentials.json / RSA keys; scans added lines for secret patterns
- trace_redactor: masks phones (+966...) and emails for PII safety
- tool_output_sanitizer: cleans tool outputs before they hit ledger/Proof Pack/UI/observability
Growth Curator (5 modules) — التحسين الذاتي
- message_curator: grades Arabic messages (0..100), detects 8 risky phrases, suggests Saudi-tone skeleton
- playbook_curator: scores playbooks by outcome (accept/reply/meeting/deal); winner/promising/needs_work/archive
- mission_curator: scores completed missions; ship_it_widely/iterate/rework_or_retire
- skill_inventory: deterministic 23-skill catalog across 5 layers
- curator_report: weekly Arabic summary "ماذا تعلمنا هذا الأسبوع"
Meeting Intelligence (5 modules) — ذكاء الاجتماعات
- transcript_parser: accepts Google Meet entries OR plain "Speaker: text" format
- meeting_brief: 6-section pre-meeting brief in Arabic (objective/questions/objections/offer/next-step)
- objection_extractor: 8 categories (price/timing/authority/trust/integration/competitor/results/complexity)
- followup_builder: email + WhatsApp drafts; live_send_allowed=False always
- deal_risk: 0..100 score from objections + missing next-step + decision-maker absence + days-since-touch
Model Router (5 modules) — موجّه النماذج
- provider_registry: 7 providers (Claude Sonnet/Haiku, GPT-4-class, GPT-4o-mini, Gemini Pro, Azure OAI KSA-region, Local Qwen Arabic-tuned)
- task_router: 10 task types × routing decisions with reasons_ar
- cost_policy: bulk → low; output > 1500 tokens → high
- fallback_policy: high-sensitivity workloads prefer KSA-region/self-hosted FIRST
- usage_dashboard: deterministic demo of all task routes
Connector Catalog (3 modules) — كتالوج التكاملات
- 14 connectors (WhatsApp Cloud, Gmail, Calendar, Google Meet, Moyasar, LinkedIn Lead Forms, Google Business Profile, X API, Instagram, Sheets, CRM, Website Forms, Composio, MCP Gateway)
- Each has launch_phase (1-4), risk_level, allowed_actions, blocked_actions, Arabic risk dossier
- WhatsApp blocks cold_send_without_consent; Moyasar blocks store_card_number; MCP requires allowlist
Agent Observability (5 modules) — مراقبة الوكلاء + التقييمات
- trace_events: SHA256-hashes user/company IDs; sanitizes payload/output before logging
- safety_eval: 7 rules (guarantee, scarcity_fake, medical_claim, financial, regulatory, personal_data, urgency); 0..100 → safe/needs_review/blocked
- saudi_tone_eval: positive markers (هلا, لاحظت, يناسبك) vs negative (تحية طيبة وبعد, synergy, leverage); arabic_ratio bonus
- eval_pack: 5 curated cases with expected verdicts
- cost_tracker: per workflow/provider/task_type aggregation
Routers (6 new) — 30 endpoints
- /api/v1/security-curator/{demo, redact, inspect-diff, sanitize-output}
- /api/v1/growth-curator/{skills/inventory, messages/grade, messages/improve, messages/duplicates, missions/next, report/weekly, report/demo}
- /api/v1/meeting-intelligence/{brief, brief/demo, transcript/summarize, followup/draft, deal-risk}
- /api/v1/model-router/{providers, tasks, route, cost-class, usage/demo}
- /api/v1/connector-catalog/{catalog, summary, status, risks, {key}}
- /api/v1/agent-observability/{trace/build, safety/eval, tone/eval, evals/run}
Tests (6 new files, 76 tests)
- test_security_curator: 16 tests (PAT detect, key redact, env diff block, payload scan, trace mask)
- test_growth_curator: 16 tests (Arabic grade, risky phrases, dup detect, playbook scoring, mission recommend, weekly report)
- test_meeting_intelligence: 13 tests (transcript parse, brief sections, objection extract, followup drafts, deal risk)
- test_dealix_model_router: 11 tests (every task → ≥1 provider, KSA-region for high sensitivity, cost class, primary override)
- test_agent_observability: 12 tests (trace hashing, safety verdicts, tone scoring, eval pack)
- test_connector_catalog: 11 tests (≥12 connectors, every has risk/blocked actions, WA cold-send blocked, Moyasar card-storage blocked)
Docs (8 new + 1 updated)
- AGENT_SECURITY_CURATOR.md (Arabic)
- GROWTH_CURATOR_STRATEGY.md (Arabic)
- MEETING_INTELLIGENCE.md (Arabic)
- MODEL_PROVIDER_ROUTER.md (Arabic)
- CONNECTOR_CATALOG.md (Arabic)
- AGENT_OBSERVABILITY_EVALS.md (Arabic)
- PRIVATE_BETA_LAUNCH_TODAY.md (Arabic) — go-checklist + offer + risks
- DEMO_SCRIPT_12_MINUTES.md (Arabic) — minute-by-minute demo flow
- FIRST_20_OUTREACH_MESSAGES.md (Arabic) — 7 personas + 3 follow-ups, all under safety/tone evals
- DEALIX_100_PERCENT_LAUNCH_PLAN.md — added §34 Self-Improving Agent Platform + §35 Private Beta Launch
Landing
- landing/private-beta.html — Arabic RTL, dark theme, pricing, 11 demo endpoints, safety banner
Test results
- 76/76 new tests pass
- Full suite: 663 passed, 2 skipped (missing API keys, unrelated)
- 0 existing tests broken
Safety
- All 6 layers honor approval-first, draft-only, no-live-send
- Hash user/company IDs before any trace
- No secrets in logs/embeddings/traces (3-layer defense: redactor + sanitizer + firewall)
- Saudi tone eval rejects "تحية طيبة وبعد" + "synergy" auto-corporate language
- Safety eval blocks "ضمان 100%" + medical claims + fake urgency
- Connector Catalog: WhatsApp blocks cold-send, Moyasar blocks card storage, MCP requires allowlist
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
202 lines
6.0 KiB
Python
202 lines
6.0 KiB
Python
"""
|
|
FastAPI application entry point.
|
|
نقطة دخول تطبيق FastAPI.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import AsyncIterator
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI, Request
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from api.middleware import RequestIDMiddleware
|
|
from api.routers import (
|
|
admin,
|
|
agent_observability,
|
|
agents,
|
|
automation,
|
|
autonomous,
|
|
business,
|
|
command_center,
|
|
connector_catalog,
|
|
customer_success,
|
|
data,
|
|
dominance,
|
|
drafts,
|
|
ecosystem,
|
|
email_send,
|
|
full_os,
|
|
growth_curator,
|
|
growth_operator,
|
|
health,
|
|
innovation,
|
|
intelligence_layer,
|
|
leads,
|
|
meeting_intelligence,
|
|
model_router,
|
|
outreach,
|
|
personal_operator,
|
|
platform_services,
|
|
pricing,
|
|
prospect,
|
|
public,
|
|
revenue,
|
|
revenue_os,
|
|
sales,
|
|
sectors,
|
|
security_curator,
|
|
v3,
|
|
webhooks,
|
|
)
|
|
from api.security import APIKeyMiddleware, setup_rate_limit
|
|
from core.config.settings import get_settings
|
|
from core.errors import AICompanyError
|
|
from core.logging import configure_logging, get_logger
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(_app: FastAPI) -> AsyncIterator[None]:
|
|
"""App startup/shutdown hook."""
|
|
configure_logging()
|
|
log = get_logger(__name__)
|
|
settings = get_settings()
|
|
log.info(
|
|
"app_startup",
|
|
app=settings.app_name,
|
|
version=settings.app_version,
|
|
env=settings.app_env,
|
|
)
|
|
# Auto-create tables on boot (additive — safe with SQLAlchemy create_all)
|
|
try:
|
|
from db.session import init_db
|
|
await init_db()
|
|
log.info("db_init_complete")
|
|
except Exception as exc:
|
|
log.warning("db_init_skipped", error=str(exc))
|
|
yield
|
|
log.info("app_shutdown")
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
"""FastAPI factory."""
|
|
settings = get_settings()
|
|
|
|
app = FastAPI(
|
|
title=settings.app_name,
|
|
version=settings.app_version,
|
|
description=(
|
|
"Multi-agent AI platform for the Saudi Arabian market.\n\n"
|
|
"**Phase 8**: Auto Client Acquisition — intake, ICP match, "
|
|
"pain extraction, qualification, CRM sync, booking, proposals.\n\n"
|
|
"**Phase 9**: Autonomous Growth — sector intel, content, distribution, "
|
|
"enrichment, competitor analysis, market research.\n\n"
|
|
"**Phase 10 / v3**: Autonomous Saudi Revenue OS — revenue memory, "
|
|
"safe agent runtime, market radar, compliance OS, revenue science, "
|
|
"and Sami Personal Strategic Operator."
|
|
),
|
|
docs_url="/docs",
|
|
redoc_url="/redoc",
|
|
openapi_url="/openapi.json",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.cors_origin_list,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
app.add_middleware(RequestIDMiddleware)
|
|
app.add_middleware(APIKeyMiddleware)
|
|
setup_rate_limit(app)
|
|
|
|
try:
|
|
from dealix.observability import instrument_fastapi, setup_sentry, setup_tracing
|
|
|
|
setup_sentry()
|
|
setup_tracing(service_name=settings.app_name, version=settings.app_version)
|
|
instrument_fastapi(app)
|
|
except Exception: # pragma: no cover
|
|
pass
|
|
|
|
@app.exception_handler(AICompanyError)
|
|
async def ai_company_error_handler(_: Request, exc: AICompanyError) -> JSONResponse:
|
|
return JSONResponse(
|
|
status_code=400,
|
|
content={"error": exc.__class__.__name__, "detail": str(exc)},
|
|
)
|
|
|
|
app.include_router(health.router)
|
|
app.include_router(leads.router)
|
|
app.include_router(sales.router)
|
|
app.include_router(sectors.router)
|
|
app.include_router(agents.router)
|
|
app.include_router(webhooks.router)
|
|
app.include_router(pricing.router)
|
|
app.include_router(prospect.router)
|
|
app.include_router(autonomous.router)
|
|
app.include_router(data.router)
|
|
app.include_router(outreach.router)
|
|
app.include_router(revenue.router)
|
|
app.include_router(automation.router)
|
|
app.include_router(email_send.router)
|
|
app.include_router(drafts.router)
|
|
app.include_router(dominance.router)
|
|
app.include_router(full_os.router)
|
|
app.include_router(customer_success.router)
|
|
app.include_router(ecosystem.router)
|
|
app.include_router(command_center.router)
|
|
app.include_router(revenue_os.router)
|
|
app.include_router(v3.router)
|
|
app.include_router(innovation.router)
|
|
app.include_router(business.router)
|
|
app.include_router(personal_operator.router)
|
|
app.include_router(growth_operator.router)
|
|
app.include_router(platform_services.router)
|
|
app.include_router(intelligence_layer.router)
|
|
app.include_router(security_curator.router)
|
|
app.include_router(growth_curator.router)
|
|
app.include_router(meeting_intelligence.router)
|
|
app.include_router(model_router.router)
|
|
app.include_router(connector_catalog.router)
|
|
app.include_router(agent_observability.router)
|
|
app.include_router(public.router)
|
|
app.include_router(admin.router)
|
|
|
|
@app.get("/", tags=["root"])
|
|
async def root() -> dict[str, object]:
|
|
return {
|
|
"name": settings.app_name,
|
|
"version": settings.app_version,
|
|
"status": "operational",
|
|
"env": settings.app_env,
|
|
"docs": "/docs",
|
|
"health": "/health",
|
|
"v3_command_center": "/api/v1/v3/command-center/snapshot",
|
|
"personal_operator_daily_brief": "/api/v1/personal-operator/daily-brief",
|
|
"personal_operator_launch_report": "/api/v1/personal-operator/launch-report",
|
|
"business_pricing": "/api/v1/business/pricing",
|
|
"innovation_command_feed_demo": "/api/v1/innovation/command-feed/demo",
|
|
}
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
settings = get_settings()
|
|
uvicorn.run(
|
|
"api.main:app",
|
|
host=settings.app_host,
|
|
port=settings.app_port,
|
|
reload=settings.is_development,
|
|
)
|