app.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. Options map[string]interface{} `json:"options,required"`
  67. Permission AgentPermission `json:"permission,required"`
  68. Tools map[string]bool `json:"tools,required"`
  69. Description string `json:"description"`
  70. Model AgentModel `json:"model"`
  71. Prompt string `json:"prompt"`
  72. Temperature float64 `json:"temperature"`
  73. TopP float64 `json:"topP"`
  74. JSON agentJSON `json:"-"`
  75. }
  76. // agentJSON contains the JSON metadata for the struct [Agent]
  77. type agentJSON struct {
  78. Mode apijson.Field
  79. Name apijson.Field
  80. Options apijson.Field
  81. Permission apijson.Field
  82. Tools apijson.Field
  83. Description apijson.Field
  84. Model apijson.Field
  85. Prompt apijson.Field
  86. Temperature apijson.Field
  87. TopP apijson.Field
  88. raw string
  89. ExtraFields map[string]apijson.Field
  90. }
  91. func (r *Agent) UnmarshalJSON(data []byte) (err error) {
  92. return apijson.UnmarshalRoot(data, r)
  93. }
  94. func (r agentJSON) RawJSON() string {
  95. return r.raw
  96. }
  97. type AgentMode string
  98. const (
  99. AgentModeSubagent AgentMode = "subagent"
  100. AgentModePrimary AgentMode = "primary"
  101. AgentModeAll AgentMode = "all"
  102. )
  103. func (r AgentMode) IsKnown() bool {
  104. switch r {
  105. case AgentModeSubagent, AgentModePrimary, AgentModeAll:
  106. return true
  107. }
  108. return false
  109. }
  110. type AgentPermission struct {
  111. Bash map[string]AgentPermissionBash `json:"bash,required"`
  112. Edit AgentPermissionEdit `json:"edit,required"`
  113. Webfetch AgentPermissionWebfetch `json:"webfetch"`
  114. JSON agentPermissionJSON `json:"-"`
  115. }
  116. // agentPermissionJSON contains the JSON metadata for the struct [AgentPermission]
  117. type agentPermissionJSON struct {
  118. Bash apijson.Field
  119. Edit apijson.Field
  120. Webfetch apijson.Field
  121. raw string
  122. ExtraFields map[string]apijson.Field
  123. }
  124. func (r *AgentPermission) UnmarshalJSON(data []byte) (err error) {
  125. return apijson.UnmarshalRoot(data, r)
  126. }
  127. func (r agentPermissionJSON) RawJSON() string {
  128. return r.raw
  129. }
  130. type AgentPermissionBash string
  131. const (
  132. AgentPermissionBashAsk AgentPermissionBash = "ask"
  133. AgentPermissionBashAllow AgentPermissionBash = "allow"
  134. AgentPermissionBashDeny AgentPermissionBash = "deny"
  135. )
  136. func (r AgentPermissionBash) IsKnown() bool {
  137. switch r {
  138. case AgentPermissionBashAsk, AgentPermissionBashAllow, AgentPermissionBashDeny:
  139. return true
  140. }
  141. return false
  142. }
  143. type AgentPermissionEdit string
  144. const (
  145. AgentPermissionEditAsk AgentPermissionEdit = "ask"
  146. AgentPermissionEditAllow AgentPermissionEdit = "allow"
  147. AgentPermissionEditDeny AgentPermissionEdit = "deny"
  148. )
  149. func (r AgentPermissionEdit) IsKnown() bool {
  150. switch r {
  151. case AgentPermissionEditAsk, AgentPermissionEditAllow, AgentPermissionEditDeny:
  152. return true
  153. }
  154. return false
  155. }
  156. type AgentPermissionWebfetch string
  157. const (
  158. AgentPermissionWebfetchAsk AgentPermissionWebfetch = "ask"
  159. AgentPermissionWebfetchAllow AgentPermissionWebfetch = "allow"
  160. AgentPermissionWebfetchDeny AgentPermissionWebfetch = "deny"
  161. )
  162. func (r AgentPermissionWebfetch) IsKnown() bool {
  163. switch r {
  164. case AgentPermissionWebfetchAsk, AgentPermissionWebfetchAllow, AgentPermissionWebfetchDeny:
  165. return true
  166. }
  167. return false
  168. }
  169. type AgentModel struct {
  170. ModelID string `json:"modelID,required"`
  171. ProviderID string `json:"providerID,required"`
  172. JSON agentModelJSON `json:"-"`
  173. }
  174. // agentModelJSON contains the JSON metadata for the struct [AgentModel]
  175. type agentModelJSON struct {
  176. ModelID apijson.Field
  177. ProviderID apijson.Field
  178. raw string
  179. ExtraFields map[string]apijson.Field
  180. }
  181. func (r *AgentModel) UnmarshalJSON(data []byte) (err error) {
  182. return apijson.UnmarshalRoot(data, r)
  183. }
  184. func (r agentModelJSON) RawJSON() string {
  185. return r.raw
  186. }
  187. type App struct {
  188. Git bool `json:"git,required"`
  189. Hostname string `json:"hostname,required"`
  190. Path AppPath `json:"path,required"`
  191. Time AppTime `json:"time,required"`
  192. JSON appJSON `json:"-"`
  193. }
  194. // appJSON contains the JSON metadata for the struct [App]
  195. type appJSON struct {
  196. Git apijson.Field
  197. Hostname apijson.Field
  198. Path apijson.Field
  199. Time apijson.Field
  200. raw string
  201. ExtraFields map[string]apijson.Field
  202. }
  203. func (r *App) UnmarshalJSON(data []byte) (err error) {
  204. return apijson.UnmarshalRoot(data, r)
  205. }
  206. func (r appJSON) RawJSON() string {
  207. return r.raw
  208. }
  209. type AppPath struct {
  210. Config string `json:"config,required"`
  211. Cwd string `json:"cwd,required"`
  212. Data string `json:"data,required"`
  213. Root string `json:"root,required"`
  214. State string `json:"state,required"`
  215. JSON appPathJSON `json:"-"`
  216. }
  217. // appPathJSON contains the JSON metadata for the struct [AppPath]
  218. type appPathJSON struct {
  219. Config apijson.Field
  220. Cwd apijson.Field
  221. Data apijson.Field
  222. Root apijson.Field
  223. State apijson.Field
  224. raw string
  225. ExtraFields map[string]apijson.Field
  226. }
  227. func (r *AppPath) UnmarshalJSON(data []byte) (err error) {
  228. return apijson.UnmarshalRoot(data, r)
  229. }
  230. func (r appPathJSON) RawJSON() string {
  231. return r.raw
  232. }
  233. type AppTime struct {
  234. Initialized float64 `json:"initialized"`
  235. JSON appTimeJSON `json:"-"`
  236. }
  237. // appTimeJSON contains the JSON metadata for the struct [AppTime]
  238. type appTimeJSON struct {
  239. Initialized apijson.Field
  240. raw string
  241. ExtraFields map[string]apijson.Field
  242. }
  243. func (r *AppTime) UnmarshalJSON(data []byte) (err error) {
  244. return apijson.UnmarshalRoot(data, r)
  245. }
  246. func (r appTimeJSON) RawJSON() string {
  247. return r.raw
  248. }
  249. type Model struct {
  250. ID string `json:"id,required"`
  251. Attachment bool `json:"attachment,required"`
  252. Cost ModelCost `json:"cost,required"`
  253. Limit ModelLimit `json:"limit,required"`
  254. Name string `json:"name,required"`
  255. Options map[string]interface{} `json:"options,required"`
  256. Reasoning bool `json:"reasoning,required"`
  257. ReleaseDate string `json:"release_date,required"`
  258. Temperature bool `json:"temperature,required"`
  259. ToolCall bool `json:"tool_call,required"`
  260. JSON modelJSON `json:"-"`
  261. }
  262. // modelJSON contains the JSON metadata for the struct [Model]
  263. type modelJSON struct {
  264. ID apijson.Field
  265. Attachment apijson.Field
  266. Cost apijson.Field
  267. Limit apijson.Field
  268. Name apijson.Field
  269. Options apijson.Field
  270. Reasoning apijson.Field
  271. ReleaseDate apijson.Field
  272. Temperature apijson.Field
  273. ToolCall apijson.Field
  274. raw string
  275. ExtraFields map[string]apijson.Field
  276. }
  277. func (r *Model) UnmarshalJSON(data []byte) (err error) {
  278. return apijson.UnmarshalRoot(data, r)
  279. }
  280. func (r modelJSON) RawJSON() string {
  281. return r.raw
  282. }
  283. type ModelCost struct {
  284. Input float64 `json:"input,required"`
  285. Output float64 `json:"output,required"`
  286. CacheRead float64 `json:"cache_read"`
  287. CacheWrite float64 `json:"cache_write"`
  288. JSON modelCostJSON `json:"-"`
  289. }
  290. // modelCostJSON contains the JSON metadata for the struct [ModelCost]
  291. type modelCostJSON struct {
  292. Input apijson.Field
  293. Output apijson.Field
  294. CacheRead apijson.Field
  295. CacheWrite apijson.Field
  296. raw string
  297. ExtraFields map[string]apijson.Field
  298. }
  299. func (r *ModelCost) UnmarshalJSON(data []byte) (err error) {
  300. return apijson.UnmarshalRoot(data, r)
  301. }
  302. func (r modelCostJSON) RawJSON() string {
  303. return r.raw
  304. }
  305. type ModelLimit struct {
  306. Context float64 `json:"context,required"`
  307. Output float64 `json:"output,required"`
  308. JSON modelLimitJSON `json:"-"`
  309. }
  310. // modelLimitJSON contains the JSON metadata for the struct [ModelLimit]
  311. type modelLimitJSON struct {
  312. Context apijson.Field
  313. Output apijson.Field
  314. raw string
  315. ExtraFields map[string]apijson.Field
  316. }
  317. func (r *ModelLimit) UnmarshalJSON(data []byte) (err error) {
  318. return apijson.UnmarshalRoot(data, r)
  319. }
  320. func (r modelLimitJSON) RawJSON() string {
  321. return r.raw
  322. }
  323. type Provider struct {
  324. ID string `json:"id,required"`
  325. Env []string `json:"env,required"`
  326. Models map[string]Model `json:"models,required"`
  327. Name string `json:"name,required"`
  328. API string `json:"api"`
  329. Npm string `json:"npm"`
  330. JSON providerJSON `json:"-"`
  331. }
  332. // providerJSON contains the JSON metadata for the struct [Provider]
  333. type providerJSON struct {
  334. ID apijson.Field
  335. Env apijson.Field
  336. Models apijson.Field
  337. Name apijson.Field
  338. API apijson.Field
  339. Npm apijson.Field
  340. raw string
  341. ExtraFields map[string]apijson.Field
  342. }
  343. func (r *Provider) UnmarshalJSON(data []byte) (err error) {
  344. return apijson.UnmarshalRoot(data, r)
  345. }
  346. func (r providerJSON) RawJSON() string {
  347. return r.raw
  348. }
  349. type AppProvidersResponse struct {
  350. Default map[string]string `json:"default,required"`
  351. Providers []Provider `json:"providers,required"`
  352. JSON appProvidersResponseJSON `json:"-"`
  353. }
  354. // appProvidersResponseJSON contains the JSON metadata for the struct
  355. // [AppProvidersResponse]
  356. type appProvidersResponseJSON struct {
  357. Default apijson.Field
  358. Providers apijson.Field
  359. raw string
  360. ExtraFields map[string]apijson.Field
  361. }
  362. func (r *AppProvidersResponse) UnmarshalJSON(data []byte) (err error) {
  363. return apijson.UnmarshalRoot(data, r)
  364. }
  365. func (r appProvidersResponseJSON) RawJSON() string {
  366. return r.raw
  367. }
  368. type AppLogParams struct {
  369. // Log level
  370. Level param.Field[AppLogParamsLevel] `json:"level,required"`
  371. // Log message
  372. Message param.Field[string] `json:"message,required"`
  373. // Service name for the log entry
  374. Service param.Field[string] `json:"service,required"`
  375. // Additional metadata for the log entry
  376. Extra param.Field[map[string]interface{}] `json:"extra"`
  377. }
  378. func (r AppLogParams) MarshalJSON() (data []byte, err error) {
  379. return apijson.MarshalRoot(r)
  380. }
  381. // Log level
  382. type AppLogParamsLevel string
  383. const (
  384. AppLogParamsLevelDebug AppLogParamsLevel = "debug"
  385. AppLogParamsLevelInfo AppLogParamsLevel = "info"
  386. AppLogParamsLevelError AppLogParamsLevel = "error"
  387. AppLogParamsLevelWarn AppLogParamsLevel = "warn"
  388. )
  389. func (r AppLogParamsLevel) IsKnown() bool {
  390. switch r {
  391. case AppLogParamsLevelDebug, AppLogParamsLevelInfo, AppLogParamsLevelError, AppLogParamsLevelWarn:
  392. return true
  393. }
  394. return false
  395. }