app.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. // List all providers
  57. func (r *AppService) Providers(ctx context.Context, opts ...option.RequestOption) (res *AppProvidersResponse, err error) {
  58. opts = append(r.Options[:], opts...)
  59. path := "config/providers"
  60. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  61. return
  62. }
  63. type App struct {
  64. Git bool `json:"git,required"`
  65. Hostname string `json:"hostname,required"`
  66. Path AppPath `json:"path,required"`
  67. Time AppTime `json:"time,required"`
  68. JSON appJSON `json:"-"`
  69. }
  70. // appJSON contains the JSON metadata for the struct [App]
  71. type appJSON struct {
  72. Git apijson.Field
  73. Hostname apijson.Field
  74. Path apijson.Field
  75. Time apijson.Field
  76. raw string
  77. ExtraFields map[string]apijson.Field
  78. }
  79. func (r *App) UnmarshalJSON(data []byte) (err error) {
  80. return apijson.UnmarshalRoot(data, r)
  81. }
  82. func (r appJSON) RawJSON() string {
  83. return r.raw
  84. }
  85. type AppPath struct {
  86. Config string `json:"config,required"`
  87. Cwd string `json:"cwd,required"`
  88. Data string `json:"data,required"`
  89. Root string `json:"root,required"`
  90. State string `json:"state,required"`
  91. JSON appPathJSON `json:"-"`
  92. }
  93. // appPathJSON contains the JSON metadata for the struct [AppPath]
  94. type appPathJSON struct {
  95. Config apijson.Field
  96. Cwd apijson.Field
  97. Data apijson.Field
  98. Root apijson.Field
  99. State apijson.Field
  100. raw string
  101. ExtraFields map[string]apijson.Field
  102. }
  103. func (r *AppPath) UnmarshalJSON(data []byte) (err error) {
  104. return apijson.UnmarshalRoot(data, r)
  105. }
  106. func (r appPathJSON) RawJSON() string {
  107. return r.raw
  108. }
  109. type AppTime struct {
  110. Initialized float64 `json:"initialized"`
  111. JSON appTimeJSON `json:"-"`
  112. }
  113. // appTimeJSON contains the JSON metadata for the struct [AppTime]
  114. type appTimeJSON struct {
  115. Initialized apijson.Field
  116. raw string
  117. ExtraFields map[string]apijson.Field
  118. }
  119. func (r *AppTime) UnmarshalJSON(data []byte) (err error) {
  120. return apijson.UnmarshalRoot(data, r)
  121. }
  122. func (r appTimeJSON) RawJSON() string {
  123. return r.raw
  124. }
  125. // Log level
  126. type LogLevel string
  127. const (
  128. LogLevelDebug LogLevel = "DEBUG"
  129. LogLevelInfo LogLevel = "INFO"
  130. LogLevelWarn LogLevel = "WARN"
  131. LogLevelError LogLevel = "ERROR"
  132. )
  133. func (r LogLevel) IsKnown() bool {
  134. switch r {
  135. case LogLevelDebug, LogLevelInfo, LogLevelWarn, LogLevelError:
  136. return true
  137. }
  138. return false
  139. }
  140. type Mode struct {
  141. Name string `json:"name,required"`
  142. Tools map[string]bool `json:"tools,required"`
  143. Model ModeModel `json:"model"`
  144. Prompt string `json:"prompt"`
  145. JSON modeJSON `json:"-"`
  146. }
  147. // modeJSON contains the JSON metadata for the struct [Mode]
  148. type modeJSON struct {
  149. Name apijson.Field
  150. Tools apijson.Field
  151. Model apijson.Field
  152. Prompt apijson.Field
  153. raw string
  154. ExtraFields map[string]apijson.Field
  155. }
  156. func (r *Mode) UnmarshalJSON(data []byte) (err error) {
  157. return apijson.UnmarshalRoot(data, r)
  158. }
  159. func (r modeJSON) RawJSON() string {
  160. return r.raw
  161. }
  162. type ModeModel struct {
  163. ModelID string `json:"modelID,required"`
  164. ProviderID string `json:"providerID,required"`
  165. JSON modeModelJSON `json:"-"`
  166. }
  167. // modeModelJSON contains the JSON metadata for the struct [ModeModel]
  168. type modeModelJSON struct {
  169. ModelID apijson.Field
  170. ProviderID apijson.Field
  171. raw string
  172. ExtraFields map[string]apijson.Field
  173. }
  174. func (r *ModeModel) UnmarshalJSON(data []byte) (err error) {
  175. return apijson.UnmarshalRoot(data, r)
  176. }
  177. func (r modeModelJSON) RawJSON() string {
  178. return r.raw
  179. }
  180. type Model struct {
  181. ID string `json:"id,required"`
  182. Attachment bool `json:"attachment,required"`
  183. Cost ModelCost `json:"cost,required"`
  184. Limit ModelLimit `json:"limit,required"`
  185. Name string `json:"name,required"`
  186. Options map[string]interface{} `json:"options,required"`
  187. Reasoning bool `json:"reasoning,required"`
  188. ReleaseDate string `json:"release_date,required"`
  189. Temperature bool `json:"temperature,required"`
  190. ToolCall bool `json:"tool_call,required"`
  191. JSON modelJSON `json:"-"`
  192. }
  193. // modelJSON contains the JSON metadata for the struct [Model]
  194. type modelJSON struct {
  195. ID apijson.Field
  196. Attachment apijson.Field
  197. Cost apijson.Field
  198. Limit apijson.Field
  199. Name apijson.Field
  200. Options apijson.Field
  201. Reasoning apijson.Field
  202. ReleaseDate apijson.Field
  203. Temperature apijson.Field
  204. ToolCall apijson.Field
  205. raw string
  206. ExtraFields map[string]apijson.Field
  207. }
  208. func (r *Model) UnmarshalJSON(data []byte) (err error) {
  209. return apijson.UnmarshalRoot(data, r)
  210. }
  211. func (r modelJSON) RawJSON() string {
  212. return r.raw
  213. }
  214. type ModelCost struct {
  215. Input float64 `json:"input,required"`
  216. Output float64 `json:"output,required"`
  217. CacheRead float64 `json:"cache_read"`
  218. CacheWrite float64 `json:"cache_write"`
  219. JSON modelCostJSON `json:"-"`
  220. }
  221. // modelCostJSON contains the JSON metadata for the struct [ModelCost]
  222. type modelCostJSON struct {
  223. Input apijson.Field
  224. Output apijson.Field
  225. CacheRead apijson.Field
  226. CacheWrite apijson.Field
  227. raw string
  228. ExtraFields map[string]apijson.Field
  229. }
  230. func (r *ModelCost) UnmarshalJSON(data []byte) (err error) {
  231. return apijson.UnmarshalRoot(data, r)
  232. }
  233. func (r modelCostJSON) RawJSON() string {
  234. return r.raw
  235. }
  236. type ModelLimit struct {
  237. Context float64 `json:"context,required"`
  238. Output float64 `json:"output,required"`
  239. JSON modelLimitJSON `json:"-"`
  240. }
  241. // modelLimitJSON contains the JSON metadata for the struct [ModelLimit]
  242. type modelLimitJSON struct {
  243. Context apijson.Field
  244. Output apijson.Field
  245. raw string
  246. ExtraFields map[string]apijson.Field
  247. }
  248. func (r *ModelLimit) UnmarshalJSON(data []byte) (err error) {
  249. return apijson.UnmarshalRoot(data, r)
  250. }
  251. func (r modelLimitJSON) RawJSON() string {
  252. return r.raw
  253. }
  254. type Provider struct {
  255. ID string `json:"id,required"`
  256. Env []string `json:"env,required"`
  257. Models map[string]Model `json:"models,required"`
  258. Name string `json:"name,required"`
  259. API string `json:"api"`
  260. Npm string `json:"npm"`
  261. JSON providerJSON `json:"-"`
  262. }
  263. // providerJSON contains the JSON metadata for the struct [Provider]
  264. type providerJSON struct {
  265. ID apijson.Field
  266. Env apijson.Field
  267. Models apijson.Field
  268. Name apijson.Field
  269. API apijson.Field
  270. Npm apijson.Field
  271. raw string
  272. ExtraFields map[string]apijson.Field
  273. }
  274. func (r *Provider) UnmarshalJSON(data []byte) (err error) {
  275. return apijson.UnmarshalRoot(data, r)
  276. }
  277. func (r providerJSON) RawJSON() string {
  278. return r.raw
  279. }
  280. type AppProvidersResponse struct {
  281. Default map[string]string `json:"default,required"`
  282. Providers []Provider `json:"providers,required"`
  283. JSON appProvidersResponseJSON `json:"-"`
  284. }
  285. // appProvidersResponseJSON contains the JSON metadata for the struct
  286. // [AppProvidersResponse]
  287. type appProvidersResponseJSON struct {
  288. Default apijson.Field
  289. Providers apijson.Field
  290. raw string
  291. ExtraFields map[string]apijson.Field
  292. }
  293. func (r *AppProvidersResponse) UnmarshalJSON(data []byte) (err error) {
  294. return apijson.UnmarshalRoot(data, r)
  295. }
  296. func (r appProvidersResponseJSON) RawJSON() string {
  297. return r.raw
  298. }
  299. type AppLogParams struct {
  300. // Log level
  301. Level param.Field[AppLogParamsLevel] `json:"level,required"`
  302. // Log message
  303. Message param.Field[string] `json:"message,required"`
  304. // Service name for the log entry
  305. Service param.Field[string] `json:"service,required"`
  306. // Additional metadata for the log entry
  307. Extra param.Field[map[string]interface{}] `json:"extra"`
  308. }
  309. func (r AppLogParams) MarshalJSON() (data []byte, err error) {
  310. return apijson.MarshalRoot(r)
  311. }
  312. // Log level
  313. type AppLogParamsLevel string
  314. const (
  315. AppLogParamsLevelDebug AppLogParamsLevel = "debug"
  316. AppLogParamsLevelInfo AppLogParamsLevel = "info"
  317. AppLogParamsLevelError AppLogParamsLevel = "error"
  318. AppLogParamsLevelWarn AppLogParamsLevel = "warn"
  319. )
  320. func (r AppLogParamsLevel) IsKnown() bool {
  321. switch r {
  322. case AppLogParamsLevelDebug, AppLogParamsLevelInfo, AppLogParamsLevelError, AppLogParamsLevelWarn:
  323. return true
  324. }
  325. return false
  326. }