agent.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. // AgentService 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 [NewAgentService] method instead.
  20. type AgentService struct {
  21. Options []option.RequestOption
  22. }
  23. // NewAgentService 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 NewAgentService(opts ...option.RequestOption) (r *AgentService) {
  27. r = &AgentService{}
  28. r.Options = opts
  29. return
  30. }
  31. // List all agents
  32. func (r *AgentService) List(ctx context.Context, query AgentListParams, opts ...option.RequestOption) (res *[]Agent, err error) {
  33. opts = slices.Concat(r.Options, opts)
  34. path := "agent"
  35. err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
  36. return
  37. }
  38. type Agent struct {
  39. BuiltIn bool `json:"builtIn,required"`
  40. Mode AgentMode `json:"mode,required"`
  41. Name string `json:"name,required"`
  42. Options map[string]interface{} `json:"options,required"`
  43. Permission AgentPermission `json:"permission,required"`
  44. Tools map[string]bool `json:"tools,required"`
  45. Color string `json:"color"`
  46. Description string `json:"description"`
  47. Model AgentModel `json:"model"`
  48. Prompt string `json:"prompt"`
  49. Temperature float64 `json:"temperature"`
  50. TopP float64 `json:"topP"`
  51. JSON agentJSON `json:"-"`
  52. }
  53. // agentJSON contains the JSON metadata for the struct [Agent]
  54. type agentJSON struct {
  55. BuiltIn apijson.Field
  56. Mode apijson.Field
  57. Name apijson.Field
  58. Options apijson.Field
  59. Permission apijson.Field
  60. Tools apijson.Field
  61. Color apijson.Field
  62. Description apijson.Field
  63. Model apijson.Field
  64. Prompt apijson.Field
  65. Temperature apijson.Field
  66. TopP apijson.Field
  67. raw string
  68. ExtraFields map[string]apijson.Field
  69. }
  70. func (r *Agent) UnmarshalJSON(data []byte) (err error) {
  71. return apijson.UnmarshalRoot(data, r)
  72. }
  73. func (r agentJSON) RawJSON() string {
  74. return r.raw
  75. }
  76. type AgentMode string
  77. const (
  78. AgentModeSubagent AgentMode = "subagent"
  79. AgentModePrimary AgentMode = "primary"
  80. AgentModeAll AgentMode = "all"
  81. )
  82. func (r AgentMode) IsKnown() bool {
  83. switch r {
  84. case AgentModeSubagent, AgentModePrimary, AgentModeAll:
  85. return true
  86. }
  87. return false
  88. }
  89. type AgentPermission struct {
  90. Bash map[string]AgentPermissionBash `json:"bash,required"`
  91. Edit AgentPermissionEdit `json:"edit,required"`
  92. Webfetch AgentPermissionWebfetch `json:"webfetch"`
  93. JSON agentPermissionJSON `json:"-"`
  94. }
  95. // agentPermissionJSON contains the JSON metadata for the struct [AgentPermission]
  96. type agentPermissionJSON struct {
  97. Bash apijson.Field
  98. Edit apijson.Field
  99. Webfetch apijson.Field
  100. raw string
  101. ExtraFields map[string]apijson.Field
  102. }
  103. func (r *AgentPermission) UnmarshalJSON(data []byte) (err error) {
  104. return apijson.UnmarshalRoot(data, r)
  105. }
  106. func (r agentPermissionJSON) RawJSON() string {
  107. return r.raw
  108. }
  109. type AgentPermissionBash string
  110. const (
  111. AgentPermissionBashAsk AgentPermissionBash = "ask"
  112. AgentPermissionBashAllow AgentPermissionBash = "allow"
  113. AgentPermissionBashDeny AgentPermissionBash = "deny"
  114. )
  115. func (r AgentPermissionBash) IsKnown() bool {
  116. switch r {
  117. case AgentPermissionBashAsk, AgentPermissionBashAllow, AgentPermissionBashDeny:
  118. return true
  119. }
  120. return false
  121. }
  122. type AgentPermissionEdit string
  123. const (
  124. AgentPermissionEditAsk AgentPermissionEdit = "ask"
  125. AgentPermissionEditAllow AgentPermissionEdit = "allow"
  126. AgentPermissionEditDeny AgentPermissionEdit = "deny"
  127. )
  128. func (r AgentPermissionEdit) IsKnown() bool {
  129. switch r {
  130. case AgentPermissionEditAsk, AgentPermissionEditAllow, AgentPermissionEditDeny:
  131. return true
  132. }
  133. return false
  134. }
  135. type AgentPermissionWebfetch string
  136. const (
  137. AgentPermissionWebfetchAsk AgentPermissionWebfetch = "ask"
  138. AgentPermissionWebfetchAllow AgentPermissionWebfetch = "allow"
  139. AgentPermissionWebfetchDeny AgentPermissionWebfetch = "deny"
  140. )
  141. func (r AgentPermissionWebfetch) IsKnown() bool {
  142. switch r {
  143. case AgentPermissionWebfetchAsk, AgentPermissionWebfetchAllow, AgentPermissionWebfetchDeny:
  144. return true
  145. }
  146. return false
  147. }
  148. type AgentModel struct {
  149. ModelID string `json:"modelID,required"`
  150. ProviderID string `json:"providerID,required"`
  151. JSON agentModelJSON `json:"-"`
  152. }
  153. // agentModelJSON contains the JSON metadata for the struct [AgentModel]
  154. type agentModelJSON struct {
  155. ModelID apijson.Field
  156. ProviderID apijson.Field
  157. raw string
  158. ExtraFields map[string]apijson.Field
  159. }
  160. func (r *AgentModel) UnmarshalJSON(data []byte) (err error) {
  161. return apijson.UnmarshalRoot(data, r)
  162. }
  163. func (r agentModelJSON) RawJSON() string {
  164. return r.raw
  165. }
  166. type AgentListParams struct {
  167. Directory param.Field[string] `query:"directory"`
  168. }
  169. // URLQuery serializes [AgentListParams]'s query parameters as `url.Values`.
  170. func (r AgentListParams) URLQuery() (v url.Values) {
  171. return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
  172. ArrayFormat: apiquery.ArrayQueryFormatComma,
  173. NestedFormat: apiquery.NestedQueryFormatBrackets,
  174. })
  175. }