app.go 13 KB

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