app.go 11 KB

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