| 1 | package equipo |
| 2 | |
| 3 | import ( |
| 4 | "log/slog" |
| 5 | "net/url" |
| 6 | "strings" |
| 7 | |
| 8 | "amadan.net/oficina/equipo/internal/equipo/chat" |
| 9 | "amadan.net/oficina/equipo/internal/websearch" |
| 10 | "amadan.net/oficina/equipo/internal/websource/guard" |
| 11 | ) |
| 12 | |
| 13 | // forgeHost is the forge the instance pushes to: never a lookup's. |
| 14 | const forgeHost = "amadan.net" |
| 15 | |
| 16 | // setupLookups configures the Assistant's lookups (spec 2026-11-26- |
| 17 | // assistant-abilities §4): the search chain from EQUIPO_WEB_SEARCH and |
| 18 | // friends, the page client, both guarded by the instance inventory and |
| 19 | // denied the instance's own hosts. With no usable backend web_lookup |
| 20 | // stays unlisted; a constructor refusing its configuration is an error. |
| 21 | func (s *Store) setupLookups(cfg Config, logger *slog.Logger) error { |
| 22 | deny := []string{forgeHost} |
| 23 | for _, origin := range append([]string{cfg.Origin, cfg.OficinaConnectOrigin}, cfg.AssistantHosts...) { |
| 24 | if u, err := url.Parse(strings.TrimSpace(origin)); err == nil && u.Hostname() != "" { |
| 25 | deny = append(deny, strings.ToLower(u.Hostname())) |
| 26 | } |
| 27 | } |
| 28 | c := s.Chat() |
| 29 | g := guard.Config{Inventory: c.InstanceInventory(), Deny: deny, Logger: logger} |
| 30 | chain, ok, err := websearch.FromConfig(cfg.WebSearch, g, websearch.DBUsage{DB: s.db.G, Caps: cfg.WebSearch.Caps}) |
| 31 | if err != nil || !ok { |
| 32 | c.SetLookups(nil) |
| 33 | return err |
| 34 | } |
| 35 | pageCfg := g |
| 36 | pageCfg.Policy, pageCfg.Redirects = guard.PolicyLookupPage, guard.MaxRedirects |
| 37 | pages, err := guard.New(pageCfg) |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | c.SetLookups(&chat.LookupConfig{Search: chain, Pages: pages, Inventory: g.Inventory, Deny: deny}) |
| 42 | return nil |
| 43 | } |
| 44 | |