app.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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/param"
  8. "github.com/sst/opencode-sdk-go/internal/requestconfig"
  9. "github.com/sst/opencode-sdk-go/option"
  10. )
  11. // AppService contains methods and other services that help with interacting with
  12. // the opencode API.
  13. //
  14. // Note, unlike clients, this service does not read variables from the environment
  15. // automatically. You should not instantiate this service directly, and instead use
  16. // the [NewAppService] method instead.
  17. type AppService struct {
  18. Options []option.RequestOption
  19. }
  20. // NewAppService generates a new service that applies the given options to each
  21. // request. These options are applied after the parent client's options (if there
  22. // is one), and before any request-specific options.
  23. func NewAppService(opts ...option.RequestOption) (r *AppService) {
  24. r = &AppService{}
  25. r.Options = opts
  26. return
  27. }
  28. // Get app info
  29. func (r *AppService) Get(ctx context.Context, opts ...option.RequestOption) (res *App, err error) {
  30. opts = append(r.Options[:], opts...)
  31. path := "app"
  32. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  33. return
  34. }
  35. // Initialize the app
  36. func (r *AppService) Init(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) {
  37. opts = append(r.Options[:], opts...)
  38. path := "app/init"
  39. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  40. return
  41. }
  42. // Write a log entry to the server logs
  43. func (r *AppService) Log(ctx context.Context, body AppLogParams, opts ...option.RequestOption) (res *bool, err error) {
  44. opts = append(r.Options[:], opts...)
  45. path := "log"
  46. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  47. return
  48. }
  49. type App struct {
  50. Git bool `json:"git,required"`
  51. Hostname string `json:"hostname,required"`
  52. Path AppPath `json:"path,required"`
  53. Time AppTime `json:"time,required"`
  54. User string `json:"user,required"`
  55. JSON appJSON `json:"-"`
  56. }
  57. // appJSON contains the JSON metadata for the struct [App]
  58. type appJSON struct {
  59. Git apijson.Field
  60. Hostname apijson.Field
  61. Path apijson.Field
  62. Time apijson.Field
  63. User apijson.Field
  64. raw string
  65. ExtraFields map[string]apijson.Field
  66. }
  67. func (r *App) UnmarshalJSON(data []byte) (err error) {
  68. return apijson.UnmarshalRoot(data, r)
  69. }
  70. func (r appJSON) RawJSON() string {
  71. return r.raw
  72. }
  73. type AppPath struct {
  74. Config string `json:"config,required"`
  75. Cwd string `json:"cwd,required"`
  76. Data string `json:"data,required"`
  77. Root string `json:"root,required"`
  78. State string `json:"state,required"`
  79. JSON appPathJSON `json:"-"`
  80. }
  81. // appPathJSON contains the JSON metadata for the struct [AppPath]
  82. type appPathJSON struct {
  83. Config apijson.Field
  84. Cwd apijson.Field
  85. Data apijson.Field
  86. Root apijson.Field
  87. State apijson.Field
  88. raw string
  89. ExtraFields map[string]apijson.Field
  90. }
  91. func (r *AppPath) UnmarshalJSON(data []byte) (err error) {
  92. return apijson.UnmarshalRoot(data, r)
  93. }
  94. func (r appPathJSON) RawJSON() string {
  95. return r.raw
  96. }
  97. type AppTime struct {
  98. Initialized float64 `json:"initialized"`
  99. JSON appTimeJSON `json:"-"`
  100. }
  101. // appTimeJSON contains the JSON metadata for the struct [AppTime]
  102. type appTimeJSON struct {
  103. Initialized apijson.Field
  104. raw string
  105. ExtraFields map[string]apijson.Field
  106. }
  107. func (r *AppTime) UnmarshalJSON(data []byte) (err error) {
  108. return apijson.UnmarshalRoot(data, r)
  109. }
  110. func (r appTimeJSON) RawJSON() string {
  111. return r.raw
  112. }
  113. // Log level
  114. type LogLevel string
  115. const (
  116. LogLevelDebug LogLevel = "DEBUG"
  117. LogLevelInfo LogLevel = "INFO"
  118. LogLevelWarn LogLevel = "WARN"
  119. LogLevelError LogLevel = "ERROR"
  120. )
  121. func (r LogLevel) IsKnown() bool {
  122. switch r {
  123. case LogLevelDebug, LogLevelInfo, LogLevelWarn, LogLevelError:
  124. return true
  125. }
  126. return false
  127. }
  128. type AppLogParams struct {
  129. // Log level
  130. Level param.Field[AppLogParamsLevel] `json:"level,required"`
  131. // Log message
  132. Message param.Field[string] `json:"message,required"`
  133. // Service name for the log entry
  134. Service param.Field[string] `json:"service,required"`
  135. // Additional metadata for the log entry
  136. Extra param.Field[map[string]interface{}] `json:"extra"`
  137. }
  138. func (r AppLogParams) MarshalJSON() (data []byte, err error) {
  139. return apijson.MarshalRoot(r)
  140. }
  141. // Log level
  142. type AppLogParamsLevel string
  143. const (
  144. AppLogParamsLevelDebug AppLogParamsLevel = "debug"
  145. AppLogParamsLevelInfo AppLogParamsLevel = "info"
  146. AppLogParamsLevelError AppLogParamsLevel = "error"
  147. AppLogParamsLevelWarn AppLogParamsLevel = "warn"
  148. )
  149. func (r AppLogParamsLevel) IsKnown() bool {
  150. switch r {
  151. case AppLogParamsLevelDebug, AppLogParamsLevelInfo, AppLogParamsLevelError, AppLogParamsLevelWarn:
  152. return true
  153. }
  154. return false
  155. }