file.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. // FileService contains methods and other services that help with interacting with
  14. // 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 [NewFileService] method instead.
  19. type FileService struct {
  20. Options []option.RequestOption
  21. }
  22. // NewFileService 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 NewFileService(opts ...option.RequestOption) (r *FileService) {
  26. r = &FileService{}
  27. r.Options = opts
  28. return
  29. }
  30. // Read a file
  31. func (r *FileService) Read(ctx context.Context, query FileReadParams, opts ...option.RequestOption) (res *FileReadResponse, err error) {
  32. opts = append(r.Options[:], opts...)
  33. path := "file"
  34. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
  35. return
  36. }
  37. // Get file status
  38. func (r *FileService) Status(ctx context.Context, opts ...option.RequestOption) (res *[]File, err error) {
  39. opts = append(r.Options[:], opts...)
  40. path := "file/status"
  41. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  42. return
  43. }
  44. type File struct {
  45. Added int64 `json:"added,required"`
  46. Path string `json:"path,required"`
  47. Removed int64 `json:"removed,required"`
  48. Status FileStatus `json:"status,required"`
  49. JSON fileJSON `json:"-"`
  50. }
  51. // fileJSON contains the JSON metadata for the struct [File]
  52. type fileJSON struct {
  53. Added apijson.Field
  54. Path apijson.Field
  55. Removed apijson.Field
  56. Status apijson.Field
  57. raw string
  58. ExtraFields map[string]apijson.Field
  59. }
  60. func (r *File) UnmarshalJSON(data []byte) (err error) {
  61. return apijson.UnmarshalRoot(data, r)
  62. }
  63. func (r fileJSON) RawJSON() string {
  64. return r.raw
  65. }
  66. type FileStatus string
  67. const (
  68. FileStatusAdded FileStatus = "added"
  69. FileStatusDeleted FileStatus = "deleted"
  70. FileStatusModified FileStatus = "modified"
  71. )
  72. func (r FileStatus) IsKnown() bool {
  73. switch r {
  74. case FileStatusAdded, FileStatusDeleted, FileStatusModified:
  75. return true
  76. }
  77. return false
  78. }
  79. type FileReadResponse struct {
  80. Content string `json:"content,required"`
  81. Type FileReadResponseType `json:"type,required"`
  82. JSON fileReadResponseJSON `json:"-"`
  83. }
  84. // fileReadResponseJSON contains the JSON metadata for the struct
  85. // [FileReadResponse]
  86. type fileReadResponseJSON struct {
  87. Content apijson.Field
  88. Type apijson.Field
  89. raw string
  90. ExtraFields map[string]apijson.Field
  91. }
  92. func (r *FileReadResponse) UnmarshalJSON(data []byte) (err error) {
  93. return apijson.UnmarshalRoot(data, r)
  94. }
  95. func (r fileReadResponseJSON) RawJSON() string {
  96. return r.raw
  97. }
  98. type FileReadResponseType string
  99. const (
  100. FileReadResponseTypeRaw FileReadResponseType = "raw"
  101. FileReadResponseTypePatch FileReadResponseType = "patch"
  102. )
  103. func (r FileReadResponseType) IsKnown() bool {
  104. switch r {
  105. case FileReadResponseTypeRaw, FileReadResponseTypePatch:
  106. return true
  107. }
  108. return false
  109. }
  110. type FileReadParams struct {
  111. Path param.Field[string] `query:"path,required"`
  112. }
  113. // URLQuery serializes [FileReadParams]'s query parameters as `url.Values`.
  114. func (r FileReadParams) URLQuery() (v url.Values) {
  115. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  116. ArrayFormat: apiquery.ArrayQueryFormatComma,
  117. NestedFormat: apiquery.NestedQueryFormatBrackets,
  118. })
  119. }