(payload []byte)
| 583 | } |
| 584 | |
| 585 | func extractMessageHashIDs(payload []byte) (primaryID, fallbackID string) { |
| 586 | var systemPrompt, firstUserMsg, firstAssistantMsg string |
| 587 | |
| 588 | // OpenAI/Claude messages format |
| 589 | messages := gjson.GetBytes(payload, "messages") |
| 590 | if messages.Exists() && messages.IsArray() { |
| 591 | messages.ForEach(func(_, msg gjson.Result) bool { |
| 592 | role := msg.Get("role").String() |
| 593 | content := extractMessageContent(msg.Get("content")) |
| 594 | if content == "" { |
| 595 | return true |
| 596 | } |
| 597 | |
| 598 | switch role { |
| 599 | case "system": |
| 600 | if systemPrompt == "" { |
| 601 | systemPrompt = truncateString(content, 100) |
| 602 | } |
| 603 | case "user": |
| 604 | if firstUserMsg == "" { |
| 605 | firstUserMsg = truncateString(content, 100) |
| 606 | } |
| 607 | case "assistant": |
| 608 | if firstAssistantMsg == "" { |
| 609 | firstAssistantMsg = truncateString(content, 100) |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | if systemPrompt != "" && firstUserMsg != "" && firstAssistantMsg != "" { |
| 614 | return false |
| 615 | } |
| 616 | return true |
| 617 | }) |
| 618 | } |
| 619 | |
| 620 | // Claude API: top-level "system" field (array or string) |
| 621 | if systemPrompt == "" { |
| 622 | topSystem := gjson.GetBytes(payload, "system") |
| 623 | if topSystem.Exists() { |
| 624 | if topSystem.IsArray() { |
| 625 | topSystem.ForEach(func(_, part gjson.Result) bool { |
| 626 | if text := part.Get("text").String(); text != "" && systemPrompt == "" { |
| 627 | systemPrompt = truncateString(text, 100) |
| 628 | return false |
| 629 | } |
| 630 | return true |
| 631 | }) |
| 632 | } else if topSystem.Type == gjson.String { |
| 633 | systemPrompt = truncateString(topSystem.String(), 100) |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | // Gemini format |
| 639 | if systemPrompt == "" && firstUserMsg == "" { |
| 640 | sysInstr := gjson.GetBytes(payload, "systemInstruction.parts") |
| 641 | if sysInstr.Exists() && sysInstr.IsArray() { |
| 642 | sysInstr.ForEach(func(_, part gjson.Result) bool { |
no test coverage detected