github.com/anthropics/anthropic-sdk-go@v1.70.1/betamemorystorememoryversion.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 "github.com/anthropics/anthropic-sdk-go/internal/requestconfig" 18 "github.com/anthropics/anthropic-sdk-go/option" 19 "github.com/anthropics/anthropic-sdk-go/packages/pagination" 20 "github.com/anthropics/anthropic-sdk-go/packages/param" 21 "github.com/anthropics/anthropic-sdk-go/packages/respjson" 22 "github.com/anthropics/anthropic-sdk-go/shared/constant" 23 ) 24 25 // BetaMemoryStoreMemoryVersionService contains methods and other services that 26 // help with 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 [NewBetaMemoryStoreMemoryVersionService] method instead. 31 type BetaMemoryStoreMemoryVersionService struct { 32 Options []option.RequestOption 33 } 34 35 // NewBetaMemoryStoreMemoryVersionService generates a new service that applies the 36 // given options to each request. These options are applied after the parent 37 // client's options (if there is one), and before any request-specific options. 38 func NewBetaMemoryStoreMemoryVersionService(opts ...option.RequestOption) (r BetaMemoryStoreMemoryVersionService) { 39 r = BetaMemoryStoreMemoryVersionService{} 40 r.Options = opts 41 return 42 } 43 44 // Retrieve a memory version 45 func (r *BetaMemoryStoreMemoryVersionService) Get(ctx context.Context, memoryVersionID string, params BetaMemoryStoreMemoryVersionGetParams, opts ...option.RequestOption) (res *BetaManagedAgentsMemoryVersion, 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", "agent-memory-2026-07-22")}, opts...) 54 if params.MemoryStoreID == "" { 55 err = errors.New("missing required memory_store_id parameter") 56 return nil, err 57 } 58 if memoryVersionID == "" { 59 err = errors.New("missing required memory_version_id parameter") 60 return nil, err 61 } 62 path := fmt.Sprintf("v1/memory_stores/%s/memory_versions/%s?beta=true", params.MemoryStoreID, memoryVersionID) 63 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, params, &res, opts...) 64 return res, err 65 } 66 67 // List memory versions 68 func (r *BetaMemoryStoreMemoryVersionService) List(ctx context.Context, memoryStoreID string, params BetaMemoryStoreMemoryVersionListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaManagedAgentsMemoryVersion], err error) { 69 var raw *http.Response 70 for _, v := range params.Betas { 71 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 72 } 73 if !param.IsOmitted(params.WorkspaceID) { 74 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 75 } 76 opts = slices.Concat(r.Options, opts) 77 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "agent-memory-2026-07-22"), option.WithResponseInto(&raw)}, opts...) 78 if memoryStoreID == "" { 79 err = errors.New("missing required memory_store_id parameter") 80 return nil, err 81 } 82 path := fmt.Sprintf("v1/memory_stores/%s/memory_versions?beta=true", memoryStoreID) 83 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) 84 if err != nil { 85 return nil, err 86 } 87 err = cfg.Execute() 88 if err != nil { 89 return nil, err 90 } 91 res.SetPageConfig(cfg, raw) 92 return res, nil 93 } 94 95 // List memory versions 96 func (r *BetaMemoryStoreMemoryVersionService) ListAutoPaging(ctx context.Context, memoryStoreID string, params BetaMemoryStoreMemoryVersionListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaManagedAgentsMemoryVersion] { 97 return pagination.NewPageCursorAutoPager(r.List(ctx, memoryStoreID, params, opts...)) 98 } 99 100 // Redact a memory version 101 func (r *BetaMemoryStoreMemoryVersionService) Redact(ctx context.Context, memoryVersionID string, params BetaMemoryStoreMemoryVersionRedactParams, opts ...option.RequestOption) (res *BetaManagedAgentsMemoryVersion, err error) { 102 for _, v := range params.Betas { 103 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 104 } 105 if !param.IsOmitted(params.WorkspaceID) { 106 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 107 } 108 opts = slices.Concat(r.Options, opts) 109 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "agent-memory-2026-07-22")}, opts...) 110 if params.MemoryStoreID == "" { 111 err = errors.New("missing required memory_store_id parameter") 112 return nil, err 113 } 114 if memoryVersionID == "" { 115 err = errors.New("missing required memory_version_id parameter") 116 return nil, err 117 } 118 path := fmt.Sprintf("v1/memory_stores/%s/memory_versions/%s/redact?beta=true", params.MemoryStoreID, memoryVersionID) 119 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) 120 return res, err 121 } 122 123 // BetaManagedAgentsActorUnion contains all possible properties and values from 124 // [BetaManagedAgentsSessionActor], [BetaManagedAgentsAPIActor], 125 // [BetaManagedAgentsUserActor], [BetaManagedAgentsServiceAccountActor]. 126 // 127 // Use the [BetaManagedAgentsActorUnion.AsAny] method to switch on the variant. 128 // 129 // Use the methods beginning with 'As' to cast the union to one of its variants. 130 type BetaManagedAgentsActorUnion struct { 131 // This field is from variant [BetaManagedAgentsSessionActor]. 132 SessionID string `json:"session_id"` 133 // Any of "session_actor", "api_actor", "user_actor", "service_account_actor". 134 Type string `json:"type"` 135 // This field is from variant [BetaManagedAgentsAPIActor]. 136 APIKeyID string `json:"api_key_id"` 137 // This field is from variant [BetaManagedAgentsUserActor]. 138 UserID string `json:"user_id"` 139 // This field is from variant [BetaManagedAgentsServiceAccountActor]. 140 ServiceAccountID string `json:"service_account_id"` 141 JSON struct { 142 SessionID respjson.Field 143 Type respjson.Field 144 APIKeyID respjson.Field 145 UserID respjson.Field 146 ServiceAccountID respjson.Field 147 raw string 148 } `json:"-"` 149 } 150 151 // anyBetaManagedAgentsActor is implemented by each variant of 152 // [BetaManagedAgentsActorUnion] to add type safety for the return type of 153 // [BetaManagedAgentsActorUnion.AsAny] 154 type anyBetaManagedAgentsActor interface { 155 implBetaManagedAgentsActorUnion() 156 } 157 158 func (BetaManagedAgentsSessionActor) implBetaManagedAgentsActorUnion() {} 159 func (BetaManagedAgentsAPIActor) implBetaManagedAgentsActorUnion() {} 160 func (BetaManagedAgentsUserActor) implBetaManagedAgentsActorUnion() {} 161 func (BetaManagedAgentsServiceAccountActor) implBetaManagedAgentsActorUnion() {} 162 163 // Use the following switch statement to find the correct variant 164 // 165 // switch variant := BetaManagedAgentsActorUnion.AsAny().(type) { 166 // case anthropic.BetaManagedAgentsSessionActor: 167 // case anthropic.BetaManagedAgentsAPIActor: 168 // case anthropic.BetaManagedAgentsUserActor: 169 // case anthropic.BetaManagedAgentsServiceAccountActor: 170 // default: 171 // fmt.Errorf("no variant present") 172 // } 173 func (u BetaManagedAgentsActorUnion) AsAny() anyBetaManagedAgentsActor { 174 switch u.Type { 175 case "session_actor": 176 return u.AsSessionActor() 177 case "api_actor": 178 return u.AsAPIActor() 179 case "user_actor": 180 return u.AsUserActor() 181 case "service_account_actor": 182 return u.AsServiceAccountActor() 183 } 184 return nil 185 } 186 187 func (u BetaManagedAgentsActorUnion) AsSessionActor() (v BetaManagedAgentsSessionActor) { 188 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 189 return 190 } 191 192 func (u BetaManagedAgentsActorUnion) AsAPIActor() (v BetaManagedAgentsAPIActor) { 193 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 194 return 195 } 196 197 func (u BetaManagedAgentsActorUnion) AsUserActor() (v BetaManagedAgentsUserActor) { 198 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 199 return 200 } 201 202 func (u BetaManagedAgentsActorUnion) AsServiceAccountActor() (v BetaManagedAgentsServiceAccountActor) { 203 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 204 return 205 } 206 207 // Returns the unmodified JSON received from the API 208 func (u BetaManagedAgentsActorUnion) RawJSON() string { return u.JSON.raw } 209 210 func (r *BetaManagedAgentsActorUnion) UnmarshalJSON(data []byte) error { 211 return apijson.UnmarshalRoot(data, r) 212 } 213 214 // Attribution for a write made directly via the public API (outside of any 215 // session). 216 type BetaManagedAgentsAPIActor struct { 217 // ID of the API key that performed the write. This identifies the key, not the 218 // secret. 219 APIKeyID string `json:"api_key_id" api:"required"` 220 // Any of "api_actor". 221 Type BetaManagedAgentsAPIActorType `json:"type" api:"required"` 222 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 223 JSON struct { 224 APIKeyID respjson.Field 225 Type respjson.Field 226 ExtraFields map[string]respjson.Field 227 raw string 228 } `json:"-"` 229 } 230 231 // Returns the unmodified JSON received from the API 232 func (r BetaManagedAgentsAPIActor) RawJSON() string { return r.JSON.raw } 233 func (r *BetaManagedAgentsAPIActor) UnmarshalJSON(data []byte) error { 234 return apijson.UnmarshalRoot(data, r) 235 } 236 237 type BetaManagedAgentsAPIActorType string 238 239 const ( 240 BetaManagedAgentsAPIActorTypeAPIActor BetaManagedAgentsAPIActorType = "api_actor" 241 ) 242 243 // A `memory_version` object: one immutable, attributed row in a memory's 244 // append-only history. Every non-no-op mutation to a memory produces a new 245 // version. Versions belong to the store (not the individual memory) and are not 246 // deleted with the memory; each version is retained for at least the version 247 // retention period after it was written, unless the store itself is deleted. 248 // Retrieving a redacted version returns 200 with `content`, `path`, 249 // `content_size_bytes`, and `content_sha256` set to `null`; branch on 250 // `redacted_at`, not HTTP status. 251 type BetaManagedAgentsMemoryVersion struct { 252 // Unique identifier for this version (a `memver_...` value). 253 ID string `json:"id" api:"required"` 254 // A timestamp in RFC 3339 format 255 CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` 256 // ID of the memory this version snapshots (a `mem_...` value). Remains valid after 257 // the memory is deleted; pass it as `memory_id` to 258 // [List memory versions](/en/api/beta/memory_stores/memory_versions/list) to 259 // retrieve the memory's retained versions, including the `deleted` row while the 260 // lineage is retained. 261 MemoryID string `json:"memory_id" api:"required"` 262 // ID of the memory store this version belongs to (a `memstore_...` value). 263 MemoryStoreID string `json:"memory_store_id" api:"required"` 264 // The kind of mutation a `memory_version` records. Every non-no-op mutation to a 265 // memory appends exactly one version row with one of these values. 266 // 267 // Any of "created", "modified", "deleted". 268 Operation BetaManagedAgentsMemoryVersionOperation `json:"operation" api:"required"` 269 // Any of "memory_version". 270 Type BetaManagedAgentsMemoryVersionType `json:"type" api:"required"` 271 // The memory's UTF-8 text content as of this version. `null` when `view=basic`, 272 // when `operation` is `deleted`, or when `redacted_at` is set. 273 Content string `json:"content" api:"nullable"` 274 // Lowercase hex SHA-256 digest of `content` as of this version (64 characters). 275 // `null` when `redacted_at` is set or `operation` is `deleted`. Populated 276 // regardless of `view` otherwise. 277 ContentSha256 string `json:"content_sha256" api:"nullable"` 278 // Size of `content` in bytes as of this version. `null` when `redacted_at` is set 279 // or `operation` is `deleted`. Populated regardless of `view` otherwise. 280 ContentSizeBytes int64 `json:"content_size_bytes" api:"nullable"` 281 // Identifies who performed a write or redact operation. Captured at write time on 282 // the `memory_version` row. The API key that created a session is not recorded on 283 // agent writes; attribution answers who made the write, not who is ultimately 284 // responsible. Look up session provenance separately via the 285 // [Sessions API](/en/api/beta/sessions/retrieve). 286 CreatedBy BetaManagedAgentsActorUnion `json:"created_by"` 287 // The memory's path at the time of this write. `null` if and only if `redacted_at` 288 // is set. 289 Path string `json:"path" api:"nullable"` 290 // A timestamp in RFC 3339 format 291 RedactedAt time.Time `json:"redacted_at" api:"nullable" format:"date-time"` 292 // Identifies who performed a write or redact operation. Captured at write time on 293 // the `memory_version` row. The API key that created a session is not recorded on 294 // agent writes; attribution answers who made the write, not who is ultimately 295 // responsible. Look up session provenance separately via the 296 // [Sessions API](/en/api/beta/sessions/retrieve). 297 RedactedBy BetaManagedAgentsActorUnion `json:"redacted_by"` 298 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 299 JSON struct { 300 ID respjson.Field 301 CreatedAt respjson.Field 302 MemoryID respjson.Field 303 MemoryStoreID respjson.Field 304 Operation respjson.Field 305 Type respjson.Field 306 Content respjson.Field 307 ContentSha256 respjson.Field 308 ContentSizeBytes respjson.Field 309 CreatedBy respjson.Field 310 Path respjson.Field 311 RedactedAt respjson.Field 312 RedactedBy respjson.Field 313 ExtraFields map[string]respjson.Field 314 raw string 315 } `json:"-"` 316 } 317 318 // Returns the unmodified JSON received from the API 319 func (r BetaManagedAgentsMemoryVersion) RawJSON() string { return r.JSON.raw } 320 func (r *BetaManagedAgentsMemoryVersion) UnmarshalJSON(data []byte) error { 321 return apijson.UnmarshalRoot(data, r) 322 } 323 324 type BetaManagedAgentsMemoryVersionType string 325 326 const ( 327 BetaManagedAgentsMemoryVersionTypeMemoryVersion BetaManagedAgentsMemoryVersionType = "memory_version" 328 ) 329 330 // The kind of mutation a `memory_version` records. Every non-no-op mutation to a 331 // memory appends exactly one version row with one of these values. 332 type BetaManagedAgentsMemoryVersionOperation string 333 334 const ( 335 BetaManagedAgentsMemoryVersionOperationCreated BetaManagedAgentsMemoryVersionOperation = "created" 336 BetaManagedAgentsMemoryVersionOperationModified BetaManagedAgentsMemoryVersionOperation = "modified" 337 BetaManagedAgentsMemoryVersionOperationDeleted BetaManagedAgentsMemoryVersionOperation = "deleted" 338 ) 339 340 // Attribution for a write made by a workload authenticated as a service account, 341 // for example via Workload Identity Federation. 342 type BetaManagedAgentsServiceAccountActor struct { 343 // ID of the service account that performed the write (a `svac_...` value). 344 ServiceAccountID string `json:"service_account_id" api:"required"` 345 Type constant.ServiceAccountActor `json:"type" default:"service_account_actor"` 346 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 347 JSON struct { 348 ServiceAccountID respjson.Field 349 Type respjson.Field 350 ExtraFields map[string]respjson.Field 351 raw string 352 } `json:"-"` 353 } 354 355 // Returns the unmodified JSON received from the API 356 func (r BetaManagedAgentsServiceAccountActor) RawJSON() string { return r.JSON.raw } 357 func (r *BetaManagedAgentsServiceAccountActor) UnmarshalJSON(data []byte) error { 358 return apijson.UnmarshalRoot(data, r) 359 } 360 361 // Attribution for a write made by an agent during a session, through the mounted 362 // filesystem at `/mnt/memory/`. 363 type BetaManagedAgentsSessionActor struct { 364 // ID of the session that performed the write (a `sesn_...` value). Look up the 365 // session via [Retrieve a session](/en/api/beta/sessions/retrieve) for further 366 // provenance. 367 SessionID string `json:"session_id" api:"required"` 368 // Any of "session_actor". 369 Type BetaManagedAgentsSessionActorType `json:"type" api:"required"` 370 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 371 JSON struct { 372 SessionID respjson.Field 373 Type respjson.Field 374 ExtraFields map[string]respjson.Field 375 raw string 376 } `json:"-"` 377 } 378 379 // Returns the unmodified JSON received from the API 380 func (r BetaManagedAgentsSessionActor) RawJSON() string { return r.JSON.raw } 381 func (r *BetaManagedAgentsSessionActor) UnmarshalJSON(data []byte) error { 382 return apijson.UnmarshalRoot(data, r) 383 } 384 385 type BetaManagedAgentsSessionActorType string 386 387 const ( 388 BetaManagedAgentsSessionActorTypeSessionActor BetaManagedAgentsSessionActorType = "session_actor" 389 ) 390 391 // Attribution for a write made by a human user through the Anthropic Console. 392 type BetaManagedAgentsUserActor struct { 393 // Any of "user_actor". 394 Type BetaManagedAgentsUserActorType `json:"type" api:"required"` 395 // ID of the user who performed the write (a `user_...` value). 396 UserID string `json:"user_id" api:"required"` 397 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 398 JSON struct { 399 Type respjson.Field 400 UserID respjson.Field 401 ExtraFields map[string]respjson.Field 402 raw string 403 } `json:"-"` 404 } 405 406 // Returns the unmodified JSON received from the API 407 func (r BetaManagedAgentsUserActor) RawJSON() string { return r.JSON.raw } 408 func (r *BetaManagedAgentsUserActor) UnmarshalJSON(data []byte) error { 409 return apijson.UnmarshalRoot(data, r) 410 } 411 412 type BetaManagedAgentsUserActorType string 413 414 const ( 415 BetaManagedAgentsUserActorTypeUserActor BetaManagedAgentsUserActorType = "user_actor" 416 ) 417 418 type BetaMemoryStoreMemoryVersionGetParams struct { 419 MemoryStoreID string `path:"memory_store_id" api:"required" json:"-"` 420 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 421 // Query parameter for view 422 // 423 // Any of "basic", "full". 424 View BetaManagedAgentsMemoryView `query:"view,omitzero" json:"-"` 425 // Optional header to specify the beta version(s) you want to use. 426 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 427 paramObj 428 } 429 430 // URLQuery serializes [BetaMemoryStoreMemoryVersionGetParams]'s query parameters 431 // as `url.Values`. 432 func (r BetaMemoryStoreMemoryVersionGetParams) URLQuery() (v url.Values, err error) { 433 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 434 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 435 NestedFormat: apiquery.NestedQueryFormatBrackets, 436 }) 437 } 438 439 type BetaMemoryStoreMemoryVersionListParams struct { 440 // Query parameter for api_key_id 441 APIKeyID param.Opt[string] `query:"api_key_id,omitzero" json:"-"` 442 // Return versions created at or after this time (inclusive). 443 CreatedAtGte param.Opt[time.Time] `query:"created_at[gte],omitzero" format:"date-time" json:"-"` 444 // Return versions created at or before this time (inclusive). 445 CreatedAtLte param.Opt[time.Time] `query:"created_at[lte],omitzero" format:"date-time" json:"-"` 446 // Query parameter for limit 447 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` 448 // Query parameter for memory_id 449 MemoryID param.Opt[string] `query:"memory_id,omitzero" json:"-"` 450 // Query parameter for page 451 Page param.Opt[string] `query:"page,omitzero" json:"-"` 452 // Query parameter for service_account_id 453 ServiceAccountID param.Opt[string] `query:"service_account_id,omitzero" json:"-"` 454 // Query parameter for session_id 455 SessionID param.Opt[string] `query:"session_id,omitzero" json:"-"` 456 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 457 // Query parameter for operation 458 // 459 // Any of "created", "modified", "deleted". 460 Operation BetaManagedAgentsMemoryVersionOperation `query:"operation,omitzero" json:"-"` 461 // Query parameter for view 462 // 463 // Any of "basic", "full". 464 View BetaManagedAgentsMemoryView `query:"view,omitzero" json:"-"` 465 // Optional header to specify the beta version(s) you want to use. 466 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 467 paramObj 468 } 469 470 // URLQuery serializes [BetaMemoryStoreMemoryVersionListParams]'s query parameters 471 // as `url.Values`. 472 func (r BetaMemoryStoreMemoryVersionListParams) URLQuery() (v url.Values, err error) { 473 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 474 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 475 NestedFormat: apiquery.NestedQueryFormatBrackets, 476 }) 477 } 478 479 type BetaMemoryStoreMemoryVersionRedactParams struct { 480 MemoryStoreID string `path:"memory_store_id" api:"required" json:"-"` 481 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 482 // Optional header to specify the beta version(s) you want to use. 483 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 484 paramObj 485 }