package gateway import ( "context" "errors" "fmt" "strings" "github.com/samcharles93/archie-core/internal/prompts" "github.com/samcharles93/archie-core/internal/tools" "github.com/samcharles93/archie-core/ui/pages" ) // DashboardPage describes one dashboard surface so the chat agent can both // understand what each place is for and point the operator there. It is the // catalogue the dashboard's own navigation renders from (ui/pages), so a page // the assistant can name is a page the operator can reach. type DashboardPage struct { // Path is the route (e.g. "/tasks"). It is what the browser hash becomes. Path string // Label is the human name the navigation shows (e.g. "Tasks"). Label string // Description is a one-line plain-language explanation of what the page // shows, so the agent can answer "where do I go for that?" correctly. Description string } // DashboardPages returns the dashboard's page catalogue, in its own order. func DashboardPages() ([]DashboardPage, error) { catalogue, err := pages.All() if err != nil { return nil, err } out := make([]DashboardPage, 0, len(catalogue)) for _, p := range catalogue { out = append(out, DashboardPage{Path: p.Path, Label: p.Label, Description: p.Description}) } return out, nil } // PageIndexResult is what page_index returns: the full list of dashboard pages // and what each one shows, so the agent can answer where to go. type PageIndexResult struct { Pages []DashboardPage `json:"pages"` ProductGuide string `json:"product_guide"` } // pageIndexTool returns the tool that lists every dashboard page. It is only // registered for the web channel (see PageIndexTools), because pointing a // non-web operator at an internal dashboard route is meaningless. func pageIndexTool() (tools.ToolEntry, bool) { entry := tools.ToolEntry{ Name: "page_index", Toolset: "dashboard", Description: "List every dashboard page, what it shows, and built-in guidance for creating workflows and using Archie. Use it to tell the operator where to go for something rather than guessing.", Classification: tools.ClassIdempotent, Handler: func(_ context.Context, _ map[string]any) (any, error) { indexed, err := DashboardPages() if err != nil { return nil, err } return PageIndexResult{Pages: indexed, ProductGuide: prompts.ProductGuide()}, nil }, } return entry, true } // dashboardNavigateTool resolves a page path and returns the navigation the UI // can follow. It validates against the registry and refuses an unknown route // rather than guessing, so a chip is only ever produced for a real page. func dashboardNavigateTool() (tools.ToolEntry, bool) { entry := tools.ToolEntry{ Name: "dashboard_navigate", Toolset: "dashboard", Description: "Point the operator at a dashboard page. Pass the page path (e.g. /tasks). Returns the page to navigate to; the web chat renders it as a clickable chip. Never guess a path, look it up with page_index first.", Classification: tools.ClassIdempotent, Schema: tools.JSONSchema{ "type": "object", "properties": map[string]any{ "path": map[string]any{ "type": "string", "description": "The dashboard route to navigate to, e.g. /tasks. Must match a page_index entry.", }, }, "required": []any{"path"}, }, Handler: func(_ context.Context, input map[string]any) (any, error) { path := strings.TrimSpace(asString(input["path"])) if path == "" { return nil, errors.New("dashboard_navigate: path is required") } indexed, err := DashboardPages() if err != nil { return nil, err } for _, p := range indexed { if p.Path == path { return DashboardNavigateResult{Path: p.Path, Label: p.Label}, nil } } return nil, fmt.Errorf("dashboard_navigate: unknown page %s", path) }, } return entry, true } // PageIndexTools returns the dashboard tools for a channel. Only the web UI // has a dashboard (and only the web chat sends a Current page), so a non-web // channel (e.g. telegram) gets none. func PageIndexTools(channel string) []tools.ToolEntry { if !strings.EqualFold(channel, "web") { return nil } pageIndex, _ := pageIndexTool() navigate, _ := dashboardNavigateTool() return []tools.ToolEntry{pageIndex, navigate} }