github.com/anthropics/anthropic-sdk-go@v1.70.1/betasession_test.go (about) 1 // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 2 3 package anthropic_test 4 5 import ( 6 "context" 7 "errors" 8 "os" 9 "testing" 10 "time" 11 12 "github.com/anthropics/anthropic-sdk-go" 13 "github.com/anthropics/anthropic-sdk-go/internal/testutil" 14 "github.com/anthropics/anthropic-sdk-go/option" 15 ) 16 17 func TestBetaSessionNewWithOptionalParams(t *testing.T) { 18 baseURL := "http://localhost:4010" 19 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 20 baseURL = envURL 21 } 22 if !testutil.CheckTestServer(t, baseURL) { 23 return 24 } 25 client := anthropic.NewClient( 26 option.WithBaseURL(baseURL), 27 option.WithAPIKey("my-anthropic-api-key"), 28 ) 29 _, err := client.Beta.Sessions.New(context.TODO(), anthropic.BetaSessionNewParams{ 30 Agent: anthropic.BetaSessionNewParamsAgentUnion{ 31 OfString: anthropic.String("agent_011CZkYpogX7uDKUyvBTophP"), 32 }, 33 EnvironmentID: "env_011CZkZ9X2dpNyB7HsEFoRfW", 34 Budget: anthropic.BetaManagedAgentsBudgetLimitParam{ 35 MaxListCost: anthropic.BetaMonetaryAmountParam{ 36 Amount: "2500", 37 Currency: anthropic.BetaCurrencyUSD, 38 }, 39 Type: anthropic.BetaManagedAgentsBudgetLimitTypeLimit, 40 }, 41 InitialEvents: []anthropic.BetaSessionNewParamsInitialEventUnion{{ 42 OfUserMessage: &anthropic.BetaManagedAgentsUserMessageEventParams{ 43 Content: []anthropic.BetaManagedAgentsUserMessageEventParamsContentUnion{{ 44 OfText: &anthropic.BetaManagedAgentsTextBlockParam{ 45 Text: "Where is my order #1234?", 46 Type: anthropic.BetaManagedAgentsTextBlockTypeText, 47 }, 48 }}, 49 Type: anthropic.BetaManagedAgentsUserMessageEventParamsTypeUserMessage, 50 }, 51 }}, 52 Metadata: map[string]string{ 53 "foo": "string", 54 }, 55 Resources: []anthropic.BetaSessionNewParamsResourceUnion{{ 56 OfFile: &anthropic.BetaManagedAgentsFileResourceParams{ 57 FileID: "file_011CNha8iCJcU1wXNR6q4V8w", 58 Type: anthropic.BetaManagedAgentsFileResourceParamsTypeFile, 59 MountPath: anthropic.String("/uploads/receipt.pdf"), 60 }, 61 }}, 62 Title: anthropic.String("Order #1234 inquiry"), 63 VaultIDs: []string{"string"}, 64 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 65 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 66 }) 67 if err != nil { 68 var apierr *anthropic.Error 69 if errors.As(err, &apierr) { 70 t.Log(string(apierr.DumpRequest(true))) 71 } 72 t.Fatalf("err should be nil: %s", err.Error()) 73 } 74 } 75 76 func TestBetaSessionGetWithOptionalParams(t *testing.T) { 77 baseURL := "http://localhost:4010" 78 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 79 baseURL = envURL 80 } 81 if !testutil.CheckTestServer(t, baseURL) { 82 return 83 } 84 client := anthropic.NewClient( 85 option.WithBaseURL(baseURL), 86 option.WithAPIKey("my-anthropic-api-key"), 87 ) 88 _, err := client.Beta.Sessions.Get( 89 context.TODO(), 90 "sesn_011CZkZAtmR3yMPDzynEDxu7", 91 anthropic.BetaSessionGetParams{ 92 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 93 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 94 }, 95 ) 96 if err != nil { 97 var apierr *anthropic.Error 98 if errors.As(err, &apierr) { 99 t.Log(string(apierr.DumpRequest(true))) 100 } 101 t.Fatalf("err should be nil: %s", err.Error()) 102 } 103 } 104 105 func TestBetaSessionUpdateWithOptionalParams(t *testing.T) { 106 baseURL := "http://localhost:4010" 107 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 108 baseURL = envURL 109 } 110 if !testutil.CheckTestServer(t, baseURL) { 111 return 112 } 113 client := anthropic.NewClient( 114 option.WithBaseURL(baseURL), 115 option.WithAPIKey("my-anthropic-api-key"), 116 ) 117 _, err := client.Beta.Sessions.Update( 118 context.TODO(), 119 "sesn_011CZkZAtmR3yMPDzynEDxu7", 120 anthropic.BetaSessionUpdateParams{ 121 Agent: anthropic.BetaManagedAgentsSessionAgentUpdateParam{ 122 MCPServers: []anthropic.BetaManagedAgentsURLMCPServerParams{{ 123 Name: "example-mcp", 124 Type: anthropic.BetaManagedAgentsURLMCPServerParamsTypeURL, 125 URL: "https://example-server.modelcontextprotocol.io/sse", 126 }}, 127 Tools: []anthropic.BetaManagedAgentsSessionAgentUpdateToolUnionParam{{ 128 OfAgentToolset20260401: &anthropic.BetaManagedAgentsAgentToolset20260401Params{ 129 Type: anthropic.BetaManagedAgentsAgentToolset20260401ParamsTypeAgentToolset20260401, 130 Configs: []anthropic.BetaManagedAgentsAgentToolConfigParamsUnion{{ 131 OfBash: &anthropic.BetaManagedAgentsBashToolConfigParams{ 132 Enabled: anthropic.Bool(true), 133 PermissionPolicy: anthropic.BetaManagedAgentsBashToolConfigParamsPermissionPolicyUnion{ 134 OfAlwaysAllow: &anthropic.BetaManagedAgentsAlwaysAllowPolicyParam{ 135 Type: anthropic.BetaManagedAgentsAlwaysAllowPolicyTypeAlwaysAllow, 136 }, 137 }, 138 Type: anthropic.BetaManagedAgentsBashToolConfigParamsTypeBash, 139 }, 140 }}, 141 DefaultConfig: anthropic.BetaManagedAgentsAgentToolsetDefaultConfigParams{ 142 Enabled: anthropic.Bool(true), 143 PermissionPolicy: anthropic.BetaManagedAgentsAgentToolsetDefaultConfigParamsPermissionPolicyUnion{ 144 OfAlwaysAllow: &anthropic.BetaManagedAgentsAlwaysAllowPolicyParam{ 145 Type: anthropic.BetaManagedAgentsAlwaysAllowPolicyTypeAlwaysAllow, 146 }, 147 }, 148 }, 149 }, 150 }}, 151 }, 152 Budget: anthropic.BetaManagedAgentsBudgetLimitParam{ 153 MaxListCost: anthropic.BetaMonetaryAmountParam{ 154 Amount: "2500", 155 Currency: anthropic.BetaCurrencyUSD, 156 }, 157 Type: anthropic.BetaManagedAgentsBudgetLimitTypeLimit, 158 }, 159 Metadata: map[string]string{ 160 "foo": "string", 161 }, 162 Title: anthropic.String("Order #1234 inquiry"), 163 VaultIDs: []string{"string"}, 164 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 165 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 166 }, 167 ) 168 if err != nil { 169 var apierr *anthropic.Error 170 if errors.As(err, &apierr) { 171 t.Log(string(apierr.DumpRequest(true))) 172 } 173 t.Fatalf("err should be nil: %s", err.Error()) 174 } 175 } 176 177 func TestBetaSessionListWithOptionalParams(t *testing.T) { 178 t.Skip("buildURL drops path-level query params (SDK-4349)") 179 baseURL := "http://localhost:4010" 180 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 181 baseURL = envURL 182 } 183 if !testutil.CheckTestServer(t, baseURL) { 184 return 185 } 186 client := anthropic.NewClient( 187 option.WithBaseURL(baseURL), 188 option.WithAPIKey("my-anthropic-api-key"), 189 ) 190 _, err := client.Beta.Sessions.List(context.TODO(), anthropic.BetaSessionListParams{ 191 AgentID: anthropic.String("agent_id"), 192 AgentVersion: anthropic.Int(0), 193 CreatedAtGt: anthropic.Time(time.Now()), 194 CreatedAtGte: anthropic.Time(time.Now()), 195 CreatedAtLt: anthropic.Time(time.Now()), 196 CreatedAtLte: anthropic.Time(time.Now()), 197 DeploymentID: anthropic.String("deployment_id"), 198 IncludeArchived: anthropic.Bool(true), 199 Limit: anthropic.Int(0), 200 MemoryStoreID: anthropic.String("memory_store_id"), 201 Order: anthropic.BetaSessionListParamsOrderAsc, 202 Page: anthropic.String("page"), 203 Statuses: []string{"rescheduling"}, 204 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 205 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 206 }) 207 if err != nil { 208 var apierr *anthropic.Error 209 if errors.As(err, &apierr) { 210 t.Log(string(apierr.DumpRequest(true))) 211 } 212 t.Fatalf("err should be nil: %s", err.Error()) 213 } 214 } 215 216 func TestBetaSessionDeleteWithOptionalParams(t *testing.T) { 217 baseURL := "http://localhost:4010" 218 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 219 baseURL = envURL 220 } 221 if !testutil.CheckTestServer(t, baseURL) { 222 return 223 } 224 client := anthropic.NewClient( 225 option.WithBaseURL(baseURL), 226 option.WithAPIKey("my-anthropic-api-key"), 227 ) 228 _, err := client.Beta.Sessions.Delete( 229 context.TODO(), 230 "sesn_011CZkZAtmR3yMPDzynEDxu7", 231 anthropic.BetaSessionDeleteParams{ 232 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 233 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 234 }, 235 ) 236 if err != nil { 237 var apierr *anthropic.Error 238 if errors.As(err, &apierr) { 239 t.Log(string(apierr.DumpRequest(true))) 240 } 241 t.Fatalf("err should be nil: %s", err.Error()) 242 } 243 } 244 245 func TestBetaSessionArchiveWithOptionalParams(t *testing.T) { 246 baseURL := "http://localhost:4010" 247 if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { 248 baseURL = envURL 249 } 250 if !testutil.CheckTestServer(t, baseURL) { 251 return 252 } 253 client := anthropic.NewClient( 254 option.WithBaseURL(baseURL), 255 option.WithAPIKey("my-anthropic-api-key"), 256 ) 257 _, err := client.Beta.Sessions.Archive( 258 context.TODO(), 259 "sesn_011CZkZAtmR3yMPDzynEDxu7", 260 anthropic.BetaSessionArchiveParams{ 261 Betas: []anthropic.AnthropicBeta{anthropic.AnthropicBetaMessageBatches2024_09_24}, 262 WorkspaceID: anthropic.String("wrkspc_011CZkZaBF1tNoB5wlCeusgy"), 263 }, 264 ) 265 if err != nil { 266 var apierr *anthropic.Error 267 if errors.As(err, &apierr) { 268 t.Log(string(apierr.DumpRequest(true))) 269 } 270 t.Fatalf("err should be nil: %s", err.Error()) 271 } 272 }