feat(agent): surface the AI500 index board in chat, tools, and sidebar

- provider/nofxos: GetAI500ListCached — 5min TTL cache with stale
  fallback on upstream failure; ResolveClient routes through the claw402
  gateway when a wallet key is configured (user's claw402 model key ->
  CLAW402_WALLET_KEY env -> direct nofxos)
- new GET /api/ai500 endpoint serving the score-sorted board
- new get_ai500_list agent tool + prompt rule: when the user wants coin
  picks or creates a strategy without naming coins, consult AI500's
  high-scoring entries by default
- web: AI500 sidebar panel (rank, score badge, gain since entry,
  5min auto-refresh); clicking an entry asks the agent to analyze it
This commit is contained in:
tinkle-community
2026-06-11 22:11:03 +08:00
parent 953240565f
commit 2c6e2827e8
12 changed files with 666 additions and 2 deletions

43
api/handler_ai500.go Normal file
View File

@@ -0,0 +1,43 @@
package api
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"nofx/agent"
)
// handleAI500List serves the AI500 index board for the agent UI panel.
// Data is fetched through the user's claw402 wallet when one is configured
// (falling back to the direct nofxos client) and served from a 5-minute
// cache, so panel polling never hammers the upstream.
func (s *Server) handleAI500List(c *gin.Context) {
userID := c.GetString("user_id")
limit := 0
if raw := c.Query("limit"); raw != "" {
parsed, err := strconv.Atoi(raw)
if err != nil || parsed < 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "limit must be a non-negative integer"})
return
}
limit = parsed
}
walletKey := agent.Claw402WalletKeyForStoreUser(s.store, userID)
entries, err := agent.AI500Board(walletKey, limit)
if err != nil {
SafeInternalError(c, "Get AI500 list", err)
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"data": gin.H{
"coins": entries,
"count": len(entries),
},
})
}

View File

@@ -213,6 +213,9 @@ func (s *Server) setupRoutes() {
// Server IP query (requires authentication, for whitelist configuration)
s.route(protected, "GET", "/server-ip", "Get server public IP (for exchange whitelist)", s.handleGetServerIP)
// AI500 index board (cached; routed through claw402 when configured)
s.route(protected, "GET", "/ai500", "AI500 index board (?limit=20)", s.handleAI500List)
// AI trader management
s.routeWithSchema(protected, "GET", "/my-traders", "List user's traders with status",
`Returns: [{"trader_id":"<EXACT id — use this as trader_id in all ?trader_id= queries and POST /traders/:id/start|stop>","trader_name":"<string>","is_running":<bool>}]