anthropics / anthropics/anthropic-sdk-go
BetaManagedAgentsEventParamsOfUserMessage helper omits required Type field
- 主要言語
- Go
- スター
- 1.2k
- フォーク
- 213
- 平均マージ
- 1日 12時間
- マージ済み PR(30日)
- 11
説明
## Bug
The helper function `BetaManagedAgentsEventParamsOfUserMessage()` in `betasessionevent.go` does not set the required `Type` field on `BetaManagedAgentsUserMessageEventParams`, resulting in a `400 Bad Request` with `events[0].type: Field required` when calling `POST /v1/sessions/{id}/events`.
## Reproduction
```go
client.Beta.Sessions.Events.Send(ctx, sessionID, anthropic.BetaSessionEventSendParams{
Events: []anthropic.BetaManagedAgentsEventParamsUnion{
anthropic.BetaManagedAgentsEventParamsOfUserMessage(
[]anthropic.BetaManagedAgentsUserMessageEventParamsContentUnion{{
OfText: &anthropic.BetaManagedAgentsTextBlockParam{
Text: "hello",
Type: anthropic.BetaManagedAgentsTextBlockTypeText,
},
}},
),
},
})
```
Returns:
```
400 Bad Request: {"type":"error","error":{"type":"invalid_request_error","message":"Failed to parse request: events[0].type: Field required"}}
```
## Root cause
The helper only sets `Content`, not `Type`:
```go
func BetaManagedAgentsEventParamsOfUserMessage(content []BetaManagedAgentsUserMessageEventParamsContentUnion) BetaManagedAgentsEventParamsUnion {
var userMessage BetaManagedAgentsUserMessageEventParams
userMessage.Content = content // ✅
// userMessage.Type is never set ❌
return BetaManagedAgentsEventParamsUnion{OfUserMessage: &userMessage}
}
```
Compare with the other helpers which DO accept and set their type parameter:
```go
func BetaManagedAgentsEventParamsOfUserInterrupt(type_ ...) { ... userInterrupt.Type = type_ ... }
func BetaManagedAgentsEventParamsOfUserToolConfirmation(result, toolUseID, type_ ...) { ... userToolConfirmation.Type = type_ ... }
```
## Suggested fix
Either set the type automatically (since there's only one valid value):
```go
func BetaManagedAgentsEventParamsOfUserMessage(content []BetaManagedAgentsUserMessageEventParamsContentUnion) BetaManagedAgentsEventParamsUnion {
var userMessage BetaManagedAgentsUserMessageEventParams
userMessage.Content = content
userMessage.Type = BetaManagedAgentsUserMessageEventParamsTypeUserMessage
return BetaManagedAgentsEventParamsUnion{OfUserMessage: &userMessage}
}
```
## Workaround
Construct the struct directly instead of using the helper:
```go
Events: []anthropic.BetaManagedAgentsEventParamsUnion{
{
OfUserMessage: &anthropic.BetaManagedAgentsUserMessageEventParams{
Content: content,
Type: anthropic.BetaManagedAgentsUserMessageEventParamsTypeUserMessage,
},
},
},
```
## Version
`anthropic-sdk-go v1.34.0`
コントリビューションガイド
評価
この issue はまだ評価されていません。