app.go 10 KB

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