app.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // AppService contains methods and other services that help with interacting with
  11. // 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 [NewAppService] method instead.
  16. type AppService struct {
  17. Options []option.RequestOption
  18. }
  19. // NewAppService 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 NewAppService(opts ...option.RequestOption) (r *AppService) {
  23. r = &AppService{}
  24. r.Options = opts
  25. return
  26. }
  27. // Get app info
  28. func (r *AppService) Get(ctx context.Context, opts ...option.RequestOption) (res *App, err error) {
  29. opts = append(r.Options[:], opts...)
  30. path := "app"
  31. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  32. return
  33. }
  34. // Initialize the app
  35. func (r *AppService) Init(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) {
  36. opts = append(r.Options[:], opts...)
  37. path := "app/init"
  38. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  39. return
  40. }
  41. type App struct {
  42. Git bool `json:"git,required"`
  43. Hostname string `json:"hostname,required"`
  44. Path AppPath `json:"path,required"`
  45. Time AppTime `json:"time,required"`
  46. User string `json:"user,required"`
  47. JSON appJSON `json:"-"`
  48. }
  49. // appJSON contains the JSON metadata for the struct [App]
  50. type appJSON struct {
  51. Git apijson.Field
  52. Hostname apijson.Field
  53. Path apijson.Field
  54. Time apijson.Field
  55. User apijson.Field
  56. raw string
  57. ExtraFields map[string]apijson.Field
  58. }
  59. func (r *App) UnmarshalJSON(data []byte) (err error) {
  60. return apijson.UnmarshalRoot(data, r)
  61. }
  62. func (r appJSON) RawJSON() string {
  63. return r.raw
  64. }
  65. type AppPath struct {
  66. Config string `json:"config,required"`
  67. Cwd string `json:"cwd,required"`
  68. Data string `json:"data,required"`
  69. Root string `json:"root,required"`
  70. State string `json:"state,required"`
  71. JSON appPathJSON `json:"-"`
  72. }
  73. // appPathJSON contains the JSON metadata for the struct [AppPath]
  74. type appPathJSON struct {
  75. Config apijson.Field
  76. Cwd apijson.Field
  77. Data apijson.Field
  78. Root apijson.Field
  79. State apijson.Field
  80. raw string
  81. ExtraFields map[string]apijson.Field
  82. }
  83. func (r *AppPath) UnmarshalJSON(data []byte) (err error) {
  84. return apijson.UnmarshalRoot(data, r)
  85. }
  86. func (r appPathJSON) RawJSON() string {
  87. return r.raw
  88. }
  89. type AppTime struct {
  90. Initialized float64 `json:"initialized"`
  91. JSON appTimeJSON `json:"-"`
  92. }
  93. // appTimeJSON contains the JSON metadata for the struct [AppTime]
  94. type appTimeJSON struct {
  95. Initialized apijson.Field
  96. raw string
  97. ExtraFields map[string]apijson.Field
  98. }
  99. func (r *AppTime) UnmarshalJSON(data []byte) (err error) {
  100. return apijson.UnmarshalRoot(data, r)
  101. }
  102. func (r appTimeJSON) RawJSON() string {
  103. return r.raw
  104. }