app.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. type Mode struct {
  126. Name string `json:"name,required"`
  127. Tools map[string]bool `json:"tools,required"`
  128. Model ModeModel `json:"model"`
  129. Prompt string `json:"prompt"`
  130. Temperature float64 `json:"temperature"`
  131. JSON modeJSON `json:"-"`
  132. }
  133. // modeJSON contains the JSON metadata for the struct [Mode]
  134. type modeJSON struct {
  135. Name apijson.Field
  136. Tools apijson.Field
  137. Model apijson.Field
  138. Prompt apijson.Field
  139. Temperature apijson.Field
  140. raw string
  141. ExtraFields map[string]apijson.Field
  142. }
  143. func (r *Mode) UnmarshalJSON(data []byte) (err error) {
  144. return apijson.UnmarshalRoot(data, r)
  145. }
  146. func (r modeJSON) RawJSON() string {
  147. return r.raw
  148. }
  149. type ModeModel struct {
  150. ModelID string `json:"modelID,required"`
  151. ProviderID string `json:"providerID,required"`
  152. JSON modeModelJSON `json:"-"`
  153. }
  154. // modeModelJSON contains the JSON metadata for the struct [ModeModel]
  155. type modeModelJSON struct {
  156. ModelID apijson.Field
  157. ProviderID apijson.Field
  158. raw string
  159. ExtraFields map[string]apijson.Field
  160. }
  161. func (r *ModeModel) UnmarshalJSON(data []byte) (err error) {
  162. return apijson.UnmarshalRoot(data, r)
  163. }
  164. func (r modeModelJSON) RawJSON() string {
  165. return r.raw
  166. }
  167. type Model struct {
  168. ID string `json:"id,required"`
  169. Attachment bool `json:"attachment,required"`
  170. Cost ModelCost `json:"cost,required"`
  171. Limit ModelLimit `json:"limit,required"`
  172. Name string `json:"name,required"`
  173. Options map[string]interface{} `json:"options,required"`
  174. Reasoning bool `json:"reasoning,required"`
  175. ReleaseDate string `json:"release_date,required"`
  176. Temperature bool `json:"temperature,required"`
  177. ToolCall bool `json:"tool_call,required"`
  178. JSON modelJSON `json:"-"`
  179. }
  180. // modelJSON contains the JSON metadata for the struct [Model]
  181. type modelJSON struct {
  182. ID apijson.Field
  183. Attachment apijson.Field
  184. Cost apijson.Field
  185. Limit apijson.Field
  186. Name apijson.Field
  187. Options apijson.Field
  188. Reasoning apijson.Field
  189. ReleaseDate apijson.Field
  190. Temperature apijson.Field
  191. ToolCall apijson.Field
  192. raw string
  193. ExtraFields map[string]apijson.Field
  194. }
  195. func (r *Model) UnmarshalJSON(data []byte) (err error) {
  196. return apijson.UnmarshalRoot(data, r)
  197. }
  198. func (r modelJSON) RawJSON() string {
  199. return r.raw
  200. }
  201. type ModelCost struct {
  202. Input float64 `json:"input,required"`
  203. Output float64 `json:"output,required"`
  204. CacheRead float64 `json:"cache_read"`
  205. CacheWrite float64 `json:"cache_write"`
  206. JSON modelCostJSON `json:"-"`
  207. }
  208. // modelCostJSON contains the JSON metadata for the struct [ModelCost]
  209. type modelCostJSON struct {
  210. Input apijson.Field
  211. Output apijson.Field
  212. CacheRead apijson.Field
  213. CacheWrite apijson.Field
  214. raw string
  215. ExtraFields map[string]apijson.Field
  216. }
  217. func (r *ModelCost) UnmarshalJSON(data []byte) (err error) {
  218. return apijson.UnmarshalRoot(data, r)
  219. }
  220. func (r modelCostJSON) RawJSON() string {
  221. return r.raw
  222. }
  223. type ModelLimit struct {
  224. Context float64 `json:"context,required"`
  225. Output float64 `json:"output,required"`
  226. JSON modelLimitJSON `json:"-"`
  227. }
  228. // modelLimitJSON contains the JSON metadata for the struct [ModelLimit]
  229. type modelLimitJSON struct {
  230. Context apijson.Field
  231. Output apijson.Field
  232. raw string
  233. ExtraFields map[string]apijson.Field
  234. }
  235. func (r *ModelLimit) UnmarshalJSON(data []byte) (err error) {
  236. return apijson.UnmarshalRoot(data, r)
  237. }
  238. func (r modelLimitJSON) RawJSON() string {
  239. return r.raw
  240. }
  241. type Provider struct {
  242. ID string `json:"id,required"`
  243. Env []string `json:"env,required"`
  244. Models map[string]Model `json:"models,required"`
  245. Name string `json:"name,required"`
  246. API string `json:"api"`
  247. Npm string `json:"npm"`
  248. JSON providerJSON `json:"-"`
  249. }
  250. // providerJSON contains the JSON metadata for the struct [Provider]
  251. type providerJSON struct {
  252. ID apijson.Field
  253. Env apijson.Field
  254. Models apijson.Field
  255. Name apijson.Field
  256. API apijson.Field
  257. Npm apijson.Field
  258. raw string
  259. ExtraFields map[string]apijson.Field
  260. }
  261. func (r *Provider) UnmarshalJSON(data []byte) (err error) {
  262. return apijson.UnmarshalRoot(data, r)
  263. }
  264. func (r providerJSON) RawJSON() string {
  265. return r.raw
  266. }
  267. type AppProvidersResponse struct {
  268. Default map[string]string `json:"default,required"`
  269. Providers []Provider `json:"providers,required"`
  270. JSON appProvidersResponseJSON `json:"-"`
  271. }
  272. // appProvidersResponseJSON contains the JSON metadata for the struct
  273. // [AppProvidersResponse]
  274. type appProvidersResponseJSON struct {
  275. Default apijson.Field
  276. Providers apijson.Field
  277. raw string
  278. ExtraFields map[string]apijson.Field
  279. }
  280. func (r *AppProvidersResponse) UnmarshalJSON(data []byte) (err error) {
  281. return apijson.UnmarshalRoot(data, r)
  282. }
  283. func (r appProvidersResponseJSON) RawJSON() string {
  284. return r.raw
  285. }
  286. type AppLogParams struct {
  287. // Log level
  288. Level param.Field[AppLogParamsLevel] `json:"level,required"`
  289. // Log message
  290. Message param.Field[string] `json:"message,required"`
  291. // Service name for the log entry
  292. Service param.Field[string] `json:"service,required"`
  293. // Additional metadata for the log entry
  294. Extra param.Field[map[string]interface{}] `json:"extra"`
  295. }
  296. func (r AppLogParams) MarshalJSON() (data []byte, err error) {
  297. return apijson.MarshalRoot(r)
  298. }
  299. // Log level
  300. type AppLogParamsLevel string
  301. const (
  302. AppLogParamsLevelDebug AppLogParamsLevel = "debug"
  303. AppLogParamsLevelInfo AppLogParamsLevel = "info"
  304. AppLogParamsLevelError AppLogParamsLevel = "error"
  305. AppLogParamsLevelWarn AppLogParamsLevel = "warn"
  306. )
  307. func (r AppLogParamsLevel) IsKnown() bool {
  308. switch r {
  309. case AppLogParamsLevelDebug, AppLogParamsLevelInfo, AppLogParamsLevelError, AppLogParamsLevelWarn:
  310. return true
  311. }
  312. return false
  313. }