github.com/anthropics/anthropic-sdk-go@v1.70.1/betaskillversion.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 // BetaSkillVersionService contains methods and other services that help with 29 // interacting 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 [NewBetaSkillVersionService] method instead. 34 type BetaSkillVersionService struct { 35 Options []option.RequestOption 36 } 37 38 // NewBetaSkillVersionService generates a new service that applies the given 39 // options to each request. These options are applied after the parent client's 40 // options (if there is one), and before any request-specific options. 41 func NewBetaSkillVersionService(opts ...option.RequestOption) (r BetaSkillVersionService) { 42 r = BetaSkillVersionService{} 43 r.Options = opts 44 return 45 } 46 47 // Create Skill Version 48 func (r *BetaSkillVersionService) New(ctx context.Context, skillID string, params BetaSkillVersionNewParams, opts ...option.RequestOption) (res *BetaSkillVersion, err error) { 49 for _, v := range params.Betas { 50 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 51 } 52 if !param.IsOmitted(params.WorkspaceID) { 53 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 54 } 55 opts = slices.Concat(r.Options, opts) 56 if skillID == "" { 57 err = errors.New("missing required skill_id parameter") 58 return nil, err 59 } 60 path := fmt.Sprintf("v1/skills/%s/versions?beta=true", skillID) 61 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 62 return res, err 63 } 64 65 // Get Skill Version 66 func (r *BetaSkillVersionService) Get(ctx context.Context, version string, params BetaSkillVersionGetParams, opts ...option.RequestOption) (res *BetaSkillVersion, err error) { 67 for _, v := range params.Betas { 68 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 69 } 70 if !param.IsOmitted(params.WorkspaceID) { 71 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 72 } 73 opts = slices.Concat(r.Options, opts) 74 if params.SkillID == "" { 75 err = errors.New("missing required skill_id parameter") 76 return nil, err 77 } 78 if version == "" { 79 err = errors.New("missing required version parameter") 80 return nil, err 81 } 82 path := fmt.Sprintf("v1/skills/%s/versions/%s?beta=true", params.SkillID, version) 83 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) 84 return res, err 85 } 86 87 // List Skill Versions 88 func (r *BetaSkillVersionService) List(ctx context.Context, skillID string, params BetaSkillVersionListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaSkillVersion], err error) { 89 var raw *http.Response 90 for _, v := range params.Betas { 91 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 92 } 93 if !param.IsOmitted(params.WorkspaceID) { 94 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 95 } 96 opts = slices.Concat(r.Options, opts) 97 opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) 98 if skillID == "" { 99 err = errors.New("missing required skill_id parameter") 100 return nil, err 101 } 102 path := fmt.Sprintf("v1/skills/%s/versions?beta=true", skillID) 103 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) 104 if err != nil { 105 return nil, err 106 } 107 err = cfg.Execute() 108 if err != nil { 109 return nil, err 110 } 111 res.SetPageConfig(cfg, raw) 112 return res, nil 113 } 114 115 // List Skill Versions 116 func (r *BetaSkillVersionService) ListAutoPaging(ctx context.Context, skillID string, params BetaSkillVersionListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaSkillVersion] { 117 return pagination.NewPageCursorAutoPager(r.List(ctx, skillID, params, opts...)) 118 } 119 120 // Delete Skill Version 121 func (r *BetaSkillVersionService) Delete(ctx context.Context, version string, params BetaSkillVersionDeleteParams, opts ...option.RequestOption) (res *BetaDeletedSkillVersion, err error) { 122 for _, v := range params.Betas { 123 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 124 } 125 if !param.IsOmitted(params.WorkspaceID) { 126 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 127 } 128 opts = slices.Concat(r.Options, opts) 129 if params.SkillID == "" { 130 err = errors.New("missing required skill_id parameter") 131 return nil, err 132 } 133 if version == "" { 134 err = errors.New("missing required version parameter") 135 return nil, err 136 } 137 path := fmt.Sprintf("v1/skills/%s/versions/%s?beta=true", params.SkillID, version) 138 err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) 139 return res, err 140 } 141 142 // Download a skill version's content as a zip archive. 143 func (r *BetaSkillVersionService) Download(ctx context.Context, version string, params BetaSkillVersionDownloadParams, opts ...option.RequestOption) (res *http.Response, err error) { 144 for _, v := range params.Betas { 145 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 146 } 147 if !param.IsOmitted(params.WorkspaceID) { 148 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 149 } 150 opts = slices.Concat(r.Options, opts) 151 opts = append([]option.RequestOption{option.WithHeader("Accept", "application/binary")}, opts...) 152 if params.SkillID == "" { 153 err = errors.New("missing required skill_id parameter") 154 return nil, err 155 } 156 if version == "" { 157 err = errors.New("missing required version parameter") 158 return nil, err 159 } 160 path := fmt.Sprintf("v1/skills/%s/versions/%s/content?beta=true", params.SkillID, version) 161 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) 162 return res, err 163 } 164 165 type BetaDeletedSkillVersion struct { 166 // Unique identifier for this Skill Version. The id addresses the version in paths 167 // and pins it in references. 168 ID string `json:"id" api:"required"` 169 // Deleted object type. 170 // 171 // For Skill Versions, this is always `"skill_version_deleted"`. 172 Type constant.SkillVersionDeleted `json:"type" default:"skill_version_deleted"` 173 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 174 JSON struct { 175 ID respjson.Field 176 Type respjson.Field 177 ExtraFields map[string]respjson.Field 178 raw string 179 } `json:"-"` 180 } 181 182 // Returns the unmodified JSON received from the API 183 func (r BetaDeletedSkillVersion) RawJSON() string { return r.JSON.raw } 184 func (r *BetaDeletedSkillVersion) UnmarshalJSON(data []byte) error { 185 return apijson.UnmarshalRoot(data, r) 186 } 187 188 type BetaSkillVersion struct { 189 // Unique identifier for this Skill Version. The id addresses the version in paths 190 // and pins it in references. 191 ID string `json:"id" api:"required"` 192 // ISO 8601 timestamp of when the skill was created. 193 CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` 194 // Description of the skill version. 195 // 196 // This is extracted from the SKILL.md file in the skill upload. 197 Description string `json:"description" api:"required"` 198 // The Skill's immutable kebab-case slug, set at creation from the first upload's 199 // SKILL.md frontmatter `name` (or its enclosing directory). Every later upload 200 // must resolve to the same value. Also the top-level directory of the Skill's 201 // mounted files and the base name of a downloaded archive. 202 Name string `json:"name" api:"required"` 203 // Unique identifier for the skill. 204 // 205 // The format and length of IDs may change over time. 206 SkillID string `json:"skill_id" api:"required"` 207 // Object type. 208 // 209 // For Skill Versions, this is always `"skill_version"`. 210 Type constant.SkillVersion `json:"type" default:"skill_version"` 211 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 212 JSON struct { 213 ID respjson.Field 214 CreatedAt respjson.Field 215 Description respjson.Field 216 Name respjson.Field 217 SkillID respjson.Field 218 Type respjson.Field 219 ExtraFields map[string]respjson.Field 220 raw string 221 } `json:"-"` 222 } 223 224 // Returns the unmodified JSON received from the API 225 func (r BetaSkillVersion) RawJSON() string { return r.JSON.raw } 226 func (r *BetaSkillVersion) UnmarshalJSON(data []byte) error { 227 return apijson.UnmarshalRoot(data, r) 228 } 229 230 type BetaSkillVersionNewParams struct { 231 // Files to upload for the skill. 232 // 233 // All files must be in the same top-level directory and must include a SKILL.md 234 // file at the root of that directory. 235 Files []io.Reader `json:"files,omitzero" api:"required" format:"binary"` 236 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 237 // Optional header to specify the beta version(s) you want to use. 238 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 239 paramObj 240 } 241 242 func (r BetaSkillVersionNewParams) MarshalMultipart() (data []byte, contentType string, err error) { 243 buf := bytes.NewBuffer(nil) 244 writer := multipart.NewWriter(buf) 245 err = apiform.MarshalRoot(r, writer) 246 if err == nil { 247 err = apiform.WriteExtras(writer, r.ExtraFields()) 248 } 249 if err != nil { 250 writer.Close() 251 return nil, "", err 252 } 253 err = writer.Close() 254 if err != nil { 255 return nil, "", err 256 } 257 return buf.Bytes(), writer.FormDataContentType(), nil 258 } 259 260 type BetaSkillVersionGetParams struct { 261 // Unique identifier for the skill. 262 // 263 // The format and length of IDs may change over time. 264 SkillID string `path:"skill_id" api:"required" json:"-"` 265 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 266 // Optional header to specify the beta version(s) you want to use. 267 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 268 paramObj 269 } 270 271 type BetaSkillVersionListParams struct { 272 // Number of results to return per page. 273 // 274 // Ranges from `1` to `1000`. Defaults to `20`. 275 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` 276 // Optionally set to the `next_page` token from the previous response. 277 Page param.Opt[string] `query:"page,omitzero" json:"-"` 278 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 279 // Optional header to specify the beta version(s) you want to use. 280 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 281 paramObj 282 } 283 284 // URLQuery serializes [BetaSkillVersionListParams]'s query parameters as 285 // `url.Values`. 286 func (r BetaSkillVersionListParams) URLQuery() (v url.Values, err error) { 287 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 288 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 289 NestedFormat: apiquery.NestedQueryFormatBrackets, 290 }) 291 } 292 293 type BetaSkillVersionDeleteParams struct { 294 // Unique identifier for the skill. 295 // 296 // The format and length of IDs may change over time. 297 SkillID string `path:"skill_id" api:"required" json:"-"` 298 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 299 // Optional header to specify the beta version(s) you want to use. 300 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 301 paramObj 302 } 303 304 type BetaSkillVersionDownloadParams struct { 305 // Unique identifier for the skill. 306 // 307 // The format and length of IDs may change over time. 308 SkillID string `path:"skill_id" api:"required" json:"-"` 309 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 310 // Optional header to specify the beta version(s) you want to use. 311 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 312 paramObj 313 }