From 434a9093b055e4f2048fce3f3b153c5117f53a31 Mon Sep 17 00:00:00 2001 From: David Young Date: Fri, 20 Nov 2026 14:54:04 -0700 Subject: [PATCH] Say on the Profile page that drafting from the website needs an AI provider MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Draft button is disabled, with a link to Settings → AI provider, until one is set up; the Overview lists the AI provider first. Co-Authored-By: Claude Opus 5.5 --- internal/web/pages.go | 6 +++--- internal/web/profile.go | 13 +++++++++++++ internal/web/server_test.go | 12 ++++++++++++ internal/web/templates/profile.html | 3 ++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/internal/web/pages.go b/internal/web/pages.go index 7d8eeec..4430434 100644 --- a/internal/web/pages.go +++ b/internal/web/pages.go @@ -84,10 +84,10 @@ func (s *Server) dashboard(w http.ResponseWriter, r *http.Request) { conns := s.connections() steps := []step{ - {Label: "Company profile", Done: p.IsSet(), Link: "/profile", - Detail: ifElse(p.IsSet(), p.Name, "Describe the company, its products and its customers")}, {Label: "AI provider", Done: aiErr == nil, Link: "/settings/ai", - Detail: ifElse(aiErr == nil, aiCfg.Provider+" · "+aiCfg.Model, "Choose Anthropic or a server on your network")}, + Detail: ifElse(aiErr == nil, aiCfg.Provider+" · "+aiCfg.Model, "Choose Anthropic or a server on your network; the profile draft and posts need it")}, + {Label: "Company profile", Done: p.IsSet(), Link: "/profile", + Detail: ifElse(p.IsSet(), p.Name, "Describe the company, its products and its customers (the AI can draft it from your website)")}, {Label: "Inventory", Done: len(entries) > 0, Link: "/inventory", Detail: inventorySummary(counts)}, {Label: "Social accounts", Done: s.Secrets.Has(secrets.XAccessToken) || s.Secrets.Has(secrets.LinkedInAccessToken) || s.Secrets.Has(secrets.RedditAccessToken), diff --git a/internal/web/profile.go b/internal/web/profile.go index b5f8c59..25f7497 100644 --- a/internal/web/profile.go +++ b/internal/web/profile.go @@ -15,6 +15,7 @@ type profileData struct { Websites []profile.Website // existing plus one blank row Drafted bool DraftURL string + NoAI bool // no AI provider yet: drafting from the website can't work } func withBlankRows(p *profile.Profile) profileData { @@ -34,6 +35,7 @@ func (s *Server) profilePage(w http.ResponseWriter, r *http.Request) { if len(p.Websites) > 0 { d.DraftURL = p.Websites[0].URL } + d.NoAI = !s.aiReady() s.render(w, r, "profile", page{Title: "Company profile", Nav: "profile", Data: d}) } @@ -129,6 +131,7 @@ func (s *Server) profileDraft(w http.ResponseWriter, r *http.Request) { d := withBlankRows(p) d.Drafted = drafted d.DraftURL = siteURL + d.NoAI = !s.aiReady() s.render(w, r, "profile", page{Title: "Company profile", Nav: "profile", Error: errMsg, Data: d}) } @@ -190,3 +193,13 @@ func merge(cur, draft *profile.Profile) *profile.Profile { out.Accounts.LinkedIn = pick(cur.Accounts.LinkedIn, draft.Accounts.LinkedIn) return &out } + +// aiReady reports whether an AI provider is set up. +func (s *Server) aiReady() bool { + cfg, err := ai.LoadConfig(s.DB) + if err != nil { + return false + } + _, err = ai.New(cfg, s.Secrets) + return err == nil +} diff --git a/internal/web/server_test.go b/internal/web/server_test.go index 1418650..8cdf637 100644 --- a/internal/web/server_test.go +++ b/internal/web/server_test.go @@ -255,3 +255,15 @@ func TestMCPNeedsTokenAndChecksIn(t *testing.T) { t.Fatalf("checkin not recorded: %+v %v", last, err) } } + +func TestProfileDraftNeedsAI(t *testing.T) { + s, h := newTestServer(t, nil) + body := do(h, http.MethodGet, "/profile", nil, nil).Body.String() + if !strings.Contains(body, `choose an AI provider`) || !strings.Contains(body, `class="secondary" disabled>Draft`) { + t.Errorf("profile without AI:\n%s", body) + } + _ = s.Secrets.Set(map[string]string{secrets.AnthropicAPIKey: "k"}) + if body := do(h, http.MethodGet, "/profile", nil, nil).Body.String(); strings.Contains(body, "choose an AI provider") { + t.Error("warning shown with an AI key saved") + } +} diff --git a/internal/web/templates/profile.html b/internal/web/templates/profile.html index 5972338..1f85e73 100644 --- a/internal/web/templates/profile.html +++ b/internal/web/templates/profile.html @@ -5,9 +5,10 @@

Reads your home page and a few pages it links to (about, products, pricing), and fills in what's empty below. Nothing is saved until you press Save.

+ {{if .NoAI}}

This uses the AI: first choose an AI provider (for Anthropic, add your API key), then come back. Or fill in the form below by hand.

{{end}}
- +

Takes up to a minute or two.