project.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. // ProjectService 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 [NewProjectService] method instead.
  20. type ProjectService struct {
  21. Options []option.RequestOption
  22. }
  23. // NewProjectService 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 NewProjectService(opts ...option.RequestOption) (r *ProjectService) {
  27. r = &ProjectService{}
  28. r.Options = opts
  29. return
  30. }
  31. // List all projects
  32. func (r *ProjectService) List(ctx context.Context, query ProjectListParams, opts ...option.RequestOption) (res *[]Project, err error) {
  33. opts = slices.Concat(r.Options, opts)
  34. path := "project"
  35. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
  36. return
  37. }
  38. // Get the current project
  39. func (r *ProjectService) Current(ctx context.Context, query ProjectCurrentParams, opts ...option.RequestOption) (res *Project, err error) {
  40. opts = slices.Concat(r.Options, opts)
  41. path := "project/current"
  42. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
  43. return
  44. }
  45. type Project struct {
  46. ID string `json:"id,required"`
  47. Time ProjectTime `json:"time,required"`
  48. Worktree string `json:"worktree,required"`
  49. Vcs ProjectVcs `json:"vcs"`
  50. JSON projectJSON `json:"-"`
  51. }
  52. // projectJSON contains the JSON metadata for the struct [Project]
  53. type projectJSON struct {
  54. ID apijson.Field
  55. Time apijson.Field
  56. Worktree apijson.Field
  57. Vcs apijson.Field
  58. raw string
  59. ExtraFields map[string]apijson.Field
  60. }
  61. func (r *Project) UnmarshalJSON(data []byte) (err error) {
  62. return apijson.UnmarshalRoot(data, r)
  63. }
  64. func (r projectJSON) RawJSON() string {
  65. return r.raw
  66. }
  67. type ProjectTime struct {
  68. Created float64 `json:"created,required"`
  69. Initialized float64 `json:"initialized"`
  70. JSON projectTimeJSON `json:"-"`
  71. }
  72. // projectTimeJSON contains the JSON metadata for the struct [ProjectTime]
  73. type projectTimeJSON struct {
  74. Created apijson.Field
  75. Initialized apijson.Field
  76. raw string
  77. ExtraFields map[string]apijson.Field
  78. }
  79. func (r *ProjectTime) UnmarshalJSON(data []byte) (err error) {
  80. return apijson.UnmarshalRoot(data, r)
  81. }
  82. func (r projectTimeJSON) RawJSON() string {
  83. return r.raw
  84. }
  85. type ProjectVcs string
  86. const (
  87. ProjectVcsGit ProjectVcs = "git"
  88. )
  89. func (r ProjectVcs) IsKnown() bool {
  90. switch r {
  91. case ProjectVcsGit:
  92. return true
  93. }
  94. return false
  95. }
  96. type ProjectListParams struct {
  97. Directory param.Field[string] `query:"directory"`
  98. }
  99. // URLQuery serializes [ProjectListParams]'s query parameters as `url.Values`.
  100. func (r ProjectListParams) URLQuery() (v url.Values) {
  101. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  102. ArrayFormat: apiquery.ArrayQueryFormatComma,
  103. NestedFormat: apiquery.NestedQueryFormatBrackets,
  104. })
  105. }
  106. type ProjectCurrentParams struct {
  107. Directory param.Field[string] `query:"directory"`
  108. }
  109. // URLQuery serializes [ProjectCurrentParams]'s query parameters as `url.Values`.
  110. func (r ProjectCurrentParams) URLQuery() (v url.Values) {
  111. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  112. ArrayFormat: apiquery.ArrayQueryFormatComma,
  113. NestedFormat: apiquery.NestedQueryFormatBrackets,
  114. })
  115. }