github.com/anthropics/anthropic-sdk-go@v1.70.1/betasessionresource.go (about) 1 // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 2 3 package anthropic 4 5 import ( 6 "context" 7 "encoding/json" 8 "errors" 9 "fmt" 10 "net/http" 11 "net/url" 12 "slices" 13 "time" 14 15 "github.com/anthropics/anthropic-sdk-go/internal/apijson" 16 "github.com/anthropics/anthropic-sdk-go/internal/apiquery" 17 shimjson "github.com/anthropics/anthropic-sdk-go/internal/encoding/json" 18 "github.com/anthropics/anthropic-sdk-go/internal/requestconfig" 19 "github.com/anthropics/anthropic-sdk-go/option" 20 "github.com/anthropics/anthropic-sdk-go/packages/pagination" 21 "github.com/anthropics/anthropic-sdk-go/packages/param" 22 "github.com/anthropics/anthropic-sdk-go/packages/respjson" 23 ) 24 25 // BetaSessionResourceService contains methods and other services that help with 26 // interacting with the anthropic API. 27 // 28 // Note, unlike clients, this service does not read variables from the environment 29 // automatically. You should not instantiate this service directly, and instead use 30 // the [NewBetaSessionResourceService] method instead. 31 type BetaSessionResourceService struct { 32 Options []option.RequestOption 33 } 34 35 // NewBetaSessionResourceService generates a new service that applies the given 36 // options to each request. These options are applied after the parent client's 37 // options (if there is one), and before any request-specific options. 38 func NewBetaSessionResourceService(opts ...option.RequestOption) (r BetaSessionResourceService) { 39 r = BetaSessionResourceService{} 40 r.Options = opts 41 return 42 } 43 44 // Get Session Resource 45 func (r *BetaSessionResourceService) Get(ctx context.Context, resourceID string, params BetaSessionResourceGetParams, opts ...option.RequestOption) (res *BetaSessionResourceGetResponseUnion, err error) { 46 for _, v := range params.Betas { 47 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 48 } 49 if !param.IsOmitted(params.WorkspaceID) { 50 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 51 } 52 opts = slices.Concat(r.Options, opts) 53 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 54 if params.SessionID == "" { 55 err = errors.New("missing required session_id parameter") 56 return nil, err 57 } 58 if resourceID == "" { 59 err = errors.New("missing required resource_id parameter") 60 return nil, err 61 } 62 path := fmt.Sprintf("v1/sessions/%s/resources/%s?beta=true", params.SessionID, resourceID) 63 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) 64 return res, err 65 } 66 67 // Update Session Resource 68 func (r *BetaSessionResourceService) Update(ctx context.Context, resourceID string, params BetaSessionResourceUpdateParams, opts ...option.RequestOption) (res *BetaSessionResourceUpdateResponseUnion, err error) { 69 for _, v := range params.Betas { 70 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 71 } 72 if !param.IsOmitted(params.WorkspaceID) { 73 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 74 } 75 opts = slices.Concat(r.Options, opts) 76 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 77 if params.SessionID == "" { 78 err = errors.New("missing required session_id parameter") 79 return nil, err 80 } 81 if resourceID == "" { 82 err = errors.New("missing required resource_id parameter") 83 return nil, err 84 } 85 path := fmt.Sprintf("v1/sessions/%s/resources/%s?beta=true", params.SessionID, resourceID) 86 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 87 return res, err 88 } 89 90 // List Session Resources 91 func (r *BetaSessionResourceService) List(ctx context.Context, sessionID string, params BetaSessionResourceListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaManagedAgentsSessionResourceUnion], err error) { 92 var raw *http.Response 93 for _, v := range params.Betas { 94 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 95 } 96 if !param.IsOmitted(params.WorkspaceID) { 97 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 98 } 99 opts = slices.Concat(r.Options, opts) 100 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01"), option.WithResponseInto(&raw)}, opts...) 101 if sessionID == "" { 102 err = errors.New("missing required session_id parameter") 103 return nil, err 104 } 105 path := fmt.Sprintf("v1/sessions/%s/resources?beta=true", sessionID) 106 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) 107 if err != nil { 108 return nil, err 109 } 110 err = cfg.Execute() 111 if err != nil { 112 return nil, err 113 } 114 res.SetPageConfig(cfg, raw) 115 return res, nil 116 } 117 118 // List Session Resources 119 func (r *BetaSessionResourceService) ListAutoPaging(ctx context.Context, sessionID string, params BetaSessionResourceListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaManagedAgentsSessionResourceUnion] { 120 return pagination.NewPageCursorAutoPager(r.List(ctx, sessionID, params, opts...)) 121 } 122 123 // Delete Session Resource 124 func (r *BetaSessionResourceService) Delete(ctx context.Context, resourceID string, params BetaSessionResourceDeleteParams, opts ...option.RequestOption) (res *BetaManagedAgentsDeleteSessionResource, err error) { 125 for _, v := range params.Betas { 126 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 127 } 128 if !param.IsOmitted(params.WorkspaceID) { 129 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 130 } 131 opts = slices.Concat(r.Options, opts) 132 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 133 if params.SessionID == "" { 134 err = errors.New("missing required session_id parameter") 135 return nil, err 136 } 137 if resourceID == "" { 138 err = errors.New("missing required resource_id parameter") 139 return nil, err 140 } 141 path := fmt.Sprintf("v1/sessions/%s/resources/%s?beta=true", params.SessionID, resourceID) 142 err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) 143 return res, err 144 } 145 146 // Add Session Resource 147 func (r *BetaSessionResourceService) Add(ctx context.Context, sessionID string, params BetaSessionResourceAddParams, opts ...option.RequestOption) (res *BetaManagedAgentsFileResource, err error) { 148 for _, v := range params.Betas { 149 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 150 } 151 if !param.IsOmitted(params.WorkspaceID) { 152 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 153 } 154 opts = slices.Concat(r.Options, opts) 155 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 156 if sessionID == "" { 157 err = errors.New("missing required session_id parameter") 158 return nil, err 159 } 160 path := fmt.Sprintf("v1/sessions/%s/resources?beta=true", sessionID) 161 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 162 return res, err 163 } 164 165 // Confirmation of resource deletion. 166 type BetaManagedAgentsDeleteSessionResource struct { 167 ID string `json:"id" api:"required"` 168 // Any of "session_resource_deleted". 169 Type BetaManagedAgentsDeleteSessionResourceType `json:"type" api:"required"` 170 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 171 JSON struct { 172 ID respjson.Field 173 Type respjson.Field 174 ExtraFields map[string]respjson.Field 175 raw string 176 } `json:"-"` 177 } 178 179 // Returns the unmodified JSON received from the API 180 func (r BetaManagedAgentsDeleteSessionResource) RawJSON() string { return r.JSON.raw } 181 func (r *BetaManagedAgentsDeleteSessionResource) UnmarshalJSON(data []byte) error { 182 return apijson.UnmarshalRoot(data, r) 183 } 184 185 type BetaManagedAgentsDeleteSessionResourceType string 186 187 const ( 188 BetaManagedAgentsDeleteSessionResourceTypeSessionResourceDeleted BetaManagedAgentsDeleteSessionResourceType = "session_resource_deleted" 189 ) 190 191 type BetaManagedAgentsFileResource struct { 192 ID string `json:"id" api:"required"` 193 // A timestamp in RFC 3339 format 194 CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` 195 FileID string `json:"file_id" api:"required"` 196 MountPath string `json:"mount_path" api:"required"` 197 // Any of "file". 198 Type BetaManagedAgentsFileResourceType `json:"type" api:"required"` 199 // A timestamp in RFC 3339 format 200 UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"` 201 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 202 JSON struct { 203 ID respjson.Field 204 CreatedAt respjson.Field 205 FileID respjson.Field 206 MountPath respjson.Field 207 Type respjson.Field 208 UpdatedAt respjson.Field 209 ExtraFields map[string]respjson.Field 210 raw string 211 } `json:"-"` 212 } 213 214 // Returns the unmodified JSON received from the API 215 func (r BetaManagedAgentsFileResource) RawJSON() string { return r.JSON.raw } 216 func (r *BetaManagedAgentsFileResource) UnmarshalJSON(data []byte) error { 217 return apijson.UnmarshalRoot(data, r) 218 } 219 220 type BetaManagedAgentsFileResourceType string 221 222 const ( 223 BetaManagedAgentsFileResourceTypeFile BetaManagedAgentsFileResourceType = "file" 224 ) 225 226 type BetaManagedAgentsGitHubRepositoryResource struct { 227 ID string `json:"id" api:"required"` 228 // A timestamp in RFC 3339 format 229 CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` 230 MountPath string `json:"mount_path" api:"required"` 231 // Any of "github_repository". 232 Type BetaManagedAgentsGitHubRepositoryResourceType `json:"type" api:"required"` 233 // A timestamp in RFC 3339 format 234 UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"` 235 URL string `json:"url" api:"required"` 236 Checkout BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion `json:"checkout" api:"nullable"` 237 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 238 JSON struct { 239 ID respjson.Field 240 CreatedAt respjson.Field 241 MountPath respjson.Field 242 Type respjson.Field 243 UpdatedAt respjson.Field 244 URL respjson.Field 245 Checkout respjson.Field 246 ExtraFields map[string]respjson.Field 247 raw string 248 } `json:"-"` 249 } 250 251 // Returns the unmodified JSON received from the API 252 func (r BetaManagedAgentsGitHubRepositoryResource) RawJSON() string { return r.JSON.raw } 253 func (r *BetaManagedAgentsGitHubRepositoryResource) UnmarshalJSON(data []byte) error { 254 return apijson.UnmarshalRoot(data, r) 255 } 256 257 type BetaManagedAgentsGitHubRepositoryResourceType string 258 259 const ( 260 BetaManagedAgentsGitHubRepositoryResourceTypeGitHubRepository BetaManagedAgentsGitHubRepositoryResourceType = "github_repository" 261 ) 262 263 // BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion contains all possible 264 // properties and values from [BetaManagedAgentsBranchCheckout], 265 // [BetaManagedAgentsCommitCheckout]. 266 // 267 // Use the [BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion.AsAny] method to 268 // switch on the variant. 269 // 270 // Use the methods beginning with 'As' to cast the union to one of its variants. 271 type BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion struct { 272 // This field is from variant [BetaManagedAgentsBranchCheckout]. 273 Name string `json:"name"` 274 // Any of "branch", "commit". 275 Type string `json:"type"` 276 // This field is from variant [BetaManagedAgentsCommitCheckout]. 277 Sha string `json:"sha"` 278 JSON struct { 279 Name respjson.Field 280 Type respjson.Field 281 Sha respjson.Field 282 raw string 283 } `json:"-"` 284 } 285 286 // anyBetaManagedAgentsGitHubRepositoryResourceCheckout is implemented by each 287 // variant of [BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion] to add type 288 // safety for the return type of 289 // [BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion.AsAny] 290 type anyBetaManagedAgentsGitHubRepositoryResourceCheckout interface { 291 implBetaManagedAgentsGitHubRepositoryResourceCheckoutUnion() 292 } 293 294 func (BetaManagedAgentsBranchCheckout) implBetaManagedAgentsGitHubRepositoryResourceCheckoutUnion() {} 295 func (BetaManagedAgentsCommitCheckout) implBetaManagedAgentsGitHubRepositoryResourceCheckoutUnion() {} 296 297 // Use the following switch statement to find the correct variant 298 // 299 // switch variant := BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion.AsAny().(type) { 300 // case anthropic.BetaManagedAgentsBranchCheckout: 301 // case anthropic.BetaManagedAgentsCommitCheckout: 302 // default: 303 // fmt.Errorf("no variant present") 304 // } 305 func (u BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion) AsAny() anyBetaManagedAgentsGitHubRepositoryResourceCheckout { 306 switch u.Type { 307 case "branch": 308 return u.AsBranch() 309 case "commit": 310 return u.AsCommit() 311 } 312 return nil 313 } 314 315 func (u BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion) AsBranch() (v BetaManagedAgentsBranchCheckout) { 316 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 317 return 318 } 319 320 func (u BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion) AsCommit() (v BetaManagedAgentsCommitCheckout) { 321 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 322 return 323 } 324 325 // Returns the unmodified JSON received from the API 326 func (u BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion) RawJSON() string { return u.JSON.raw } 327 328 func (r *BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion) UnmarshalJSON(data []byte) error { 329 return apijson.UnmarshalRoot(data, r) 330 } 331 332 // A memory store attached to an agent session. 333 type BetaManagedAgentsMemoryStoreResource struct { 334 // The memory store ID (memstore\_...). Must belong to the caller's organization 335 // and workspace. 336 MemoryStoreID string `json:"memory_store_id" api:"required"` 337 // Any of "memory_store". 338 Type BetaManagedAgentsMemoryStoreResourceType `json:"type" api:"required"` 339 // Access mode for an attached memory store. 340 // 341 // Any of "read_write", "read_only". 342 Access BetaManagedAgentsMemoryStoreResourceAccess `json:"access" api:"nullable"` 343 // Description of the memory store, snapshotted at attach time. Rendered into the 344 // agent's system prompt. Empty string when the store has no description. 345 Description string `json:"description"` 346 // Per-attachment guidance for the agent on how to use this store. Rendered into 347 // the memory section of the system prompt. Max 4096 chars. 348 Instructions string `json:"instructions" api:"nullable"` 349 // Filesystem path where the store is mounted in the session container, e.g. 350 // /mnt/memory/user-preferences. Derived from the store's name. Output-only. 351 MountPath string `json:"mount_path" api:"nullable"` 352 // Display name of the memory store, snapshotted at attach time. Later edits to the 353 // store's name do not propagate to this resource. 354 Name string `json:"name" api:"nullable"` 355 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 356 JSON struct { 357 MemoryStoreID respjson.Field 358 Type respjson.Field 359 Access respjson.Field 360 Description respjson.Field 361 Instructions respjson.Field 362 MountPath respjson.Field 363 Name respjson.Field 364 ExtraFields map[string]respjson.Field 365 raw string 366 } `json:"-"` 367 } 368 369 // Returns the unmodified JSON received from the API 370 func (r BetaManagedAgentsMemoryStoreResource) RawJSON() string { return r.JSON.raw } 371 func (r *BetaManagedAgentsMemoryStoreResource) UnmarshalJSON(data []byte) error { 372 return apijson.UnmarshalRoot(data, r) 373 } 374 375 type BetaManagedAgentsMemoryStoreResourceType string 376 377 const ( 378 BetaManagedAgentsMemoryStoreResourceTypeMemoryStore BetaManagedAgentsMemoryStoreResourceType = "memory_store" 379 ) 380 381 // Access mode for an attached memory store. 382 type BetaManagedAgentsMemoryStoreResourceAccess string 383 384 const ( 385 BetaManagedAgentsMemoryStoreResourceAccessReadWrite BetaManagedAgentsMemoryStoreResourceAccess = "read_write" 386 BetaManagedAgentsMemoryStoreResourceAccessReadOnly BetaManagedAgentsMemoryStoreResourceAccess = "read_only" 387 ) 388 389 // BetaManagedAgentsSessionResourceUnion contains all possible properties and 390 // values from [BetaManagedAgentsGitHubRepositoryResource], 391 // [BetaManagedAgentsFileResource], [BetaManagedAgentsMemoryStoreResource]. 392 // 393 // Use the [BetaManagedAgentsSessionResourceUnion.AsAny] method to switch on the 394 // variant. 395 // 396 // Use the methods beginning with 'As' to cast the union to one of its variants. 397 type BetaManagedAgentsSessionResourceUnion struct { 398 ID string `json:"id"` 399 CreatedAt time.Time `json:"created_at"` 400 MountPath string `json:"mount_path"` 401 // Any of "github_repository", "file", "memory_store". 402 Type string `json:"type"` 403 UpdatedAt time.Time `json:"updated_at"` 404 // This field is from variant [BetaManagedAgentsGitHubRepositoryResource]. 405 URL string `json:"url"` 406 // This field is from variant [BetaManagedAgentsGitHubRepositoryResource]. 407 Checkout BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion `json:"checkout"` 408 // This field is from variant [BetaManagedAgentsFileResource]. 409 FileID string `json:"file_id"` 410 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 411 MemoryStoreID string `json:"memory_store_id"` 412 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 413 Access BetaManagedAgentsMemoryStoreResourceAccess `json:"access"` 414 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 415 Description string `json:"description"` 416 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 417 Instructions string `json:"instructions"` 418 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 419 Name string `json:"name"` 420 JSON struct { 421 ID respjson.Field 422 CreatedAt respjson.Field 423 MountPath respjson.Field 424 Type respjson.Field 425 UpdatedAt respjson.Field 426 URL respjson.Field 427 Checkout respjson.Field 428 FileID respjson.Field 429 MemoryStoreID respjson.Field 430 Access respjson.Field 431 Description respjson.Field 432 Instructions respjson.Field 433 Name respjson.Field 434 raw string 435 } `json:"-"` 436 } 437 438 // anyBetaManagedAgentsSessionResource is implemented by each variant of 439 // [BetaManagedAgentsSessionResourceUnion] to add type safety for the return type 440 // of [BetaManagedAgentsSessionResourceUnion.AsAny] 441 type anyBetaManagedAgentsSessionResource interface { 442 implBetaManagedAgentsSessionResourceUnion() 443 } 444 445 func (BetaManagedAgentsGitHubRepositoryResource) implBetaManagedAgentsSessionResourceUnion() {} 446 func (BetaManagedAgentsFileResource) implBetaManagedAgentsSessionResourceUnion() {} 447 func (BetaManagedAgentsMemoryStoreResource) implBetaManagedAgentsSessionResourceUnion() {} 448 449 // Use the following switch statement to find the correct variant 450 // 451 // switch variant := BetaManagedAgentsSessionResourceUnion.AsAny().(type) { 452 // case anthropic.BetaManagedAgentsGitHubRepositoryResource: 453 // case anthropic.BetaManagedAgentsFileResource: 454 // case anthropic.BetaManagedAgentsMemoryStoreResource: 455 // default: 456 // fmt.Errorf("no variant present") 457 // } 458 func (u BetaManagedAgentsSessionResourceUnion) AsAny() anyBetaManagedAgentsSessionResource { 459 switch u.Type { 460 case "github_repository": 461 return u.AsGitHubRepository() 462 case "file": 463 return u.AsFile() 464 case "memory_store": 465 return u.AsMemoryStore() 466 } 467 return nil 468 } 469 470 func (u BetaManagedAgentsSessionResourceUnion) AsGitHubRepository() (v BetaManagedAgentsGitHubRepositoryResource) { 471 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 472 return 473 } 474 475 func (u BetaManagedAgentsSessionResourceUnion) AsFile() (v BetaManagedAgentsFileResource) { 476 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 477 return 478 } 479 480 func (u BetaManagedAgentsSessionResourceUnion) AsMemoryStore() (v BetaManagedAgentsMemoryStoreResource) { 481 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 482 return 483 } 484 485 // Returns the unmodified JSON received from the API 486 func (u BetaManagedAgentsSessionResourceUnion) RawJSON() string { return u.JSON.raw } 487 488 func (r *BetaManagedAgentsSessionResourceUnion) UnmarshalJSON(data []byte) error { 489 return apijson.UnmarshalRoot(data, r) 490 } 491 492 // BetaSessionResourceGetResponseUnion contains all possible properties and values 493 // from [BetaManagedAgentsGitHubRepositoryResource], 494 // [BetaManagedAgentsFileResource], [BetaManagedAgentsMemoryStoreResource]. 495 // 496 // Use the [BetaSessionResourceGetResponseUnion.AsAny] method to switch on the 497 // variant. 498 // 499 // Use the methods beginning with 'As' to cast the union to one of its variants. 500 type BetaSessionResourceGetResponseUnion struct { 501 ID string `json:"id"` 502 CreatedAt time.Time `json:"created_at"` 503 MountPath string `json:"mount_path"` 504 // Any of "github_repository", "file", "memory_store". 505 Type string `json:"type"` 506 UpdatedAt time.Time `json:"updated_at"` 507 // This field is from variant [BetaManagedAgentsGitHubRepositoryResource]. 508 URL string `json:"url"` 509 // This field is from variant [BetaManagedAgentsGitHubRepositoryResource]. 510 Checkout BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion `json:"checkout"` 511 // This field is from variant [BetaManagedAgentsFileResource]. 512 FileID string `json:"file_id"` 513 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 514 MemoryStoreID string `json:"memory_store_id"` 515 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 516 Access BetaManagedAgentsMemoryStoreResourceAccess `json:"access"` 517 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 518 Description string `json:"description"` 519 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 520 Instructions string `json:"instructions"` 521 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 522 Name string `json:"name"` 523 JSON struct { 524 ID respjson.Field 525 CreatedAt respjson.Field 526 MountPath respjson.Field 527 Type respjson.Field 528 UpdatedAt respjson.Field 529 URL respjson.Field 530 Checkout respjson.Field 531 FileID respjson.Field 532 MemoryStoreID respjson.Field 533 Access respjson.Field 534 Description respjson.Field 535 Instructions respjson.Field 536 Name respjson.Field 537 raw string 538 } `json:"-"` 539 } 540 541 // anyBetaSessionResourceGetResponse is implemented by each variant of 542 // [BetaSessionResourceGetResponseUnion] to add type safety for the return type of 543 // [BetaSessionResourceGetResponseUnion.AsAny] 544 type anyBetaSessionResourceGetResponse interface { 545 implBetaSessionResourceGetResponseUnion() 546 } 547 548 func (BetaManagedAgentsGitHubRepositoryResource) implBetaSessionResourceGetResponseUnion() {} 549 func (BetaManagedAgentsFileResource) implBetaSessionResourceGetResponseUnion() {} 550 func (BetaManagedAgentsMemoryStoreResource) implBetaSessionResourceGetResponseUnion() {} 551 552 // Use the following switch statement to find the correct variant 553 // 554 // switch variant := BetaSessionResourceGetResponseUnion.AsAny().(type) { 555 // case anthropic.BetaManagedAgentsGitHubRepositoryResource: 556 // case anthropic.BetaManagedAgentsFileResource: 557 // case anthropic.BetaManagedAgentsMemoryStoreResource: 558 // default: 559 // fmt.Errorf("no variant present") 560 // } 561 func (u BetaSessionResourceGetResponseUnion) AsAny() anyBetaSessionResourceGetResponse { 562 switch u.Type { 563 case "github_repository": 564 return u.AsGitHubRepository() 565 case "file": 566 return u.AsFile() 567 case "memory_store": 568 return u.AsMemoryStore() 569 } 570 return nil 571 } 572 573 func (u BetaSessionResourceGetResponseUnion) AsGitHubRepository() (v BetaManagedAgentsGitHubRepositoryResource) { 574 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 575 return 576 } 577 578 func (u BetaSessionResourceGetResponseUnion) AsFile() (v BetaManagedAgentsFileResource) { 579 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 580 return 581 } 582 583 func (u BetaSessionResourceGetResponseUnion) AsMemoryStore() (v BetaManagedAgentsMemoryStoreResource) { 584 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 585 return 586 } 587 588 // Returns the unmodified JSON received from the API 589 func (u BetaSessionResourceGetResponseUnion) RawJSON() string { return u.JSON.raw } 590 591 func (r *BetaSessionResourceGetResponseUnion) UnmarshalJSON(data []byte) error { 592 return apijson.UnmarshalRoot(data, r) 593 } 594 595 // BetaSessionResourceUpdateResponseUnion contains all possible properties and 596 // values from [BetaManagedAgentsGitHubRepositoryResource], 597 // [BetaManagedAgentsFileResource], [BetaManagedAgentsMemoryStoreResource]. 598 // 599 // Use the [BetaSessionResourceUpdateResponseUnion.AsAny] method to switch on the 600 // variant. 601 // 602 // Use the methods beginning with 'As' to cast the union to one of its variants. 603 type BetaSessionResourceUpdateResponseUnion struct { 604 ID string `json:"id"` 605 CreatedAt time.Time `json:"created_at"` 606 MountPath string `json:"mount_path"` 607 // Any of "github_repository", "file", "memory_store". 608 Type string `json:"type"` 609 UpdatedAt time.Time `json:"updated_at"` 610 // This field is from variant [BetaManagedAgentsGitHubRepositoryResource]. 611 URL string `json:"url"` 612 // This field is from variant [BetaManagedAgentsGitHubRepositoryResource]. 613 Checkout BetaManagedAgentsGitHubRepositoryResourceCheckoutUnion `json:"checkout"` 614 // This field is from variant [BetaManagedAgentsFileResource]. 615 FileID string `json:"file_id"` 616 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 617 MemoryStoreID string `json:"memory_store_id"` 618 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 619 Access BetaManagedAgentsMemoryStoreResourceAccess `json:"access"` 620 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 621 Description string `json:"description"` 622 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 623 Instructions string `json:"instructions"` 624 // This field is from variant [BetaManagedAgentsMemoryStoreResource]. 625 Name string `json:"name"` 626 JSON struct { 627 ID respjson.Field 628 CreatedAt respjson.Field 629 MountPath respjson.Field 630 Type respjson.Field 631 UpdatedAt respjson.Field 632 URL respjson.Field 633 Checkout respjson.Field 634 FileID respjson.Field 635 MemoryStoreID respjson.Field 636 Access respjson.Field 637 Description respjson.Field 638 Instructions respjson.Field 639 Name respjson.Field 640 raw string 641 } `json:"-"` 642 } 643 644 // anyBetaSessionResourceUpdateResponse is implemented by each variant of 645 // [BetaSessionResourceUpdateResponseUnion] to add type safety for the return type 646 // of [BetaSessionResourceUpdateResponseUnion.AsAny] 647 type anyBetaSessionResourceUpdateResponse interface { 648 implBetaSessionResourceUpdateResponseUnion() 649 } 650 651 func (BetaManagedAgentsGitHubRepositoryResource) implBetaSessionResourceUpdateResponseUnion() {} 652 func (BetaManagedAgentsFileResource) implBetaSessionResourceUpdateResponseUnion() {} 653 func (BetaManagedAgentsMemoryStoreResource) implBetaSessionResourceUpdateResponseUnion() {} 654 655 // Use the following switch statement to find the correct variant 656 // 657 // switch variant := BetaSessionResourceUpdateResponseUnion.AsAny().(type) { 658 // case anthropic.BetaManagedAgentsGitHubRepositoryResource: 659 // case anthropic.BetaManagedAgentsFileResource: 660 // case anthropic.BetaManagedAgentsMemoryStoreResource: 661 // default: 662 // fmt.Errorf("no variant present") 663 // } 664 func (u BetaSessionResourceUpdateResponseUnion) AsAny() anyBetaSessionResourceUpdateResponse { 665 switch u.Type { 666 case "github_repository": 667 return u.AsGitHubRepository() 668 case "file": 669 return u.AsFile() 670 case "memory_store": 671 return u.AsMemoryStore() 672 } 673 return nil 674 } 675 676 func (u BetaSessionResourceUpdateResponseUnion) AsGitHubRepository() (v BetaManagedAgentsGitHubRepositoryResource) { 677 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 678 return 679 } 680 681 func (u BetaSessionResourceUpdateResponseUnion) AsFile() (v BetaManagedAgentsFileResource) { 682 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 683 return 684 } 685 686 func (u BetaSessionResourceUpdateResponseUnion) AsMemoryStore() (v BetaManagedAgentsMemoryStoreResource) { 687 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 688 return 689 } 690 691 // Returns the unmodified JSON received from the API 692 func (u BetaSessionResourceUpdateResponseUnion) RawJSON() string { return u.JSON.raw } 693 694 func (r *BetaSessionResourceUpdateResponseUnion) UnmarshalJSON(data []byte) error { 695 return apijson.UnmarshalRoot(data, r) 696 } 697 698 type BetaSessionResourceGetParams struct { 699 SessionID string `path:"session_id" api:"required" json:"-"` 700 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 701 // Optional header to specify the beta version(s) you want to use. 702 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 703 paramObj 704 } 705 706 type BetaSessionResourceUpdateParams struct { 707 SessionID string `path:"session_id" api:"required" json:"-"` 708 // New authorization token for the resource. Currently only `github_repository` 709 // resources support token rotation. 710 AuthorizationToken string `json:"authorization_token" api:"required"` 711 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 712 // Optional header to specify the beta version(s) you want to use. 713 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 714 paramObj 715 } 716 717 func (r BetaSessionResourceUpdateParams) MarshalJSON() (data []byte, err error) { 718 type shadow BetaSessionResourceUpdateParams 719 return param.MarshalObject(r, (*shadow)(&r)) 720 } 721 func (r *BetaSessionResourceUpdateParams) UnmarshalJSON(data []byte) error { 722 return apijson.UnmarshalRoot(data, r) 723 } 724 725 type BetaSessionResourceListParams struct { 726 // Maximum number of resources to return per page (max 1000). If omitted, returns 727 // all resources. 728 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` 729 // Opaque cursor from a previous response's `next_page` field. 730 Page param.Opt[string] `query:"page,omitzero" json:"-"` 731 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 732 // Optional header to specify the beta version(s) you want to use. 733 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 734 paramObj 735 } 736 737 // URLQuery serializes [BetaSessionResourceListParams]'s query parameters as 738 // `url.Values`. 739 func (r BetaSessionResourceListParams) URLQuery() (v url.Values, err error) { 740 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 741 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 742 NestedFormat: apiquery.NestedQueryFormatBrackets, 743 }) 744 } 745 746 type BetaSessionResourceDeleteParams struct { 747 SessionID string `path:"session_id" api:"required" json:"-"` 748 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 749 // Optional header to specify the beta version(s) you want to use. 750 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 751 paramObj 752 } 753 754 type BetaSessionResourceAddParams struct { 755 // Mount a file uploaded via the Files API into the session. 756 BetaManagedAgentsFileResourceParams BetaManagedAgentsFileResourceParams 757 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 758 // Optional header to specify the beta version(s) you want to use. 759 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 760 paramObj 761 } 762 763 func (r BetaSessionResourceAddParams) MarshalJSON() (data []byte, err error) { 764 return shimjson.Marshal(r.BetaManagedAgentsFileResourceParams) 765 } 766 func (r *BetaSessionResourceAddParams) UnmarshalJSON(data []byte) error { 767 return apijson.UnmarshalRoot(data, r) 768 }