tui.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. "github.com/sst/opencode-sdk-go/internal/apijson"
  7. "github.com/sst/opencode-sdk-go/internal/param"
  8. "github.com/sst/opencode-sdk-go/internal/requestconfig"
  9. "github.com/sst/opencode-sdk-go/option"
  10. )
  11. // TuiService contains methods and other services that help with interacting with
  12. // the opencode API.
  13. //
  14. // Note, unlike clients, this service does not read variables from the environment
  15. // automatically. You should not instantiate this service directly, and instead use
  16. // the [NewTuiService] method instead.
  17. type TuiService struct {
  18. Options []option.RequestOption
  19. }
  20. // NewTuiService generates a new service that applies the given options to each
  21. // request. These options are applied after the parent client's options (if there
  22. // is one), and before any request-specific options.
  23. func NewTuiService(opts ...option.RequestOption) (r *TuiService) {
  24. r = &TuiService{}
  25. r.Options = opts
  26. return
  27. }
  28. // Append prompt to the TUI
  29. func (r *TuiService) AppendPrompt(ctx context.Context, body TuiAppendPromptParams, opts ...option.RequestOption) (res *bool, err error) {
  30. opts = append(r.Options[:], opts...)
  31. path := "tui/append-prompt"
  32. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  33. return
  34. }
  35. // Clear the prompt
  36. func (r *TuiService) ClearPrompt(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) {
  37. opts = append(r.Options[:], opts...)
  38. path := "tui/clear-prompt"
  39. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  40. return
  41. }
  42. // Execute a TUI command (e.g. agent_cycle)
  43. func (r *TuiService) ExecuteCommand(ctx context.Context, body TuiExecuteCommandParams, opts ...option.RequestOption) (res *bool, err error) {
  44. opts = append(r.Options[:], opts...)
  45. path := "tui/execute-command"
  46. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  47. return
  48. }
  49. // Open the help dialog
  50. func (r *TuiService) OpenHelp(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) {
  51. opts = append(r.Options[:], opts...)
  52. path := "tui/open-help"
  53. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  54. return
  55. }
  56. // Open the model dialog
  57. func (r *TuiService) OpenModels(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) {
  58. opts = append(r.Options[:], opts...)
  59. path := "tui/open-models"
  60. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  61. return
  62. }
  63. // Open the session dialog
  64. func (r *TuiService) OpenSessions(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) {
  65. opts = append(r.Options[:], opts...)
  66. path := "tui/open-sessions"
  67. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  68. return
  69. }
  70. // Open the theme dialog
  71. func (r *TuiService) OpenThemes(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) {
  72. opts = append(r.Options[:], opts...)
  73. path := "tui/open-themes"
  74. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  75. return
  76. }
  77. // Show a toast notification in the TUI
  78. func (r *TuiService) ShowToast(ctx context.Context, body TuiShowToastParams, opts ...option.RequestOption) (res *bool, err error) {
  79. opts = append(r.Options[:], opts...)
  80. path := "tui/show-toast"
  81. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  82. return
  83. }
  84. // Submit the prompt
  85. func (r *TuiService) SubmitPrompt(ctx context.Context, opts ...option.RequestOption) (res *bool, err error) {
  86. opts = append(r.Options[:], opts...)
  87. path := "tui/submit-prompt"
  88. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
  89. return
  90. }
  91. type TuiAppendPromptParams struct {
  92. Text param.Field[string] `json:"text,required"`
  93. }
  94. func (r TuiAppendPromptParams) MarshalJSON() (data []byte, err error) {
  95. return apijson.MarshalRoot(r)
  96. }
  97. type TuiExecuteCommandParams struct {
  98. Command param.Field[string] `json:"command,required"`
  99. }
  100. func (r TuiExecuteCommandParams) MarshalJSON() (data []byte, err error) {
  101. return apijson.MarshalRoot(r)
  102. }
  103. type TuiShowToastParams struct {
  104. Message param.Field[string] `json:"message,required"`
  105. Variant param.Field[TuiShowToastParamsVariant] `json:"variant,required"`
  106. Title param.Field[string] `json:"title"`
  107. }
  108. func (r TuiShowToastParams) MarshalJSON() (data []byte, err error) {
  109. return apijson.MarshalRoot(r)
  110. }
  111. type TuiShowToastParamsVariant string
  112. const (
  113. TuiShowToastParamsVariantInfo TuiShowToastParamsVariant = "info"
  114. TuiShowToastParamsVariantSuccess TuiShowToastParamsVariant = "success"
  115. TuiShowToastParamsVariantWarning TuiShowToastParamsVariant = "warning"
  116. TuiShowToastParamsVariantError TuiShowToastParamsVariant = "error"
  117. )
  118. func (r TuiShowToastParamsVariant) IsKnown() bool {
  119. switch r {
  120. case TuiShowToastParamsVariantInfo, TuiShowToastParamsVariantSuccess, TuiShowToastParamsVariantWarning, TuiShowToastParamsVariantError:
  121. return true
  122. }
  123. return false
  124. }