diff --git a/.stats.yml b/.stats.yml index db94070..5f66550 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 43 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/opencode%2Fopencode-46826ba8640557721614b0c9a3f1860681d825ca8d8b12869652fa25aacb0b4c.yml -openapi_spec_hash: 33b8db6fde3021579b21325ce910197d +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/opencode%2Fopencode-0a51d4de32ff494edb3423c9dfd6907b101baab3a967cf47a2fe4a11e53e6bd9.yml +openapi_spec_hash: f408670a086f9a79e331863b5d04b7b6 config_hash: 026ef000d34bf2f930e7b41e77d2d3ff diff --git a/README.md b/README.md index f26e58f..b3b68c5 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ import ( func main() { client := opencode.NewClient() - sessions, err := client.Session.List(context.TODO(), opencode.SessionListParams{}) + sessions, err := client.Session.List(context.TODO()) if err != nil { panic(err.Error()) } @@ -171,7 +171,7 @@ When the API returns a non-success status code, we return an error with type To handle errors, we recommend that you use the `errors.As` pattern: ```go -_, err := client.Session.List(context.TODO(), opencode.SessionListParams{}) +_, err := client.Session.List(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -198,7 +198,6 @@ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() client.Session.List( ctx, - opencode.SessionListParams{}, // This sets the per-retry timeout option.WithRequestTimeout(20*time.Second), ) @@ -232,11 +231,7 @@ client := opencode.NewClient( ) // Override per-request: -client.Session.List( - context.TODO(), - opencode.SessionListParams{}, - option.WithMaxRetries(5), -) +client.Session.List(context.TODO(), option.WithMaxRetries(5)) ``` ### Accessing raw response data (e.g. response headers) @@ -247,11 +242,7 @@ you need to examine response headers, status codes, or other details. ```go // Create a variable to store the HTTP response var response *http.Response -sessions, err := client.Session.List( - context.TODO(), - opencode.SessionListParams{}, - option.WithResponseInto(&response), -) +sessions, err := client.Session.List(context.TODO(), option.WithResponseInto(&response)) if err != nil { // handle error } diff --git a/agent.go b/agent.go index 5e8f495..fe8b318 100644 --- a/agent.go +++ b/agent.go @@ -5,11 +5,8 @@ package opencode import ( "context" "net/http" - "net/url" "github.com/sst/opencode-sdk-go/internal/apijson" - "github.com/sst/opencode-sdk-go/internal/apiquery" - "github.com/sst/opencode-sdk-go/internal/param" "github.com/sst/opencode-sdk-go/internal/requestconfig" "github.com/sst/opencode-sdk-go/option" ) @@ -34,10 +31,10 @@ func NewAgentService(opts ...option.RequestOption) (r *AgentService) { } // List all agents -func (r *AgentService) List(ctx context.Context, query AgentListParams, opts ...option.RequestOption) (res *[]Agent, err error) { +func (r *AgentService) List(ctx context.Context, opts ...option.RequestOption) (res *[]Agent, err error) { opts = append(r.Options[:], opts...) path := "agent" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } @@ -190,15 +187,3 @@ func (r *AgentModel) UnmarshalJSON(data []byte) (err error) { func (r agentModelJSON) RawJSON() string { return r.raw } - -type AgentListParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [AgentListParams]'s query parameters as `url.Values`. -func (r AgentListParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} diff --git a/agent_test.go b/agent_test.go index 0827df5..c3984b5 100644 --- a/agent_test.go +++ b/agent_test.go @@ -13,7 +13,7 @@ import ( "github.com/sst/opencode-sdk-go/option" ) -func TestAgentListWithOptionalParams(t *testing.T) { +func TestAgentList(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -25,9 +25,7 @@ func TestAgentListWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Agent.List(context.TODO(), opencode.AgentListParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Agent.List(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { diff --git a/aliases.go b/aliases.go index 6ab36d0..50beeae 100644 --- a/aliases.go +++ b/aliases.go @@ -12,6 +12,9 @@ type Error = apierror.Error // This is an alias to an internal type. type MessageAbortedError = shared.MessageAbortedError +// This is an alias to an internal type. +type MessageAbortedErrorData = shared.MessageAbortedErrorData + // This is an alias to an internal type. type MessageAbortedErrorName = shared.MessageAbortedErrorName diff --git a/api.md b/api.md index 02ac42b..6ac0031 100644 --- a/api.md +++ b/api.md @@ -12,7 +12,7 @@ Response Types: Methods: -- client.Event.List(ctx context.Context, query opencode.EventListParams) (opencode.EventListResponse, error) +- client.Event.List(ctx context.Context) (opencode.EventListResponse, error) # Path @@ -22,7 +22,7 @@ Response Types: Methods: -- client.Path.Get(ctx context.Context, query opencode.PathGetParams) (opencode.Path, error) +- client.Path.Get(ctx context.Context) (opencode.Path, error) # App @@ -34,8 +34,8 @@ Response Types: Methods: -- client.App.Log(ctx context.Context, params opencode.AppLogParams) (bool, error) -- client.App.Providers(ctx context.Context, query opencode.AppProvidersParams) (opencode.AppProvidersResponse, error) +- client.App.Log(ctx context.Context, body opencode.AppLogParams) (bool, error) +- client.App.Providers(ctx context.Context) (opencode.AppProvidersResponse, error) # Agent @@ -45,7 +45,7 @@ Response Types: Methods: -- client.Agent.List(ctx context.Context, query opencode.AgentListParams) ([]opencode.Agent, error) +- client.Agent.List(ctx context.Context) ([]opencode.Agent, error) # Find @@ -72,7 +72,7 @@ Methods: - client.File.List(ctx context.Context, query opencode.FileListParams) ([]opencode.FileNode, error) - client.File.Read(ctx context.Context, query opencode.FileReadParams) (opencode.FileReadResponse, error) -- client.File.Status(ctx context.Context, query opencode.FileStatusParams) ([]opencode.File, error) +- client.File.Status(ctx context.Context) ([]opencode.File, error) # Config @@ -85,7 +85,7 @@ Response Types: Methods: -- client.Config.Get(ctx context.Context, query opencode.ConfigGetParams) (opencode.Config, error) +- client.Config.Get(ctx context.Context) (opencode.Config, error) # Command @@ -95,7 +95,7 @@ Response Types: Methods: -- client.Command.List(ctx context.Context, query opencode.CommandListParams) ([]opencode.Command, error) +- client.Command.List(ctx context.Context) ([]opencode.Command, error) # Project @@ -105,8 +105,8 @@ Response Types: Methods: -- client.Project.List(ctx context.Context, query opencode.ProjectListParams) ([]opencode.Project, error) -- client.Project.Current(ctx context.Context, query opencode.ProjectCurrentParams) (opencode.Project, error) +- client.Project.List(ctx context.Context) ([]opencode.Project, error) +- client.Project.Current(ctx context.Context) (opencode.Project, error) # Session @@ -151,23 +151,23 @@ Response Types: Methods: - client.Session.New(ctx context.Context, params opencode.SessionNewParams) (opencode.Session, error) -- client.Session.Update(ctx context.Context, id string, params opencode.SessionUpdateParams) (opencode.Session, error) -- client.Session.List(ctx context.Context, query opencode.SessionListParams) ([]opencode.Session, error) -- client.Session.Delete(ctx context.Context, id string, body opencode.SessionDeleteParams) (bool, error) -- client.Session.Abort(ctx context.Context, id string, body opencode.SessionAbortParams) (bool, error) -- client.Session.Children(ctx context.Context, id string, query opencode.SessionChildrenParams) ([]opencode.Session, error) -- client.Session.Command(ctx context.Context, id string, params opencode.SessionCommandParams) (opencode.SessionCommandResponse, error) -- client.Session.Get(ctx context.Context, id string, query opencode.SessionGetParams) (opencode.Session, error) -- client.Session.Init(ctx context.Context, id string, params opencode.SessionInitParams) (bool, error) -- client.Session.Message(ctx context.Context, id string, messageID string, query opencode.SessionMessageParams) (opencode.SessionMessageResponse, error) -- client.Session.Messages(ctx context.Context, id string, query opencode.SessionMessagesParams) ([]opencode.SessionMessagesResponse, error) -- client.Session.Prompt(ctx context.Context, id string, params opencode.SessionPromptParams) (opencode.SessionPromptResponse, error) -- client.Session.Revert(ctx context.Context, id string, params opencode.SessionRevertParams) (opencode.Session, error) -- client.Session.Share(ctx context.Context, id string, body opencode.SessionShareParams) (opencode.Session, error) -- client.Session.Shell(ctx context.Context, id string, params opencode.SessionShellParams) (opencode.AssistantMessage, error) -- client.Session.Summarize(ctx context.Context, id string, params opencode.SessionSummarizeParams) (bool, error) -- client.Session.Unrevert(ctx context.Context, id string, body opencode.SessionUnrevertParams) (opencode.Session, error) -- client.Session.Unshare(ctx context.Context, id string, body opencode.SessionUnshareParams) (opencode.Session, error) +- client.Session.Update(ctx context.Context, id string, body opencode.SessionUpdateParams) (opencode.Session, error) +- client.Session.List(ctx context.Context) ([]opencode.Session, error) +- client.Session.Delete(ctx context.Context, id string) (bool, error) +- client.Session.Abort(ctx context.Context, id string) (bool, error) +- client.Session.Children(ctx context.Context, id string) ([]opencode.Session, error) +- client.Session.Command(ctx context.Context, id string, body opencode.SessionCommandParams) (opencode.SessionCommandResponse, error) +- client.Session.Get(ctx context.Context, id string) (opencode.Session, error) +- client.Session.Init(ctx context.Context, id string, body opencode.SessionInitParams) (bool, error) +- client.Session.Message(ctx context.Context, id string, messageID string) (opencode.SessionMessageResponse, error) +- client.Session.Messages(ctx context.Context, id string) ([]opencode.SessionMessagesResponse, error) +- client.Session.Prompt(ctx context.Context, id string, body opencode.SessionPromptParams) (opencode.SessionPromptResponse, error) +- client.Session.Revert(ctx context.Context, id string, body opencode.SessionRevertParams) (opencode.Session, error) +- client.Session.Share(ctx context.Context, id string) (opencode.Session, error) +- client.Session.Shell(ctx context.Context, id string, body opencode.SessionShellParams) (opencode.AssistantMessage, error) +- client.Session.Summarize(ctx context.Context, id string, body opencode.SessionSummarizeParams) (bool, error) +- client.Session.Unrevert(ctx context.Context, id string) (opencode.Session, error) +- client.Session.Unshare(ctx context.Context, id string) (opencode.Session, error) ## Permissions @@ -177,18 +177,18 @@ Response Types: Methods: -- client.Session.Permissions.Respond(ctx context.Context, id string, permissionID string, params opencode.SessionPermissionRespondParams) (bool, error) +- client.Session.Permissions.Respond(ctx context.Context, id string, permissionID string, body opencode.SessionPermissionRespondParams) (bool, error) # Tui Methods: -- client.Tui.AppendPrompt(ctx context.Context, params opencode.TuiAppendPromptParams) (bool, error) -- client.Tui.ClearPrompt(ctx context.Context, body opencode.TuiClearPromptParams) (bool, error) -- client.Tui.ExecuteCommand(ctx context.Context, params opencode.TuiExecuteCommandParams) (bool, error) -- client.Tui.OpenHelp(ctx context.Context, body opencode.TuiOpenHelpParams) (bool, error) -- client.Tui.OpenModels(ctx context.Context, body opencode.TuiOpenModelsParams) (bool, error) -- client.Tui.OpenSessions(ctx context.Context, body opencode.TuiOpenSessionsParams) (bool, error) -- client.Tui.OpenThemes(ctx context.Context, body opencode.TuiOpenThemesParams) (bool, error) -- client.Tui.ShowToast(ctx context.Context, params opencode.TuiShowToastParams) (bool, error) -- client.Tui.SubmitPrompt(ctx context.Context, body opencode.TuiSubmitPromptParams) (bool, error) +- client.Tui.AppendPrompt(ctx context.Context, body opencode.TuiAppendPromptParams) (bool, error) +- client.Tui.ClearPrompt(ctx context.Context) (bool, error) +- client.Tui.ExecuteCommand(ctx context.Context, body opencode.TuiExecuteCommandParams) (bool, error) +- client.Tui.OpenHelp(ctx context.Context) (bool, error) +- client.Tui.OpenModels(ctx context.Context) (bool, error) +- client.Tui.OpenSessions(ctx context.Context) (bool, error) +- client.Tui.OpenThemes(ctx context.Context) (bool, error) +- client.Tui.ShowToast(ctx context.Context, body opencode.TuiShowToastParams) (bool, error) +- client.Tui.SubmitPrompt(ctx context.Context) (bool, error) diff --git a/app.go b/app.go index 62d86f9..a133014 100644 --- a/app.go +++ b/app.go @@ -5,10 +5,8 @@ package opencode import ( "context" "net/http" - "net/url" "github.com/sst/opencode-sdk-go/internal/apijson" - "github.com/sst/opencode-sdk-go/internal/apiquery" "github.com/sst/opencode-sdk-go/internal/param" "github.com/sst/opencode-sdk-go/internal/requestconfig" "github.com/sst/opencode-sdk-go/option" @@ -34,18 +32,18 @@ func NewAppService(opts ...option.RequestOption) (r *AppService) { } // Write a log entry to the server logs -func (r *AppService) Log(ctx context.Context, params AppLogParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *AppService) Log(ctx context.Context, body AppLogParams, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) path := "log" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return } // List all providers -func (r *AppService) Providers(ctx context.Context, query AppProvidersParams, opts ...option.RequestOption) (res *AppProvidersResponse, err error) { +func (r *AppService) Providers(ctx context.Context, opts ...option.RequestOption) (res *AppProvidersResponse, err error) { opts = append(r.Options[:], opts...) path := "config/providers" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } @@ -218,8 +216,7 @@ type AppLogParams struct { // Log message Message param.Field[string] `json:"message,required"` // Service name for the log entry - Service param.Field[string] `json:"service,required"` - Directory param.Field[string] `query:"directory"` + Service param.Field[string] `json:"service,required"` // Additional metadata for the log entry Extra param.Field[map[string]interface{}] `json:"extra"` } @@ -228,14 +225,6 @@ func (r AppLogParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -// URLQuery serializes [AppLogParams]'s query parameters as `url.Values`. -func (r AppLogParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - // Log level type AppLogParamsLevel string @@ -253,15 +242,3 @@ func (r AppLogParamsLevel) IsKnown() bool { } return false } - -type AppProvidersParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [AppProvidersParams]'s query parameters as `url.Values`. -func (r AppProvidersParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} diff --git a/app_test.go b/app_test.go index eb2fc92..847ec5c 100644 --- a/app_test.go +++ b/app_test.go @@ -26,10 +26,9 @@ func TestAppLogWithOptionalParams(t *testing.T) { option.WithBaseURL(baseURL), ) _, err := client.App.Log(context.TODO(), opencode.AppLogParams{ - Level: opencode.F(opencode.AppLogParamsLevelDebug), - Message: opencode.F("message"), - Service: opencode.F("service"), - Directory: opencode.F("directory"), + Level: opencode.F(opencode.AppLogParamsLevelDebug), + Message: opencode.F("message"), + Service: opencode.F("service"), Extra: opencode.F(map[string]interface{}{ "foo": "bar", }), @@ -43,7 +42,7 @@ func TestAppLogWithOptionalParams(t *testing.T) { } } -func TestAppProvidersWithOptionalParams(t *testing.T) { +func TestAppProviders(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -55,9 +54,7 @@ func TestAppProvidersWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.App.Providers(context.TODO(), opencode.AppProvidersParams{ - Directory: opencode.F("directory"), - }) + _, err := client.App.Providers(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { diff --git a/client_test.go b/client_test.go index d620da8..0f5b820 100644 --- a/client_test.go +++ b/client_test.go @@ -38,7 +38,7 @@ func TestUserAgentHeader(t *testing.T) { }, }), ) - client.Session.List(context.Background(), opencode.SessionListParams{}) + client.Session.List(context.Background()) if userAgent != fmt.Sprintf("Opencode/Go %s", internal.PackageVersion) { t.Errorf("Expected User-Agent to be correct, but got: %#v", userAgent) } @@ -61,7 +61,7 @@ func TestRetryAfter(t *testing.T) { }, }), ) - _, err := client.Session.List(context.Background(), opencode.SessionListParams{}) + _, err := client.Session.List(context.Background()) if err == nil { t.Error("Expected there to be a cancel error") } @@ -95,7 +95,7 @@ func TestDeleteRetryCountHeader(t *testing.T) { }), option.WithHeaderDel("X-Stainless-Retry-Count"), ) - _, err := client.Session.List(context.Background(), opencode.SessionListParams{}) + _, err := client.Session.List(context.Background()) if err == nil { t.Error("Expected there to be a cancel error") } @@ -124,7 +124,7 @@ func TestOverwriteRetryCountHeader(t *testing.T) { }), option.WithHeader("X-Stainless-Retry-Count", "42"), ) - _, err := client.Session.List(context.Background(), opencode.SessionListParams{}) + _, err := client.Session.List(context.Background()) if err == nil { t.Error("Expected there to be a cancel error") } @@ -152,7 +152,7 @@ func TestRetryAfterMs(t *testing.T) { }, }), ) - _, err := client.Session.List(context.Background(), opencode.SessionListParams{}) + _, err := client.Session.List(context.Background()) if err == nil { t.Error("Expected there to be a cancel error") } @@ -174,7 +174,7 @@ func TestContextCancel(t *testing.T) { ) cancelCtx, cancel := context.WithCancel(context.Background()) cancel() - _, err := client.Session.List(cancelCtx, opencode.SessionListParams{}) + _, err := client.Session.List(cancelCtx) if err == nil { t.Error("Expected there to be a cancel error") } @@ -193,7 +193,7 @@ func TestContextCancelDelay(t *testing.T) { ) cancelCtx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond) defer cancel() - _, err := client.Session.List(cancelCtx, opencode.SessionListParams{}) + _, err := client.Session.List(cancelCtx) if err == nil { t.Error("expected there to be a cancel error") } @@ -218,7 +218,7 @@ func TestContextDeadline(t *testing.T) { }, }), ) - _, err := client.Session.List(deadlineCtx, opencode.SessionListParams{}) + _, err := client.Session.List(deadlineCtx) if err == nil { t.Error("expected there to be a deadline error") } @@ -262,7 +262,7 @@ func TestContextDeadlineStreaming(t *testing.T) { }, }), ) - stream := client.Event.ListStreaming(deadlineCtx, opencode.EventListParams{}) + stream := client.Event.ListStreaming(deadlineCtx) for stream.Next() { _ = stream.Current() } @@ -306,11 +306,7 @@ func TestContextDeadlineStreamingWithRequestTimeout(t *testing.T) { }, }), ) - stream := client.Event.ListStreaming( - context.Background(), - opencode.EventListParams{}, - option.WithRequestTimeout((100 * time.Millisecond)), - ) + stream := client.Event.ListStreaming(context.Background(), option.WithRequestTimeout((100 * time.Millisecond))) for stream.Next() { _ = stream.Current() } diff --git a/command.go b/command.go index 2638fc6..31ca16d 100644 --- a/command.go +++ b/command.go @@ -5,11 +5,8 @@ package opencode import ( "context" "net/http" - "net/url" "github.com/sst/opencode-sdk-go/internal/apijson" - "github.com/sst/opencode-sdk-go/internal/apiquery" - "github.com/sst/opencode-sdk-go/internal/param" "github.com/sst/opencode-sdk-go/internal/requestconfig" "github.com/sst/opencode-sdk-go/option" ) @@ -34,10 +31,10 @@ func NewCommandService(opts ...option.RequestOption) (r *CommandService) { } // List all commands -func (r *CommandService) List(ctx context.Context, query CommandListParams, opts ...option.RequestOption) (res *[]Command, err error) { +func (r *CommandService) List(ctx context.Context, opts ...option.RequestOption) (res *[]Command, err error) { opts = append(r.Options[:], opts...) path := "command" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } @@ -47,6 +44,7 @@ type Command struct { Agent string `json:"agent"` Description string `json:"description"` Model string `json:"model"` + Subtask bool `json:"subtask"` JSON commandJSON `json:"-"` } @@ -57,6 +55,7 @@ type commandJSON struct { Agent apijson.Field Description apijson.Field Model apijson.Field + Subtask apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -68,15 +67,3 @@ func (r *Command) UnmarshalJSON(data []byte) (err error) { func (r commandJSON) RawJSON() string { return r.raw } - -type CommandListParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [CommandListParams]'s query parameters as `url.Values`. -func (r CommandListParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} diff --git a/command_test.go b/command_test.go index 781498b..5e62ffb 100644 --- a/command_test.go +++ b/command_test.go @@ -13,7 +13,7 @@ import ( "github.com/sst/opencode-sdk-go/option" ) -func TestCommandListWithOptionalParams(t *testing.T) { +func TestCommandList(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -25,9 +25,7 @@ func TestCommandListWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Command.List(context.TODO(), opencode.CommandListParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Command.List(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { diff --git a/config.go b/config.go index b0473f8..494da98 100644 --- a/config.go +++ b/config.go @@ -5,12 +5,9 @@ package opencode import ( "context" "net/http" - "net/url" "reflect" "github.com/sst/opencode-sdk-go/internal/apijson" - "github.com/sst/opencode-sdk-go/internal/apiquery" - "github.com/sst/opencode-sdk-go/internal/param" "github.com/sst/opencode-sdk-go/internal/requestconfig" "github.com/sst/opencode-sdk-go/option" "github.com/sst/opencode-sdk-go/shared" @@ -37,10 +34,10 @@ func NewConfigService(opts ...option.RequestOption) (r *ConfigService) { } // Get config info -func (r *ConfigService) Get(ctx context.Context, query ConfigGetParams, opts ...option.RequestOption) (res *Config, err error) { +func (r *ConfigService) Get(ctx context.Context, opts ...option.RequestOption) (res *Config, err error) { opts = append(r.Options[:], opts...) path := "config" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } @@ -676,6 +673,7 @@ type ConfigCommand struct { Agent string `json:"agent"` Description string `json:"description"` Model string `json:"model"` + Subtask bool `json:"subtask"` JSON configCommandJSON `json:"-"` } @@ -685,6 +683,7 @@ type configCommandJSON struct { Agent apijson.Field Description apijson.Field Model apijson.Field + Subtask apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -698,16 +697,18 @@ func (r configCommandJSON) RawJSON() string { } type ConfigExperimental struct { - Hook ConfigExperimentalHook `json:"hook"` - JSON configExperimentalJSON `json:"-"` + DisablePasteSummary bool `json:"disable_paste_summary"` + Hook ConfigExperimentalHook `json:"hook"` + JSON configExperimentalJSON `json:"-"` } // configExperimentalJSON contains the JSON metadata for the struct // [ConfigExperimental] type configExperimentalJSON struct { - Hook apijson.Field - raw string - ExtraFields map[string]apijson.Field + DisablePasteSummary apijson.Field + Hook apijson.Field + raw string + ExtraFields map[string]apijson.Field } func (r *ConfigExperimental) UnmarshalJSON(data []byte) (err error) { @@ -1020,16 +1021,14 @@ type ConfigMcpUnion interface { func init() { apijson.RegisterUnion( reflect.TypeOf((*ConfigMcpUnion)(nil)).Elem(), - "type", + "", apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(McpLocalConfig{}), - DiscriminatorValue: "local", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(McpLocalConfig{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(McpRemoteConfig{}), - DiscriminatorValue: "remote", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(McpRemoteConfig{}), }, ) } @@ -1751,7 +1750,7 @@ func (r ConfigShare) IsKnown() bool { // TUI specific settings type ConfigTui struct { // TUI scroll speed - ScrollSpeed float64 `json:"scroll_speed,required"` + ScrollSpeed float64 `json:"scroll_speed"` JSON configTuiJSON `json:"-"` } @@ -1770,105 +1769,106 @@ func (r configTuiJSON) RawJSON() string { return r.raw } +// Custom keybind configurations type KeybindsConfig struct { // Next agent - AgentCycle string `json:"agent_cycle,required"` + AgentCycle string `json:"agent_cycle"` // Previous agent - AgentCycleReverse string `json:"agent_cycle_reverse,required"` + AgentCycleReverse string `json:"agent_cycle_reverse"` // List agents - AgentList string `json:"agent_list,required"` + AgentList string `json:"agent_list"` // Exit the application - AppExit string `json:"app_exit,required"` + AppExit string `json:"app_exit"` // Show help dialog - AppHelp string `json:"app_help,required"` + AppHelp string `json:"app_help"` // Open external editor - EditorOpen string `json:"editor_open,required"` + EditorOpen string `json:"editor_open"` // @deprecated Close file - FileClose string `json:"file_close,required"` + FileClose string `json:"file_close"` // @deprecated Split/unified diff - FileDiffToggle string `json:"file_diff_toggle,required"` + FileDiffToggle string `json:"file_diff_toggle"` // @deprecated Currently not available. List files - FileList string `json:"file_list,required"` + FileList string `json:"file_list"` // @deprecated Search file - FileSearch string `json:"file_search,required"` + FileSearch string `json:"file_search"` // Clear input field - InputClear string `json:"input_clear,required"` + InputClear string `json:"input_clear"` // Insert newline in input - InputNewline string `json:"input_newline,required"` + InputNewline string `json:"input_newline"` // Paste from clipboard - InputPaste string `json:"input_paste,required"` + InputPaste string `json:"input_paste"` // Submit input - InputSubmit string `json:"input_submit,required"` + InputSubmit string `json:"input_submit"` // Leader key for keybind combinations - Leader string `json:"leader,required"` + Leader string `json:"leader"` // Copy message - MessagesCopy string `json:"messages_copy,required"` + MessagesCopy string `json:"messages_copy"` // Navigate to first message - MessagesFirst string `json:"messages_first,required"` + MessagesFirst string `json:"messages_first"` // Scroll messages down by half page - MessagesHalfPageDown string `json:"messages_half_page_down,required"` + MessagesHalfPageDown string `json:"messages_half_page_down"` // Scroll messages up by half page - MessagesHalfPageUp string `json:"messages_half_page_up,required"` + MessagesHalfPageUp string `json:"messages_half_page_up"` // Navigate to last message - MessagesLast string `json:"messages_last,required"` + MessagesLast string `json:"messages_last"` // @deprecated Toggle layout - MessagesLayoutToggle string `json:"messages_layout_toggle,required"` + MessagesLayoutToggle string `json:"messages_layout_toggle"` // @deprecated Navigate to next message - MessagesNext string `json:"messages_next,required"` + MessagesNext string `json:"messages_next"` // Scroll messages down by one page - MessagesPageDown string `json:"messages_page_down,required"` + MessagesPageDown string `json:"messages_page_down"` // Scroll messages up by one page - MessagesPageUp string `json:"messages_page_up,required"` + MessagesPageUp string `json:"messages_page_up"` // @deprecated Navigate to previous message - MessagesPrevious string `json:"messages_previous,required"` + MessagesPrevious string `json:"messages_previous"` // Redo message - MessagesRedo string `json:"messages_redo,required"` + MessagesRedo string `json:"messages_redo"` // @deprecated use messages_undo. Revert message - MessagesRevert string `json:"messages_revert,required"` + MessagesRevert string `json:"messages_revert"` // Undo message - MessagesUndo string `json:"messages_undo,required"` + MessagesUndo string `json:"messages_undo"` // Next recent model - ModelCycleRecent string `json:"model_cycle_recent,required"` + ModelCycleRecent string `json:"model_cycle_recent"` // Previous recent model - ModelCycleRecentReverse string `json:"model_cycle_recent_reverse,required"` + ModelCycleRecentReverse string `json:"model_cycle_recent_reverse"` // List available models - ModelList string `json:"model_list,required"` + ModelList string `json:"model_list"` // Create/update AGENTS.md - ProjectInit string `json:"project_init,required"` + ProjectInit string `json:"project_init"` // Cycle to next child session - SessionChildCycle string `json:"session_child_cycle,required"` + SessionChildCycle string `json:"session_child_cycle"` // Cycle to previous child session - SessionChildCycleReverse string `json:"session_child_cycle_reverse,required"` + SessionChildCycleReverse string `json:"session_child_cycle_reverse"` // Compact the session - SessionCompact string `json:"session_compact,required"` + SessionCompact string `json:"session_compact"` // Export session to editor - SessionExport string `json:"session_export,required"` + SessionExport string `json:"session_export"` // Interrupt current session - SessionInterrupt string `json:"session_interrupt,required"` + SessionInterrupt string `json:"session_interrupt"` // List all sessions - SessionList string `json:"session_list,required"` + SessionList string `json:"session_list"` // Create a new session - SessionNew string `json:"session_new,required"` + SessionNew string `json:"session_new"` // Share current session - SessionShare string `json:"session_share,required"` + SessionShare string `json:"session_share"` // Show session timeline - SessionTimeline string `json:"session_timeline,required"` + SessionTimeline string `json:"session_timeline"` // Unshare current session - SessionUnshare string `json:"session_unshare,required"` + SessionUnshare string `json:"session_unshare"` // @deprecated use agent_cycle. Next agent - SwitchAgent string `json:"switch_agent,required"` + SwitchAgent string `json:"switch_agent"` // @deprecated use agent_cycle_reverse. Previous agent - SwitchAgentReverse string `json:"switch_agent_reverse,required"` + SwitchAgentReverse string `json:"switch_agent_reverse"` // @deprecated use agent_cycle. Next mode - SwitchMode string `json:"switch_mode,required"` + SwitchMode string `json:"switch_mode"` // @deprecated use agent_cycle_reverse. Previous mode - SwitchModeReverse string `json:"switch_mode_reverse,required"` + SwitchModeReverse string `json:"switch_mode_reverse"` // List available themes - ThemeList string `json:"theme_list,required"` + ThemeList string `json:"theme_list"` // Toggle thinking blocks - ThinkingBlocks string `json:"thinking_blocks,required"` + ThinkingBlocks string `json:"thinking_blocks"` // Toggle tool details - ToolDetails string `json:"tool_details,required"` + ToolDetails string `json:"tool_details"` JSON keybindsConfigJSON `json:"-"` } @@ -2028,15 +2028,3 @@ func (r McpRemoteConfigType) IsKnown() bool { } return false } - -type ConfigGetParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [ConfigGetParams]'s query parameters as `url.Values`. -func (r ConfigGetParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} diff --git a/config_test.go b/config_test.go index f188d7e..9a2676b 100644 --- a/config_test.go +++ b/config_test.go @@ -13,7 +13,7 @@ import ( "github.com/sst/opencode-sdk-go/option" ) -func TestConfigGetWithOptionalParams(t *testing.T) { +func TestConfigGet(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -25,9 +25,7 @@ func TestConfigGetWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Config.Get(context.TODO(), opencode.ConfigGetParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Config.Get(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { diff --git a/event.go b/event.go index 00ba202..3cb67af 100644 --- a/event.go +++ b/event.go @@ -5,12 +5,9 @@ package opencode import ( "context" "net/http" - "net/url" "reflect" "github.com/sst/opencode-sdk-go/internal/apijson" - "github.com/sst/opencode-sdk-go/internal/apiquery" - "github.com/sst/opencode-sdk-go/internal/param" "github.com/sst/opencode-sdk-go/internal/requestconfig" "github.com/sst/opencode-sdk-go/option" "github.com/sst/opencode-sdk-go/packages/ssestream" @@ -38,7 +35,7 @@ func NewEventService(opts ...option.RequestOption) (r *EventService) { } // Get events -func (r *EventService) ListStreaming(ctx context.Context, query EventListParams, opts ...option.RequestOption) (stream *ssestream.Stream[EventListResponse]) { +func (r *EventService) ListStreaming(ctx context.Context, opts ...option.RequestOption) (stream *ssestream.Stream[EventListResponse]) { var ( raw *http.Response err error @@ -46,7 +43,7 @@ func (r *EventService) ListStreaming(ctx context.Context, query EventListParams, opts = append(r.Options[:], opts...) opts = append([]option.RequestOption{option.WithHeader("Accept", "text/event-stream")}, opts...) path := "event" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &raw, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &raw, opts...) return ssestream.NewStream[EventListResponse](ssestream.NewDecoder(raw), err) } @@ -57,14 +54,14 @@ type EventListResponse struct { // [EventListResponseEventMessageUpdatedProperties], // [EventListResponseEventMessageRemovedProperties], // [EventListResponseEventMessagePartUpdatedProperties], - // [EventListResponseEventMessagePartRemovedProperties], [Permission], + // [EventListResponseEventMessagePartRemovedProperties], + // [EventListResponseEventSessionCompactedProperties], [Permission], // [EventListResponseEventPermissionRepliedProperties], // [EventListResponseEventFileEditedProperties], + // [EventListResponseEventSessionIdleProperties], // [EventListResponseEventSessionUpdatedProperties], // [EventListResponseEventSessionDeletedProperties], - // [EventListResponseEventSessionIdleProperties], - // [EventListResponseEventSessionErrorProperties], - // [EventListResponseEventSessionCompactedProperties], [interface{}]. + // [EventListResponseEventSessionErrorProperties], [interface{}]. Properties interface{} `json:"properties,required"` Type EventListResponseType `json:"type,required"` JSON eventListResponseJSON `json:"-"` @@ -102,11 +99,11 @@ func (r *EventListResponse) UnmarshalJSON(data []byte) (err error) { // [EventListResponseEventMessageUpdated], [EventListResponseEventMessageRemoved], // [EventListResponseEventMessagePartUpdated], // [EventListResponseEventMessagePartRemoved], +// [EventListResponseEventSessionCompacted], // [EventListResponseEventPermissionUpdated], // [EventListResponseEventPermissionReplied], [EventListResponseEventFileEdited], -// [EventListResponseEventSessionUpdated], [EventListResponseEventSessionDeleted], -// [EventListResponseEventSessionIdle], [EventListResponseEventSessionError], -// [EventListResponseEventSessionCompacted], +// [EventListResponseEventSessionIdle], [EventListResponseEventSessionUpdated], +// [EventListResponseEventSessionDeleted], [EventListResponseEventSessionError], // [EventListResponseEventServerConnected]. func (r EventListResponse) AsUnion() EventListResponseUnion { return r.union @@ -117,11 +114,11 @@ func (r EventListResponse) AsUnion() EventListResponseUnion { // [EventListResponseEventMessageUpdated], [EventListResponseEventMessageRemoved], // [EventListResponseEventMessagePartUpdated], // [EventListResponseEventMessagePartRemoved], +// [EventListResponseEventSessionCompacted], // [EventListResponseEventPermissionUpdated], // [EventListResponseEventPermissionReplied], [EventListResponseEventFileEdited], -// [EventListResponseEventSessionUpdated], [EventListResponseEventSessionDeleted], -// [EventListResponseEventSessionIdle], [EventListResponseEventSessionError], -// [EventListResponseEventSessionCompacted] or +// [EventListResponseEventSessionIdle], [EventListResponseEventSessionUpdated], +// [EventListResponseEventSessionDeleted], [EventListResponseEventSessionError] or // [EventListResponseEventServerConnected]. type EventListResponseUnion interface { implementsEventListResponse() @@ -130,81 +127,66 @@ type EventListResponseUnion interface { func init() { apijson.RegisterUnion( reflect.TypeOf((*EventListResponseUnion)(nil)).Elem(), - "type", + "", apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventInstallationUpdated{}), - DiscriminatorValue: "installation.updated", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventInstallationUpdated{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventLspClientDiagnostics{}), - DiscriminatorValue: "lsp.client.diagnostics", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventLspClientDiagnostics{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventMessageUpdated{}), - DiscriminatorValue: "message.updated", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventMessageUpdated{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventMessageRemoved{}), - DiscriminatorValue: "message.removed", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventMessageRemoved{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventMessagePartUpdated{}), - DiscriminatorValue: "message.part.updated", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventMessagePartUpdated{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventMessagePartRemoved{}), - DiscriminatorValue: "message.part.removed", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventMessagePartRemoved{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventPermissionUpdated{}), - DiscriminatorValue: "permission.updated", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventSessionCompacted{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventPermissionReplied{}), - DiscriminatorValue: "permission.replied", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventPermissionUpdated{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventFileEdited{}), - DiscriminatorValue: "file.edited", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventPermissionReplied{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventSessionUpdated{}), - DiscriminatorValue: "session.updated", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventFileEdited{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventSessionDeleted{}), - DiscriminatorValue: "session.deleted", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventSessionIdle{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventSessionIdle{}), - DiscriminatorValue: "session.idle", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventSessionUpdated{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventSessionError{}), - DiscriminatorValue: "session.error", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventSessionDeleted{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventSessionCompacted{}), - DiscriminatorValue: "session.compacted", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventSessionError{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventServerConnected{}), - DiscriminatorValue: "server.connected", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventServerConnected{}), }, ) } @@ -577,6 +559,66 @@ func (r EventListResponseEventMessagePartRemovedType) IsKnown() bool { return false } +type EventListResponseEventSessionCompacted struct { + Properties EventListResponseEventSessionCompactedProperties `json:"properties,required"` + Type EventListResponseEventSessionCompactedType `json:"type,required"` + JSON eventListResponseEventSessionCompactedJSON `json:"-"` +} + +// eventListResponseEventSessionCompactedJSON contains the JSON metadata for the +// struct [EventListResponseEventSessionCompacted] +type eventListResponseEventSessionCompactedJSON struct { + Properties apijson.Field + Type apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *EventListResponseEventSessionCompacted) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r eventListResponseEventSessionCompactedJSON) RawJSON() string { + return r.raw +} + +func (r EventListResponseEventSessionCompacted) implementsEventListResponse() {} + +type EventListResponseEventSessionCompactedProperties struct { + SessionID string `json:"sessionID,required"` + JSON eventListResponseEventSessionCompactedPropertiesJSON `json:"-"` +} + +// eventListResponseEventSessionCompactedPropertiesJSON contains the JSON metadata +// for the struct [EventListResponseEventSessionCompactedProperties] +type eventListResponseEventSessionCompactedPropertiesJSON struct { + SessionID apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *EventListResponseEventSessionCompactedProperties) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r eventListResponseEventSessionCompactedPropertiesJSON) RawJSON() string { + return r.raw +} + +type EventListResponseEventSessionCompactedType string + +const ( + EventListResponseEventSessionCompactedTypeSessionCompacted EventListResponseEventSessionCompactedType = "session.compacted" +) + +func (r EventListResponseEventSessionCompactedType) IsKnown() bool { + switch r { + case EventListResponseEventSessionCompactedTypeSessionCompacted: + return true + } + return false +} + type EventListResponseEventPermissionUpdated struct { Properties Permission `json:"properties,required"` Type EventListResponseEventPermissionUpdatedType `json:"type,required"` @@ -740,6 +782,66 @@ func (r EventListResponseEventFileEditedType) IsKnown() bool { return false } +type EventListResponseEventSessionIdle struct { + Properties EventListResponseEventSessionIdleProperties `json:"properties,required"` + Type EventListResponseEventSessionIdleType `json:"type,required"` + JSON eventListResponseEventSessionIdleJSON `json:"-"` +} + +// eventListResponseEventSessionIdleJSON contains the JSON metadata for the struct +// [EventListResponseEventSessionIdle] +type eventListResponseEventSessionIdleJSON struct { + Properties apijson.Field + Type apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *EventListResponseEventSessionIdle) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r eventListResponseEventSessionIdleJSON) RawJSON() string { + return r.raw +} + +func (r EventListResponseEventSessionIdle) implementsEventListResponse() {} + +type EventListResponseEventSessionIdleProperties struct { + SessionID string `json:"sessionID,required"` + JSON eventListResponseEventSessionIdlePropertiesJSON `json:"-"` +} + +// eventListResponseEventSessionIdlePropertiesJSON contains the JSON metadata for +// the struct [EventListResponseEventSessionIdleProperties] +type eventListResponseEventSessionIdlePropertiesJSON struct { + SessionID apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *EventListResponseEventSessionIdleProperties) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r eventListResponseEventSessionIdlePropertiesJSON) RawJSON() string { + return r.raw +} + +type EventListResponseEventSessionIdleType string + +const ( + EventListResponseEventSessionIdleTypeSessionIdle EventListResponseEventSessionIdleType = "session.idle" +) + +func (r EventListResponseEventSessionIdleType) IsKnown() bool { + switch r { + case EventListResponseEventSessionIdleTypeSessionIdle: + return true + } + return false +} + type EventListResponseEventSessionUpdated struct { Properties EventListResponseEventSessionUpdatedProperties `json:"properties,required"` Type EventListResponseEventSessionUpdatedType `json:"type,required"` @@ -860,66 +962,6 @@ func (r EventListResponseEventSessionDeletedType) IsKnown() bool { return false } -type EventListResponseEventSessionIdle struct { - Properties EventListResponseEventSessionIdleProperties `json:"properties,required"` - Type EventListResponseEventSessionIdleType `json:"type,required"` - JSON eventListResponseEventSessionIdleJSON `json:"-"` -} - -// eventListResponseEventSessionIdleJSON contains the JSON metadata for the struct -// [EventListResponseEventSessionIdle] -type eventListResponseEventSessionIdleJSON struct { - Properties apijson.Field - Type apijson.Field - raw string - ExtraFields map[string]apijson.Field -} - -func (r *EventListResponseEventSessionIdle) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) -} - -func (r eventListResponseEventSessionIdleJSON) RawJSON() string { - return r.raw -} - -func (r EventListResponseEventSessionIdle) implementsEventListResponse() {} - -type EventListResponseEventSessionIdleProperties struct { - SessionID string `json:"sessionID,required"` - JSON eventListResponseEventSessionIdlePropertiesJSON `json:"-"` -} - -// eventListResponseEventSessionIdlePropertiesJSON contains the JSON metadata for -// the struct [EventListResponseEventSessionIdleProperties] -type eventListResponseEventSessionIdlePropertiesJSON struct { - SessionID apijson.Field - raw string - ExtraFields map[string]apijson.Field -} - -func (r *EventListResponseEventSessionIdleProperties) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) -} - -func (r eventListResponseEventSessionIdlePropertiesJSON) RawJSON() string { - return r.raw -} - -type EventListResponseEventSessionIdleType string - -const ( - EventListResponseEventSessionIdleTypeSessionIdle EventListResponseEventSessionIdleType = "session.idle" -) - -func (r EventListResponseEventSessionIdleType) IsKnown() bool { - switch r { - case EventListResponseEventSessionIdleTypeSessionIdle: - return true - } - return false -} - type EventListResponseEventSessionError struct { Properties EventListResponseEventSessionErrorProperties `json:"properties,required"` Type EventListResponseEventSessionErrorType `json:"type,required"` @@ -970,7 +1012,7 @@ func (r eventListResponseEventSessionErrorPropertiesJSON) RawJSON() string { type EventListResponseEventSessionErrorPropertiesError struct { // This field can have the runtime type of [shared.ProviderAuthErrorData], - // [shared.UnknownErrorData], [interface{}]. + // [shared.UnknownErrorData], [interface{}], [shared.MessageAbortedErrorData]. Data interface{} `json:"data,required"` Name EventListResponseEventSessionErrorPropertiesErrorName `json:"name,required"` JSON eventListResponseEventSessionErrorPropertiesErrorJSON `json:"-"` @@ -1020,26 +1062,22 @@ type EventListResponseEventSessionErrorPropertiesErrorUnion interface { func init() { apijson.RegisterUnion( reflect.TypeOf((*EventListResponseEventSessionErrorPropertiesErrorUnion)(nil)).Elem(), - "name", + "", apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(shared.ProviderAuthError{}), - DiscriminatorValue: "ProviderAuthError", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(shared.ProviderAuthError{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(shared.UnknownError{}), - DiscriminatorValue: "UnknownError", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(shared.UnknownError{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthError{}), - DiscriminatorValue: "MessageOutputLengthError", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthError{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(shared.MessageAbortedError{}), - DiscriminatorValue: "MessageAbortedError", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(shared.MessageAbortedError{}), }, ) } @@ -1116,66 +1154,6 @@ func (r EventListResponseEventSessionErrorType) IsKnown() bool { return false } -type EventListResponseEventSessionCompacted struct { - Properties EventListResponseEventSessionCompactedProperties `json:"properties,required"` - Type EventListResponseEventSessionCompactedType `json:"type,required"` - JSON eventListResponseEventSessionCompactedJSON `json:"-"` -} - -// eventListResponseEventSessionCompactedJSON contains the JSON metadata for the -// struct [EventListResponseEventSessionCompacted] -type eventListResponseEventSessionCompactedJSON struct { - Properties apijson.Field - Type apijson.Field - raw string - ExtraFields map[string]apijson.Field -} - -func (r *EventListResponseEventSessionCompacted) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) -} - -func (r eventListResponseEventSessionCompactedJSON) RawJSON() string { - return r.raw -} - -func (r EventListResponseEventSessionCompacted) implementsEventListResponse() {} - -type EventListResponseEventSessionCompactedProperties struct { - SessionID string `json:"sessionID,required"` - JSON eventListResponseEventSessionCompactedPropertiesJSON `json:"-"` -} - -// eventListResponseEventSessionCompactedPropertiesJSON contains the JSON metadata -// for the struct [EventListResponseEventSessionCompactedProperties] -type eventListResponseEventSessionCompactedPropertiesJSON struct { - SessionID apijson.Field - raw string - ExtraFields map[string]apijson.Field -} - -func (r *EventListResponseEventSessionCompactedProperties) UnmarshalJSON(data []byte) (err error) { - return apijson.UnmarshalRoot(data, r) -} - -func (r eventListResponseEventSessionCompactedPropertiesJSON) RawJSON() string { - return r.raw -} - -type EventListResponseEventSessionCompactedType string - -const ( - EventListResponseEventSessionCompactedTypeSessionCompacted EventListResponseEventSessionCompactedType = "session.compacted" -) - -func (r EventListResponseEventSessionCompactedType) IsKnown() bool { - switch r { - case EventListResponseEventSessionCompactedTypeSessionCompacted: - return true - } - return false -} - type EventListResponseEventServerConnected struct { Properties interface{} `json:"properties,required"` Type EventListResponseEventServerConnectedType `json:"type,required"` @@ -1224,33 +1202,21 @@ const ( EventListResponseTypeMessageRemoved EventListResponseType = "message.removed" EventListResponseTypeMessagePartUpdated EventListResponseType = "message.part.updated" EventListResponseTypeMessagePartRemoved EventListResponseType = "message.part.removed" + EventListResponseTypeSessionCompacted EventListResponseType = "session.compacted" EventListResponseTypePermissionUpdated EventListResponseType = "permission.updated" EventListResponseTypePermissionReplied EventListResponseType = "permission.replied" EventListResponseTypeFileEdited EventListResponseType = "file.edited" + EventListResponseTypeSessionIdle EventListResponseType = "session.idle" EventListResponseTypeSessionUpdated EventListResponseType = "session.updated" EventListResponseTypeSessionDeleted EventListResponseType = "session.deleted" - EventListResponseTypeSessionIdle EventListResponseType = "session.idle" EventListResponseTypeSessionError EventListResponseType = "session.error" - EventListResponseTypeSessionCompacted EventListResponseType = "session.compacted" EventListResponseTypeServerConnected EventListResponseType = "server.connected" ) func (r EventListResponseType) IsKnown() bool { switch r { - case EventListResponseTypeInstallationUpdated, EventListResponseTypeLspClientDiagnostics, EventListResponseTypeMessageUpdated, EventListResponseTypeMessageRemoved, EventListResponseTypeMessagePartUpdated, EventListResponseTypeMessagePartRemoved, EventListResponseTypePermissionUpdated, EventListResponseTypePermissionReplied, EventListResponseTypeFileEdited, EventListResponseTypeSessionUpdated, EventListResponseTypeSessionDeleted, EventListResponseTypeSessionIdle, EventListResponseTypeSessionError, EventListResponseTypeSessionCompacted, EventListResponseTypeServerConnected: + case EventListResponseTypeInstallationUpdated, EventListResponseTypeLspClientDiagnostics, EventListResponseTypeMessageUpdated, EventListResponseTypeMessageRemoved, EventListResponseTypeMessagePartUpdated, EventListResponseTypeMessagePartRemoved, EventListResponseTypeSessionCompacted, EventListResponseTypePermissionUpdated, EventListResponseTypePermissionReplied, EventListResponseTypeFileEdited, EventListResponseTypeSessionIdle, EventListResponseTypeSessionUpdated, EventListResponseTypeSessionDeleted, EventListResponseTypeSessionError, EventListResponseTypeServerConnected: return true } return false } - -type EventListParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [EventListParams]'s query parameters as `url.Values`. -func (r EventListParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} diff --git a/file.go b/file.go index bc36075..ef2d975 100644 --- a/file.go +++ b/file.go @@ -50,10 +50,10 @@ func (r *FileService) Read(ctx context.Context, query FileReadParams, opts ...op } // Get file status -func (r *FileService) Status(ctx context.Context, query FileStatusParams, opts ...option.RequestOption) (res *[]File, err error) { +func (r *FileService) Status(ctx context.Context, opts ...option.RequestOption) (res *[]File, err error) { opts = append(r.Options[:], opts...) path := "file/status" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } @@ -228,8 +228,7 @@ func (r fileReadResponsePatchHunkJSON) RawJSON() string { } type FileListParams struct { - Path param.Field[string] `query:"path,required"` - Directory param.Field[string] `query:"directory"` + Path param.Field[string] `query:"path,required"` } // URLQuery serializes [FileListParams]'s query parameters as `url.Values`. @@ -241,8 +240,7 @@ func (r FileListParams) URLQuery() (v url.Values) { } type FileReadParams struct { - Path param.Field[string] `query:"path,required"` - Directory param.Field[string] `query:"directory"` + Path param.Field[string] `query:"path,required"` } // URLQuery serializes [FileReadParams]'s query parameters as `url.Values`. @@ -252,15 +250,3 @@ func (r FileReadParams) URLQuery() (v url.Values) { NestedFormat: apiquery.NestedQueryFormatBrackets, }) } - -type FileStatusParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [FileStatusParams]'s query parameters as `url.Values`. -func (r FileStatusParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} diff --git a/file_test.go b/file_test.go index 2790fff..273f6e8 100644 --- a/file_test.go +++ b/file_test.go @@ -13,7 +13,7 @@ import ( "github.com/sst/opencode-sdk-go/option" ) -func TestFileListWithOptionalParams(t *testing.T) { +func TestFileList(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -26,8 +26,7 @@ func TestFileListWithOptionalParams(t *testing.T) { option.WithBaseURL(baseURL), ) _, err := client.File.List(context.TODO(), opencode.FileListParams{ - Path: opencode.F("path"), - Directory: opencode.F("directory"), + Path: opencode.F("path"), }) if err != nil { var apierr *opencode.Error @@ -38,7 +37,7 @@ func TestFileListWithOptionalParams(t *testing.T) { } } -func TestFileReadWithOptionalParams(t *testing.T) { +func TestFileRead(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -51,8 +50,7 @@ func TestFileReadWithOptionalParams(t *testing.T) { option.WithBaseURL(baseURL), ) _, err := client.File.Read(context.TODO(), opencode.FileReadParams{ - Path: opencode.F("path"), - Directory: opencode.F("directory"), + Path: opencode.F("path"), }) if err != nil { var apierr *opencode.Error @@ -63,7 +61,7 @@ func TestFileReadWithOptionalParams(t *testing.T) { } } -func TestFileStatusWithOptionalParams(t *testing.T) { +func TestFileStatus(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -75,9 +73,7 @@ func TestFileStatusWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.File.Status(context.TODO(), opencode.FileStatusParams{ - Directory: opencode.F("directory"), - }) + _, err := client.File.Status(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { diff --git a/find.go b/find.go index e869116..a993a35 100644 --- a/find.go +++ b/find.go @@ -290,8 +290,7 @@ func (r findTextResponseSubmatchesMatchJSON) RawJSON() string { } type FindFilesParams struct { - Query param.Field[string] `query:"query,required"` - Directory param.Field[string] `query:"directory"` + Query param.Field[string] `query:"query,required"` } // URLQuery serializes [FindFilesParams]'s query parameters as `url.Values`. @@ -303,8 +302,7 @@ func (r FindFilesParams) URLQuery() (v url.Values) { } type FindSymbolsParams struct { - Query param.Field[string] `query:"query,required"` - Directory param.Field[string] `query:"directory"` + Query param.Field[string] `query:"query,required"` } // URLQuery serializes [FindSymbolsParams]'s query parameters as `url.Values`. @@ -316,8 +314,7 @@ func (r FindSymbolsParams) URLQuery() (v url.Values) { } type FindTextParams struct { - Pattern param.Field[string] `query:"pattern,required"` - Directory param.Field[string] `query:"directory"` + Pattern param.Field[string] `query:"pattern,required"` } // URLQuery serializes [FindTextParams]'s query parameters as `url.Values`. diff --git a/find_test.go b/find_test.go index 901a895..22b5b95 100644 --- a/find_test.go +++ b/find_test.go @@ -13,7 +13,7 @@ import ( "github.com/sst/opencode-sdk-go/option" ) -func TestFindFilesWithOptionalParams(t *testing.T) { +func TestFindFiles(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -26,8 +26,7 @@ func TestFindFilesWithOptionalParams(t *testing.T) { option.WithBaseURL(baseURL), ) _, err := client.Find.Files(context.TODO(), opencode.FindFilesParams{ - Query: opencode.F("query"), - Directory: opencode.F("directory"), + Query: opencode.F("query"), }) if err != nil { var apierr *opencode.Error @@ -38,7 +37,7 @@ func TestFindFilesWithOptionalParams(t *testing.T) { } } -func TestFindSymbolsWithOptionalParams(t *testing.T) { +func TestFindSymbols(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -51,8 +50,7 @@ func TestFindSymbolsWithOptionalParams(t *testing.T) { option.WithBaseURL(baseURL), ) _, err := client.Find.Symbols(context.TODO(), opencode.FindSymbolsParams{ - Query: opencode.F("query"), - Directory: opencode.F("directory"), + Query: opencode.F("query"), }) if err != nil { var apierr *opencode.Error @@ -63,7 +61,7 @@ func TestFindSymbolsWithOptionalParams(t *testing.T) { } } -func TestFindTextWithOptionalParams(t *testing.T) { +func TestFindText(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -76,8 +74,7 @@ func TestFindTextWithOptionalParams(t *testing.T) { option.WithBaseURL(baseURL), ) _, err := client.Find.Text(context.TODO(), opencode.FindTextParams{ - Pattern: opencode.F("pattern"), - Directory: opencode.F("directory"), + Pattern: opencode.F("pattern"), }) if err != nil { var apierr *opencode.Error diff --git a/path.go b/path.go index 63e5026..91a0fda 100644 --- a/path.go +++ b/path.go @@ -5,11 +5,8 @@ package opencode import ( "context" "net/http" - "net/url" "github.com/sst/opencode-sdk-go/internal/apijson" - "github.com/sst/opencode-sdk-go/internal/apiquery" - "github.com/sst/opencode-sdk-go/internal/param" "github.com/sst/opencode-sdk-go/internal/requestconfig" "github.com/sst/opencode-sdk-go/option" ) @@ -34,10 +31,10 @@ func NewPathService(opts ...option.RequestOption) (r *PathService) { } // Get the current path -func (r *PathService) Get(ctx context.Context, query PathGetParams, opts ...option.RequestOption) (res *Path, err error) { +func (r *PathService) Get(ctx context.Context, opts ...option.RequestOption) (res *Path, err error) { opts = append(r.Options[:], opts...) path := "path" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } @@ -66,15 +63,3 @@ func (r *Path) UnmarshalJSON(data []byte) (err error) { func (r pathJSON) RawJSON() string { return r.raw } - -type PathGetParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [PathGetParams]'s query parameters as `url.Values`. -func (r PathGetParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} diff --git a/path_test.go b/path_test.go index 08273ce..e8b274a 100644 --- a/path_test.go +++ b/path_test.go @@ -13,7 +13,7 @@ import ( "github.com/sst/opencode-sdk-go/option" ) -func TestPathGetWithOptionalParams(t *testing.T) { +func TestPathGet(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -25,9 +25,7 @@ func TestPathGetWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Path.Get(context.TODO(), opencode.PathGetParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Path.Get(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { diff --git a/project.go b/project.go index 3b349da..73a0ba8 100644 --- a/project.go +++ b/project.go @@ -5,11 +5,8 @@ package opencode import ( "context" "net/http" - "net/url" "github.com/sst/opencode-sdk-go/internal/apijson" - "github.com/sst/opencode-sdk-go/internal/apiquery" - "github.com/sst/opencode-sdk-go/internal/param" "github.com/sst/opencode-sdk-go/internal/requestconfig" "github.com/sst/opencode-sdk-go/option" ) @@ -34,18 +31,18 @@ func NewProjectService(opts ...option.RequestOption) (r *ProjectService) { } // List all projects -func (r *ProjectService) List(ctx context.Context, query ProjectListParams, opts ...option.RequestOption) (res *[]Project, err error) { +func (r *ProjectService) List(ctx context.Context, opts ...option.RequestOption) (res *[]Project, err error) { opts = append(r.Options[:], opts...) path := "project" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } // Get the current project -func (r *ProjectService) Current(ctx context.Context, query ProjectCurrentParams, opts ...option.RequestOption) (res *Project, err error) { +func (r *ProjectService) Current(ctx context.Context, opts ...option.RequestOption) (res *Project, err error) { opts = append(r.Options[:], opts...) path := "project/current" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } @@ -110,27 +107,3 @@ func (r ProjectVcs) IsKnown() bool { } return false } - -type ProjectListParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [ProjectListParams]'s query parameters as `url.Values`. -func (r ProjectListParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type ProjectCurrentParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [ProjectCurrentParams]'s query parameters as `url.Values`. -func (r ProjectCurrentParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} diff --git a/project_test.go b/project_test.go index adf3dbf..20c8ca2 100644 --- a/project_test.go +++ b/project_test.go @@ -13,7 +13,7 @@ import ( "github.com/sst/opencode-sdk-go/option" ) -func TestProjectListWithOptionalParams(t *testing.T) { +func TestProjectList(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -25,9 +25,7 @@ func TestProjectListWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Project.List(context.TODO(), opencode.ProjectListParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Project.List(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -37,7 +35,7 @@ func TestProjectListWithOptionalParams(t *testing.T) { } } -func TestProjectCurrentWithOptionalParams(t *testing.T) { +func TestProjectCurrent(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -49,9 +47,7 @@ func TestProjectCurrentWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Project.Current(context.TODO(), opencode.ProjectCurrentParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Project.Current(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { diff --git a/session.go b/session.go index 6696e0f..5de9e2a 100644 --- a/session.go +++ b/session.go @@ -49,99 +49,99 @@ func (r *SessionService) New(ctx context.Context, params SessionNewParams, opts } // Update session properties -func (r *SessionService) Update(ctx context.Context, id string, params SessionUpdateParams, opts ...option.RequestOption) (res *Session, err error) { +func (r *SessionService) Update(ctx context.Context, id string, body SessionUpdateParams, 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", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...) return } // List all sessions -func (r *SessionService) List(ctx context.Context, query SessionListParams, opts ...option.RequestOption) (res *[]Session, err error) { +func (r *SessionService) List(ctx context.Context, opts ...option.RequestOption) (res *[]Session, err error) { opts = append(r.Options[:], opts...) path := "session" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } // Delete a session and all its data -func (r *SessionService) Delete(ctx context.Context, id string, body SessionDeleteParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *SessionService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) if id == "" { err = errors.New("missing required id parameter") return } path := fmt.Sprintf("session/%s", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, body, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) return } // Abort a session -func (r *SessionService) Abort(ctx context.Context, id string, body SessionAbortParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *SessionService) Abort(ctx context.Context, id string, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) if id == "" { err = errors.New("missing required id parameter") return } path := fmt.Sprintf("session/%s/abort", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) return } // Get a session's children -func (r *SessionService) Children(ctx context.Context, id string, query SessionChildrenParams, opts ...option.RequestOption) (res *[]Session, err error) { +func (r *SessionService) Children(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/children", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } // Send a new command to a session -func (r *SessionService) Command(ctx context.Context, id string, params SessionCommandParams, opts ...option.RequestOption) (res *SessionCommandResponse, err error) { +func (r *SessionService) Command(ctx context.Context, id string, body SessionCommandParams, opts ...option.RequestOption) (res *SessionCommandResponse, err error) { opts = append(r.Options[:], opts...) if id == "" { err = errors.New("missing required id parameter") return } path := fmt.Sprintf("session/%s/command", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return } // Get session -func (r *SessionService) Get(ctx context.Context, id string, query SessionGetParams, opts ...option.RequestOption) (res *Session, err error) { +func (r *SessionService) Get(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", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } // Analyze the app and create an AGENTS.md file -func (r *SessionService) Init(ctx context.Context, id string, params SessionInitParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *SessionService) Init(ctx context.Context, id string, body SessionInitParams, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) if id == "" { err = errors.New("missing required id parameter") return } path := fmt.Sprintf("session/%s/init", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return } // Get a message from a session -func (r *SessionService) Message(ctx context.Context, id string, messageID string, query SessionMessageParams, opts ...option.RequestOption) (res *SessionMessageResponse, err error) { +func (r *SessionService) Message(ctx context.Context, id string, messageID string, opts ...option.RequestOption) (res *SessionMessageResponse, err error) { opts = append(r.Options[:], opts...) if id == "" { err = errors.New("missing required id parameter") @@ -152,103 +152,103 @@ func (r *SessionService) Message(ctx context.Context, id string, messageID strin return } path := fmt.Sprintf("session/%s/message/%s", id, messageID) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } // List messages for a session -func (r *SessionService) Messages(ctx context.Context, id string, query SessionMessagesParams, opts ...option.RequestOption) (res *[]SessionMessagesResponse, err error) { +func (r *SessionService) Messages(ctx context.Context, id string, opts ...option.RequestOption) (res *[]SessionMessagesResponse, err error) { opts = append(r.Options[:], opts...) if id == "" { err = errors.New("missing required id parameter") return } path := fmt.Sprintf("session/%s/message", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) return } // Create and send a new message to a session -func (r *SessionService) Prompt(ctx context.Context, id string, params SessionPromptParams, opts ...option.RequestOption) (res *SessionPromptResponse, err error) { +func (r *SessionService) Prompt(ctx context.Context, id string, body SessionPromptParams, opts ...option.RequestOption) (res *SessionPromptResponse, err error) { opts = append(r.Options[:], opts...) if id == "" { err = errors.New("missing required id parameter") return } path := fmt.Sprintf("session/%s/message", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return } // Revert a message -func (r *SessionService) Revert(ctx context.Context, id string, params SessionRevertParams, opts ...option.RequestOption) (res *Session, err error) { +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, params, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return } // Share a session -func (r *SessionService) Share(ctx context.Context, id string, body SessionShareParams, opts ...option.RequestOption) (res *Session, err error) { +func (r *SessionService) Share(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/share", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) return } // Run a shell command -func (r *SessionService) Shell(ctx context.Context, id string, params SessionShellParams, opts ...option.RequestOption) (res *AssistantMessage, err error) { +func (r *SessionService) Shell(ctx context.Context, id string, body SessionShellParams, opts ...option.RequestOption) (res *AssistantMessage, err error) { opts = append(r.Options[:], opts...) if id == "" { err = errors.New("missing required id parameter") return } path := fmt.Sprintf("session/%s/shell", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return } // Summarize the session -func (r *SessionService) Summarize(ctx context.Context, id string, params SessionSummarizeParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *SessionService) Summarize(ctx context.Context, id string, body SessionSummarizeParams, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) if id == "" { err = errors.New("missing required id parameter") return } path := fmt.Sprintf("session/%s/summarize", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return } // Restore all reverted messages -func (r *SessionService) Unrevert(ctx context.Context, id string, body SessionUnrevertParams, opts ...option.RequestOption) (res *Session, err error) { +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, body, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) return } // Unshare the session -func (r *SessionService) Unshare(ctx context.Context, id string, body SessionUnshareParams, opts ...option.RequestOption) (res *Session, err error) { +func (r *SessionService) Unshare(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/share", id) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, body, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) return } @@ -518,7 +518,7 @@ func (r assistantMessageTokensCacheJSON) RawJSON() string { type AssistantMessageError struct { // This field can have the runtime type of [shared.ProviderAuthErrorData], - // [shared.UnknownErrorData], [interface{}]. + // [shared.UnknownErrorData], [interface{}], [shared.MessageAbortedErrorData]. Data interface{} `json:"data,required"` Name AssistantMessageErrorName `json:"name,required"` JSON assistantMessageErrorJSON `json:"-"` @@ -566,26 +566,22 @@ type AssistantMessageErrorUnion interface { func init() { apijson.RegisterUnion( reflect.TypeOf((*AssistantMessageErrorUnion)(nil)).Elem(), - "name", + "", apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(shared.ProviderAuthError{}), - DiscriminatorValue: "ProviderAuthError", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(shared.ProviderAuthError{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(shared.UnknownError{}), - DiscriminatorValue: "UnknownError", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(shared.UnknownError{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(AssistantMessageErrorMessageOutputLengthError{}), - DiscriminatorValue: "MessageOutputLengthError", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(AssistantMessageErrorMessageOutputLengthError{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(shared.MessageAbortedError{}), - DiscriminatorValue: "MessageAbortedError", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(shared.MessageAbortedError{}), }, ) } @@ -778,16 +774,14 @@ type FilePartSourceUnion interface { func init() { apijson.RegisterUnion( reflect.TypeOf((*FilePartSourceUnion)(nil)).Elem(), - "type", + "", apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(FileSource{}), - DiscriminatorValue: "file", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(FileSource{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(SymbolSource{}), - DiscriminatorValue: "symbol", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(SymbolSource{}), }, ) } @@ -986,16 +980,14 @@ type MessageUnion interface { func init() { apijson.RegisterUnion( reflect.TypeOf((*MessageUnion)(nil)).Elem(), - "role", + "", apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(UserMessage{}), - DiscriminatorValue: "user", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(UserMessage{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(AssistantMessage{}), - DiscriminatorValue: "assistant", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(AssistantMessage{}), }, ) } @@ -1107,51 +1099,42 @@ type PartUnion interface { func init() { apijson.RegisterUnion( reflect.TypeOf((*PartUnion)(nil)).Elem(), - "type", + "", apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(TextPart{}), - DiscriminatorValue: "text", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(TextPart{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(ReasoningPart{}), - DiscriminatorValue: "reasoning", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(ReasoningPart{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(FilePart{}), - DiscriminatorValue: "file", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(FilePart{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(ToolPart{}), - DiscriminatorValue: "tool", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(ToolPart{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(StepStartPart{}), - DiscriminatorValue: "step-start", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(StepStartPart{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(StepFinishPart{}), - DiscriminatorValue: "step-finish", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(StepFinishPart{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(SnapshotPart{}), - DiscriminatorValue: "snapshot", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(SnapshotPart{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(PartPatchPart{}), - DiscriminatorValue: "patch", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(PartPatchPart{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(AgentPart{}), - DiscriminatorValue: "agent", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(AgentPart{}), }, ) } @@ -1941,26 +1924,22 @@ type ToolPartStateUnion interface { func init() { apijson.RegisterUnion( reflect.TypeOf((*ToolPartStateUnion)(nil)).Elem(), - "status", + "", apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(ToolStatePending{}), - DiscriminatorValue: "pending", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(ToolStatePending{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(ToolStateRunning{}), - DiscriminatorValue: "running", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(ToolStateRunning{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(ToolStateCompleted{}), - DiscriminatorValue: "completed", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(ToolStateCompleted{}), }, apijson.UnionVariant{ - TypeFilter: gjson.JSON, - Type: reflect.TypeOf(ToolStateError{}), - DiscriminatorValue: "error", + TypeFilter: gjson.JSON, + Type: reflect.TypeOf(ToolStateError{}), }, ) } @@ -2044,9 +2023,10 @@ func (r ToolStateCompletedStatus) IsKnown() bool { } type ToolStateCompletedTime struct { - End float64 `json:"end,required"` - Start float64 `json:"start,required"` - JSON toolStateCompletedTimeJSON `json:"-"` + End float64 `json:"end,required"` + Start float64 `json:"start,required"` + Compacted float64 `json:"compacted"` + JSON toolStateCompletedTimeJSON `json:"-"` } // toolStateCompletedTimeJSON contains the JSON metadata for the struct @@ -2054,6 +2034,7 @@ type ToolStateCompletedTime struct { type toolStateCompletedTimeJSON struct { End apijson.Field Start apijson.Field + Compacted apijson.Field raw string ExtraFields map[string]apijson.Field } @@ -2171,9 +2152,9 @@ func (r ToolStatePendingStatus) IsKnown() bool { } type ToolStateRunning struct { + Input interface{} `json:"input,required"` Status ToolStateRunningStatus `json:"status,required"` Time ToolStateRunningTime `json:"time,required"` - Input interface{} `json:"input"` Metadata map[string]interface{} `json:"metadata"` Title string `json:"title"` JSON toolStateRunningJSON `json:"-"` @@ -2182,9 +2163,9 @@ type ToolStateRunning struct { // toolStateRunningJSON contains the JSON metadata for the struct // [ToolStateRunning] type toolStateRunningJSON struct { + Input apijson.Field Status apijson.Field Time apijson.Field - Input apijson.Field Metadata apijson.Field Title apijson.Field raw string @@ -2409,74 +2390,16 @@ func (r SessionNewParams) URLQuery() (v url.Values) { } type SessionUpdateParams struct { - Directory param.Field[string] `query:"directory"` - Title param.Field[string] `json:"title"` + Title param.Field[string] `json:"title"` } func (r SessionUpdateParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -// URLQuery serializes [SessionUpdateParams]'s query parameters as `url.Values`. -func (r SessionUpdateParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type SessionListParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [SessionListParams]'s query parameters as `url.Values`. -func (r SessionListParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type SessionDeleteParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [SessionDeleteParams]'s query parameters as `url.Values`. -func (r SessionDeleteParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type SessionAbortParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [SessionAbortParams]'s query parameters as `url.Values`. -func (r SessionAbortParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type SessionChildrenParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [SessionChildrenParams]'s query parameters as `url.Values`. -func (r SessionChildrenParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - type SessionCommandParams struct { Arguments param.Field[string] `json:"arguments,required"` Command param.Field[string] `json:"command,required"` - Directory param.Field[string] `query:"directory"` Agent param.Field[string] `json:"agent"` MessageID param.Field[string] `json:"messageID"` Model param.Field[string] `json:"model"` @@ -2486,72 +2409,18 @@ func (r SessionCommandParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -// URLQuery serializes [SessionCommandParams]'s query parameters as `url.Values`. -func (r SessionCommandParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type SessionGetParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [SessionGetParams]'s query parameters as `url.Values`. -func (r SessionGetParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - type SessionInitParams struct { MessageID param.Field[string] `json:"messageID,required"` ModelID param.Field[string] `json:"modelID,required"` ProviderID param.Field[string] `json:"providerID,required"` - Directory param.Field[string] `query:"directory"` } func (r SessionInitParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -// URLQuery serializes [SessionInitParams]'s query parameters as `url.Values`. -func (r SessionInitParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type SessionMessageParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [SessionMessageParams]'s query parameters as `url.Values`. -func (r SessionMessageParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type SessionMessagesParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [SessionMessagesParams]'s query parameters as `url.Values`. -func (r SessionMessagesParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - type SessionPromptParams struct { Parts param.Field[[]SessionPromptParamsPartUnion] `json:"parts,required"` - Directory param.Field[string] `query:"directory"` Agent param.Field[string] `json:"agent"` MessageID param.Field[string] `json:"messageID"` Model param.Field[SessionPromptParamsModel] `json:"model"` @@ -2563,14 +2432,6 @@ func (r SessionPromptParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -// URLQuery serializes [SessionPromptParams]'s query parameters as `url.Values`. -func (r SessionPromptParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - type SessionPromptParamsPart struct { Type param.Field[SessionPromptParamsPartsType] `json:"type,required"` ID param.Field[string] `json:"id"` @@ -2623,7 +2484,6 @@ func (r SessionPromptParamsModel) MarshalJSON() (data []byte, err error) { type SessionRevertParams struct { MessageID param.Field[string] `json:"messageID,required"` - Directory param.Field[string] `query:"directory"` PartID param.Field[string] `json:"partID"` } @@ -2631,82 +2491,20 @@ func (r SessionRevertParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -// URLQuery serializes [SessionRevertParams]'s query parameters as `url.Values`. -func (r SessionRevertParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type SessionShareParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [SessionShareParams]'s query parameters as `url.Values`. -func (r SessionShareParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - type SessionShellParams struct { - Agent param.Field[string] `json:"agent,required"` - Command param.Field[string] `json:"command,required"` - Directory param.Field[string] `query:"directory"` + Agent param.Field[string] `json:"agent,required"` + Command param.Field[string] `json:"command,required"` } func (r SessionShellParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -// URLQuery serializes [SessionShellParams]'s query parameters as `url.Values`. -func (r SessionShellParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - type SessionSummarizeParams struct { ModelID param.Field[string] `json:"modelID,required"` ProviderID param.Field[string] `json:"providerID,required"` - Directory param.Field[string] `query:"directory"` } func (r SessionSummarizeParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } - -// URLQuery serializes [SessionSummarizeParams]'s query parameters as `url.Values`. -func (r SessionSummarizeParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type SessionUnrevertParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [SessionUnrevertParams]'s query parameters as `url.Values`. -func (r SessionUnrevertParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type SessionUnshareParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [SessionUnshareParams]'s query parameters as `url.Values`. -func (r SessionUnshareParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} diff --git a/session_test.go b/session_test.go index f4cbc04..8ef76bb 100644 --- a/session_test.go +++ b/session_test.go @@ -55,8 +55,7 @@ func TestSessionUpdateWithOptionalParams(t *testing.T) { context.TODO(), "id", opencode.SessionUpdateParams{ - Directory: opencode.F("directory"), - Title: opencode.F("title"), + Title: opencode.F("title"), }, ) if err != nil { @@ -68,7 +67,7 @@ func TestSessionUpdateWithOptionalParams(t *testing.T) { } } -func TestSessionListWithOptionalParams(t *testing.T) { +func TestSessionList(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -80,9 +79,7 @@ func TestSessionListWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Session.List(context.TODO(), opencode.SessionListParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Session.List(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -92,7 +89,7 @@ func TestSessionListWithOptionalParams(t *testing.T) { } } -func TestSessionDeleteWithOptionalParams(t *testing.T) { +func TestSessionDelete(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -104,13 +101,7 @@ func TestSessionDeleteWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Session.Delete( - context.TODO(), - "id", - opencode.SessionDeleteParams{ - Directory: opencode.F("directory"), - }, - ) + _, err := client.Session.Delete(context.TODO(), "id") if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -120,7 +111,7 @@ func TestSessionDeleteWithOptionalParams(t *testing.T) { } } -func TestSessionAbortWithOptionalParams(t *testing.T) { +func TestSessionAbort(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -132,13 +123,7 @@ func TestSessionAbortWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Session.Abort( - context.TODO(), - "id", - opencode.SessionAbortParams{ - Directory: opencode.F("directory"), - }, - ) + _, err := client.Session.Abort(context.TODO(), "id") if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -148,7 +133,7 @@ func TestSessionAbortWithOptionalParams(t *testing.T) { } } -func TestSessionChildrenWithOptionalParams(t *testing.T) { +func TestSessionChildren(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -160,13 +145,7 @@ func TestSessionChildrenWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Session.Children( - context.TODO(), - "id", - opencode.SessionChildrenParams{ - Directory: opencode.F("directory"), - }, - ) + _, err := client.Session.Children(context.TODO(), "id") if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -194,9 +173,8 @@ func TestSessionCommandWithOptionalParams(t *testing.T) { opencode.SessionCommandParams{ Arguments: opencode.F("arguments"), Command: opencode.F("command"), - Directory: opencode.F("directory"), Agent: opencode.F("agent"), - MessageID: opencode.F("msg"), + MessageID: opencode.F("msgJ!"), Model: opencode.F("model"), }, ) @@ -209,7 +187,7 @@ func TestSessionCommandWithOptionalParams(t *testing.T) { } } -func TestSessionGetWithOptionalParams(t *testing.T) { +func TestSessionGet(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -221,13 +199,7 @@ func TestSessionGetWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Session.Get( - context.TODO(), - "id", - opencode.SessionGetParams{ - Directory: opencode.F("directory"), - }, - ) + _, err := client.Session.Get(context.TODO(), "id") if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -237,7 +209,7 @@ func TestSessionGetWithOptionalParams(t *testing.T) { } } -func TestSessionInitWithOptionalParams(t *testing.T) { +func TestSessionInit(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -256,7 +228,6 @@ func TestSessionInitWithOptionalParams(t *testing.T) { MessageID: opencode.F("messageID"), ModelID: opencode.F("modelID"), ProviderID: opencode.F("providerID"), - Directory: opencode.F("directory"), }, ) if err != nil { @@ -268,7 +239,7 @@ func TestSessionInitWithOptionalParams(t *testing.T) { } } -func TestSessionMessageWithOptionalParams(t *testing.T) { +func TestSessionMessage(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -284,9 +255,6 @@ func TestSessionMessageWithOptionalParams(t *testing.T) { context.TODO(), "id", "messageID", - opencode.SessionMessageParams{ - Directory: opencode.F("directory"), - }, ) if err != nil { var apierr *opencode.Error @@ -297,7 +265,7 @@ func TestSessionMessageWithOptionalParams(t *testing.T) { } } -func TestSessionMessagesWithOptionalParams(t *testing.T) { +func TestSessionMessages(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -309,13 +277,7 @@ func TestSessionMessagesWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Session.Messages( - context.TODO(), - "id", - opencode.SessionMessagesParams{ - Directory: opencode.F("directory"), - }, - ) + _, err := client.Session.Messages(context.TODO(), "id") if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -351,9 +313,8 @@ func TestSessionPromptWithOptionalParams(t *testing.T) { End: opencode.F(0.000000), }), }}), - Directory: opencode.F("directory"), Agent: opencode.F("agent"), - MessageID: opencode.F("msg"), + MessageID: opencode.F("msgJ!"), Model: opencode.F(opencode.SessionPromptParamsModel{ ModelID: opencode.F("modelID"), ProviderID: opencode.F("providerID"), @@ -389,9 +350,8 @@ func TestSessionRevertWithOptionalParams(t *testing.T) { context.TODO(), "id", opencode.SessionRevertParams{ - MessageID: opencode.F("msg"), - Directory: opencode.F("directory"), - PartID: opencode.F("prt"), + MessageID: opencode.F("msgJ!"), + PartID: opencode.F("prtJ!"), }, ) if err != nil { @@ -403,7 +363,7 @@ func TestSessionRevertWithOptionalParams(t *testing.T) { } } -func TestSessionShareWithOptionalParams(t *testing.T) { +func TestSessionShare(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -415,13 +375,7 @@ func TestSessionShareWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Session.Share( - context.TODO(), - "id", - opencode.SessionShareParams{ - Directory: opencode.F("directory"), - }, - ) + _, err := client.Session.Share(context.TODO(), "id") if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -431,7 +385,7 @@ func TestSessionShareWithOptionalParams(t *testing.T) { } } -func TestSessionShellWithOptionalParams(t *testing.T) { +func TestSessionShell(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -447,9 +401,8 @@ func TestSessionShellWithOptionalParams(t *testing.T) { context.TODO(), "id", opencode.SessionShellParams{ - Agent: opencode.F("agent"), - Command: opencode.F("command"), - Directory: opencode.F("directory"), + Agent: opencode.F("agent"), + Command: opencode.F("command"), }, ) if err != nil { @@ -461,7 +414,7 @@ func TestSessionShellWithOptionalParams(t *testing.T) { } } -func TestSessionSummarizeWithOptionalParams(t *testing.T) { +func TestSessionSummarize(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -479,7 +432,6 @@ func TestSessionSummarizeWithOptionalParams(t *testing.T) { opencode.SessionSummarizeParams{ ModelID: opencode.F("modelID"), ProviderID: opencode.F("providerID"), - Directory: opencode.F("directory"), }, ) if err != nil { @@ -491,7 +443,7 @@ func TestSessionSummarizeWithOptionalParams(t *testing.T) { } } -func TestSessionUnrevertWithOptionalParams(t *testing.T) { +func TestSessionUnrevert(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -503,13 +455,7 @@ func TestSessionUnrevertWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Session.Unrevert( - context.TODO(), - "id", - opencode.SessionUnrevertParams{ - Directory: opencode.F("directory"), - }, - ) + _, err := client.Session.Unrevert(context.TODO(), "id") if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -519,7 +465,7 @@ func TestSessionUnrevertWithOptionalParams(t *testing.T) { } } -func TestSessionUnshareWithOptionalParams(t *testing.T) { +func TestSessionUnshare(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -531,13 +477,7 @@ func TestSessionUnshareWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Session.Unshare( - context.TODO(), - "id", - opencode.SessionUnshareParams{ - Directory: opencode.F("directory"), - }, - ) + _, err := client.Session.Unshare(context.TODO(), "id") if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { diff --git a/sessionpermission.go b/sessionpermission.go index 4d49bd8..85e55bd 100644 --- a/sessionpermission.go +++ b/sessionpermission.go @@ -7,10 +7,8 @@ import ( "errors" "fmt" "net/http" - "net/url" "github.com/sst/opencode-sdk-go/internal/apijson" - "github.com/sst/opencode-sdk-go/internal/apiquery" "github.com/sst/opencode-sdk-go/internal/param" "github.com/sst/opencode-sdk-go/internal/requestconfig" "github.com/sst/opencode-sdk-go/option" @@ -36,7 +34,7 @@ func NewSessionPermissionService(opts ...option.RequestOption) (r *SessionPermis } // Respond to a permission request -func (r *SessionPermissionService) Respond(ctx context.Context, id string, permissionID string, params SessionPermissionRespondParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *SessionPermissionService) Respond(ctx context.Context, id string, permissionID string, body SessionPermissionRespondParams, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) if id == "" { err = errors.New("missing required id parameter") @@ -47,7 +45,7 @@ func (r *SessionPermissionService) Respond(ctx context.Context, id string, permi return } path := fmt.Sprintf("session/%s/permissions/%s", id, permissionID) - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return } @@ -108,23 +106,13 @@ func (r permissionTimeJSON) RawJSON() string { } type SessionPermissionRespondParams struct { - Response param.Field[SessionPermissionRespondParamsResponse] `json:"response,required"` - Directory param.Field[string] `query:"directory"` + Response param.Field[SessionPermissionRespondParamsResponse] `json:"response,required"` } func (r SessionPermissionRespondParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -// URLQuery serializes [SessionPermissionRespondParams]'s query parameters as -// `url.Values`. -func (r SessionPermissionRespondParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - type SessionPermissionRespondParamsResponse string const ( diff --git a/sessionpermission_test.go b/sessionpermission_test.go index ed396b5..6a60f2f 100644 --- a/sessionpermission_test.go +++ b/sessionpermission_test.go @@ -13,7 +13,7 @@ import ( "github.com/sst/opencode-sdk-go/option" ) -func TestSessionPermissionRespondWithOptionalParams(t *testing.T) { +func TestSessionPermissionRespond(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -30,8 +30,7 @@ func TestSessionPermissionRespondWithOptionalParams(t *testing.T) { "id", "permissionID", opencode.SessionPermissionRespondParams{ - Response: opencode.F(opencode.SessionPermissionRespondParamsResponseOnce), - Directory: opencode.F("directory"), + Response: opencode.F(opencode.SessionPermissionRespondParamsResponseOnce), }, ) if err != nil { diff --git a/shared/shared.go b/shared/shared.go index 58baf3d..f2c6db0 100644 --- a/shared/shared.go +++ b/shared/shared.go @@ -7,7 +7,7 @@ import ( ) type MessageAbortedError struct { - Data interface{} `json:"data,required"` + Data MessageAbortedErrorData `json:"data,required"` Name MessageAbortedErrorName `json:"name,required"` JSON messageAbortedErrorJSON `json:"-"` } @@ -33,6 +33,27 @@ func (r MessageAbortedError) ImplementsEventListResponseEventSessionErrorPropert func (r MessageAbortedError) ImplementsAssistantMessageError() {} +type MessageAbortedErrorData struct { + Message string `json:"message,required"` + JSON messageAbortedErrorDataJSON `json:"-"` +} + +// messageAbortedErrorDataJSON contains the JSON metadata for the struct +// [MessageAbortedErrorData] +type messageAbortedErrorDataJSON struct { + Message apijson.Field + raw string + ExtraFields map[string]apijson.Field +} + +func (r *MessageAbortedErrorData) UnmarshalJSON(data []byte) (err error) { + return apijson.UnmarshalRoot(data, r) +} + +func (r messageAbortedErrorDataJSON) RawJSON() string { + return r.raw +} + type MessageAbortedErrorName string const ( diff --git a/tui.go b/tui.go index b7a8483..ab5ed64 100644 --- a/tui.go +++ b/tui.go @@ -5,10 +5,8 @@ package opencode import ( "context" "net/http" - "net/url" "github.com/sst/opencode-sdk-go/internal/apijson" - "github.com/sst/opencode-sdk-go/internal/apiquery" "github.com/sst/opencode-sdk-go/internal/param" "github.com/sst/opencode-sdk-go/internal/requestconfig" "github.com/sst/opencode-sdk-go/option" @@ -34,191 +32,103 @@ func NewTuiService(opts ...option.RequestOption) (r *TuiService) { } // Append prompt to the TUI -func (r *TuiService) AppendPrompt(ctx context.Context, params TuiAppendPromptParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *TuiService) AppendPrompt(ctx context.Context, body TuiAppendPromptParams, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) path := "tui/append-prompt" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return } // Clear the prompt -func (r *TuiService) ClearPrompt(ctx context.Context, body TuiClearPromptParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *TuiService) ClearPrompt(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) path := "tui/clear-prompt" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) return } // Execute a TUI command (e.g. agent_cycle) -func (r *TuiService) ExecuteCommand(ctx context.Context, params TuiExecuteCommandParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *TuiService) ExecuteCommand(ctx context.Context, body TuiExecuteCommandParams, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) path := "tui/execute-command" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return } // Open the help dialog -func (r *TuiService) OpenHelp(ctx context.Context, body TuiOpenHelpParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *TuiService) OpenHelp(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) path := "tui/open-help" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) return } // Open the model dialog -func (r *TuiService) OpenModels(ctx context.Context, body TuiOpenModelsParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *TuiService) OpenModels(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) path := "tui/open-models" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) return } // Open the session dialog -func (r *TuiService) OpenSessions(ctx context.Context, body TuiOpenSessionsParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *TuiService) OpenSessions(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) path := "tui/open-sessions" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) return } // Open the theme dialog -func (r *TuiService) OpenThemes(ctx context.Context, body TuiOpenThemesParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *TuiService) OpenThemes(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) path := "tui/open-themes" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) return } // Show a toast notification in the TUI -func (r *TuiService) ShowToast(ctx context.Context, params TuiShowToastParams, opts ...option.RequestOption) (res *bool, err error) { +func (r *TuiService) ShowToast(ctx context.Context, body TuiShowToastParams, opts ...option.RequestOption) (res *bool, err error) { opts = append(r.Options[:], opts...) path := "tui/show-toast" - err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) - return -} - -// Submit the prompt -func (r *TuiService) SubmitPrompt(ctx context.Context, body TuiSubmitPromptParams, opts ...option.RequestOption) (res *bool, err error) { - opts = append(r.Options[:], opts...) - path := "tui/submit-prompt" err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) return } +// Submit the prompt +func (r *TuiService) SubmitPrompt(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) { + opts = append(r.Options[:], opts...) + path := "tui/submit-prompt" + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) + return +} + type TuiAppendPromptParams struct { - Text param.Field[string] `json:"text,required"` - Directory param.Field[string] `query:"directory"` + Text param.Field[string] `json:"text,required"` } func (r TuiAppendPromptParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -// URLQuery serializes [TuiAppendPromptParams]'s query parameters as `url.Values`. -func (r TuiAppendPromptParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type TuiClearPromptParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [TuiClearPromptParams]'s query parameters as `url.Values`. -func (r TuiClearPromptParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - type TuiExecuteCommandParams struct { - Command param.Field[string] `json:"command,required"` - Directory param.Field[string] `query:"directory"` + Command param.Field[string] `json:"command,required"` } func (r TuiExecuteCommandParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -// URLQuery serializes [TuiExecuteCommandParams]'s query parameters as -// `url.Values`. -func (r TuiExecuteCommandParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type TuiOpenHelpParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [TuiOpenHelpParams]'s query parameters as `url.Values`. -func (r TuiOpenHelpParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type TuiOpenModelsParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [TuiOpenModelsParams]'s query parameters as `url.Values`. -func (r TuiOpenModelsParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type TuiOpenSessionsParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [TuiOpenSessionsParams]'s query parameters as `url.Values`. -func (r TuiOpenSessionsParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - -type TuiOpenThemesParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [TuiOpenThemesParams]'s query parameters as `url.Values`. -func (r TuiOpenThemesParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - type TuiShowToastParams struct { - Message param.Field[string] `json:"message,required"` - Variant param.Field[TuiShowToastParamsVariant] `json:"variant,required"` - Directory param.Field[string] `query:"directory"` - Title param.Field[string] `json:"title"` + Message param.Field[string] `json:"message,required"` + Variant param.Field[TuiShowToastParamsVariant] `json:"variant,required"` + Title param.Field[string] `json:"title"` } func (r TuiShowToastParams) MarshalJSON() (data []byte, err error) { return apijson.MarshalRoot(r) } -// URLQuery serializes [TuiShowToastParams]'s query parameters as `url.Values`. -func (r TuiShowToastParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} - type TuiShowToastParamsVariant string const ( @@ -235,15 +145,3 @@ func (r TuiShowToastParamsVariant) IsKnown() bool { } return false } - -type TuiSubmitPromptParams struct { - Directory param.Field[string] `query:"directory"` -} - -// URLQuery serializes [TuiSubmitPromptParams]'s query parameters as `url.Values`. -func (r TuiSubmitPromptParams) URLQuery() (v url.Values) { - return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ - ArrayFormat: apiquery.ArrayQueryFormatComma, - NestedFormat: apiquery.NestedQueryFormatBrackets, - }) -} diff --git a/tui_test.go b/tui_test.go index 635473b..55faee8 100644 --- a/tui_test.go +++ b/tui_test.go @@ -13,7 +13,7 @@ import ( "github.com/sst/opencode-sdk-go/option" ) -func TestTuiAppendPromptWithOptionalParams(t *testing.T) { +func TestTuiAppendPrompt(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -26,8 +26,7 @@ func TestTuiAppendPromptWithOptionalParams(t *testing.T) { option.WithBaseURL(baseURL), ) _, err := client.Tui.AppendPrompt(context.TODO(), opencode.TuiAppendPromptParams{ - Text: opencode.F("text"), - Directory: opencode.F("directory"), + Text: opencode.F("text"), }) if err != nil { var apierr *opencode.Error @@ -38,7 +37,7 @@ func TestTuiAppendPromptWithOptionalParams(t *testing.T) { } } -func TestTuiClearPromptWithOptionalParams(t *testing.T) { +func TestTuiClearPrompt(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -50,9 +49,7 @@ func TestTuiClearPromptWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Tui.ClearPrompt(context.TODO(), opencode.TuiClearPromptParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Tui.ClearPrompt(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -62,7 +59,7 @@ func TestTuiClearPromptWithOptionalParams(t *testing.T) { } } -func TestTuiExecuteCommandWithOptionalParams(t *testing.T) { +func TestTuiExecuteCommand(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -75,8 +72,7 @@ func TestTuiExecuteCommandWithOptionalParams(t *testing.T) { option.WithBaseURL(baseURL), ) _, err := client.Tui.ExecuteCommand(context.TODO(), opencode.TuiExecuteCommandParams{ - Command: opencode.F("command"), - Directory: opencode.F("directory"), + Command: opencode.F("command"), }) if err != nil { var apierr *opencode.Error @@ -87,7 +83,7 @@ func TestTuiExecuteCommandWithOptionalParams(t *testing.T) { } } -func TestTuiOpenHelpWithOptionalParams(t *testing.T) { +func TestTuiOpenHelp(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -99,9 +95,7 @@ func TestTuiOpenHelpWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Tui.OpenHelp(context.TODO(), opencode.TuiOpenHelpParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Tui.OpenHelp(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -111,7 +105,7 @@ func TestTuiOpenHelpWithOptionalParams(t *testing.T) { } } -func TestTuiOpenModelsWithOptionalParams(t *testing.T) { +func TestTuiOpenModels(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -123,9 +117,7 @@ func TestTuiOpenModelsWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Tui.OpenModels(context.TODO(), opencode.TuiOpenModelsParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Tui.OpenModels(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -135,7 +127,7 @@ func TestTuiOpenModelsWithOptionalParams(t *testing.T) { } } -func TestTuiOpenSessionsWithOptionalParams(t *testing.T) { +func TestTuiOpenSessions(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -147,9 +139,7 @@ func TestTuiOpenSessionsWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Tui.OpenSessions(context.TODO(), opencode.TuiOpenSessionsParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Tui.OpenSessions(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -159,7 +149,7 @@ func TestTuiOpenSessionsWithOptionalParams(t *testing.T) { } } -func TestTuiOpenThemesWithOptionalParams(t *testing.T) { +func TestTuiOpenThemes(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -171,9 +161,7 @@ func TestTuiOpenThemesWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Tui.OpenThemes(context.TODO(), opencode.TuiOpenThemesParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Tui.OpenThemes(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { @@ -196,10 +184,9 @@ func TestTuiShowToastWithOptionalParams(t *testing.T) { option.WithBaseURL(baseURL), ) _, err := client.Tui.ShowToast(context.TODO(), opencode.TuiShowToastParams{ - Message: opencode.F("message"), - Variant: opencode.F(opencode.TuiShowToastParamsVariantInfo), - Directory: opencode.F("directory"), - Title: opencode.F("title"), + Message: opencode.F("message"), + Variant: opencode.F(opencode.TuiShowToastParamsVariantInfo), + Title: opencode.F("title"), }) if err != nil { var apierr *opencode.Error @@ -210,7 +197,7 @@ func TestTuiShowToastWithOptionalParams(t *testing.T) { } } -func TestTuiSubmitPromptWithOptionalParams(t *testing.T) { +func TestTuiSubmitPrompt(t *testing.T) { t.Skip("Prism tests are disabled") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -222,9 +209,7 @@ func TestTuiSubmitPromptWithOptionalParams(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - _, err := client.Tui.SubmitPrompt(context.TODO(), opencode.TuiSubmitPromptParams{ - Directory: opencode.F("directory"), - }) + _, err := client.Tui.SubmitPrompt(context.TODO()) if err != nil { var apierr *opencode.Error if errors.As(err, &apierr) { diff --git a/usage_test.go b/usage_test.go index 2652b58..ef7ce8b 100644 --- a/usage_test.go +++ b/usage_test.go @@ -23,7 +23,7 @@ func TestUsage(t *testing.T) { client := opencode.NewClient( option.WithBaseURL(baseURL), ) - sessions, err := client.Session.List(context.TODO(), opencode.SessionListParams{}) + sessions, err := client.Session.List(context.TODO()) if err != nil { t.Error(err) return