sessionpermission.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. package opencode
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "net/http"
  8. "github.com/sst/opencode-sdk-go/internal/apijson"
  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. // SessionPermissionService contains methods and other services that help with
  14. // interacting with 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 [NewSessionPermissionService] method instead.
  19. type SessionPermissionService struct {
  20. Options []option.RequestOption
  21. }
  22. // NewSessionPermissionService generates a new service that applies the given
  23. // options to each request. These options are applied after the parent client's
  24. // options (if there is one), and before any request-specific options.
  25. func NewSessionPermissionService(opts ...option.RequestOption) (r *SessionPermissionService) {
  26. r = &SessionPermissionService{}
  27. r.Options = opts
  28. return
  29. }
  30. // Respond to a permission request
  31. func (r *SessionPermissionService) Respond(ctx context.Context, id string, permissionID string, body SessionPermissionRespondParams, opts ...option.RequestOption) (res *bool, err error) {
  32. opts = append(r.Options[:], opts...)
  33. if id == "" {
  34. err = errors.New("missing required id parameter")
  35. return
  36. }
  37. if permissionID == "" {
  38. err = errors.New("missing required permissionID parameter")
  39. return
  40. }
  41. path := fmt.Sprintf("session/%s/permissions/%s", id, permissionID)
  42. err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  43. return
  44. }
  45. type Permission struct {
  46. ID string `json:"id,required"`
  47. MessageID string `json:"messageID,required"`
  48. Metadata map[string]interface{} `json:"metadata,required"`
  49. SessionID string `json:"sessionID,required"`
  50. Time PermissionTime `json:"time,required"`
  51. Title string `json:"title,required"`
  52. Type string `json:"type,required"`
  53. CallID string `json:"callID"`
  54. Pattern string `json:"pattern"`
  55. JSON permissionJSON `json:"-"`
  56. }
  57. // permissionJSON contains the JSON metadata for the struct [Permission]
  58. type permissionJSON struct {
  59. ID apijson.Field
  60. MessageID apijson.Field
  61. Metadata apijson.Field
  62. SessionID apijson.Field
  63. Time apijson.Field
  64. Title apijson.Field
  65. Type apijson.Field
  66. CallID apijson.Field
  67. Pattern apijson.Field
  68. raw string
  69. ExtraFields map[string]apijson.Field
  70. }
  71. func (r *Permission) UnmarshalJSON(data []byte) (err error) {
  72. return apijson.UnmarshalRoot(data, r)
  73. }
  74. func (r permissionJSON) RawJSON() string {
  75. return r.raw
  76. }
  77. type PermissionTime struct {
  78. Created float64 `json:"created,required"`
  79. JSON permissionTimeJSON `json:"-"`
  80. }
  81. // permissionTimeJSON contains the JSON metadata for the struct [PermissionTime]
  82. type permissionTimeJSON struct {
  83. Created apijson.Field
  84. raw string
  85. ExtraFields map[string]apijson.Field
  86. }
  87. func (r *PermissionTime) UnmarshalJSON(data []byte) (err error) {
  88. return apijson.UnmarshalRoot(data, r)
  89. }
  90. func (r permissionTimeJSON) RawJSON() string {
  91. return r.raw
  92. }
  93. type SessionPermissionRespondParams struct {
  94. Response param.Field[SessionPermissionRespondParamsResponse] `json:"response,required"`
  95. }
  96. func (r SessionPermissionRespondParams) MarshalJSON() (data []byte, err error) {
  97. return apijson.MarshalRoot(r)
  98. }
  99. type SessionPermissionRespondParamsResponse string
  100. const (
  101. SessionPermissionRespondParamsResponseOnce SessionPermissionRespondParamsResponse = "once"
  102. SessionPermissionRespondParamsResponseAlways SessionPermissionRespondParamsResponse = "always"
  103. SessionPermissionRespondParamsResponseReject SessionPermissionRespondParamsResponse = "reject"
  104. )
  105. func (r SessionPermissionRespondParamsResponse) IsKnown() bool {
  106. switch r {
  107. case SessionPermissionRespondParamsResponseOnce, SessionPermissionRespondParamsResponseAlways, SessionPermissionRespondParamsResponseReject:
  108. return true
  109. }
  110. return false
  111. }