|
| 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 | + "time" |
| 13 | + |
| 14 | + "github.com/anthropics/anthropic-sdk-go/internal/apijson" |
| 15 | + "github.com/anthropics/anthropic-sdk-go/internal/apiquery" |
| 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 | +) |
| 22 | + |
| 23 | +// BetaMemoryStoreService contains methods and other services that help with |
| 24 | +// interacting with the anthropic API. |
| 25 | +// |
| 26 | +// Note, unlike clients, this service does not read variables from the environment |
| 27 | +// automatically. You should not instantiate this service directly, and instead use |
| 28 | +// the [NewBetaMemoryStoreService] method instead. |
| 29 | +type BetaMemoryStoreService struct { |
| 30 | + Options []option.RequestOption |
| 31 | + Memories BetaMemoryStoreMemoryService |
| 32 | + MemoryVersions BetaMemoryStoreMemoryVersionService |
| 33 | +} |
| 34 | + |
| 35 | +// NewBetaMemoryStoreService generates a new service that applies the given options |
| 36 | +// to each request. These options are applied after the parent client's options (if |
| 37 | +// there is one), and before any request-specific options. |
| 38 | +func NewBetaMemoryStoreService(opts ...option.RequestOption) (r BetaMemoryStoreService) { |
| 39 | + r = BetaMemoryStoreService{} |
| 40 | + r.Options = opts |
| 41 | + r.Memories = NewBetaMemoryStoreMemoryService(opts...) |
| 42 | + r.MemoryVersions = NewBetaMemoryStoreMemoryVersionService(opts...) |
| 43 | + return |
| 44 | +} |
| 45 | + |
| 46 | +// CreateMemoryStore |
| 47 | +func (r *BetaMemoryStoreService) New(ctx context.Context, params BetaMemoryStoreNewParams, opts ...option.RequestOption) (res *BetaManagedAgentsMemoryStore, err error) { |
| 48 | + for _, v := range params.Betas { |
| 49 | + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) |
| 50 | + } |
| 51 | + opts = slices.Concat(r.Options, opts) |
| 52 | + opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) |
| 53 | + path := "v1/memory_stores?beta=true" |
| 54 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) |
| 55 | + return res, err |
| 56 | +} |
| 57 | + |
| 58 | +// GetMemoryStore |
| 59 | +func (r *BetaMemoryStoreService) Get(ctx context.Context, memoryStoreID string, query BetaMemoryStoreGetParams, opts ...option.RequestOption) (res *BetaManagedAgentsMemoryStore, err error) { |
| 60 | + for _, v := range query.Betas { |
| 61 | + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) |
| 62 | + } |
| 63 | + opts = slices.Concat(r.Options, opts) |
| 64 | + opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) |
| 65 | + if memoryStoreID == "" { |
| 66 | + err = errors.New("missing required memory_store_id parameter") |
| 67 | + return nil, err |
| 68 | + } |
| 69 | + path := fmt.Sprintf("v1/memory_stores/%s?beta=true", memoryStoreID) |
| 70 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) |
| 71 | + return res, err |
| 72 | +} |
| 73 | + |
| 74 | +// UpdateMemoryStore |
| 75 | +func (r *BetaMemoryStoreService) Update(ctx context.Context, memoryStoreID string, params BetaMemoryStoreUpdateParams, opts ...option.RequestOption) (res *BetaManagedAgentsMemoryStore, err error) { |
| 76 | + for _, v := range params.Betas { |
| 77 | + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) |
| 78 | + } |
| 79 | + opts = slices.Concat(r.Options, opts) |
| 80 | + opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) |
| 81 | + if memoryStoreID == "" { |
| 82 | + err = errors.New("missing required memory_store_id parameter") |
| 83 | + return nil, err |
| 84 | + } |
| 85 | + path := fmt.Sprintf("v1/memory_stores/%s?beta=true", memoryStoreID) |
| 86 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) |
| 87 | + return res, err |
| 88 | +} |
| 89 | + |
| 90 | +// ListMemoryStores |
| 91 | +func (r *BetaMemoryStoreService) List(ctx context.Context, params BetaMemoryStoreListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaManagedAgentsMemoryStore], 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 | + opts = slices.Concat(r.Options, opts) |
| 97 | + opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01"), option.WithResponseInto(&raw)}, opts...) |
| 98 | + path := "v1/memory_stores?beta=true" |
| 99 | + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) |
| 100 | + if err != nil { |
| 101 | + return nil, err |
| 102 | + } |
| 103 | + err = cfg.Execute() |
| 104 | + if err != nil { |
| 105 | + return nil, err |
| 106 | + } |
| 107 | + res.SetPageConfig(cfg, raw) |
| 108 | + return res, nil |
| 109 | +} |
| 110 | + |
| 111 | +// ListMemoryStores |
| 112 | +func (r *BetaMemoryStoreService) ListAutoPaging(ctx context.Context, params BetaMemoryStoreListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaManagedAgentsMemoryStore] { |
| 113 | + return pagination.NewPageCursorAutoPager(r.List(ctx, params, opts...)) |
| 114 | +} |
| 115 | + |
| 116 | +// DeleteMemoryStore |
| 117 | +func (r *BetaMemoryStoreService) Delete(ctx context.Context, memoryStoreID string, body BetaMemoryStoreDeleteParams, opts ...option.RequestOption) (res *BetaManagedAgentsDeletedMemoryStore, err error) { |
| 118 | + for _, v := range body.Betas { |
| 119 | + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) |
| 120 | + } |
| 121 | + opts = slices.Concat(r.Options, opts) |
| 122 | + opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) |
| 123 | + if memoryStoreID == "" { |
| 124 | + err = errors.New("missing required memory_store_id parameter") |
| 125 | + return nil, err |
| 126 | + } |
| 127 | + path := fmt.Sprintf("v1/memory_stores/%s?beta=true", memoryStoreID) |
| 128 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) |
| 129 | + return res, err |
| 130 | +} |
| 131 | + |
| 132 | +// ArchiveMemoryStore |
| 133 | +func (r *BetaMemoryStoreService) Archive(ctx context.Context, memoryStoreID string, body BetaMemoryStoreArchiveParams, opts ...option.RequestOption) (res *BetaManagedAgentsMemoryStore, err error) { |
| 134 | + for _, v := range body.Betas { |
| 135 | + opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) |
| 136 | + } |
| 137 | + opts = slices.Concat(r.Options, opts) |
| 138 | + opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) |
| 139 | + if memoryStoreID == "" { |
| 140 | + err = errors.New("missing required memory_store_id parameter") |
| 141 | + return nil, err |
| 142 | + } |
| 143 | + path := fmt.Sprintf("v1/memory_stores/%s/archive?beta=true", memoryStoreID) |
| 144 | + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) |
| 145 | + return res, err |
| 146 | +} |
| 147 | + |
| 148 | +type BetaManagedAgentsDeletedMemoryStore struct { |
| 149 | + ID string `json:"id" api:"required"` |
| 150 | + // Any of "memory_store_deleted". |
| 151 | + Type BetaManagedAgentsDeletedMemoryStoreType `json:"type" api:"required"` |
| 152 | + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. |
| 153 | + JSON struct { |
| 154 | + ID respjson.Field |
| 155 | + Type respjson.Field |
| 156 | + ExtraFields map[string]respjson.Field |
| 157 | + raw string |
| 158 | + } `json:"-"` |
| 159 | +} |
| 160 | + |
| 161 | +// Returns the unmodified JSON received from the API |
| 162 | +func (r BetaManagedAgentsDeletedMemoryStore) RawJSON() string { return r.JSON.raw } |
| 163 | +func (r *BetaManagedAgentsDeletedMemoryStore) UnmarshalJSON(data []byte) error { |
| 164 | + return apijson.UnmarshalRoot(data, r) |
| 165 | +} |
| 166 | + |
| 167 | +type BetaManagedAgentsDeletedMemoryStoreType string |
| 168 | + |
| 169 | +const ( |
| 170 | + BetaManagedAgentsDeletedMemoryStoreTypeMemoryStoreDeleted BetaManagedAgentsDeletedMemoryStoreType = "memory_store_deleted" |
| 171 | +) |
| 172 | + |
| 173 | +type BetaManagedAgentsMemoryStore struct { |
| 174 | + ID string `json:"id" api:"required"` |
| 175 | + // A timestamp in RFC 3339 format |
| 176 | + CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` |
| 177 | + Name string `json:"name" api:"required"` |
| 178 | + // Any of "memory_store". |
| 179 | + Type BetaManagedAgentsMemoryStoreType `json:"type" api:"required"` |
| 180 | + // A timestamp in RFC 3339 format |
| 181 | + UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"` |
| 182 | + // A timestamp in RFC 3339 format |
| 183 | + ArchivedAt time.Time `json:"archived_at" api:"nullable" format:"date-time"` |
| 184 | + Description string `json:"description"` |
| 185 | + Metadata map[string]string `json:"metadata"` |
| 186 | + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. |
| 187 | + JSON struct { |
| 188 | + ID respjson.Field |
| 189 | + CreatedAt respjson.Field |
| 190 | + Name respjson.Field |
| 191 | + Type respjson.Field |
| 192 | + UpdatedAt respjson.Field |
| 193 | + ArchivedAt respjson.Field |
| 194 | + Description respjson.Field |
| 195 | + Metadata respjson.Field |
| 196 | + ExtraFields map[string]respjson.Field |
| 197 | + raw string |
| 198 | + } `json:"-"` |
| 199 | +} |
| 200 | + |
| 201 | +// Returns the unmodified JSON received from the API |
| 202 | +func (r BetaManagedAgentsMemoryStore) RawJSON() string { return r.JSON.raw } |
| 203 | +func (r *BetaManagedAgentsMemoryStore) UnmarshalJSON(data []byte) error { |
| 204 | + return apijson.UnmarshalRoot(data, r) |
| 205 | +} |
| 206 | + |
| 207 | +type BetaManagedAgentsMemoryStoreType string |
| 208 | + |
| 209 | +const ( |
| 210 | + BetaManagedAgentsMemoryStoreTypeMemoryStore BetaManagedAgentsMemoryStoreType = "memory_store" |
| 211 | +) |
| 212 | + |
| 213 | +type BetaMemoryStoreNewParams struct { |
| 214 | + Name string `json:"name" api:"required"` |
| 215 | + Description param.Opt[string] `json:"description,omitzero"` |
| 216 | + Metadata map[string]string `json:"metadata,omitzero"` |
| 217 | + // Optional header to specify the beta version(s) you want to use. |
| 218 | + Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` |
| 219 | + paramObj |
| 220 | +} |
| 221 | + |
| 222 | +func (r BetaMemoryStoreNewParams) MarshalJSON() (data []byte, err error) { |
| 223 | + type shadow BetaMemoryStoreNewParams |
| 224 | + return param.MarshalObject(r, (*shadow)(&r)) |
| 225 | +} |
| 226 | +func (r *BetaMemoryStoreNewParams) UnmarshalJSON(data []byte) error { |
| 227 | + return apijson.UnmarshalRoot(data, r) |
| 228 | +} |
| 229 | + |
| 230 | +type BetaMemoryStoreGetParams struct { |
| 231 | + // Optional header to specify the beta version(s) you want to use. |
| 232 | + Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` |
| 233 | + paramObj |
| 234 | +} |
| 235 | + |
| 236 | +type BetaMemoryStoreUpdateParams struct { |
| 237 | + Description param.Opt[string] `json:"description,omitzero"` |
| 238 | + Name param.Opt[string] `json:"name,omitzero"` |
| 239 | + // Metadata patch. Set a key to a string to upsert it, or to null to delete it. |
| 240 | + // Omit the field to preserve. The stored bag is limited to 16 keys (up to 64 chars |
| 241 | + // each) with values up to 512 chars. |
| 242 | + Metadata map[string]string `json:"metadata,omitzero"` |
| 243 | + // Optional header to specify the beta version(s) you want to use. |
| 244 | + Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` |
| 245 | + paramObj |
| 246 | +} |
| 247 | + |
| 248 | +func (r BetaMemoryStoreUpdateParams) MarshalJSON() (data []byte, err error) { |
| 249 | + type shadow BetaMemoryStoreUpdateParams |
| 250 | + return param.MarshalObject(r, (*shadow)(&r)) |
| 251 | +} |
| 252 | +func (r *BetaMemoryStoreUpdateParams) UnmarshalJSON(data []byte) error { |
| 253 | + return apijson.UnmarshalRoot(data, r) |
| 254 | +} |
| 255 | + |
| 256 | +type BetaMemoryStoreListParams struct { |
| 257 | + // Return stores created at or after this time (inclusive). |
| 258 | + CreatedAtGte param.Opt[time.Time] `query:"created_at[gte],omitzero" format:"date-time" json:"-"` |
| 259 | + // Return stores created at or before this time (inclusive). |
| 260 | + CreatedAtLte param.Opt[time.Time] `query:"created_at[lte],omitzero" format:"date-time" json:"-"` |
| 261 | + // Query parameter for include_archived |
| 262 | + IncludeArchived param.Opt[bool] `query:"include_archived,omitzero" json:"-"` |
| 263 | + // Query parameter for limit |
| 264 | + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` |
| 265 | + // Query parameter for page |
| 266 | + Page param.Opt[string] `query:"page,omitzero" json:"-"` |
| 267 | + // Optional header to specify the beta version(s) you want to use. |
| 268 | + Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` |
| 269 | + paramObj |
| 270 | +} |
| 271 | + |
| 272 | +// URLQuery serializes [BetaMemoryStoreListParams]'s query parameters as |
| 273 | +// `url.Values`. |
| 274 | +func (r BetaMemoryStoreListParams) URLQuery() (v url.Values, err error) { |
| 275 | + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ |
| 276 | + ArrayFormat: apiquery.ArrayQueryFormatComma, |
| 277 | + NestedFormat: apiquery.NestedQueryFormatBrackets, |
| 278 | + }) |
| 279 | +} |
| 280 | + |
| 281 | +type BetaMemoryStoreDeleteParams struct { |
| 282 | + // Optional header to specify the beta version(s) you want to use. |
| 283 | + Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` |
| 284 | + paramObj |
| 285 | +} |
| 286 | + |
| 287 | +type BetaMemoryStoreArchiveParams struct { |
| 288 | + // Optional header to specify the beta version(s) you want to use. |
| 289 | + Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` |
| 290 | + paramObj |
| 291 | +} |
0 commit comments