Say on the Profile page that drafting from the website needs an AI provider
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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, `<a href="/settings/ai">choose an AI provider</a>`) || !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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
<form class="card inline-form" method="post" action="/profile/draft">
|
||||
<label for="draft_url"><strong>Draft from your website</strong></label>
|
||||
<p class="help">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.</p>
|
||||
{{if .NoAI}}<p class="warn-text">This uses the AI: first <a href="/settings/ai">choose an AI provider</a> (for Anthropic, add your API key), then come back. Or fill in the form below by hand.</p>{{end}}
|
||||
<div class="row">
|
||||
<input id="draft_url" name="draft_url" type="url" placeholder="https://example.com" value="{{.DraftURL}}" required>
|
||||
<button type="submit" class="secondary">Draft</button>
|
||||
<button type="submit" class="secondary" {{if .NoAI}}disabled{{end}}>Draft</button>
|
||||
</div>
|
||||
<p class="help">Takes up to a minute or two.</p>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user