diff --git a/cli/cli.go b/cli/cli.go index 80c26b7..d1d907f 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -9,12 +9,12 @@ import ( "strings" "time" - "github.com/inference-gateway/a2a-debugger/a2a" - "github.com/inference-gateway/a2a/adk" - "github.com/inference-gateway/a2a/adk/client" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "go.uber.org/zap" + a2a "github.com/inference-gateway/a2a-debugger/a2a" + client "github.com/inference-gateway/adk/client" + adk "github.com/inference-gateway/adk/types" + cobra "github.com/spf13/cobra" + viper "github.com/spf13/viper" + zap "go.uber.org/zap" ) var ( @@ -194,6 +194,79 @@ func handleA2AError(err error, method string) error { return err } +// displayPart displays a message part with proper formatting based on its type +func displayPart(part interface{}, partIndex int, prefix string) { + if partMap, ok := part.(map[string]interface{}); ok { + kind, kindExists := partMap["kind"] + if !kindExists { + fmt.Printf("%s%d. Unknown part (no kind field)\n", prefix, partIndex) + return + } + + switch kind { + case "text": + if text, exists := partMap["text"]; exists { + fmt.Printf("%s%d. [Text] %v\n", prefix, partIndex, text) + } else { + fmt.Printf("%s%d. [Text] (no text content)\n", prefix, partIndex) + } + + case "data": + fmt.Printf("%s%d. [Data] ", prefix, partIndex) + if data, exists := partMap["data"]; exists { + // Pretty print the data content + if dataJSON, err := json.MarshalIndent(data, "", " "); err == nil { + fmt.Printf("\n%s %s\n", prefix, strings.ReplaceAll(string(dataJSON), "\n", "\n"+prefix+" ")) + } else { + fmt.Printf("%v\n", data) + } + } else { + fmt.Printf("(no data content)\n") + } + + case "file": + fmt.Printf("%s%d. [File] ", prefix, partIndex) + if file, exists := partMap["file"]; exists { + if fileMap, ok := file.(map[string]interface{}); ok { + if name, exists := fileMap["name"]; exists { + fmt.Printf("Name: %v", name) + } + if mimeType, exists := fileMap["mimeType"]; exists { + fmt.Printf(" Type: %v", mimeType) + } + if uri, exists := fileMap["uri"]; exists { + fmt.Printf(" URI: %v", uri) + } else if bytes, exists := fileMap["bytes"]; exists { + if bytesStr, ok := bytes.(string); ok { + fmt.Printf(" Size: %d bytes", len(bytesStr)) + } + } + } + fmt.Printf("\n") + } else { + fmt.Printf("(no file content)\n") + } + + default: + fmt.Printf("%s%d. [%v] ", prefix, partIndex, kind) + // Try to display any content we can find + if text, exists := partMap["text"]; exists { + fmt.Printf("Text: %v\n", text) + } else if data, exists := partMap["data"]; exists { + if dataJSON, err := json.MarshalIndent(data, "", " "); err == nil { + fmt.Printf("Data:\n%s %s\n", prefix, strings.ReplaceAll(string(dataJSON), "\n", "\n"+prefix+" ")) + } else { + fmt.Printf("Data: %v\n", data) + } + } else { + fmt.Printf("(unknown content)\n") + } + } + } else { + fmt.Printf("%s%d. Invalid part format\n", prefix, partIndex) + } +} + // Config namespace command var configCmd = &cobra.Command{ Use: "config", @@ -428,14 +501,7 @@ var getTaskCmd = &cobra.Command{ fmt.Printf(" Parts: %d\n", len(task.Status.Message.Parts)) for i, part := range task.Status.Message.Parts { - if partMap, ok := part.(map[string]interface{}); ok { - if kind, exists := partMap["kind"]; exists { - fmt.Printf(" %d. Kind: %v\n", i+1, kind) - if text, exists := partMap["text"]; exists { - fmt.Printf(" Text: %v\n", text) - } - } - } + displayPart(part, i+1, " ") } } @@ -444,11 +510,7 @@ var getTaskCmd = &cobra.Command{ for i, msg := range task.History { fmt.Printf(" %d. [%s] %s\n", i+1, msg.Role, msg.MessageID) for j, part := range msg.Parts { - if partMap, ok := part.(map[string]interface{}); ok { - if text, exists := partMap["text"]; exists { - fmt.Printf(" Part %d: %v\n", j+1, text) - } - } + displayPart(part, j+1, " ") } } } @@ -503,11 +565,7 @@ var historyCmd = &cobra.Command{ for i, msg := range task.History { fmt.Printf(" %d. [%s] %s\n", i+1, msg.Role, msg.MessageID) for j, part := range msg.Parts { - if partMap, ok := part.(map[string]interface{}); ok { - if text, exists := partMap["text"]; exists { - fmt.Printf(" %d: %v\n", j+1, text) - } - } + displayPart(part, j+1, " ") } } } @@ -515,11 +573,7 @@ var historyCmd = &cobra.Command{ if task.Status.Message != nil { fmt.Printf(" Current: [%s] %s\n", task.Status.Message.Role, task.Status.Message.MessageID) for j, part := range task.Status.Message.Parts { - if partMap, ok := part.(map[string]interface{}); ok { - if text, exists := partMap["text"]; exists { - fmt.Printf(" %d: %v\n", j+1, text) - } - } + displayPart(part, j+1, " ") } } fmt.Printf("\n") diff --git a/go.mod b/go.mod index 77a74d7..611142f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/inference-gateway/a2a-debugger go 1.24 require ( - github.com/inference-gateway/a2a v0.4.0-rc.3 + github.com/inference-gateway/adk v0.7.4 github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 go.uber.org/zap v1.27.0 diff --git a/go.sum b/go.sum index 073ceca..8281f74 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/inference-gateway/a2a v0.4.0-rc.3 h1:XiDSXI6iBpXMLagsD8uu2GFSYajIVExdAHhnXrJRrrk= -github.com/inference-gateway/a2a v0.4.0-rc.3/go.mod h1:rj9JbIdgwLnaMidtEHtBriXu4bZNc17MCwyl+MFuiZo= +github.com/inference-gateway/adk v0.7.4 h1:lGbiuHxygyqZrBll7JeyjsCUjESbv9iTFHhgd8s4IUQ= +github.com/inference-gateway/adk v0.7.4/go.mod h1:Ed5s0OHGamsldoDydYUiJp2v+l4s3EqvJqYzk6tNA0Q= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=