Redesign the UI on brain's look: sidebar with search, Overview, modules, grouped Settings
- Left sidebar as in brain: search at the top (press /), Overview, Inventory, the modules (Content with Inbox, Sources, Scheduled and Published; later phases greyed out), Settings at the bottom; a top bar with breadcrumbs, and a menu that slides in on narrow screens. - brain's colour tokens, type, radius and shadows, with a dark theme that follows the system setting. - Settings as grouped tabs: Profile; Social accounts (was Credentials, now keys and sign-in together per network); Core & Hermes; AI, which now holds the API keys too. Old addresses redirect. - /search matches every word across posts, fetched items, the inventory, products and settings pages. - Overview: a card per module, then the setup checklist, folded once done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+116
-46
@@ -31,13 +31,15 @@ func (s *Server) aiPage(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) renderAI(w http.ResponseWriter, r *http.Request, cfg ai.Config, errMsg string) {
|
||||
s.render(w, r, "ai", page{Title: "AI provider", Nav: "settings", Error: errMsg, Data: map[string]any{
|
||||
s.render(w, r, "ai", page{Title: "AI", Nav: "settings/ai", Error: errMsg, Data: map[string]any{
|
||||
"Cfg": cfg,
|
||||
"AnthropicModels": anthropicModels,
|
||||
"Efforts": efforts,
|
||||
"Tasks": ai.Tasks,
|
||||
"Servers": s.aiServers(),
|
||||
"HasAnthropicKey": s.Secrets.Has(secrets.AnthropicAPIKey),
|
||||
"Keys": aiKeys,
|
||||
"Set": s.secretState(secrets.AnthropicAPIKey, secrets.OpenAIAPIKey),
|
||||
"Shared": ai.LoadShared(),
|
||||
}})
|
||||
}
|
||||
@@ -70,6 +72,11 @@ func (s *Server) aiSave(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// Keys first: they're kept even if the rest of the form needs fixing.
|
||||
if err := s.saveSecrets(r, aiKeys); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
cfg := aiFromForm(r)
|
||||
switch {
|
||||
case cfg.Model == "":
|
||||
@@ -132,52 +139,37 @@ func (s *Server) aiModels(w http.ResponseWriter, r *http.Request) {
|
||||
s.fragment(w, "ai", "model-list", data)
|
||||
}
|
||||
|
||||
// --- Credentials ---
|
||||
// --- Secrets forms ---
|
||||
|
||||
// credentialFields are the secrets the credentials form edits, in order.
|
||||
var credentialFields = []struct {
|
||||
// secretField is one secret a settings form edits. Saved values are never
|
||||
// shown: an empty field keeps what's saved.
|
||||
type secretField struct {
|
||||
Group, Name, Label, Help string
|
||||
}{
|
||||
{"AI", secrets.AnthropicAPIKey, "Anthropic API key", "From console.anthropic.com."},
|
||||
{"AI", secrets.OpenAIAPIKey, "API key for an OpenAI-compatible server", "Only if your server asks for one (Ollama and LM Studio don't)."},
|
||||
}
|
||||
|
||||
// aiKeys are edited on the AI tab.
|
||||
var aiKeys = []secretField{
|
||||
{"anthropic", secrets.AnthropicAPIKey, "Anthropic API key", "From console.anthropic.com."},
|
||||
{"openai", secrets.OpenAIAPIKey, "API key for the server", "Only if your server asks for one (Ollama and LM Studio don't)."},
|
||||
}
|
||||
|
||||
// accountFields are edited on the Social accounts tab, by network.
|
||||
var accountFields = []secretField{
|
||||
{"X", secrets.XBearerToken, "Bearer token", "For reading posts. Needs an X API plan with read access."},
|
||||
{"X", secrets.XClientID, "OAuth 2.0 client ID", "For posting. From your app in the X developer portal."},
|
||||
{"X", secrets.XClientSecret, "OAuth 2.0 client secret", "Only for confidential clients; leave empty for a public client."},
|
||||
{"LinkedIn", secrets.LinkedInClientID, "Client ID", "From your app at linkedin.com/developers."},
|
||||
{"LinkedIn", secrets.LinkedInClientSecret, "Client secret", ""},
|
||||
{"YouTube", secrets.YouTubeAPIKey, "API key", "Free, from console.cloud.google.com (YouTube Data API v3)."},
|
||||
{"Reddit", secrets.RedditClientID, "Client ID", "From a \"web app\" at reddit.com/prefs/apps: the string under the app's name."},
|
||||
{"Reddit", secrets.RedditClientSecret, "Client secret", ""},
|
||||
{"YouTube", secrets.YouTubeAPIKey, "API key", "Free, from console.cloud.google.com (YouTube Data API v3). For reading channels' videos."},
|
||||
}
|
||||
|
||||
func (s *Server) credentialsPage(w http.ResponseWriter, r *http.Request) {
|
||||
names := make([]string, 0, len(credentialFields)+2)
|
||||
for _, f := range credentialFields {
|
||||
names = append(names, f.Name)
|
||||
}
|
||||
names = append(names, secrets.XAccessToken, secrets.LinkedInAccessToken, secrets.RedditAccessToken)
|
||||
s.render(w, r, "credentials", page{Title: "Credentials", Nav: "settings", Data: map[string]any{
|
||||
"Fields": credentialFields,
|
||||
"Set": s.secretState(names...),
|
||||
"Connections": s.connections(),
|
||||
"XRedirect": s.PublicURL + "/auth/x/callback",
|
||||
"LIRedirect": s.PublicURL + "/auth/linkedin/callback",
|
||||
"RedditRedirect": s.PublicURL + "/auth/reddit/callback",
|
||||
"RedditToken": secrets.RedditAccessToken,
|
||||
"XToken": secrets.XAccessToken,
|
||||
"LIToken": secrets.LinkedInAccessToken,
|
||||
}})
|
||||
}
|
||||
|
||||
// credentialsSave stores what was typed. An empty field keeps the saved
|
||||
// value; "remove" clears it.
|
||||
func (s *Server) credentialsSave(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// saveSecrets stores what was typed into these fields. An empty field keeps
|
||||
// the saved value; "remove:<name>" clears it.
|
||||
func (s *Server) saveSecrets(r *http.Request, fields []secretField) error {
|
||||
updates := map[string]string{}
|
||||
for _, f := range credentialFields {
|
||||
for _, f := range fields {
|
||||
if r.PostForm.Get("remove:"+f.Name) == "on" {
|
||||
updates[f.Name] = ""
|
||||
continue
|
||||
@@ -186,13 +178,91 @@ func (s *Server) credentialsSave(w http.ResponseWriter, r *http.Request) {
|
||||
updates[f.Name] = v
|
||||
}
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
if err := s.Secrets.Set(updates); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
if len(updates) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.Secrets.Set(updates)
|
||||
}
|
||||
|
||||
// --- Social accounts ---
|
||||
|
||||
// network is one card on the Social accounts tab: its keys, and the sign-in
|
||||
// that lets Supermarket post as you.
|
||||
type network struct {
|
||||
Name string
|
||||
Fields []secretField
|
||||
Connect *connectInfo // nil: read-only, no sign-in
|
||||
}
|
||||
|
||||
type connectInfo struct {
|
||||
Provider string // the /auth/{provider} path segment
|
||||
Redirect string // the callback URL to register with the network
|
||||
Setup string // where to register it
|
||||
Ready bool // the keys the sign-in needs are saved
|
||||
Signed bool // a token is saved
|
||||
Account string
|
||||
At time.Time
|
||||
Note string
|
||||
}
|
||||
|
||||
func (s *Server) accountsPage(w http.ResponseWriter, r *http.Request) {
|
||||
names := []string{secrets.XAccessToken, secrets.LinkedInAccessToken, secrets.RedditAccessToken}
|
||||
for _, f := range accountFields {
|
||||
names = append(names, f.Name)
|
||||
}
|
||||
set := s.secretState(names...)
|
||||
conns := s.connections()
|
||||
connect := func(provider, token, setup, note string, ready bool, account func(string) string) *connectInfo {
|
||||
c := conns[provider]
|
||||
return &connectInfo{Provider: provider, Redirect: s.PublicURL + "/auth/" + provider + "/callback",
|
||||
Setup: setup, Note: note, Ready: ready, Signed: set[token], Account: account(c.Account), At: c.At}
|
||||
}
|
||||
at := func(prefix string) func(string) string {
|
||||
return func(a string) string {
|
||||
if a == "" {
|
||||
return ""
|
||||
}
|
||||
return prefix + a
|
||||
}
|
||||
}
|
||||
redirect(w, r, "/settings/credentials", "saved")
|
||||
var nets []network
|
||||
for _, name := range []string{"X", "LinkedIn", "Reddit", "YouTube"} {
|
||||
n := network{Name: name}
|
||||
for _, f := range accountFields {
|
||||
if f.Group == name {
|
||||
n.Fields = append(n.Fields, f)
|
||||
}
|
||||
}
|
||||
switch name {
|
||||
case "X":
|
||||
n.Connect = connect("x", secrets.XAccessToken, "In the X developer portal, add this callback URL to your app:", "",
|
||||
set[secrets.XClientID], at("@"))
|
||||
case "LinkedIn":
|
||||
n.Connect = connect("linkedin", secrets.LinkedInAccessToken, "In your LinkedIn app's Auth settings, add this redirect URL:", "",
|
||||
set[secrets.LinkedInClientID] && set[secrets.LinkedInClientSecret], func(string) string { return "" })
|
||||
case "Reddit":
|
||||
n.Connect = connect("reddit", secrets.RedditAccessToken, "At reddit.com/prefs/apps, create a web app with this redirect URI:",
|
||||
"Reddit's API terms need approval for commercial use: Supermarket is meant for a few hand-approved posts, not volume.",
|
||||
set[secrets.RedditClientID] && set[secrets.RedditClientSecret], at("u/"))
|
||||
}
|
||||
nets = append(nets, n)
|
||||
}
|
||||
s.render(w, r, "accounts", page{Title: "Social accounts", Nav: "settings/accounts", Data: map[string]any{
|
||||
"Networks": nets,
|
||||
"Set": set,
|
||||
}})
|
||||
}
|
||||
|
||||
func (s *Server) accountsSave(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := s.saveSecrets(r, accountFields); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/settings/accounts", "saved")
|
||||
}
|
||||
|
||||
// --- OAuth ---
|
||||
@@ -256,12 +326,12 @@ func (s *Server) oauthCallback(w http.ResponseWriter, r *http.Request) {
|
||||
delete(s.pending, q.Get("state")) // a state is good for one callback
|
||||
s.mu.Unlock()
|
||||
if p == nil || p.Provider != provider || time.Since(p.Started) > oauthTTL {
|
||||
redirect(w, r, "/settings/credentials", "oauth-expired")
|
||||
redirect(w, r, "/settings/accounts", "oauth-expired")
|
||||
return
|
||||
}
|
||||
fail := func(msg string) {
|
||||
s.render(w, r, "message", page{Title: "Sign-in failed", Nav: "settings", Error: msg,
|
||||
Data: map[string]string{"Back": "/settings/credentials"}})
|
||||
s.render(w, r, "message", page{Title: "Sign-in failed", Nav: "settings/accounts", Error: msg,
|
||||
Data: map[string]string{"Back": "/settings/accounts"}})
|
||||
}
|
||||
if e := q.Get("error"); e != "" {
|
||||
fail("The provider said: " + e + " " + q.Get("error_description"))
|
||||
@@ -295,7 +365,7 @@ func (s *Server) oauthCallback(w http.ResponseWriter, r *http.Request) {
|
||||
if err := s.saveConnection("x", Connection{Account: account, At: time.Now()}); err != nil {
|
||||
s.Log.Error("saving connection", "err", err)
|
||||
}
|
||||
redirect(w, r, "/settings/credentials", "x-connected")
|
||||
redirect(w, r, "/settings/accounts", "x-connected")
|
||||
case "linkedin":
|
||||
res, err := oauth.LinkedInExchange(ctx, s.Secrets.Get(secrets.LinkedInClientID), s.Secrets.Get(secrets.LinkedInClientSecret), code, p)
|
||||
if err != nil {
|
||||
@@ -314,7 +384,7 @@ func (s *Server) oauthCallback(w http.ResponseWriter, r *http.Request) {
|
||||
if err := s.saveConnection("linkedin", Connection{Account: urn, At: time.Now()}); err != nil {
|
||||
s.Log.Error("saving connection", "err", err)
|
||||
}
|
||||
redirect(w, r, "/settings/credentials", "li-connected")
|
||||
redirect(w, r, "/settings/accounts", "li-connected")
|
||||
case "reddit":
|
||||
res, err := oauth.RedditExchange(ctx, s.Secrets.Get(secrets.RedditClientID), s.Secrets.Get(secrets.RedditClientSecret),
|
||||
s.redditUserAgent(), code, p)
|
||||
@@ -336,7 +406,7 @@ func (s *Server) oauthCallback(w http.ResponseWriter, r *http.Request) {
|
||||
if err := s.saveConnection("reddit", Connection{Account: name, At: time.Now()}); err != nil {
|
||||
s.Log.Error("saving connection", "err", err)
|
||||
}
|
||||
redirect(w, r, "/settings/credentials", "reddit-connected")
|
||||
redirect(w, r, "/settings/accounts", "reddit-connected")
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user