agent.go 5.7 KB

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