github.com/anthropics/anthropic-sdk-go@v1.70.1/betaenvironmentwork.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 "errors" 8 "fmt" 9 "net/http" 10 "net/url" 11 "slices" 12 13 "github.com/anthropics/anthropic-sdk-go/internal/apijson" 14 "github.com/anthropics/anthropic-sdk-go/internal/apiquery" 15 shimjson "github.com/anthropics/anthropic-sdk-go/internal/encoding/json" 16 "github.com/anthropics/anthropic-sdk-go/internal/requestconfig" 17 "github.com/anthropics/anthropic-sdk-go/option" 18 "github.com/anthropics/anthropic-sdk-go/packages/pagination" 19 "github.com/anthropics/anthropic-sdk-go/packages/param" 20 "github.com/anthropics/anthropic-sdk-go/packages/respjson" 21 "github.com/anthropics/anthropic-sdk-go/shared/constant" 22 ) 23 24 // BetaEnvironmentWorkService contains methods and other services that help with 25 // interacting with the anthropic API. 26 // 27 // Note, unlike clients, this service does not read variables from the environment 28 // automatically. You should not instantiate this service directly, and instead use 29 // the [NewBetaEnvironmentWorkService] method instead. 30 type BetaEnvironmentWorkService struct { 31 Options []option.RequestOption 32 } 33 34 // NewBetaEnvironmentWorkService generates a new service that applies the given 35 // options to each request. These options are applied after the parent client's 36 // options (if there is one), and before any request-specific options. 37 func NewBetaEnvironmentWorkService(opts ...option.RequestOption) (r BetaEnvironmentWorkService) { 38 r = BetaEnvironmentWorkService{} 39 r.Options = opts 40 return 41 } 42 43 // Note: these endpoints are called automatically by the pre-built environment 44 // worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted 45 // sandbox environments. They are included here as a reference; you do not need to 46 // invoke them directly. 47 // 48 // Retrieve detailed information about a specific work item. 49 func (r *BetaEnvironmentWorkService) Get(ctx context.Context, workID string, params BetaEnvironmentWorkGetParams, opts ...option.RequestOption) (res *BetaSelfHostedWork, err error) { 50 for _, v := range params.Betas { 51 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 52 } 53 if !param.IsOmitted(params.WorkspaceID) { 54 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 55 } 56 opts = slices.Concat(r.Options, opts) 57 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 58 if params.EnvironmentID == "" { 59 err = errors.New("missing required environment_id parameter") 60 return nil, err 61 } 62 if workID == "" { 63 err = errors.New("missing required work_id parameter") 64 return nil, err 65 } 66 path := fmt.Sprintf("v1/environments/%s/work/%s?beta=true", params.EnvironmentID, workID) 67 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) 68 return res, err 69 } 70 71 // Note: these endpoints are called automatically by the pre-built environment 72 // worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted 73 // sandbox environments. They are included here as a reference; you do not need to 74 // invoke them directly. 75 // 76 // Update work item metadata with merge semantics. 77 func (r *BetaEnvironmentWorkService) Update(ctx context.Context, workID string, params BetaEnvironmentWorkUpdateParams, opts ...option.RequestOption) (res *BetaSelfHostedWork, err error) { 78 for _, v := range params.Betas { 79 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 80 } 81 if !param.IsOmitted(params.WorkspaceID) { 82 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 83 } 84 opts = slices.Concat(r.Options, opts) 85 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 86 if params.EnvironmentID == "" { 87 err = errors.New("missing required environment_id parameter") 88 return nil, err 89 } 90 if workID == "" { 91 err = errors.New("missing required work_id parameter") 92 return nil, err 93 } 94 path := fmt.Sprintf("v1/environments/%s/work/%s?beta=true", params.EnvironmentID, workID) 95 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 96 return res, err 97 } 98 99 // Note: these endpoints are called automatically by the pre-built environment 100 // worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted 101 // sandbox environments. They are included here as a reference; you do not need to 102 // invoke them directly. 103 // 104 // List work items in an environment. 105 func (r *BetaEnvironmentWorkService) List(ctx context.Context, environmentID string, params BetaEnvironmentWorkListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaSelfHostedWork], err error) { 106 var raw *http.Response 107 for _, v := range params.Betas { 108 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 109 } 110 opts = slices.Concat(r.Options, opts) 111 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01"), option.WithResponseInto(&raw)}, opts...) 112 if environmentID == "" { 113 err = errors.New("missing required environment_id parameter") 114 return nil, err 115 } 116 path := fmt.Sprintf("v1/environments/%s/work?beta=true", environmentID) 117 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) 118 if err != nil { 119 return nil, err 120 } 121 err = cfg.Execute() 122 if err != nil { 123 return nil, err 124 } 125 res.SetPageConfig(cfg, raw) 126 return res, nil 127 } 128 129 // Note: these endpoints are called automatically by the pre-built environment 130 // worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted 131 // sandbox environments. They are included here as a reference; you do not need to 132 // invoke them directly. 133 // 134 // List work items in an environment. 135 func (r *BetaEnvironmentWorkService) ListAutoPaging(ctx context.Context, environmentID string, params BetaEnvironmentWorkListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaSelfHostedWork] { 136 return pagination.NewPageCursorAutoPager(r.List(ctx, environmentID, params, opts...)) 137 } 138 139 // Note: these endpoints are called automatically by the pre-built environment 140 // worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted 141 // sandbox environments. They are included here as a reference; you do not need to 142 // invoke them directly. 143 // 144 // Acknowledge receipt of a work item, transitioning it from 'queued' to 'starting' 145 // and removing it from the queue. 146 func (r *BetaEnvironmentWorkService) Ack(ctx context.Context, workID string, params BetaEnvironmentWorkAckParams, opts ...option.RequestOption) (res *BetaSelfHostedWork, err error) { 147 for _, v := range params.Betas { 148 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 149 } 150 opts = slices.Concat(r.Options, opts) 151 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 152 if params.EnvironmentID == "" { 153 err = errors.New("missing required environment_id parameter") 154 return nil, err 155 } 156 if workID == "" { 157 err = errors.New("missing required work_id parameter") 158 return nil, err 159 } 160 path := fmt.Sprintf("v1/environments/%s/work/%s/ack?beta=true", params.EnvironmentID, workID) 161 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) 162 return res, err 163 } 164 165 // Note: these endpoints are called automatically by the pre-built environment 166 // worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted 167 // sandbox environments. They are included here as a reference; you do not need to 168 // invoke them directly. 169 // 170 // Record a heartbeat for a work item to maintain the lease. 171 func (r *BetaEnvironmentWorkService) Heartbeat(ctx context.Context, workID string, params BetaEnvironmentWorkHeartbeatParams, opts ...option.RequestOption) (res *BetaSelfHostedWorkHeartbeatResponse, err error) { 172 for _, v := range params.Betas { 173 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 174 } 175 opts = slices.Concat(r.Options, opts) 176 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 177 if params.EnvironmentID == "" { 178 err = errors.New("missing required environment_id parameter") 179 return nil, err 180 } 181 if workID == "" { 182 err = errors.New("missing required work_id parameter") 183 return nil, err 184 } 185 path := fmt.Sprintf("v1/environments/%s/work/%s/heartbeat?beta=true", params.EnvironmentID, workID) 186 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 187 return res, err 188 } 189 190 // Note: these endpoints are called automatically by the pre-built environment 191 // worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted 192 // sandbox environments. They are included here as a reference; you do not need to 193 // invoke them directly. 194 // 195 // Long poll for work items in the queue. 196 func (r *BetaEnvironmentWorkService) Poll(ctx context.Context, environmentID string, params BetaEnvironmentWorkPollParams, opts ...option.RequestOption) (res *BetaSelfHostedWork, err error) { 197 for _, v := range params.Betas { 198 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 199 } 200 if !param.IsOmitted(params.AnthropicWorkerID) { 201 opts = append(opts, option.WithHeader("Anthropic-Worker-ID", fmt.Sprintf("%v", params.AnthropicWorkerID.Value))) 202 } 203 opts = slices.Concat(r.Options, opts) 204 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 205 if environmentID == "" { 206 err = errors.New("missing required environment_id parameter") 207 return nil, err 208 } 209 path := fmt.Sprintf("v1/environments/%s/work/poll?beta=true", environmentID) 210 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, params, &res, opts...) 211 return res, err 212 } 213 214 // Get statistics about the work queue for an environment. 215 func (r *BetaEnvironmentWorkService) Stats(ctx context.Context, environmentID string, query BetaEnvironmentWorkStatsParams, opts ...option.RequestOption) (res *BetaSelfHostedWorkQueueStats, err error) { 216 for _, v := range query.Betas { 217 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 218 } 219 if !param.IsOmitted(query.WorkspaceID) { 220 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", query.WorkspaceID.Value))) 221 } 222 opts = slices.Concat(r.Options, opts) 223 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 224 if environmentID == "" { 225 err = errors.New("missing required environment_id parameter") 226 return nil, err 227 } 228 path := fmt.Sprintf("v1/environments/%s/work/stats?beta=true", environmentID) 229 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) 230 return res, err 231 } 232 233 // Note: these endpoints are called automatically by the pre-built environment 234 // worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted 235 // sandbox environments. They are included here as a reference; you do not need to 236 // invoke them directly. 237 // 238 // Stop a work item, initiating graceful or forced shutdown. 239 func (r *BetaEnvironmentWorkService) Stop(ctx context.Context, workID string, params BetaEnvironmentWorkStopParams, opts ...option.RequestOption) (res *BetaSelfHostedWork, err error) { 240 for _, v := range params.Betas { 241 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 242 } 243 if !param.IsOmitted(params.WorkspaceID) { 244 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 245 } 246 opts = slices.Concat(r.Options, opts) 247 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 248 if params.EnvironmentID == "" { 249 err = errors.New("missing required environment_id parameter") 250 return nil, err 251 } 252 if workID == "" { 253 err = errors.New("missing required work_id parameter") 254 return nil, err 255 } 256 path := fmt.Sprintf("v1/environments/%s/work/%s/stop?beta=true", params.EnvironmentID, workID) 257 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 258 return res, err 259 } 260 261 // Work data for environment health checks. 262 // 263 // This resource type is used for assessing the health of containers where work 264 // occurs. The data is opaque to users; the runner handles the health check by 265 // probing connectivity to required services. 266 type BetaHealthCheckWorkData struct { 267 // Health check identifier 268 ID string `json:"id" api:"required"` 269 // Type of work data 270 // 271 // Any of "healthcheck". 272 Type BetaHealthCheckWorkDataType `json:"type"` 273 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 274 JSON struct { 275 ID respjson.Field 276 Type respjson.Field 277 ExtraFields map[string]respjson.Field 278 raw string 279 } `json:"-"` 280 } 281 282 // Returns the unmodified JSON received from the API 283 func (r BetaHealthCheckWorkData) RawJSON() string { return r.JSON.raw } 284 func (r *BetaHealthCheckWorkData) UnmarshalJSON(data []byte) error { 285 return apijson.UnmarshalRoot(data, r) 286 } 287 288 // Type of work data 289 type BetaHealthCheckWorkDataType string 290 291 const ( 292 BetaHealthCheckWorkDataTypeHealthcheck BetaHealthCheckWorkDataType = "healthcheck" 293 ) 294 295 // Work resource representing a unit of work in a self-hosted environment. 296 // 297 // Work items are queued when sessions are created or when long-dormant sessions 298 // receive new messages. The Environment Manager polls for work items and executes 299 // them on customer-hosted infrastructure. 300 type BetaSelfHostedWork struct { 301 // Work identifier (e.g., 'work\_...') 302 ID string `json:"id" api:"required"` 303 // RFC 3339 timestamp when work was acknowledged by Environment Manager 304 AcknowledgedAt string `json:"acknowledged_at" api:"required"` 305 // RFC 3339 timestamp when work was created 306 CreatedAt string `json:"created_at" api:"required"` 307 // The actual work to be performed 308 Data BetaSessionWorkData `json:"data" api:"required"` 309 // Environment identifier this work belongs to (e.g., `env_...`) 310 EnvironmentID string `json:"environment_id" api:"required"` 311 // RFC 3339 timestamp of the most recent heartbeat 312 LatestHeartbeatAt string `json:"latest_heartbeat_at" api:"required"` 313 // User-provided metadata key-value pairs associated with this work item 314 Metadata map[string]string `json:"metadata" api:"required"` 315 // Credential payload used by the environment worker to execute this work item. May 316 // be populated when polling for work; null on all other retrieval paths. 317 Secret string `json:"secret" api:"required"` 318 // RFC 3339 timestamp when work execution started 319 StartedAt string `json:"started_at" api:"required"` 320 // Current state of the work item 321 // 322 // Any of "queued", "starting", "active", "stopping", "stopped". 323 State BetaSelfHostedWorkState `json:"state" api:"required"` 324 // RFC 3339 timestamp when stop was requested 325 StopRequestedAt string `json:"stop_requested_at" api:"required"` 326 // RFC 3339 timestamp when work execution stopped 327 StoppedAt string `json:"stopped_at" api:"required"` 328 // The type of object (always 'work') 329 Type constant.Work `json:"type" default:"work"` 330 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 331 JSON struct { 332 ID respjson.Field 333 AcknowledgedAt respjson.Field 334 CreatedAt respjson.Field 335 Data respjson.Field 336 EnvironmentID respjson.Field 337 LatestHeartbeatAt respjson.Field 338 Metadata respjson.Field 339 Secret respjson.Field 340 StartedAt respjson.Field 341 State respjson.Field 342 StopRequestedAt respjson.Field 343 StoppedAt respjson.Field 344 Type respjson.Field 345 ExtraFields map[string]respjson.Field 346 raw string 347 } `json:"-"` 348 } 349 350 // Returns the unmodified JSON received from the API 351 func (r BetaSelfHostedWork) RawJSON() string { return r.JSON.raw } 352 func (r *BetaSelfHostedWork) UnmarshalJSON(data []byte) error { 353 return apijson.UnmarshalRoot(data, r) 354 } 355 356 // Current state of the work item 357 type BetaSelfHostedWorkState string 358 359 const ( 360 BetaSelfHostedWorkStateQueued BetaSelfHostedWorkState = "queued" 361 BetaSelfHostedWorkStateStarting BetaSelfHostedWorkState = "starting" 362 BetaSelfHostedWorkStateActive BetaSelfHostedWorkState = "active" 363 BetaSelfHostedWorkStateStopping BetaSelfHostedWorkState = "stopping" 364 BetaSelfHostedWorkStateStopped BetaSelfHostedWorkState = "stopped" 365 ) 366 367 // Response after recording a heartbeat for a work item. 368 type BetaSelfHostedWorkHeartbeatResponse struct { 369 // RFC 3339 timestamp of the actual heartbeat from DB 370 LastHeartbeat string `json:"last_heartbeat" api:"required"` 371 // Whether the heartbeat succeeded in extending the lease 372 LeaseExtended bool `json:"lease_extended" api:"required"` 373 // Current state of the work item (active/stopping/stopped) 374 // 375 // Any of "queued", "starting", "active", "stopping", "stopped". 376 State BetaSelfHostedWorkHeartbeatResponseState `json:"state" api:"required"` 377 // Effective TTL applied to the lease 378 TTLSeconds int64 `json:"ttl_seconds" api:"required"` 379 // The type of response 380 Type constant.WorkHeartbeat `json:"type" default:"work_heartbeat"` 381 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 382 JSON struct { 383 LastHeartbeat respjson.Field 384 LeaseExtended respjson.Field 385 State respjson.Field 386 TTLSeconds respjson.Field 387 Type respjson.Field 388 ExtraFields map[string]respjson.Field 389 raw string 390 } `json:"-"` 391 } 392 393 // Returns the unmodified JSON received from the API 394 func (r BetaSelfHostedWorkHeartbeatResponse) RawJSON() string { return r.JSON.raw } 395 func (r *BetaSelfHostedWorkHeartbeatResponse) UnmarshalJSON(data []byte) error { 396 return apijson.UnmarshalRoot(data, r) 397 } 398 399 // Current state of the work item (active/stopping/stopped) 400 type BetaSelfHostedWorkHeartbeatResponseState string 401 402 const ( 403 BetaSelfHostedWorkHeartbeatResponseStateQueued BetaSelfHostedWorkHeartbeatResponseState = "queued" 404 BetaSelfHostedWorkHeartbeatResponseStateStarting BetaSelfHostedWorkHeartbeatResponseState = "starting" 405 BetaSelfHostedWorkHeartbeatResponseStateActive BetaSelfHostedWorkHeartbeatResponseState = "active" 406 BetaSelfHostedWorkHeartbeatResponseStateStopping BetaSelfHostedWorkHeartbeatResponseState = "stopping" 407 BetaSelfHostedWorkHeartbeatResponseStateStopped BetaSelfHostedWorkHeartbeatResponseState = "stopped" 408 ) 409 410 // Response when listing work items with cursor-based pagination. 411 type BetaSelfHostedWorkListResponse struct { 412 // List of work items 413 Data []BetaSelfHostedWork `json:"data" api:"required"` 414 // Opaque cursor for fetching the next page of results 415 NextPage string `json:"next_page" api:"required"` 416 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 417 JSON struct { 418 Data respjson.Field 419 NextPage respjson.Field 420 ExtraFields map[string]respjson.Field 421 raw string 422 } `json:"-"` 423 } 424 425 // Returns the unmodified JSON received from the API 426 func (r BetaSelfHostedWorkListResponse) RawJSON() string { return r.JSON.raw } 427 func (r *BetaSelfHostedWorkListResponse) UnmarshalJSON(data []byte) error { 428 return apijson.UnmarshalRoot(data, r) 429 } 430 431 // Statistics about the work queue for an environment. 432 // 433 // Uses Redis Stream consumer group metrics for O(1) queries. 434 type BetaSelfHostedWorkQueueStats struct { 435 // Number of work items waiting to be picked up (lag from consumer group) 436 Depth int64 `json:"depth" api:"required"` 437 // RFC 3339 timestamp of oldest item in the work stream (includes both queued and 438 // pending items), null if stream empty 439 OldestQueuedAt string `json:"oldest_queued_at" api:"required"` 440 // Number of work items being processed (polled but not acknowledged) 441 Pending int64 `json:"pending" api:"required"` 442 // The type of object 443 Type constant.WorkQueueStats `json:"type" default:"work_queue_stats"` 444 // Number of workers that have polled for work in the last 30 seconds. Requires 445 // worker_id to be sent with poll requests. 446 WorkersPolling int64 `json:"workers_polling" api:"required"` 447 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 448 JSON struct { 449 Depth respjson.Field 450 OldestQueuedAt respjson.Field 451 Pending respjson.Field 452 Type respjson.Field 453 WorkersPolling respjson.Field 454 ExtraFields map[string]respjson.Field 455 raw string 456 } `json:"-"` 457 } 458 459 // Returns the unmodified JSON received from the API 460 func (r BetaSelfHostedWorkQueueStats) RawJSON() string { return r.JSON.raw } 461 func (r *BetaSelfHostedWorkQueueStats) UnmarshalJSON(data []byte) error { 462 return apijson.UnmarshalRoot(data, r) 463 } 464 465 // Request to stop a work item. 466 type BetaSelfHostedWorkStopRequestParam struct { 467 // If true, immediately stop work without graceful shutdown 468 Force param.Opt[bool] `json:"force,omitzero"` 469 paramObj 470 } 471 472 func (r BetaSelfHostedWorkStopRequestParam) MarshalJSON() (data []byte, err error) { 473 type shadow BetaSelfHostedWorkStopRequestParam 474 return param.MarshalObject(r, (*shadow)(&r)) 475 } 476 func (r *BetaSelfHostedWorkStopRequestParam) UnmarshalJSON(data []byte) error { 477 return apijson.UnmarshalRoot(data, r) 478 } 479 480 // Request to update work item metadata. 481 // 482 // The property Metadata is required. 483 type BetaSelfHostedWorkUpdateRequestParam struct { 484 // Metadata patch. Set a key to a string to upsert it, or to null to delete it. 485 // Omit the field to preserve existing metadata. 486 Metadata map[string]string `json:"metadata,omitzero" api:"required"` 487 paramObj 488 } 489 490 func (r BetaSelfHostedWorkUpdateRequestParam) MarshalJSON() (data []byte, err error) { 491 type shadow BetaSelfHostedWorkUpdateRequestParam 492 return param.MarshalObject(r, (*shadow)(&r)) 493 } 494 func (r *BetaSelfHostedWorkUpdateRequestParam) UnmarshalJSON(data []byte) error { 495 return apijson.UnmarshalRoot(data, r) 496 } 497 498 // Work data for session work items. 499 // 500 // This resource type is used when work represents a session that needs to be 501 // executed in a self-hosted environment. 502 type BetaSessionWorkData struct { 503 // Session identifier (e.g., 'session\_...') 504 ID string `json:"id" api:"required"` 505 // Type of work data 506 Type constant.Session `json:"type" default:"session"` 507 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 508 JSON struct { 509 ID respjson.Field 510 Type respjson.Field 511 ExtraFields map[string]respjson.Field 512 raw string 513 } `json:"-"` 514 } 515 516 // Returns the unmodified JSON received from the API 517 func (r BetaSessionWorkData) RawJSON() string { return r.JSON.raw } 518 func (r *BetaSessionWorkData) UnmarshalJSON(data []byte) error { 519 return apijson.UnmarshalRoot(data, r) 520 } 521 522 type BetaEnvironmentWorkGetParams struct { 523 EnvironmentID string `path:"environment_id" api:"required" json:"-"` 524 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 525 // Optional header to specify the beta version(s) you want to use. 526 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 527 paramObj 528 } 529 530 type BetaEnvironmentWorkUpdateParams struct { 531 EnvironmentID string `path:"environment_id" api:"required" json:"-"` 532 // Request to update work item metadata. 533 BetaSelfHostedWorkUpdateRequest BetaSelfHostedWorkUpdateRequestParam 534 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 535 // Optional header to specify the beta version(s) you want to use. 536 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 537 paramObj 538 } 539 540 func (r BetaEnvironmentWorkUpdateParams) MarshalJSON() (data []byte, err error) { 541 return shimjson.Marshal(r.BetaSelfHostedWorkUpdateRequest) 542 } 543 func (r *BetaEnvironmentWorkUpdateParams) UnmarshalJSON(data []byte) error { 544 return apijson.UnmarshalRoot(data, r) 545 } 546 547 type BetaEnvironmentWorkListParams struct { 548 // Opaque cursor from previous response for pagination 549 Page param.Opt[string] `query:"page,omitzero" json:"-"` 550 // Maximum number of work items to return 551 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` 552 // Optional header to specify the beta version(s) you want to use. 553 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 554 paramObj 555 } 556 557 // URLQuery serializes [BetaEnvironmentWorkListParams]'s query parameters as 558 // `url.Values`. 559 func (r BetaEnvironmentWorkListParams) URLQuery() (v url.Values, err error) { 560 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 561 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 562 NestedFormat: apiquery.NestedQueryFormatBrackets, 563 }) 564 } 565 566 type BetaEnvironmentWorkAckParams struct { 567 EnvironmentID string `path:"environment_id" api:"required" json:"-"` 568 // Optional header to specify the beta version(s) you want to use. 569 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 570 paramObj 571 } 572 573 type BetaEnvironmentWorkHeartbeatParams struct { 574 EnvironmentID string `path:"environment_id" api:"required" json:"-"` 575 // Desired TTL in seconds 576 DesiredTTLSeconds param.Opt[int64] `query:"desired_ttl_seconds,omitzero" json:"-"` 577 // Expected last_heartbeat for conditional update (optimistic concurrency). Use 578 // literal 'NO_HEARTBEAT' to claim an unclaimed lease (first heartbeat). For 579 // subsequent heartbeats, echo the server's previous last_heartbeat value exactly. 580 // Returns 412 Precondition Failed if the actual value doesn't match. 581 ExpectedLastHeartbeat param.Opt[string] `query:"expected_last_heartbeat,omitzero" json:"-"` 582 // Optional header to specify the beta version(s) you want to use. 583 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 584 paramObj 585 } 586 587 // URLQuery serializes [BetaEnvironmentWorkHeartbeatParams]'s query parameters as 588 // `url.Values`. 589 func (r BetaEnvironmentWorkHeartbeatParams) URLQuery() (v url.Values, err error) { 590 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 591 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 592 NestedFormat: apiquery.NestedQueryFormatBrackets, 593 }) 594 } 595 596 type BetaEnvironmentWorkPollParams struct { 597 // How long to wait for work to arrive before returning. Must be 1-999 in 598 // milliseconds. Defaults to non-blocking (returns immediately if no work is 599 // available). 600 BlockMs param.Opt[int64] `query:"block_ms,omitzero" json:"-"` 601 // Reclaim unacknowledged work items older than this many milliseconds. If omitted, 602 // uses the default (5000ms). 603 ReclaimOlderThanMs param.Opt[int64] `query:"reclaim_older_than_ms,omitzero" json:"-"` 604 // Unique identifier for the specific worker polling, used to track aggregated 605 // environment-level work metrics in Console 606 AnthropicWorkerID param.Opt[string] `header:"Anthropic-Worker-ID,omitzero" json:"-"` 607 // Optional header to specify the beta version(s) you want to use. 608 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 609 paramObj 610 } 611 612 // URLQuery serializes [BetaEnvironmentWorkPollParams]'s query parameters as 613 // `url.Values`. 614 func (r BetaEnvironmentWorkPollParams) URLQuery() (v url.Values, err error) { 615 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 616 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 617 NestedFormat: apiquery.NestedQueryFormatBrackets, 618 }) 619 } 620 621 type BetaEnvironmentWorkStatsParams struct { 622 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 623 // Optional header to specify the beta version(s) you want to use. 624 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 625 paramObj 626 } 627 628 type BetaEnvironmentWorkStopParams struct { 629 EnvironmentID string `path:"environment_id" api:"required" json:"-"` 630 // Request to stop a work item. 631 BetaSelfHostedWorkStopRequest BetaSelfHostedWorkStopRequestParam 632 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 633 // Optional header to specify the beta version(s) you want to use. 634 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 635 paramObj 636 } 637 638 func (r BetaEnvironmentWorkStopParams) MarshalJSON() (data []byte, err error) { 639 return shimjson.Marshal(r.BetaSelfHostedWorkStopRequest) 640 } 641 func (r *BetaEnvironmentWorkStopParams) UnmarshalJSON(data []byte) error { 642 return apijson.UnmarshalRoot(data, r) 643 }