File size: 3,457 Bytes
e94087f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import gradio as gr
import requests
import json
import os
from datetime import datetime

GATEWAY_URL = os.environ.get("NULLSTATE_GATEWAY_URL", "https://greensol.me/nullstate")

def fetch_status():
    try:
        r = requests.get(f"{GATEWAY_URL}/health", timeout=10, verify=False)
        data = r.json()
        return (
            f"Tasks: {data.get('tasks', 'N/A')}\n"
            f"Ledger: {data.get('ledger', 'N/A')}\n"
            f"Balance: ${data.get('balance', '0.00')} USDC\n"
            f"AI: {data.get('ai_model', 'N/A')}\n"
            f"Pricing: {data.get('pricing', 'N/A')}"
        )
    except Exception as e:
        return f"Gateway unreachable: {e}"

def get_kya_challenge():
    try:
        r = requests.get(f"{GATEWAY_URL}/kya/challenge", timeout=10, verify=False)
        return r.text
    except Exception as e:
        return f"Error: {e}"

def submit_solution(task_id: str, solution: str):
    try:
        r = requests.post(
            f"{GATEWAY_URL}/mcp",
            json={
                "jsonrpc": "2.0",
                "id": 1,
                "method": "tools/call",
                "params": {"name": "submit_solution", "arguments": {"task_id": task_id, "solution": solution}}
            },
            timeout=15,
            verify=False
        )
        return json.dumps(r.json(), indent=2)
    except Exception as e:
        return f"Error: {e}"

def query_intelligence(prompt: str):
    try:
        r = requests.post(
            f"{GATEWAY_URL}/mcp",
            json={
                "jsonrpc": "2.0",
                "id": 1,
                "method": "tools/call",
                "params": {"name": "get_intelligence", "arguments": {"prompt": prompt}}
            },
            timeout=30,
            verify=False
        )
        return json.dumps(r.json(), indent=2)
    except Exception as e:
        return f"Error: {e}"

with gr.Blocks(theme=gr.themes.Soft(primary_hue="green"), title="NullState Gateway") as demo:
    gr.Markdown("""# ⚡ NullState Gateway
**Payment Infrastructure for AI Agents** — x402 · AP2 · MCP · KYA
""")
    
    with gr.Tab("Status"):
        status_btn = gr.Button("Refresh Status", variant="primary")
        status_output = gr.Textbox(label="Gateway Health", lines=6)
        status_btn.click(fn=fetch_status, outputs=status_output)
    
    with gr.Tab("KYA Challenge"):
        kya_btn = gr.Button("Get KYA Challenge", variant="primary")
        kya_output = gr.Textbox(label="Challenge Response", lines=8)
        kya_btn.click(fn=get_kya_challenge, outputs=kya_output)
    
    with gr.Tab("Submit Solution"):
        task_id = gr.Textbox(label="Task ID", placeholder="task_abc123")
        solution = gr.Textbox(label="Solution", lines=4, placeholder="Your solution here...")
        submit_btn = gr.Button("Submit", variant="primary")
        submit_output = gr.Textbox(label="Response", lines=6)
        submit_btn.click(fn=submit_solution, inputs=[task_id, solution], outputs=submit_output)
    
    with gr.Tab("Query AI"):
        prompt = gr.Textbox(label="Prompt", lines=3, placeholder="Ask NullState AI...")
        query_btn = gr.Button("Query", variant="primary")
        query_output = gr.Textbox(label="Response", lines=8)
        query_btn.click(fn=query_intelligence, inputs=[prompt], outputs=query_output)
    
    gr.Markdown("""---
Built with ❤️ by [NullState](https://greensol.me/nullstate) — Open-source MIT
""")

demo.launch()