agent.go 5.7 KB

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