File size: 1,817 Bytes
34815e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Datei: app.py
import json
import uuid
import time
import gradio as gr
from firebase_service import track_and_attribute_revenue_to_db

# --- HIER: DIE ERSTE MCP-FUNKTION ---
def track_and_attribute_revenue(source: str, product_id: str, amount: float, lead_id: str = None) -> str:
    """
    MCP-Funktion zur Verbuchung von Umsätzen. 
    Wird von Sky Meilin 5.0 über Tool-Calling aufgerufen.
    """
    
    # 1. Generiere IDs
    transaction_id = f"TRX-{uuid.uuid4().hex[:8]}"
    accounting_ref = f"ACC-{int(time.time())}"
    
    # 2. Bauen des Datenobjekts
    transaction_data = {
        "timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
        "transaction_source": source,
        "item_sku": product_id,
        "revenue_amount": amount,
        "attributed_lead_id": lead_id if lead_id else "N/A",
        "accounting_ref": accounting_ref,
        "transaction_id": transaction_id
    }

    # 3. DATEN SPEICHERN (Der kritische Schritt zur Accounting KI)
    success = track_and_attribute_revenue_to_db(transaction_data)
    
    # 4. Rückgabe an Sky Meilin 5.0
    return_value = {
        "success": success,
        "transaction_id": transaction_id,
        "accounting_ref": accounting_ref
    }
    
    return json.dumps(return_value)

# --- GRADIO INTERFACE (FÜR HUGGING FACE TEST) ---
# Das Gradio Interface dient dazu, die Funktion in Ihrem Space zu testen
iface = gr.Interface(
    fn=track_and_attribute_revenue,
    inputs=[
        gr.Textbox(label="Source", value="X_Affiliate_A1"),
        gr.Textbox(label="Product ID", value="E-Book-V2"),
        gr.Number(label="Amount", value=49.99),
        gr.Textbox(label="Lead ID", value="L-456", optional=True)
    ],
    outputs="json",
    title="Sky Meilin MCP Tool: Revenue Tracker"
)

if __name__ == "__main__":
    iface.launch()