Merge agent and mode into one (#1689)
The concept of mode has been deprecated, there is now only the agent field in the config. An agent can be cycled through as your primary agent with <tab> or you can spawn a subagent by @ mentioning it. if you include a description of when to use it, the primary agent will try to automatically use it Full docs here: https://opencode.ai/docs/agents/
This commit is contained in:
74
packages/tui/internal/completions/agents.go
Normal file
74
packages/tui/internal/completions/agents.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package completions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/sst/opencode-sdk-go"
|
||||
"github.com/sst/opencode/internal/app"
|
||||
"github.com/sst/opencode/internal/styles"
|
||||
"github.com/sst/opencode/internal/theme"
|
||||
)
|
||||
|
||||
type agentsContextGroup struct {
|
||||
app *app.App
|
||||
}
|
||||
|
||||
func (cg *agentsContextGroup) GetId() string {
|
||||
return "agents"
|
||||
}
|
||||
|
||||
func (cg *agentsContextGroup) GetEmptyMessage() string {
|
||||
return "no matching agents"
|
||||
}
|
||||
|
||||
func (cg *agentsContextGroup) GetChildEntries(
|
||||
query string,
|
||||
) ([]CompletionSuggestion, error) {
|
||||
items := make([]CompletionSuggestion, 0)
|
||||
|
||||
query = strings.TrimSpace(query)
|
||||
|
||||
agents, err := cg.app.Client.App.Agents(
|
||||
context.Background(),
|
||||
)
|
||||
if err != nil {
|
||||
slog.Error("Failed to get agent list", "error", err)
|
||||
return items, err
|
||||
}
|
||||
if agents == nil {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
for _, agent := range *agents {
|
||||
if query != "" && !strings.Contains(strings.ToLower(agent.Name), strings.ToLower(query)) {
|
||||
continue
|
||||
}
|
||||
if agent.Mode == opencode.AgentModePrimary || agent.Name == "general" {
|
||||
continue
|
||||
}
|
||||
|
||||
displayFunc := func(s styles.Style) string {
|
||||
t := theme.CurrentTheme()
|
||||
muted := s.Foreground(t.TextMuted()).Render
|
||||
return s.Render(agent.Name) + muted(" (agent)")
|
||||
}
|
||||
|
||||
item := CompletionSuggestion{
|
||||
Display: displayFunc,
|
||||
Value: agent.Name,
|
||||
ProviderID: cg.GetId(),
|
||||
RawData: agent,
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func NewAgentsContextGroup(app *app.App) CompletionProvider {
|
||||
return &agentsContextGroup{
|
||||
app: app,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user