helpers for observe parsing
(role string, msg gjson.Result)
| 1095 | // helpers for observe parsing |
| 1096 | |
| 1097 | func printMessageSummary(role string, msg gjson.Result) { |
| 1098 | content := msg.Get("content") |
| 1099 | if content.Type == gjson.String { |
| 1100 | text := content.String() |
| 1101 | if text != "" { |
| 1102 | fmt.Printf(" \033[36m%s:\033[0m %s\n", role, truncate(text, 200)) |
| 1103 | } |
| 1104 | return |
| 1105 | } |
| 1106 | if content.IsArray() { |
| 1107 | for _, block := range content.Array() { |
| 1108 | blockType := block.Get("type").String() |
| 1109 | switch blockType { |
| 1110 | case "text": |
| 1111 | fmt.Printf(" \033[36m%s:\033[0m %s\n", role, truncate(block.Get("text").String(), 200)) |
| 1112 | case "tool_use": |
| 1113 | name := block.Get("name").String() |
| 1114 | fmt.Printf(" \033[36m[tool_use: %s]\033[0m %s\n", name, truncate(block.Get("input").Raw, 150)) |
| 1115 | case "tool_result": |
| 1116 | toolID := block.Get("tool_use_id").String() |
| 1117 | resultContent := block.Get("content").String() |
| 1118 | fmt.Printf(" \033[36m[tool_result: %s]\033[0m (%d chars)\n", toolID, len(resultContent)) |
| 1119 | default: |
| 1120 | fmt.Printf(" \033[36m%s [%s]\033[0m %s\n", role, blockType, truncate(block.Raw, 100)) |
| 1121 | } |
| 1122 | } |
| 1123 | return |
| 1124 | } |
| 1125 | // tool role messages |
| 1126 | if role == "tool" { |
| 1127 | toolCallID := msg.Get("tool_call_id").String() |
| 1128 | text := content.String() |
| 1129 | fmt.Printf(" \033[36m[tool_result: %s]\033[0m (%d chars)\n", toolCallID, len(text)) |
| 1130 | return |
| 1131 | } |
| 1132 | if content.Raw != "" { |
| 1133 | fmt.Printf(" \033[36m%s:\033[0m %s\n", role, truncate(content.Raw, 200)) |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | func printTruncated(s string, max int) { |
| 1138 | if len(s) > max { |
no test coverage detected