github.com/anthropics/anthropic-sdk-go@v1.70.1/betaskill.go (about) 1 // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 2 3 package anthropic 4 5 import ( 6 "bytes" 7 "context" 8 "errors" 9 "fmt" 10 "io" 11 "mime/multipart" 12 "net/http" 13 "net/url" 14 "slices" 15 "time" 16 17 "github.com/anthropics/anthropic-sdk-go/internal/apiform" 18 "github.com/anthropics/anthropic-sdk-go/internal/apijson" 19 "github.com/anthropics/anthropic-sdk-go/internal/apiquery" 20 "github.com/anthropics/anthropic-sdk-go/internal/requestconfig" 21 "github.com/anthropics/anthropic-sdk-go/option" 22 "github.com/anthropics/anthropic-sdk-go/packages/pagination" 23 "github.com/anthropics/anthropic-sdk-go/packages/param" 24 "github.com/anthropics/anthropic-sdk-go/packages/respjson" 25 "github.com/anthropics/anthropic-sdk-go/shared/constant" 26 ) 27 28 // BetaSkillService contains methods and other services that help with interacting 29 // with the anthropic API. 30 // 31 // Note, unlike clients, this service does not read variables from the environment 32 // automatically. You should not instantiate this service directly, and instead use 33 // the [NewBetaSkillService] method instead. 34 type BetaSkillService struct { 35 Options []option.RequestOption 36 Versions BetaSkillVersionService 37 } 38 39 // NewBetaSkillService generates a new service that applies the given options to 40 // each request. These options are applied after the parent client's options (if 41 // there is one), and before any request-specific options. 42 func NewBetaSkillService(opts ...option.RequestOption) (r BetaSkillService) { 43 r = BetaSkillService{} 44 r.Options = opts 45 r.Versions = NewBetaSkillVersionService(opts...) 46 return 47 } 48 49 // Create Skill 50 func (r *BetaSkillService) New(ctx context.Context, params BetaSkillNewParams, opts ...option.RequestOption) (res *BetaSkill, err error) { 51 for _, v := range params.Betas { 52 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 53 } 54 if !param.IsOmitted(params.WorkspaceID) { 55 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 56 } 57 opts = slices.Concat(r.Options, opts) 58 path := "v1/skills?beta=true" 59 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 60 return res, err 61 } 62 63 // Get Skill 64 func (r *BetaSkillService) Get(ctx context.Context, skillID string, query BetaSkillGetParams, opts ...option.RequestOption) (res *BetaSkill, err error) { 65 for _, v := range query.Betas { 66 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 67 } 68 if !param.IsOmitted(query.WorkspaceID) { 69 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", query.WorkspaceID.Value))) 70 } 71 opts = slices.Concat(r.Options, opts) 72 if skillID == "" { 73 err = errors.New("missing required skill_id parameter") 74 return nil, err 75 } 76 path := fmt.Sprintf("v1/skills/%s?beta=true", skillID) 77 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) 78 return res, err 79 } 80 81 // List Skills 82 func (r *BetaSkillService) List(ctx context.Context, params BetaSkillListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaSkill], err error) { 83 var raw *http.Response 84 for _, v := range params.Betas { 85 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 86 } 87 if !param.IsOmitted(params.WorkspaceID) { 88 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 89 } 90 opts = slices.Concat(r.Options, opts) 91 opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) 92 path := "v1/skills?beta=true" 93 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) 94 if err != nil { 95 return nil, err 96 } 97 err = cfg.Execute() 98 if err != nil { 99 return nil, err 100 } 101 res.SetPageConfig(cfg, raw) 102 return res, nil 103 } 104 105 // List Skills 106 func (r *BetaSkillService) ListAutoPaging(ctx context.Context, params BetaSkillListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaSkill] { 107 return pagination.NewPageCursorAutoPager(r.List(ctx, params, opts...)) 108 } 109 110 // Delete Skill 111 func (r *BetaSkillService) Delete(ctx context.Context, skillID string, body BetaSkillDeleteParams, opts ...option.RequestOption) (res *BetaDeletedSkill, err error) { 112 for _, v := range body.Betas { 113 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 114 } 115 if !param.IsOmitted(body.WorkspaceID) { 116 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", body.WorkspaceID.Value))) 117 } 118 opts = slices.Concat(r.Options, opts) 119 if skillID == "" { 120 err = errors.New("missing required skill_id parameter") 121 return nil, err 122 } 123 path := fmt.Sprintf("v1/skills/%s?beta=true", skillID) 124 err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) 125 return res, err 126 } 127 128 type BetaDeletedSkill struct { 129 // Unique identifier for the skill. 130 // 131 // The format and length of IDs may change over time. 132 ID string `json:"id" api:"required"` 133 // Deleted object type. 134 // 135 // For Skills, this is always `"skill_deleted"`. 136 Type constant.SkillDeleted `json:"type" default:"skill_deleted"` 137 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 138 JSON struct { 139 ID respjson.Field 140 Type respjson.Field 141 ExtraFields map[string]respjson.Field 142 raw string 143 } `json:"-"` 144 } 145 146 // Returns the unmodified JSON received from the API 147 func (r BetaDeletedSkill) RawJSON() string { return r.JSON.raw } 148 func (r *BetaDeletedSkill) UnmarshalJSON(data []byte) error { 149 return apijson.UnmarshalRoot(data, r) 150 } 151 152 type BetaSkill struct { 153 // Unique identifier for the skill. 154 // 155 // The format and length of IDs may change over time. 156 ID string `json:"id" api:"required"` 157 // ISO 8601 timestamp of when the skill was created. 158 CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` 159 // Human-readable, single-line label for the Skill. Maximum 255 characters. Always 160 // set: derived from the SKILL.md frontmatter `name` when omitted at creation. Not 161 // unique. 162 DisplayName string `json:"display_name" api:"required"` 163 // ID of the newest Skill Version — what `latest` references resolve to. Always 164 // set: a Skill holds at least one version. 165 LatestVersionID string `json:"latest_version_id" api:"required"` 166 // Where the Skill comes from. 167 // 168 // Possible values: 169 // 170 // - `"custom"`: authored by the platform user; private to their workspace 171 // - `"anthropic"`: published by Anthropic; shared and read-only 172 // - `"anthropic_example"`: Anthropic-published sample Skill 173 // - `"plugin"`: resolved from an installed plugin 174 Source BetaSkillSource `json:"source" api:"required"` 175 // Object type. 176 // 177 // For Skills, this is always `"skill"`. 178 Type constant.Skill `json:"type" default:"skill"` 179 // ISO 8601 timestamp of when the skill was last updated. 180 UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"` 181 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 182 JSON struct { 183 ID respjson.Field 184 CreatedAt respjson.Field 185 DisplayName respjson.Field 186 LatestVersionID respjson.Field 187 Source respjson.Field 188 Type respjson.Field 189 UpdatedAt respjson.Field 190 ExtraFields map[string]respjson.Field 191 raw string 192 } `json:"-"` 193 } 194 195 // Returns the unmodified JSON received from the API 196 func (r BetaSkill) RawJSON() string { return r.JSON.raw } 197 func (r *BetaSkill) UnmarshalJSON(data []byte) error { 198 return apijson.UnmarshalRoot(data, r) 199 } 200 201 type BetaSkillSource struct { 202 // Where the Skill comes from. 203 // 204 // Possible values: 205 // 206 // - `"custom"`: authored by the platform user; private to their workspace 207 // - `"anthropic"`: published by Anthropic; shared and read-only 208 // - `"anthropic_example"`: Anthropic-published sample Skill 209 // - `"plugin"`: resolved from an installed plugin 210 // 211 // Any of "custom", "anthropic", "anthropic_example", "plugin". 212 Type BetaSkillSourceType `json:"type" api:"required"` 213 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 214 JSON struct { 215 Type respjson.Field 216 ExtraFields map[string]respjson.Field 217 raw string 218 } `json:"-"` 219 } 220 221 // Returns the unmodified JSON received from the API 222 func (r BetaSkillSource) RawJSON() string { return r.JSON.raw } 223 func (r *BetaSkillSource) UnmarshalJSON(data []byte) error { 224 return apijson.UnmarshalRoot(data, r) 225 } 226 227 // Where the Skill comes from. 228 // 229 // Possible values: 230 // 231 // - `"custom"`: authored by the platform user; private to their workspace 232 // - `"anthropic"`: published by Anthropic; shared and read-only 233 // - `"anthropic_example"`: Anthropic-published sample Skill 234 // - `"plugin"`: resolved from an installed plugin 235 type BetaSkillSourceType string 236 237 const ( 238 BetaSkillSourceTypeCustom BetaSkillSourceType = "custom" 239 BetaSkillSourceTypeAnthropic BetaSkillSourceType = "anthropic" 240 BetaSkillSourceTypeAnthropicExample BetaSkillSourceType = "anthropic_example" 241 BetaSkillSourceTypePlugin BetaSkillSourceType = "plugin" 242 ) 243 244 type BetaSkillNewParams struct { 245 // Files to upload for the skill. 246 // 247 // All files must be in the same top-level directory and must include a SKILL.md 248 // file at the root of that directory. 249 Files []io.Reader `json:"files,omitzero" api:"required" format:"binary"` 250 // Human-readable, single-line label for the Skill. Maximum 255 characters. Always 251 // set: derived from the SKILL.md frontmatter `name` when omitted at creation. Not 252 // unique. 253 DisplayName param.Opt[string] `json:"display_name,omitzero"` 254 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 255 // Optional header to specify the beta version(s) you want to use. 256 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 257 paramObj 258 } 259 260 func (r BetaSkillNewParams) MarshalMultipart() (data []byte, contentType string, err error) { 261 buf := bytes.NewBuffer(nil) 262 writer := multipart.NewWriter(buf) 263 err = apiform.MarshalRoot(r, writer) 264 if err == nil { 265 err = apiform.WriteExtras(writer, r.ExtraFields()) 266 } 267 if err != nil { 268 writer.Close() 269 return nil, "", err 270 } 271 err = writer.Close() 272 if err != nil { 273 return nil, "", err 274 } 275 return buf.Bytes(), writer.FormDataContentType(), nil 276 } 277 278 type BetaSkillGetParams struct { 279 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 280 // Optional header to specify the beta version(s) you want to use. 281 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 282 paramObj 283 } 284 285 type BetaSkillListParams struct { 286 // Pagination token for fetching a specific page of results. 287 // 288 // Pass the value from a previous response's `next_page` field to get the next page 289 // of results. 290 Page param.Opt[string] `query:"page,omitzero" json:"-"` 291 // Filter skills by source. 292 // 293 // If provided, only skills from the specified source will be returned: 294 // 295 // - `"custom"`: only return user-created skills 296 // - `"anthropic"`: only return Anthropic-created skills 297 Source param.Opt[string] `query:"source,omitzero" json:"-"` 298 // Number of results to return per page. 299 // 300 // Ranges from `1` to `1000`. Defaults to `20`. 301 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` 302 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 303 // Optional header to specify the beta version(s) you want to use. 304 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 305 paramObj 306 } 307 308 // URLQuery serializes [BetaSkillListParams]'s query parameters as `url.Values`. 309 func (r BetaSkillListParams) URLQuery() (v url.Values, err error) { 310 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 311 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 312 NestedFormat: apiquery.NestedQueryFormatBrackets, 313 }) 314 } 315 316 type BetaSkillDeleteParams struct { 317 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 318 // Optional header to specify the beta version(s) you want to use. 319 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 320 paramObj 321 }