tui.go 8.7 KB

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