main: show active backend in status bar
Derive a human-readable backend label from OLLIE_BACKEND and OLLIE_OPENAI_URL at startup and store it in model.backendName. For the openai backend, inspect OLLIE_OPENAI_URL to distinguish known providers (openrouter, together, groq, mistral, anthropic) from a generic openai-compatible endpoint, so the bar shows e.g. "openrouter" instead of "openai" when using OpenRouter. Status bar format changes from: [model] state | ... to: [backend :: model] state | ...
This commit is contained in:
parent
8a2f2feecf
commit
ace6afb853
70
main.go
70
main.go
|
|
@ -121,6 +121,40 @@ const (
|
||||||
agentRunningTool
|
agentRunningTool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// resolveBackendName returns a short human-readable backend label derived
|
||||||
|
// from OLLIE_BACKEND and (for openai-compatible backends) OLLIE_OPENAI_URL.
|
||||||
|
// Known provider hostnames are mapped to friendly names so that e.g.
|
||||||
|
// openrouter.ai shows up as "openrouter" rather than "openai".
|
||||||
|
func resolveBackendName() string {
|
||||||
|
which := os.Getenv("OLLIE_BACKEND")
|
||||||
|
if which == "" {
|
||||||
|
which = "ollama"
|
||||||
|
}
|
||||||
|
if which != "openai" {
|
||||||
|
return which
|
||||||
|
}
|
||||||
|
// For openai-compatible backends, try to identify the provider from the URL.
|
||||||
|
url := strings.ToLower(os.Getenv("OLLIE_OPENAI_URL"))
|
||||||
|
switch {
|
||||||
|
case strings.Contains(url, "openrouter"):
|
||||||
|
return "openrouter"
|
||||||
|
case strings.Contains(url, "together"):
|
||||||
|
return "together"
|
||||||
|
case strings.Contains(url, "groq"):
|
||||||
|
return "groq"
|
||||||
|
case strings.Contains(url, "mistral"):
|
||||||
|
return "mistral"
|
||||||
|
case strings.Contains(url, "anthropic"):
|
||||||
|
return "anthropic"
|
||||||
|
case strings.Contains(url, "localhost") || strings.Contains(url, "127.0.0.1"):
|
||||||
|
return "local"
|
||||||
|
case url == "":
|
||||||
|
return "openai"
|
||||||
|
default:
|
||||||
|
return "openai"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: buf and display lines use plain strings; bubbletea copies the model
|
// NOTE: buf and display lines use plain strings; bubbletea copies the model
|
||||||
// by value on every Update(), so strings.Builder and other copy-sensitive
|
// by value on every Update(), so strings.Builder and other copy-sensitive
|
||||||
// types will panic.
|
// types will panic.
|
||||||
|
|
@ -137,20 +171,21 @@ type model struct {
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
doneCh chan struct{}
|
doneCh chan struct{}
|
||||||
modelName string
|
modelName string
|
||||||
|
backendName string // e.g. "ollama", "openrouter", "openai"
|
||||||
|
|
||||||
// status bar state
|
// status bar state
|
||||||
state agentState
|
state agentState
|
||||||
currentTool string // name of tool currently executing
|
currentTool string
|
||||||
lastUsage backend.Usage
|
lastUsage backend.Usage
|
||||||
ctxStats agent.ContextStats
|
ctxStats agent.ContextStats
|
||||||
}
|
}
|
||||||
|
|
||||||
type agentMsg struct {
|
type agentMsg struct {
|
||||||
role string
|
role string
|
||||||
content string
|
content string
|
||||||
name string
|
name string
|
||||||
done bool
|
done bool
|
||||||
usage backend.Usage
|
usage backend.Usage
|
||||||
ctxStats agent.ContextStats
|
ctxStats agent.ContextStats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,6 +254,10 @@ func main() {
|
||||||
modelName = "qwen3:8b"
|
modelName = "qwen3:8b"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve after backend.New() so that loadEnvFile has already run and
|
||||||
|
// populated OLLIE_BACKEND / OLLIE_OPENAI_URL from ~/.config/ollie/env.
|
||||||
|
backendName := resolveBackendName()
|
||||||
|
|
||||||
home, _ := os.UserHomeDir()
|
home, _ := os.UserHomeDir()
|
||||||
builtinExec := execpkg.New(
|
builtinExec := execpkg.New(
|
||||||
home+"/.local/state/ollie",
|
home+"/.local/state/ollie",
|
||||||
|
|
@ -272,13 +311,14 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
p := tea.NewProgram(model{
|
p := tea.NewProgram(model{
|
||||||
textarea: ta,
|
textarea: ta,
|
||||||
viewport: vp,
|
viewport: vp,
|
||||||
loopcfg: loopcfg,
|
loopcfg: loopcfg,
|
||||||
hooks: hooks,
|
hooks: hooks,
|
||||||
display: startup,
|
display: startup,
|
||||||
modelName: modelName,
|
modelName: modelName,
|
||||||
state: agentIdle,
|
backendName: backendName,
|
||||||
|
state: agentIdle,
|
||||||
})
|
})
|
||||||
|
|
||||||
if hook := hooks["agentSpawn"]; hook != "" {
|
if hook := hooks["agentSpawn"]; hook != "" {
|
||||||
|
|
@ -346,7 +386,8 @@ func (m model) renderStatusBar() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bar := fmt.Sprintf("[%s] %s | %s | %s", m.modelName, stateStr, usageStr, ctxStr)
|
bar := fmt.Sprintf("[%s :: %s] %s | %s | %s",
|
||||||
|
m.backendName, m.modelName, stateStr, usageStr, ctxStr)
|
||||||
return statusBarStyle.Width(m.viewport.Width).Render(bar)
|
return statusBarStyle.Width(m.viewport.Width).Render(bar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -495,7 +536,6 @@ func (m model) startAgent(session *agent.Session) (chan tea.Msg, context.CancelF
|
||||||
msg.content = em.Content
|
msg.content = em.Content
|
||||||
msg.name = em.Name
|
msg.name = em.Name
|
||||||
|
|
||||||
// Attach live usage + context stats on every usage event.
|
|
||||||
if em.Role == "usage" {
|
if em.Role == "usage" {
|
||||||
msg.usage = em.Usage
|
msg.usage = em.Usage
|
||||||
msg.ctxStats = session.ContextStats()
|
msg.ctxStats = session.ContextStats()
|
||||||
|
|
|
||||||
Reference in New Issue