command.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. JSON commandJSON `json:"-"`
  44. }
  45. // commandJSON contains the JSON metadata for the struct [Command]
  46. type commandJSON struct {
  47. Name apijson.Field
  48. Template apijson.Field
  49. Agent apijson.Field
  50. Description apijson.Field
  51. Model apijson.Field
  52. raw string
  53. ExtraFields map[string]apijson.Field
  54. }
  55. func (r *Command) UnmarshalJSON(data []byte) (err error) {
  56. return apijson.UnmarshalRoot(data, r)
  57. }
  58. func (r commandJSON) RawJSON() string {
  59. return r.raw
  60. }
  61. type CommandListParams struct {
  62. Directory param.Field[string] `query:"directory"`
  63. }
  64. // URLQuery serializes [CommandListParams]'s query parameters as `url.Values`.
  65. func (r CommandListParams) URLQuery() (v url.Values) {
  66. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  67. ArrayFormat: apiquery.ArrayQueryFormatComma,
  68. NestedFormat: apiquery.NestedQueryFormatBrackets,
  69. })
  70. }