app.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. // List all modes
  50. func (r *AppService) Modes(ctx context.Context, opts ...option.RequestOption) (res *[]Mode, err error) {
  51. opts = append(r.Options[:], opts...)
  52. path := "mode"
  53. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  54. return
  55. }
  56. type App struct {
  57. Git bool `json:"git,required"`
  58. Hostname string `json:"hostname,required"`
  59. Path AppPath `json:"path,required"`
  60. Time AppTime `json:"time,required"`
  61. User string `json:"user,required"`
  62. JSON appJSON `json:"-"`
  63. }
  64. // appJSON contains the JSON metadata for the struct [App]
  65. type appJSON struct {
  66. Git apijson.Field
  67. Hostname apijson.Field
  68. Path apijson.Field
  69. Time apijson.Field
  70. User apijson.Field
  71. raw string
  72. ExtraFields map[string]apijson.Field
  73. }
  74. func (r *App) UnmarshalJSON(data []byte) (err error) {
  75. return apijson.UnmarshalRoot(data, r)
  76. }
  77. func (r appJSON) RawJSON() string {
  78. return r.raw
  79. }
  80. type AppPath struct {
  81. Config string `json:"config,required"`
  82. Cwd string `json:"cwd,required"`
  83. Data string `json:"data,required"`
  84. Root string `json:"root,required"`
  85. State string `json:"state,required"`
  86. JSON appPathJSON `json:"-"`
  87. }
  88. // appPathJSON contains the JSON metadata for the struct [AppPath]
  89. type appPathJSON struct {
  90. Config apijson.Field
  91. Cwd apijson.Field
  92. Data apijson.Field
  93. Root apijson.Field
  94. State apijson.Field
  95. raw string
  96. ExtraFields map[string]apijson.Field
  97. }
  98. func (r *AppPath) UnmarshalJSON(data []byte) (err error) {
  99. return apijson.UnmarshalRoot(data, r)
  100. }
  101. func (r appPathJSON) RawJSON() string {
  102. return r.raw
  103. }
  104. type AppTime struct {
  105. Initialized float64 `json:"initialized"`
  106. JSON appTimeJSON `json:"-"`
  107. }
  108. // appTimeJSON contains the JSON metadata for the struct [AppTime]
  109. type appTimeJSON struct {
  110. Initialized apijson.Field
  111. raw string
  112. ExtraFields map[string]apijson.Field
  113. }
  114. func (r *AppTime) UnmarshalJSON(data []byte) (err error) {
  115. return apijson.UnmarshalRoot(data, r)
  116. }
  117. func (r appTimeJSON) RawJSON() string {
  118. return r.raw
  119. }
  120. // Log level
  121. type LogLevel string
  122. const (
  123. LogLevelDebug LogLevel = "DEBUG"
  124. LogLevelInfo LogLevel = "INFO"
  125. LogLevelWarn LogLevel = "WARN"
  126. LogLevelError LogLevel = "ERROR"
  127. )
  128. func (r LogLevel) IsKnown() bool {
  129. switch r {
  130. case LogLevelDebug, LogLevelInfo, LogLevelWarn, LogLevelError:
  131. return true
  132. }
  133. return false
  134. }
  135. type Mode struct {
  136. Name string `json:"name,required"`
  137. Tools map[string]bool `json:"tools,required"`
  138. Model ModeModel `json:"model"`
  139. Prompt string `json:"prompt"`
  140. JSON modeJSON `json:"-"`
  141. }
  142. // modeJSON contains the JSON metadata for the struct [Mode]
  143. type modeJSON struct {
  144. Name apijson.Field
  145. Tools apijson.Field
  146. Model apijson.Field
  147. Prompt apijson.Field
  148. raw string
  149. ExtraFields map[string]apijson.Field
  150. }
  151. func (r *Mode) UnmarshalJSON(data []byte) (err error) {
  152. return apijson.UnmarshalRoot(data, r)
  153. }
  154. func (r modeJSON) RawJSON() string {
  155. return r.raw
  156. }
  157. type ModeModel struct {
  158. ModelID string `json:"modelID,required"`
  159. ProviderID string `json:"providerID,required"`
  160. JSON modeModelJSON `json:"-"`
  161. }
  162. // modeModelJSON contains the JSON metadata for the struct [ModeModel]
  163. type modeModelJSON struct {
  164. ModelID apijson.Field
  165. ProviderID apijson.Field
  166. raw string
  167. ExtraFields map[string]apijson.Field
  168. }
  169. func (r *ModeModel) UnmarshalJSON(data []byte) (err error) {
  170. return apijson.UnmarshalRoot(data, r)
  171. }
  172. func (r modeModelJSON) RawJSON() string {
  173. return r.raw
  174. }
  175. type AppLogParams struct {
  176. // Log level
  177. Level param.Field[AppLogParamsLevel] `json:"level,required"`
  178. // Log message
  179. Message param.Field[string] `json:"message,required"`
  180. // Service name for the log entry
  181. Service param.Field[string] `json:"service,required"`
  182. // Additional metadata for the log entry
  183. Extra param.Field[map[string]interface{}] `json:"extra"`
  184. }
  185. func (r AppLogParams) MarshalJSON() (data []byte, err error) {
  186. return apijson.MarshalRoot(r)
  187. }
  188. // Log level
  189. type AppLogParamsLevel string
  190. const (
  191. AppLogParamsLevelDebug AppLogParamsLevel = "debug"
  192. AppLogParamsLevelInfo AppLogParamsLevel = "info"
  193. AppLogParamsLevelError AppLogParamsLevel = "error"
  194. AppLogParamsLevelWarn AppLogParamsLevel = "warn"
  195. )
  196. func (r AppLogParamsLevel) IsKnown() bool {
  197. switch r {
  198. case AppLogParamsLevelDebug, AppLogParamsLevelInfo, AppLogParamsLevelError, AppLogParamsLevelWarn:
  199. return true
  200. }
  201. return false
  202. }