toResponseMessages converts step content into messages suitable for appending to the conversation. Mirrors fantasy's toResponseMessages logic.
()
| 249 | // for appending to the conversation. Mirrors fantasy's |
| 250 | // toResponseMessages logic. |
| 251 | func (r stepResult) toResponseMessages() []fantasy.Message { |
| 252 | var assistantParts []fantasy.MessagePart |
| 253 | var toolParts []fantasy.MessagePart |
| 254 | |
| 255 | for _, c := range r.content { |
| 256 | switch c.GetType() { |
| 257 | case fantasy.ContentTypeText: |
| 258 | text, ok := fantasy.AsContentType[fantasy.TextContent](c) |
| 259 | if !ok || strings.TrimSpace(text.Text) == "" { |
| 260 | continue |
| 261 | } |
| 262 | assistantParts = append(assistantParts, fantasy.TextPart{ |
| 263 | Text: text.Text, |
| 264 | ProviderOptions: fantasy.ProviderOptions(text.ProviderMetadata), |
| 265 | }) |
| 266 | case fantasy.ContentTypeReasoning: |
| 267 | reasoning, ok := fantasy.AsContentType[fantasy.ReasoningContent](c) |
| 268 | if !ok { |
| 269 | continue |
| 270 | } |
| 271 | opts := fantasy.ProviderOptions(reasoning.ProviderMetadata) |
| 272 | if strings.TrimSpace(reasoning.Text) == "" && !chatsanitize.HasAnthropicSignedReasoningOptions(opts) { |
| 273 | continue |
| 274 | } |
| 275 | assistantParts = append(assistantParts, fantasy.ReasoningPart{ |
| 276 | Text: reasoning.Text, |
| 277 | ProviderOptions: opts, |
| 278 | }) |
| 279 | case fantasy.ContentTypeToolCall: |
| 280 | toolCall, ok := fantasy.AsContentType[fantasy.ToolCallContent](c) |
| 281 | if !ok { |
| 282 | continue |
| 283 | } |
| 284 | assistantParts = append(assistantParts, fantasy.ToolCallPart{ |
| 285 | ToolCallID: toolCall.ToolCallID, |
| 286 | ToolName: toolCall.ToolName, |
| 287 | Input: toolCall.Input, |
| 288 | ProviderExecuted: toolCall.ProviderExecuted, |
| 289 | ProviderOptions: fantasy.ProviderOptions(toolCall.ProviderMetadata), |
| 290 | }) |
| 291 | case fantasy.ContentTypeFile: |
| 292 | file, ok := fantasy.AsContentType[fantasy.FileContent](c) |
| 293 | if !ok { |
| 294 | continue |
| 295 | } |
| 296 | assistantParts = append(assistantParts, fantasy.FilePart{ |
| 297 | Data: file.Data, |
| 298 | MediaType: file.MediaType, |
| 299 | ProviderOptions: fantasy.ProviderOptions(file.ProviderMetadata), |
| 300 | }) |
| 301 | case fantasy.ContentTypeSource: |
| 302 | // Sources are metadata about references; they don't |
| 303 | // need to be included in conversation messages. |
| 304 | continue |
| 305 | case fantasy.ContentTypeToolResult: |
| 306 | result, ok := fantasy.AsContentType[fantasy.ToolResultContent](c) |
| 307 | if !ok { |
| 308 | continue |