command.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. package opencode
  3. import (
  4. "context"
  5. "net/http"
  6. "net/url"
  7. "github.com/sst/opencode-sdk-go/internal/apijson"
  8. "github.com/sst/opencode-sdk-go/internal/apiquery"
  9. "github.com/sst/opencode-sdk-go/internal/param"
  10. "github.com/sst/opencode-sdk-go/internal/requestconfig"
  11. "github.com/sst/opencode-sdk-go/option"
  12. )
  13. // CommandService contains methods and other services that help with interacting
  14. // with the opencode API.
  15. //
  16. // Note, unlike clients, this service does not read variables from the environment
  17. // automatically. You should not instantiate this service directly, and instead use
  18. // the [NewCommandService] method instead.
  19. type CommandService struct {
  20. Options []option.RequestOption
  21. }
  22. // NewCommandService generates a new service that applies the given options to each
  23. // request. These options are applied after the parent client's options (if there
  24. // is one), and before any request-specific options.
  25. func NewCommandService(opts ...option.RequestOption) (r *CommandService) {
  26. r = &CommandService{}
  27. r.Options = opts
  28. return
  29. }
  30. // List all commands
  31. func (r *CommandService) List(ctx context.Context, query CommandListParams, opts ...option.RequestOption) (res *[]Command, err error) {
  32. opts = append(r.Options[:], opts...)
  33. path := "command"
  34. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
  35. return
  36. }
  37. type Command struct {
  38. Name string `json:"name,required"`
  39. Template string `json:"template,required"`
  40. Agent string `json:"agent"`
  41. Description string `json:"description"`
  42. Model string `json:"model"`
  43. Subtask bool `json:"subtask"`
  44. JSON commandJSON `json:"-"`
  45. }
  46. // commandJSON contains the JSON metadata for the struct [Command]
  47. type commandJSON struct {
  48. Name apijson.Field
  49. Template apijson.Field
  50. Agent apijson.Field
  51. Description apijson.Field
  52. Model apijson.Field
  53. Subtask apijson.Field
  54. raw string
  55. ExtraFields map[string]apijson.Field
  56. }
  57. func (r *Command) UnmarshalJSON(data []byte) (err error) {
  58. return apijson.UnmarshalRoot(data, r)
  59. }
  60. func (r commandJSON) RawJSON() string {
  61. return r.raw
  62. }
  63. type CommandListParams struct {
  64. Directory param.Field[string] `query:"directory"`
  65. }
  66. // URLQuery serializes [CommandListParams]'s query parameters as `url.Values`.
  67. func (r CommandListParams) URLQuery() (v url.Values) {
  68. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  69. ArrayFormat: apiquery.ArrayQueryFormatComma,
  70. NestedFormat: apiquery.NestedQueryFormatBrackets,
  71. })
  72. }