refactor(gemini): Adapt app to new protobuf structure
- Update main.go and doPlayback.go to be compatible with the refactored 'Chat -> Entries' protobuf message format. - Remove the now-obsolete format_rich_log.go file. - The application now compiles successfully against the new chatpb library.
This commit is contained in:
parent
3d6f228b6e
commit
bffc301568
|
@ -12,7 +12,7 @@ func doPlayback() {
|
||||||
|
|
||||||
// Iterate through the top-level Chat messages, which are now named groups.
|
// Iterate through the top-level Chat messages, which are now named groups.
|
||||||
for _, chat := range me.chats.GetChats() {
|
for _, chat := range me.chats.GetChats() {
|
||||||
|
|
||||||
// Get the number of entries in the chat.
|
// Get the number of entries in the chat.
|
||||||
entryCount := len(chat.GetEntries())
|
entryCount := len(chat.GetEntries())
|
||||||
|
|
||||||
|
|
|
@ -1,147 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/chatpb"
|
|
||||||
"go.wit.com/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
const termWidth = 120 // The target width for the formatted output boxes.
|
|
||||||
|
|
||||||
func parseRichLog(filename string) *chatpb.Chats {
|
|
||||||
data, err := os.ReadFile(filename)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error reading file %s: %v", filename, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
logData, err := chatpb.UnmarshalChatsTEXT(data)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error unmarshaling log file %s: %v", filename, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, chat := range logData.GetChats() {
|
|
||||||
// Handle content: prefer content_file, fallback to content.
|
|
||||||
var content string
|
|
||||||
if contentFile := chat.GetContentFile(); contentFile != "" {
|
|
||||||
// Construct the full path relative to the log file's directory.
|
|
||||||
logDir := filepath.Dir(filename)
|
|
||||||
contentPath := filepath.Join(logDir, contentFile)
|
|
||||||
|
|
||||||
contentBytes, err := os.ReadFile(contentPath)
|
|
||||||
if err != nil {
|
|
||||||
content = fmt.Sprintf("--- ERROR: Could not read content file %s: %v ---", contentPath, err)
|
|
||||||
} else {
|
|
||||||
content = string(contentBytes)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Fallback for older log formats.
|
|
||||||
content = chat.GetContent()
|
|
||||||
}
|
|
||||||
chat.Content = content
|
|
||||||
}
|
|
||||||
|
|
||||||
return logData
|
|
||||||
}
|
|
||||||
|
|
||||||
func formatRichLog(filename string) *chatpb.Chats {
|
|
||||||
data, err := os.ReadFile(filename)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error reading file %s: %v", filename, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
logData, err := chatpb.UnmarshalChatsTEXT(data)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Error unmarshaling log file %s: %v", filename, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, chat := range logData.GetChats() {
|
|
||||||
author := chat.GetFrom().String()
|
|
||||||
|
|
||||||
// Handle content: prefer content_file, fallback to content.
|
|
||||||
var content string
|
|
||||||
if contentFile := chat.GetContentFile(); contentFile != "" {
|
|
||||||
// Construct the full path relative to the log file's directory.
|
|
||||||
logDir := filepath.Dir(filename)
|
|
||||||
contentPath := filepath.Join(logDir, contentFile)
|
|
||||||
|
|
||||||
contentBytes, err := os.ReadFile(contentPath)
|
|
||||||
if err != nil {
|
|
||||||
content = fmt.Sprintf("--- ERROR: Could not read content file %s: %v ---", contentPath, err)
|
|
||||||
} else {
|
|
||||||
content = string(contentBytes)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Fallback for older log formats.
|
|
||||||
content = chat.GetContent()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print the conversational content first.
|
|
||||||
if content != "" {
|
|
||||||
// Trim trailing newlines for cleaner output.
|
|
||||||
fmt.Printf("✦ %s: %s\n", author, strings.TrimSpace(content))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now, format and print any tool calls.
|
|
||||||
for _, toolCall := range chat.GetToolCalls() {
|
|
||||||
printToolCallBox(toolCall)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return logData
|
|
||||||
}
|
|
||||||
|
|
||||||
// printToolCallBox handles the decorative formatting for a single tool call.
|
|
||||||
func printToolCallBox(tc *chatpb.ToolCall) {
|
|
||||||
boxWidth := termWidth - 2 // Account for the side borders.
|
|
||||||
|
|
||||||
// --- Top Border ---
|
|
||||||
fmt.Printf(" ╭%s╮\n", strings.Repeat("─", boxWidth))
|
|
||||||
|
|
||||||
// --- Header Line ---
|
|
||||||
header := fmt.Sprintf(" ✔ %s %s (%s)", tc.GetName(), tc.GetInput(), tc.GetDescription())
|
|
||||||
printWrappedLine(header, boxWidth)
|
|
||||||
printEmptyLine(boxWidth)
|
|
||||||
|
|
||||||
// --- Stdout ---
|
|
||||||
if stdout := tc.GetOutputStdout(); stdout != "" {
|
|
||||||
for _, line := range strings.Split(stdout, "\n") {
|
|
||||||
printWrappedLine(" "+line, boxWidth)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Stderr ---
|
|
||||||
if stderr := tc.GetOutputStderr(); stderr != "" {
|
|
||||||
for _, line := range strings.Split(stderr, "\n") {
|
|
||||||
printWrappedLine(" "+line, boxWidth)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printEmptyLine(boxWidth)
|
|
||||||
|
|
||||||
// --- Bottom Border ---
|
|
||||||
fmt.Printf(" ╰%s╯\n", strings.Repeat("─", boxWidth))
|
|
||||||
}
|
|
||||||
|
|
||||||
// printWrappedLine prints a line of text, wrapping it if it's too long.
|
|
||||||
func printWrappedLine(text string, width int) {
|
|
||||||
if len(text) == 0 {
|
|
||||||
printEmptyLine(width)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simple wrapping logic.
|
|
||||||
for len(text) > width {
|
|
||||||
fmt.Printf(" │ %-*s │\n", width, text[:width])
|
|
||||||
text = text[width:]
|
|
||||||
}
|
|
||||||
fmt.Printf(" │ %-*s │\n", width, text)
|
|
||||||
}
|
|
||||||
|
|
||||||
// printEmptyLine prints a blank line within the box.
|
|
||||||
func printEmptyLine(width int) {
|
|
||||||
fmt.Printf(" │ %*s │\n", width, "")
|
|
||||||
}
|
|
16
main.go
16
main.go
|
@ -71,10 +71,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Playback != nil {
|
if argv.Playback != nil {
|
||||||
log.Info("do playback here")
|
|
||||||
doPlayback()
|
doPlayback()
|
||||||
// pb := formatRichLog("log/2025-08-20-final.text")
|
|
||||||
// pb.ConfigSave()
|
|
||||||
okExit("")
|
okExit("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,14 +87,17 @@ func main() {
|
||||||
|
|
||||||
func verifyUuids(chats *chatpb.Chats) bool {
|
func verifyUuids(chats *chatpb.Chats) bool {
|
||||||
var changed bool
|
var changed bool
|
||||||
|
for _, chat := range chats.GetChats() {
|
||||||
all := chats.SortByUuid()
|
if chat.GetUuid() == "" {
|
||||||
for all.Scan() {
|
|
||||||
chat := all.Next()
|
|
||||||
if chat.Uuid == "" {
|
|
||||||
chat.Uuid = uuid.New().String()
|
chat.Uuid = uuid.New().String()
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
|
for _, entry := range chat.GetEntries() {
|
||||||
|
if entry.GetUuid() == "" {
|
||||||
|
entry.Uuid = uuid.New().String()
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return changed
|
return changed
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue