app.go 6.2 KB

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