tui.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. // TuiService 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 [NewTuiService] method instead.
  20. type TuiService struct {
  21. Options []option.RequestOption
  22. }
  23. // NewTuiService 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 NewTuiService(opts ...option.RequestOption) (r *TuiService) {
  27. r = &TuiService{}
  28. r.Options = opts
  29. return
  30. }
  31. // Append prompt to the TUI
  32. func (r *TuiService) AppendPrompt(ctx context.Context, params TuiAppendPromptParams, opts ...option.RequestOption) (res *bool, err error) {
  33. opts = slices.Concat(r.Options, opts)
  34. path := "tui/append-prompt"
  35. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
  36. return
  37. }
  38. // Clear the prompt
  39. func (r *TuiService) ClearPrompt(ctx context.Context, body TuiClearPromptParams, opts ...option.RequestOption) (res *bool, err error) {
  40. opts = slices.Concat(r.Options, opts)
  41. path := "tui/clear-prompt"
  42. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  43. return
  44. }
  45. // Execute a TUI command (e.g. agent_cycle)
  46. func (r *TuiService) ExecuteCommand(ctx context.Context, params TuiExecuteCommandParams, opts ...option.RequestOption) (res *bool, err error) {
  47. opts = slices.Concat(r.Options, opts)
  48. path := "tui/execute-command"
  49. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
  50. return
  51. }
  52. // Open the help dialog
  53. func (r *TuiService) OpenHelp(ctx context.Context, body TuiOpenHelpParams, opts ...option.RequestOption) (res *bool, err error) {
  54. opts = slices.Concat(r.Options, opts)
  55. path := "tui/open-help"
  56. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  57. return
  58. }
  59. // Open the model dialog
  60. func (r *TuiService) OpenModels(ctx context.Context, body TuiOpenModelsParams, opts ...option.RequestOption) (res *bool, err error) {
  61. opts = slices.Concat(r.Options, opts)
  62. path := "tui/open-models"
  63. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  64. return
  65. }
  66. // Open the session dialog
  67. func (r *TuiService) OpenSessions(ctx context.Context, body TuiOpenSessionsParams, opts ...option.RequestOption) (res *bool, err error) {
  68. opts = slices.Concat(r.Options, opts)
  69. path := "tui/open-sessions"
  70. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  71. return
  72. }
  73. // Open the theme dialog
  74. func (r *TuiService) OpenThemes(ctx context.Context, body TuiOpenThemesParams, opts ...option.RequestOption) (res *bool, err error) {
  75. opts = slices.Concat(r.Options, opts)
  76. path := "tui/open-themes"
  77. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  78. return
  79. }
  80. // Show a toast notification in the TUI
  81. func (r *TuiService) ShowToast(ctx context.Context, params TuiShowToastParams, opts ...option.RequestOption) (res *bool, err error) {
  82. opts = slices.Concat(r.Options, opts)
  83. path := "tui/show-toast"
  84. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
  85. return
  86. }
  87. // Submit the prompt
  88. func (r *TuiService) SubmitPrompt(ctx context.Context, body TuiSubmitPromptParams, opts ...option.RequestOption) (res *bool, err error) {
  89. opts = slices.Concat(r.Options, opts)
  90. path := "tui/submit-prompt"
  91. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  92. return
  93. }
  94. type TuiAppendPromptParams struct {
  95. Text param.Field[string] `json:"text,required"`
  96. Directory param.Field[string] `query:"directory"`
  97. }
  98. func (r TuiAppendPromptParams) MarshalJSON() (data []byte, err error) {
  99. return apijson.MarshalRoot(r)
  100. }
  101. // URLQuery serializes [TuiAppendPromptParams]'s query parameters as `url.Values`.
  102. func (r TuiAppendPromptParams) URLQuery() (v url.Values) {
  103. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  104. ArrayFormat: apiquery.ArrayQueryFormatComma,
  105. NestedFormat: apiquery.NestedQueryFormatBrackets,
  106. })
  107. }
  108. type TuiClearPromptParams struct {
  109. Directory param.Field[string] `query:"directory"`
  110. }
  111. // URLQuery serializes [TuiClearPromptParams]'s query parameters as `url.Values`.
  112. func (r TuiClearPromptParams) URLQuery() (v url.Values) {
  113. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  114. ArrayFormat: apiquery.ArrayQueryFormatComma,
  115. NestedFormat: apiquery.NestedQueryFormatBrackets,
  116. })
  117. }
  118. type TuiExecuteCommandParams struct {
  119. Command param.Field[string] `json:"command,required"`
  120. Directory param.Field[string] `query:"directory"`
  121. }
  122. func (r TuiExecuteCommandParams) MarshalJSON() (data []byte, err error) {
  123. return apijson.MarshalRoot(r)
  124. }
  125. // URLQuery serializes [TuiExecuteCommandParams]'s query parameters as
  126. // `url.Values`.
  127. func (r TuiExecuteCommandParams) URLQuery() (v url.Values) {
  128. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  129. ArrayFormat: apiquery.ArrayQueryFormatComma,
  130. NestedFormat: apiquery.NestedQueryFormatBrackets,
  131. })
  132. }
  133. type TuiOpenHelpParams struct {
  134. Directory param.Field[string] `query:"directory"`
  135. }
  136. // URLQuery serializes [TuiOpenHelpParams]'s query parameters as `url.Values`.
  137. func (r TuiOpenHelpParams) URLQuery() (v url.Values) {
  138. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  139. ArrayFormat: apiquery.ArrayQueryFormatComma,
  140. NestedFormat: apiquery.NestedQueryFormatBrackets,
  141. })
  142. }
  143. type TuiOpenModelsParams struct {
  144. Directory param.Field[string] `query:"directory"`
  145. }
  146. // URLQuery serializes [TuiOpenModelsParams]'s query parameters as `url.Values`.
  147. func (r TuiOpenModelsParams) URLQuery() (v url.Values) {
  148. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  149. ArrayFormat: apiquery.ArrayQueryFormatComma,
  150. NestedFormat: apiquery.NestedQueryFormatBrackets,
  151. })
  152. }
  153. type TuiOpenSessionsParams struct {
  154. Directory param.Field[string] `query:"directory"`
  155. }
  156. // URLQuery serializes [TuiOpenSessionsParams]'s query parameters as `url.Values`.
  157. func (r TuiOpenSessionsParams) URLQuery() (v url.Values) {
  158. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  159. ArrayFormat: apiquery.ArrayQueryFormatComma,
  160. NestedFormat: apiquery.NestedQueryFormatBrackets,
  161. })
  162. }
  163. type TuiOpenThemesParams struct {
  164. Directory param.Field[string] `query:"directory"`
  165. }
  166. // URLQuery serializes [TuiOpenThemesParams]'s query parameters as `url.Values`.
  167. func (r TuiOpenThemesParams) URLQuery() (v url.Values) {
  168. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  169. ArrayFormat: apiquery.ArrayQueryFormatComma,
  170. NestedFormat: apiquery.NestedQueryFormatBrackets,
  171. })
  172. }
  173. type TuiShowToastParams struct {
  174. Message param.Field[string] `json:"message,required"`
  175. Variant param.Field[TuiShowToastParamsVariant] `json:"variant,required"`
  176. Directory param.Field[string] `query:"directory"`
  177. Title param.Field[string] `json:"title"`
  178. }
  179. func (r TuiShowToastParams) MarshalJSON() (data []byte, err error) {
  180. return apijson.MarshalRoot(r)
  181. }
  182. // URLQuery serializes [TuiShowToastParams]'s query parameters as `url.Values`.
  183. func (r TuiShowToastParams) URLQuery() (v url.Values) {
  184. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  185. ArrayFormat: apiquery.ArrayQueryFormatComma,
  186. NestedFormat: apiquery.NestedQueryFormatBrackets,
  187. })
  188. }
  189. type TuiShowToastParamsVariant string
  190. const (
  191. TuiShowToastParamsVariantInfo TuiShowToastParamsVariant = "info"
  192. TuiShowToastParamsVariantSuccess TuiShowToastParamsVariant = "success"
  193. TuiShowToastParamsVariantWarning TuiShowToastParamsVariant = "warning"
  194. TuiShowToastParamsVariantError TuiShowToastParamsVariant = "error"
  195. )
  196. func (r TuiShowToastParamsVariant) IsKnown() bool {
  197. switch r {
  198. case TuiShowToastParamsVariantInfo, TuiShowToastParamsVariantSuccess, TuiShowToastParamsVariantWarning, TuiShowToastParamsVariantError:
  199. return true
  200. }
  201. return false
  202. }
  203. type TuiSubmitPromptParams struct {
  204. Directory param.Field[string] `query:"directory"`
  205. }
  206. // URLQuery serializes [TuiSubmitPromptParams]'s query parameters as `url.Values`.
  207. func (r TuiSubmitPromptParams) URLQuery() (v url.Values) {
  208. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  209. ArrayFormat: apiquery.ArrayQueryFormatComma,
  210. NestedFormat: apiquery.NestedQueryFormatBrackets,
  211. })
  212. }