app.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. JSON modelJSON `json:"-"`
  56. }
  57. // modelJSON contains the JSON metadata for the struct [Model]
  58. type modelJSON struct {
  59. ID apijson.Field
  60. Attachment apijson.Field
  61. Cost apijson.Field
  62. Limit apijson.Field
  63. Name apijson.Field
  64. Options apijson.Field
  65. Reasoning apijson.Field
  66. ReleaseDate apijson.Field
  67. Temperature apijson.Field
  68. ToolCall apijson.Field
  69. raw string
  70. ExtraFields map[string]apijson.Field
  71. }
  72. func (r *Model) UnmarshalJSON(data []byte) (err error) {
  73. return apijson.UnmarshalRoot(data, r)
  74. }
  75. func (r modelJSON) RawJSON() string {
  76. return r.raw
  77. }
  78. type ModelCost struct {
  79. Input float64 `json:"input,required"`
  80. Output float64 `json:"output,required"`
  81. CacheRead float64 `json:"cache_read"`
  82. CacheWrite float64 `json:"cache_write"`
  83. JSON modelCostJSON `json:"-"`
  84. }
  85. // modelCostJSON contains the JSON metadata for the struct [ModelCost]
  86. type modelCostJSON struct {
  87. Input apijson.Field
  88. Output apijson.Field
  89. CacheRead apijson.Field
  90. CacheWrite apijson.Field
  91. raw string
  92. ExtraFields map[string]apijson.Field
  93. }
  94. func (r *ModelCost) UnmarshalJSON(data []byte) (err error) {
  95. return apijson.UnmarshalRoot(data, r)
  96. }
  97. func (r modelCostJSON) RawJSON() string {
  98. return r.raw
  99. }
  100. type ModelLimit struct {
  101. Context float64 `json:"context,required"`
  102. Output float64 `json:"output,required"`
  103. JSON modelLimitJSON `json:"-"`
  104. }
  105. // modelLimitJSON contains the JSON metadata for the struct [ModelLimit]
  106. type modelLimitJSON struct {
  107. Context apijson.Field
  108. Output apijson.Field
  109. raw string
  110. ExtraFields map[string]apijson.Field
  111. }
  112. func (r *ModelLimit) UnmarshalJSON(data []byte) (err error) {
  113. return apijson.UnmarshalRoot(data, r)
  114. }
  115. func (r modelLimitJSON) RawJSON() string {
  116. return r.raw
  117. }
  118. type Provider struct {
  119. ID string `json:"id,required"`
  120. Env []string `json:"env,required"`
  121. Models map[string]Model `json:"models,required"`
  122. Name string `json:"name,required"`
  123. API string `json:"api"`
  124. Npm string `json:"npm"`
  125. JSON providerJSON `json:"-"`
  126. }
  127. // providerJSON contains the JSON metadata for the struct [Provider]
  128. type providerJSON struct {
  129. ID apijson.Field
  130. Env apijson.Field
  131. Models apijson.Field
  132. Name apijson.Field
  133. API apijson.Field
  134. Npm apijson.Field
  135. raw string
  136. ExtraFields map[string]apijson.Field
  137. }
  138. func (r *Provider) UnmarshalJSON(data []byte) (err error) {
  139. return apijson.UnmarshalRoot(data, r)
  140. }
  141. func (r providerJSON) RawJSON() string {
  142. return r.raw
  143. }
  144. type AppProvidersResponse struct {
  145. Default map[string]string `json:"default,required"`
  146. Providers []Provider `json:"providers,required"`
  147. JSON appProvidersResponseJSON `json:"-"`
  148. }
  149. // appProvidersResponseJSON contains the JSON metadata for the struct
  150. // [AppProvidersResponse]
  151. type appProvidersResponseJSON struct {
  152. Default apijson.Field
  153. Providers apijson.Field
  154. raw string
  155. ExtraFields map[string]apijson.Field
  156. }
  157. func (r *AppProvidersResponse) UnmarshalJSON(data []byte) (err error) {
  158. return apijson.UnmarshalRoot(data, r)
  159. }
  160. func (r appProvidersResponseJSON) RawJSON() string {
  161. return r.raw
  162. }
  163. type AppLogParams struct {
  164. // Log level
  165. Level param.Field[AppLogParamsLevel] `json:"level,required"`
  166. // Log message
  167. Message param.Field[string] `json:"message,required"`
  168. // Service name for the log entry
  169. Service param.Field[string] `json:"service,required"`
  170. Directory param.Field[string] `query:"directory"`
  171. // Additional metadata for the log entry
  172. Extra param.Field[map[string]interface{}] `json:"extra"`
  173. }
  174. func (r AppLogParams) MarshalJSON() (data []byte, err error) {
  175. return apijson.MarshalRoot(r)
  176. }
  177. // URLQuery serializes [AppLogParams]'s query parameters as `url.Values`.
  178. func (r AppLogParams) URLQuery() (v url.Values) {
  179. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  180. ArrayFormat: apiquery.ArrayQueryFormatComma,
  181. NestedFormat: apiquery.NestedQueryFormatBrackets,
  182. })
  183. }
  184. // Log level
  185. type AppLogParamsLevel string
  186. const (
  187. AppLogParamsLevelDebug AppLogParamsLevel = "debug"
  188. AppLogParamsLevelInfo AppLogParamsLevel = "info"
  189. AppLogParamsLevelError AppLogParamsLevel = "error"
  190. AppLogParamsLevelWarn AppLogParamsLevel = "warn"
  191. )
  192. func (r AppLogParamsLevel) IsKnown() bool {
  193. switch r {
  194. case AppLogParamsLevelDebug, AppLogParamsLevelInfo, AppLogParamsLevelError, AppLogParamsLevelWarn:
  195. return true
  196. }
  197. return false
  198. }
  199. type AppProvidersParams struct {
  200. Directory param.Field[string] `query:"directory"`
  201. }
  202. // URLQuery serializes [AppProvidersParams]'s query parameters as `url.Values`.
  203. func (r AppProvidersParams) URLQuery() (v url.Values) {
  204. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  205. ArrayFormat: apiquery.ArrayQueryFormatComma,
  206. NestedFormat: apiquery.NestedQueryFormatBrackets,
  207. })
  208. }