core: sync updates across opencode, sdk, tui, and plugin components

This commit is contained in:
Dax Raad
2025-08-31 20:19:30 -04:00
parent b51975fd67
commit 55cfacc6f4
45 changed files with 960 additions and 341 deletions
+36 -22
View File
@@ -2,7 +2,6 @@ package main
import (
"context"
"encoding/json"
"io"
"log/slog"
"os"
@@ -19,6 +18,7 @@ import (
"github.com/sst/opencode/internal/clipboard"
"github.com/sst/opencode/internal/tui"
"github.com/sst/opencode/internal/util"
"golang.org/x/sync/errgroup"
)
var Version = "dev"
@@ -37,13 +37,6 @@ func main() {
url := os.Getenv("OPENCODE_SERVER")
var project opencode.Project
err := json.Unmarshal([]byte(os.Getenv("OPENCODE_PROJECT")), &project)
if err != nil {
slog.Error("Failed to unmarshal app info", "error", err)
os.Exit(1)
}
stat, err := os.Stdin.Stat()
if err != nil {
slog.Error("Failed to stat stdin", "error", err)
@@ -72,21 +65,42 @@ func main() {
option.WithBaseURL(url),
)
// Fetch agents from the /agent endpoint
agentsPtr, err := httpClient.Agent.List(context.Background())
if err != nil {
slog.Error("Failed to fetch agents", "error", err)
os.Exit(1)
}
if agentsPtr == nil {
slog.Error("No agents returned from server")
os.Exit(1)
}
agents := *agentsPtr
var agents []opencode.Agent
var path *opencode.Path
var project *opencode.Project
path, err := httpClient.Path.Get(context.Background())
batch := errgroup.Group{}
batch.Go(func() error {
result, err := httpClient.Project.Current(context.Background(), opencode.ProjectCurrentParams{})
if err != nil {
return err
}
project = result
return nil
})
batch.Go(func() error {
result, err := httpClient.Agent.List(context.Background(), opencode.AgentListParams{})
if err != nil {
return err
}
agents = *result
return nil
})
batch.Go(func() error {
result, err := httpClient.Path.Get(context.Background(), opencode.PathGetParams{})
if err != nil {
return err
}
path = result
return nil
})
err = batch.Wait()
if err != nil {
os.Exit(1)
panic(err)
}
ctx, cancel := context.WithCancel(context.Background())
@@ -122,7 +136,7 @@ func main() {
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)
go func() {
stream := httpClient.Event.ListStreaming(ctx)
stream := httpClient.Event.ListStreaming(ctx, opencode.EventListParams{})
for stream.Next() {
evt := stream.Current().AsUnion()
program.Send(evt)
+10 -10
View File
@@ -101,7 +101,7 @@ type PermissionRespondedToMsg struct {
func New(
ctx context.Context,
version string,
project opencode.Project,
project *opencode.Project,
path *opencode.Path,
agents []opencode.Agent,
httpClient *opencode.Client,
@@ -113,7 +113,7 @@ func New(
util.RootPath = project.Worktree
util.CwdPath, _ = os.Getwd()
configInfo, err := httpClient.Config.Get(ctx)
configInfo, err := httpClient.Config.Get(ctx, opencode.ConfigGetParams{})
if err != nil {
return nil, err
}
@@ -188,13 +188,13 @@ func New(
slog.Debug("Loaded config", "config", configInfo)
customCommands, err := httpClient.Command.List(ctx)
customCommands, err := httpClient.Command.List(ctx, opencode.CommandListParams{})
if err != nil {
return nil, err
}
app := &App{
Project: project,
Project: *project,
Agents: agents,
Version: version,
StatePath: appStatePath,
@@ -460,7 +460,7 @@ func findProviderByID(providers []opencode.Provider, providerID string) *opencod
}
func (a *App) InitializeProvider() tea.Cmd {
providersResponse, err := a.Client.App.Providers(context.Background())
providersResponse, err := a.Client.App.Providers(context.Background(), opencode.AppProvidersParams{})
if err != nil {
slog.Error("Failed to list providers", "error", err)
// TODO: notify user
@@ -879,7 +879,7 @@ func (a *App) Cancel(ctx context.Context, sessionID string) error {
a.compactCancel = nil
}
_, err := a.Client.Session.Abort(ctx, sessionID)
_, err := a.Client.Session.Abort(ctx, sessionID, opencode.SessionAbortParams{})
if err != nil {
slog.Error("Failed to cancel session", "error", err)
return err
@@ -888,7 +888,7 @@ func (a *App) Cancel(ctx context.Context, sessionID string) error {
}
func (a *App) ListSessions(ctx context.Context) ([]opencode.Session, error) {
response, err := a.Client.Session.List(ctx)
response, err := a.Client.Session.List(ctx, opencode.SessionListParams{})
if err != nil {
return nil, err
}
@@ -900,7 +900,7 @@ func (a *App) ListSessions(ctx context.Context) ([]opencode.Session, error) {
}
func (a *App) DeleteSession(ctx context.Context, sessionID string) error {
_, err := a.Client.Session.Delete(ctx, sessionID)
_, err := a.Client.Session.Delete(ctx, sessionID, opencode.SessionDeleteParams{})
if err != nil {
slog.Error("Failed to delete session", "error", err)
return err
@@ -920,7 +920,7 @@ func (a *App) UpdateSession(ctx context.Context, sessionID string, title string)
}
func (a *App) ListMessages(ctx context.Context, sessionId string) ([]Message, error) {
response, err := a.Client.Session.Messages(ctx, sessionId)
response, err := a.Client.Session.Messages(ctx, sessionId, opencode.SessionMessagesParams{})
if err != nil {
return nil, err
}
@@ -942,7 +942,7 @@ func (a *App) ListMessages(ctx context.Context, sessionId string) ([]Message, er
}
func (a *App) ListProviders(ctx context.Context) ([]opencode.Provider, error) {
response, err := a.Client.App.Providers(ctx)
response, err := a.Client.App.Providers(ctx, opencode.AppProvidersParams{})
if err != nil {
return nil, err
}
@@ -32,6 +32,7 @@ func (cg *agentsContextGroup) GetChildEntries(
agents, err := cg.app.Client.Agent.List(
context.Background(),
opencode.AgentListParams{},
)
if err != nil {
slog.Error("Failed to get agent list", "error", err)
+1 -1
View File
@@ -29,7 +29,7 @@ func (cg *filesContextGroup) GetEmptyMessage() string {
func (cg *filesContextGroup) getGitFiles() []CompletionSuggestion {
items := make([]CompletionSuggestion, 0)
status, _ := cg.app.Client.File.Status(context.Background())
status, _ := cg.app.Client.File.Status(context.Background(), opencode.FileStatusParams{})
if status != nil {
files := *status
sort.Slice(files, func(i, j int) bool {
@@ -769,6 +769,7 @@ func (m *messagesComponent) renderView() tea.Cmd {
context.Background(),
m.app.CurrentPermission.SessionID,
m.app.CurrentPermission.MessageID,
opencode.SessionMessageParams{},
)
if err != nil || response == nil {
slog.Error("Failed to get message from child session", "error", err)
@@ -1238,6 +1239,7 @@ func (m *messagesComponent) RedoLastMessage() (tea.Model, tea.Cmd) {
response, err := m.app.Client.Session.Unrevert(
context.Background(),
m.app.Session.ID,
opencode.SessionUnrevertParams{},
)
if err != nil {
slog.Error("Failed to unrevert session", "error", err)
+10 -10
View File
@@ -393,7 +393,7 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
a.showCompletionDialog = false
// If we're in a child session, switch back to parent before sending prompt
if a.app.Session.ParentID != "" {
parentSession, err := a.app.Client.Session.Get(context.Background(), a.app.Session.ParentID)
parentSession, err := a.app.Client.Session.Get(context.Background(), a.app.Session.ParentID, opencode.SessionGetParams{})
if err != nil {
slog.Error("Failed to get parent session", "error", err)
return a, toast.NewErrorToast("Failed to get parent session")
@@ -411,7 +411,7 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case app.SendCommand:
// If we're in a child session, switch back to parent before sending prompt
if a.app.Session.ParentID != "" {
parentSession, err := a.app.Client.Session.Get(context.Background(), a.app.Session.ParentID)
parentSession, err := a.app.Client.Session.Get(context.Background(), a.app.Session.ParentID, opencode.SessionGetParams{})
if err != nil {
slog.Error("Failed to get parent session", "error", err)
return a, toast.NewErrorToast("Failed to get parent session")
@@ -429,7 +429,7 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case app.SendShell:
// If we're in a child session, switch back to parent before sending prompt
if a.app.Session.ParentID != "" {
parentSession, err := a.app.Client.Session.Get(context.Background(), a.app.Session.ParentID)
parentSession, err := a.app.Client.Session.Get(context.Background(), a.app.Session.ParentID, opencode.SessionGetParams{})
if err != nil {
slog.Error("Failed to get parent session", "error", err)
return a, toast.NewErrorToast("Failed to get parent session")
@@ -676,7 +676,7 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if nextMessageID == "" {
// Last message - use unrevert to restore full conversation
response, err = a.app.Client.Session.Unrevert(context.Background(), a.app.Session.ID)
response, err = a.app.Client.Session.Unrevert(context.Background(), a.app.Session.ID, opencode.SessionUnrevertParams{})
} else {
// Revert to next message to make target the last visible
response, err = a.app.Client.Session.Revert(context.Background(), a.app.Session.ID,
@@ -1185,7 +1185,7 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
if a.app.Session.ID == "" {
return a, nil
}
response, err := a.app.Client.Session.Share(context.Background(), a.app.Session.ID)
response, err := a.app.Client.Session.Share(context.Background(), a.app.Session.ID, opencode.SessionShareParams{})
if err != nil {
slog.Error("Failed to share session", "error", err)
return a, toast.NewErrorToast("Failed to share session")
@@ -1197,7 +1197,7 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
if a.app.Session.ID == "" {
return a, nil
}
_, err := a.app.Client.Session.Unshare(context.Background(), a.app.Session.ID)
_, err := a.app.Client.Session.Unshare(context.Background(), a.app.Session.ID, opencode.SessionUnshareParams{})
if err != nil {
slog.Error("Failed to unshare session", "error", err)
return a, toast.NewErrorToast("Failed to unshare session")
@@ -1225,7 +1225,7 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
var parentSession *opencode.Session
if a.app.Session.ParentID != "" {
parentSessionID = a.app.Session.ParentID
session, err := a.app.Client.Session.Get(context.Background(), parentSessionID)
session, err := a.app.Client.Session.Get(context.Background(), parentSessionID, opencode.SessionGetParams{})
if err != nil {
slog.Error("Failed to get parent session", "error", err)
return toast.NewErrorToast("Failed to get parent session")
@@ -1235,7 +1235,7 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
parentSession = a.app.Session
}
children, err := a.app.Client.Session.Children(context.Background(), parentSessionID)
children, err := a.app.Client.Session.Children(context.Background(), parentSessionID, opencode.SessionChildrenParams{})
if err != nil {
slog.Error("Failed to get session children", "error", err)
return toast.NewErrorToast("Failed to get session children")
@@ -1283,7 +1283,7 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
var parentSession *opencode.Session
if a.app.Session.ParentID != "" {
parentSessionID = a.app.Session.ParentID
session, err := a.app.Client.Session.Get(context.Background(), parentSessionID)
session, err := a.app.Client.Session.Get(context.Background(), parentSessionID, opencode.SessionGetParams{})
if err != nil {
slog.Error("Failed to get parent session", "error", err)
return toast.NewErrorToast("Failed to get parent session")
@@ -1293,7 +1293,7 @@ func (a Model) executeCommand(command commands.Command) (tea.Model, tea.Cmd) {
parentSession = a.app.Session
}
children, err := a.app.Client.Session.Children(context.Background(), parentSessionID)
children, err := a.app.Client.Session.Children(context.Background(), parentSessionID, opencode.SessionChildrenParams{})
if err != nil {
slog.Error("Failed to get session children", "error", err)
return toast.NewErrorToast("Failed to get session children")