app.go 10 KB

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