extractTextFromTask extracts the text result from a completed Task.
(task *a2atype.Task)
| 491 | |
| 492 | // extractTextFromTask extracts the text result from a completed Task. |
| 493 | func extractTextFromTask(task *a2atype.Task) string { |
| 494 | if task == nil { |
| 495 | return "" |
| 496 | } |
| 497 | // Prefer artifacts (canonical result). |
| 498 | if len(task.Artifacts) > 0 { |
| 499 | var texts []string |
| 500 | for _, artifact := range task.Artifacts { |
| 501 | for _, part := range artifact.Parts { |
| 502 | if tp, ok := part.(a2atype.TextPart); ok && tp.Text != "" { |
| 503 | texts = append(texts, tp.Text) |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | if len(texts) > 0 { |
| 508 | return strings.Join(texts, "\n") |
| 509 | } |
| 510 | } |
| 511 | // Fall back to status message. |
| 512 | if task.Status.Message != nil { |
| 513 | return extractTextFromMessage(task.Status.Message) |
| 514 | } |
| 515 | return "" |
| 516 | } |
| 517 | |
| 518 | // extractTextFromMessage extracts text from a direct A2A Message response. |
| 519 | func extractTextFromMessage(message *a2atype.Message) string { |
no test coverage detected