diff options
| author | Dax <[email protected]> | 2025-07-23 20:30:46 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-23 20:30:46 -0400 |
| commit | 96866e52ce4b28d8f380d84722f411e786781f51 (patch) | |
| tree | fbe8df4e706510b3158d1659d8aa54b0c533c849 /packages/tui/sdk | |
| parent | 507c975e929d1d8bd58ae26e7bbcf9537daaf5b6 (diff) | |
| download | opencode-96866e52ce4b28d8f380d84722f411e786781f51.tar.gz opencode-96866e52ce4b28d8f380d84722f411e786781f51.zip | |
basic undo feature (#1268)
Co-authored-by: adamdotdevin <[email protected]>
Co-authored-by: Jay V <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
Co-authored-by: Andrew Joslin <[email protected]>
Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Tobias Walle <[email protected]>
Diffstat (limited to 'packages/tui/sdk')
| -rw-r--r-- | packages/tui/sdk/.stats.yml | 8 | ||||
| -rw-r--r-- | packages/tui/sdk/api.md | 2 | ||||
| -rw-r--r-- | packages/tui/sdk/config.go | 8 | ||||
| -rw-r--r-- | packages/tui/sdk/session.go | 37 | ||||
| -rw-r--r-- | packages/tui/sdk/session_test.go | 51 |
5 files changed, 99 insertions, 7 deletions
diff --git a/packages/tui/sdk/.stats.yml b/packages/tui/sdk/.stats.yml index f9f86831f..da0b08b5a 100644 --- a/packages/tui/sdk/.stats.yml +++ b/packages/tui/sdk/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 24 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/opencode%2Fopencode-9574184bd9e916aa69eae8e26e0679556038d3fcfb4009a445c97c6cc3e4f3ee.yml -openapi_spec_hash: 93ba1215ab0dc853a1691b049cc47d75 -config_hash: 09e4835d57ec7ed0b2d316c6815bcf0a +configured_endpoints: 26 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/opencode%2Fopencode-1efc45c35b58e88b0550fbb0c7a204ef66522742f87c9e29c76a18b120c0d945.yml +openapi_spec_hash: 5e15d85e4704624f9b13bae1c71aa416 +config_hash: 1ae82c93499b9f0b9ba828b8919f9cb3 diff --git a/packages/tui/sdk/api.md b/packages/tui/sdk/api.md index 1f5191cad..0bb72433c 100644 --- a/packages/tui/sdk/api.md +++ b/packages/tui/sdk/api.md @@ -114,8 +114,10 @@ Methods: - <code title="post /session/{id}/message">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Chat">Chat</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionChatParams">SessionChatParams</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#AssistantMessage">AssistantMessage</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code> - <code title="post /session/{id}/init">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Init">Init</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionInitParams">SessionInitParams</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code> - <code title="get /session/{id}/message">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Messages">Messages</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) ([]<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionMessagesResponse">SessionMessagesResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code> +- <code title="post /session/{id}/revert">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Revert">Revert</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionRevertParams">SessionRevertParams</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code> - <code title="post /session/{id}/share">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Share">Share</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code> - <code title="post /session/{id}/summarize">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Summarize">Summarize</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionSummarizeParams">SessionSummarizeParams</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code> +- <code title="post /session/{id}/unrevert">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Unrevert">Unrevert</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code> - <code title="delete /session/{id}/share">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Unshare">Unshare</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code> # Tui diff --git a/packages/tui/sdk/config.go b/packages/tui/sdk/config.go index 0461cba87..96759fc47 100644 --- a/packages/tui/sdk/config.go +++ b/packages/tui/sdk/config.go @@ -510,8 +510,12 @@ type KeybindsConfig struct { MessagesPageUp string `json:"messages_page_up,required"` // Navigate to previous message MessagesPrevious string `json:"messages_previous,required"` - // Revert message + // Redo message + MessagesRedo string `json:"messages_redo,required"` + // @deprecated use messages_undo. Revert message MessagesRevert string `json:"messages_revert,required"` + // Undo message + MessagesUndo string `json:"messages_undo,required"` // List available models ModelList string `json:"model_list,required"` // Create/update AGENTS.md @@ -565,7 +569,9 @@ type keybindsConfigJSON struct { MessagesPageDown apijson.Field MessagesPageUp apijson.Field MessagesPrevious apijson.Field + MessagesRedo apijson.Field MessagesRevert apijson.Field + MessagesUndo apijson.Field ModelList apijson.Field ProjectInit apijson.Field SessionCompact apijson.Field diff --git a/packages/tui/sdk/session.go b/packages/tui/sdk/session.go index 8426b64eb..86d46000d 100644 --- a/packages/tui/sdk/session.go +++ b/packages/tui/sdk/session.go @@ -112,6 +112,18 @@ func (r *SessionService) Messages(ctx context.Context, id string, opts ...option return } +// Revert a message +func (r *SessionService) Revert(ctx context.Context, id string, body SessionRevertParams, opts ...option.RequestOption) (res *Session, err error) { + opts = append(r.Options[:], opts...) + if id == "" { + err = errors.New("missing required id parameter") + return + } + path := fmt.Sprintf("session/%s/revert", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return +} + // Share a session func (r *SessionService) Share(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) { opts = append(r.Options[:], opts...) @@ -136,6 +148,18 @@ func (r *SessionService) Summarize(ctx context.Context, id string, body SessionS return } +// Restore all reverted messages +func (r *SessionService) Unrevert(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) { + opts = append(r.Options[:], opts...) + if id == "" { + err = errors.New("missing required id parameter") + return + } + path := fmt.Sprintf("session/%s/unrevert", id) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) + return +} + // Unshare the session func (r *SessionService) Unshare(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) { opts = append(r.Options[:], opts...) @@ -988,7 +1012,7 @@ func (r sessionTimeJSON) RawJSON() string { type SessionRevert struct { MessageID string `json:"messageID,required"` - Part float64 `json:"part,required"` + PartID string `json:"partID"` Snapshot string `json:"snapshot"` JSON sessionRevertJSON `json:"-"` } @@ -996,7 +1020,7 @@ type SessionRevert struct { // sessionRevertJSON contains the JSON metadata for the struct [SessionRevert] type sessionRevertJSON struct { MessageID apijson.Field - Part apijson.Field + PartID apijson.Field Snapshot apijson.Field raw string ExtraFields map[string]apijson.Field @@ -2010,6 +2034,15 @@ func (r SessionInitParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } +type SessionRevertParams struct { + MessageID param.Field[string] `json:"messageID,required"` + PartID param.Field[string] `json:"partID"` +} + +func (r SessionRevertParams) MarshalJSON() (data []byte, err error) { + return apijson.MarshalRoot(r) +} + type SessionSummarizeParams struct { ModelID param.Field[string] `json:"modelID,required"` ProviderID param.Field[string] `json:"providerID,required"` diff --git a/packages/tui/sdk/session_test.go b/packages/tui/sdk/session_test.go index 5d7c55cad..807f19563 100644 --- a/packages/tui/sdk/session_test.go +++ b/packages/tui/sdk/session_test.go @@ -197,6 +197,35 @@ func TestSessionMessages(t *testing.T) { } } +func TestSessionRevertWithOptionalParams(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := opencode.NewClient( + option.WithBaseURL(baseURL), + ) + _, err := client.Session.Revert( + context.TODO(), + "id", + opencode.SessionRevertParams{ + MessageID: opencode.F("msg"), + PartID: opencode.F("prt"), + }, + ) + if err != nil { + var apierr *opencode.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + func TestSessionShare(t *testing.T) { t.Skip("skipped: tests are disabled for the time being") baseURL := "http://localhost:4010" @@ -248,6 +277,28 @@ func TestSessionSummarize(t *testing.T) { } } +func TestSessionUnrevert(t *testing.T) { + t.Skip("skipped: tests are disabled for the time being") + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := opencode.NewClient( + option.WithBaseURL(baseURL), + ) + _, err := client.Session.Unrevert(context.TODO(), "id") + if err != nil { + var apierr *opencode.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + func TestSessionUnshare(t *testing.T) { t.Skip("skipped: tests are disabled for the time being") baseURL := "http://localhost:4010" |
