app.go 7.8 KB

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