command.go 2.6 KB

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