Files
vessel/backend/internal/api/routes.go
vikingowl b99fc3d0c1 feat: add IP-based geolocation fallback for location tool
- Add /api/v1/location endpoint using ip-api.com for IP geolocation
- Update get_location tool to try browser GPS first, then IP fallback
- Make tool description directive to trigger automatic usage
- Handle private IPs by letting ip-api.com auto-detect

The tool chain now works: get_location → web_search → fetch_url
Browser geolocation often fails on desktop Linux; IP fallback
provides city-level accuracy which is sufficient for weather queries.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 21:04:31 +01:00

52 lines
1.2 KiB
Go

package api
import (
"database/sql"
"github.com/gin-gonic/gin"
)
// SetupRoutes configures all API routes
func SetupRoutes(r *gin.Engine, db *sql.DB, ollamaURL string) {
// Health check
r.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{"status": "ok"})
})
// API v1 routes
v1 := r.Group("/api/v1")
{
// Chat routes
chats := v1.Group("/chats")
{
chats.GET("", ListChatsHandler(db))
chats.POST("", CreateChatHandler(db))
chats.GET("/:id", GetChatHandler(db))
chats.PUT("/:id", UpdateChatHandler(db))
chats.DELETE("/:id", DeleteChatHandler(db))
// Message routes (nested under chats)
chats.POST("/:id/messages", CreateMessageHandler(db))
}
// Sync routes
sync := v1.Group("/sync")
{
sync.POST("/push", PushChangesHandler(db))
sync.GET("/pull", PullChangesHandler(db))
}
// URL fetch proxy (for tools that need to fetch external URLs)
v1.POST("/proxy/fetch", URLFetchProxyHandler())
// Web search proxy (for web_search tool)
v1.POST("/proxy/search", WebSearchProxyHandler())
// IP-based geolocation (fallback when browser geolocation fails)
v1.GET("/location", IPGeolocationHandler())
// Ollama proxy (optional)
v1.Any("/ollama/*path", OllamaProxyHandler(ollamaURL))
}
}