project.go 3.9 KB

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