command.go 2.0 KB

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