Files
nofx/api/handler_ai500.go
tinkle-community 2c6e2827e8 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
2026-06-11 22:11:03 +08:00

44 lines
1016 B
Go

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),
},
})
}