Skip to content

Commit a52f08e

Browse files
committed
fix(providers/openai): send only API action fields for unstored searches
Copying WebSearchAction would also send any field added to the stored metadata later, which the API could reject on every unstored turn.
1 parent a410684 commit a52f08e

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

‎providers/openai/responses_language_model.go‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -928,25 +928,41 @@ func isResponsesWebSearchToolCall(toolCallPart fantasy.ToolCallPart) bool {
928928
// metadata, which unlike the call input keeps the status and the
929929
// deprecated single query. The item has no id: history from a stored turn
930930
// or another credential carries real ids, and the API replaces the sent
931-
// action with the stored item of that id. Sources are left out because
932-
// the API ignores them on input.
931+
// action with the stored item of that id.
933932
func unstoredWebSearchCallItem(meta *WebSearchCallMetadata) (responses.ResponseInputItemUnionParam, error) {
934933
if meta.Action == nil {
935-
return responses.ResponseInputItemUnionParam{}, errors.New("it has no action")
934+
return responses.ResponseInputItemUnionParam{}, errors.New("metadata has no action")
936935
}
937936
// The API rejects the whole request for any other action type.
938937
switch meta.Action.Type {
939938
case "search", "open_page", "find_in_page":
940939
default:
941940
return responses.ResponseInputItemUnionParam{}, fmt.Errorf("action type %q cannot be replayed", meta.Action.Type)
942941
}
943-
action := *meta.Action
944-
action.Sources = nil
942+
// Only fields the API takes are sent, so a field added to the stored
943+
// metadata cannot break replay.
944+
type action struct {
945+
Type string `json:"type"`
946+
Queries []string `json:"queries,omitempty"`
947+
Query string `json:"query,omitempty"`
948+
URL string `json:"url,omitempty"`
949+
Pattern string `json:"pattern,omitempty"`
950+
}
945951
item := param.Override[responses.ResponseFunctionWebSearchParam](struct {
946-
Type string `json:"type"`
947-
Status string `json:"status,omitempty"`
948-
Action *WebSearchAction `json:"action"`
949-
}{Type: "web_search_call", Status: meta.Status, Action: &action})
952+
Type string `json:"type"`
953+
Status string `json:"status,omitempty"`
954+
Action action `json:"action"`
955+
}{
956+
Type: "web_search_call",
957+
Status: meta.Status,
958+
Action: action{
959+
Type: meta.Action.Type,
960+
Queries: meta.Action.Queries,
961+
Query: meta.Action.Query,
962+
URL: meta.Action.URL,
963+
Pattern: meta.Action.Pattern,
964+
},
965+
})
950966
return responses.ResponseInputItemUnionParam{OfWebSearchCall: &item}, nil
951967
}
952968

‎providers/openai/responses_web_search_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ func TestResponsesToPrompt_WebSearchCallReplay(t *testing.T) {
586586
answer,
587587
),
588588
want: `[` + userJSON + `,` + answerJSON + `]`,
589-
wantWarning: `dropping web search "ws_01": it has no action`,
589+
wantWarning: `dropping web search "ws_01": metadata has no action`,
590590
},
591591
{
592592
name: "UnstoredWithoutMetadata",

0 commit comments

Comments
 (0)