app.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. "net/url"
  7. "slices"
  8. "github.com/sst/opencode-sdk-go/internal/apijson"
  9. "github.com/sst/opencode-sdk-go/internal/apiquery"
  10. "github.com/sst/opencode-sdk-go/internal/param"
  11. "github.com/sst/opencode-sdk-go/internal/requestconfig"
  12. "github.com/sst/opencode-sdk-go/option"
  13. )
  14. // AppService contains methods and other services that help with interacting with
  15. // the opencode API.
  16. //
  17. // Note, unlike clients, this service does not read variables from the environment
  18. // automatically. You should not instantiate this service directly, and instead use
  19. // the [NewAppService] method instead.
  20. type AppService struct {
  21. Options []option.RequestOption
  22. }
  23. // NewAppService generates a new service that applies the given options to each
  24. // request. These options are applied after the parent client's options (if there
  25. // is one), and before any request-specific options.
  26. func NewAppService(opts ...option.RequestOption) (r *AppService) {
  27. r = &AppService{}
  28. r.Options = opts
  29. return
  30. }
  31. // Write a log entry to the server logs
  32. func (r *AppService) Log(ctx context.Context, params AppLogParams, opts ...option.RequestOption) (res *bool, err error) {
  33. opts = slices.Concat(r.Options, opts)
  34. path := "log"
  35. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
  36. return
  37. }
  38. // List all providers
  39. func (r *AppService) Providers(ctx context.Context, query AppProvidersParams, opts ...option.RequestOption) (res *AppProvidersResponse, err error) {
  40. opts = slices.Concat(r.Options, opts)
  41. path := "config/providers"
  42. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
  43. return
  44. }
  45. type Model struct {
  46. ID string `json:"id,required"`
  47. Attachment bool `json:"attachment,required"`
  48. Cost ModelCost `json:"cost,required"`
  49. Limit ModelLimit `json:"limit,required"`
  50. Name string `json:"name,required"`
  51. Options map[string]interface{} `json:"options,required"`
  52. Reasoning bool `json:"reasoning,required"`
  53. ReleaseDate string `json:"release_date,required"`
  54. Temperature bool `json:"temperature,required"`
  55. ToolCall bool `json:"tool_call,required"`
  56. Experimental bool `json:"experimental"`
  57. Provider ModelProvider `json:"provider"`
  58. JSON modelJSON `json:"-"`
  59. }
  60. // modelJSON contains the JSON metadata for the struct [Model]
  61. type modelJSON struct {
  62. ID apijson.Field
  63. Attachment apijson.Field
  64. Cost apijson.Field
  65. Limit apijson.Field
  66. Name apijson.Field
  67. Options apijson.Field
  68. Reasoning apijson.Field
  69. ReleaseDate apijson.Field
  70. Temperature apijson.Field
  71. ToolCall apijson.Field
  72. Experimental apijson.Field
  73. Provider apijson.Field
  74. raw string
  75. ExtraFields map[string]apijson.Field
  76. }
  77. func (r *Model) UnmarshalJSON(data []byte) (err error) {
  78. return apijson.UnmarshalRoot(data, r)
  79. }
  80. func (r modelJSON) RawJSON() string {
  81. return r.raw
  82. }
  83. type ModelCost struct {
  84. Input float64 `json:"input,required"`
  85. Output float64 `json:"output,required"`
  86. CacheRead float64 `json:"cache_read"`
  87. CacheWrite float64 `json:"cache_write"`
  88. JSON modelCostJSON `json:"-"`
  89. }
  90. // modelCostJSON contains the JSON metadata for the struct [ModelCost]
  91. type modelCostJSON struct {
  92. Input apijson.Field
  93. Output apijson.Field
  94. CacheRead apijson.Field
  95. CacheWrite apijson.Field
  96. raw string
  97. ExtraFields map[string]apijson.Field
  98. }
  99. func (r *ModelCost) UnmarshalJSON(data []byte) (err error) {
  100. return apijson.UnmarshalRoot(data, r)
  101. }
  102. func (r modelCostJSON) RawJSON() string {
  103. return r.raw
  104. }
  105. type ModelLimit struct {
  106. Context float64 `json:"context,required"`
  107. Output float64 `json:"output,required"`
  108. JSON modelLimitJSON `json:"-"`
  109. }
  110. // modelLimitJSON contains the JSON metadata for the struct [ModelLimit]
  111. type modelLimitJSON struct {
  112. Context apijson.Field
  113. Output apijson.Field
  114. raw string
  115. ExtraFields map[string]apijson.Field
  116. }
  117. func (r *ModelLimit) UnmarshalJSON(data []byte) (err error) {
  118. return apijson.UnmarshalRoot(data, r)
  119. }
  120. func (r modelLimitJSON) RawJSON() string {
  121. return r.raw
  122. }
  123. type ModelProvider struct {
  124. Npm string `json:"npm,required"`
  125. JSON modelProviderJSON `json:"-"`
  126. }
  127. // modelProviderJSON contains the JSON metadata for the struct [ModelProvider]
  128. type modelProviderJSON struct {
  129. Npm apijson.Field
  130. raw string
  131. ExtraFields map[string]apijson.Field
  132. }
  133. func (r *ModelProvider) UnmarshalJSON(data []byte) (err error) {
  134. return apijson.UnmarshalRoot(data, r)
  135. }
  136. func (r modelProviderJSON) RawJSON() string {
  137. return r.raw
  138. }
  139. type Provider struct {
  140. ID string `json:"id,required"`
  141. Env []string `json:"env,required"`
  142. Models map[string]Model `json:"models,required"`
  143. Name string `json:"name,required"`
  144. API string `json:"api"`
  145. Npm string `json:"npm"`
  146. JSON providerJSON `json:"-"`
  147. }
  148. // providerJSON contains the JSON metadata for the struct [Provider]
  149. type providerJSON struct {
  150. ID apijson.Field
  151. Env apijson.Field
  152. Models apijson.Field
  153. Name apijson.Field
  154. API apijson.Field
  155. Npm apijson.Field
  156. raw string
  157. ExtraFields map[string]apijson.Field
  158. }
  159. func (r *Provider) UnmarshalJSON(data []byte) (err error) {
  160. return apijson.UnmarshalRoot(data, r)
  161. }
  162. func (r providerJSON) RawJSON() string {
  163. return r.raw
  164. }
  165. type AppProvidersResponse struct {
  166. Default map[string]string `json:"default,required"`
  167. Providers []Provider `json:"providers,required"`
  168. JSON appProvidersResponseJSON `json:"-"`
  169. }
  170. // appProvidersResponseJSON contains the JSON metadata for the struct
  171. // [AppProvidersResponse]
  172. type appProvidersResponseJSON struct {
  173. Default apijson.Field
  174. Providers apijson.Field
  175. raw string
  176. ExtraFields map[string]apijson.Field
  177. }
  178. func (r *AppProvidersResponse) UnmarshalJSON(data []byte) (err error) {
  179. return apijson.UnmarshalRoot(data, r)
  180. }
  181. func (r appProvidersResponseJSON) RawJSON() string {
  182. return r.raw
  183. }
  184. type AppLogParams struct {
  185. // Log level
  186. Level param.Field[AppLogParamsLevel] `json:"level,required"`
  187. // Log message
  188. Message param.Field[string] `json:"message,required"`
  189. // Service name for the log entry
  190. Service param.Field[string] `json:"service,required"`
  191. Directory param.Field[string] `query:"directory"`
  192. // Additional metadata for the log entry
  193. Extra param.Field[map[string]interface{}] `json:"extra"`
  194. }
  195. func (r AppLogParams) MarshalJSON() (data []byte, err error) {
  196. return apijson.MarshalRoot(r)
  197. }
  198. // URLQuery serializes [AppLogParams]'s query parameters as `url.Values`.
  199. func (r AppLogParams) URLQuery() (v url.Values) {
  200. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  201. ArrayFormat: apiquery.ArrayQueryFormatComma,
  202. NestedFormat: apiquery.NestedQueryFormatBrackets,
  203. })
  204. }
  205. // Log level
  206. type AppLogParamsLevel string
  207. const (
  208. AppLogParamsLevelDebug AppLogParamsLevel = "debug"
  209. AppLogParamsLevelInfo AppLogParamsLevel = "info"
  210. AppLogParamsLevelError AppLogParamsLevel = "error"
  211. AppLogParamsLevelWarn AppLogParamsLevel = "warn"
  212. )
  213. func (r AppLogParamsLevel) IsKnown() bool {
  214. switch r {
  215. case AppLogParamsLevelDebug, AppLogParamsLevelInfo, AppLogParamsLevelError, AppLogParamsLevelWarn:
  216. return true
  217. }
  218. return false
  219. }
  220. type AppProvidersParams struct {
  221. Directory param.Field[string] `query:"directory"`
  222. }
  223. // URLQuery serializes [AppProvidersParams]'s query parameters as `url.Values`.
  224. func (r AppProvidersParams) URLQuery() (v url.Values) {
  225. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  226. ArrayFormat: apiquery.ArrayQueryFormatComma,
  227. NestedFormat: apiquery.NestedQueryFormatBrackets,
  228. })
  229. }