diff --git a/cmd/nlm/main.go b/cmd/nlm/main.go index 7d0d893..065a3df 100644 --- a/cmd/nlm/main.go +++ b/cmd/nlm/main.go @@ -286,6 +286,20 @@ func listSources(c *api.Client, notebookID string) error { return fmt.Errorf("list sources: %w", err) } + // Removed auth check that was masking beprotojson array nesting bug + + // Debug: print project details + if debug { + fmt.Fprintf(os.Stderr, "=== Project Debug ===\n") + fmt.Fprintf(os.Stderr, "Project ID: %s\n", p.ProjectId) + fmt.Fprintf(os.Stderr, "Project Title: %s\n", p.Title) + fmt.Fprintf(os.Stderr, "Sources count: %d\n", len(p.Sources)) + for i, src := range p.Sources { + fmt.Fprintf(os.Stderr, "Source %d: %+v\n", i, src) + } + fmt.Fprintf(os.Stderr, "=====================\n") + } + w := tabwriter.NewWriter(os.Stdout, 0, 4, 4, ' ', 0) fmt.Fprintln(w, "ID\tTITLE\tTYPE\tSTATUS\tLAST UPDATED") for _, src := range p.Sources { diff --git a/internal/api/client.go b/internal/api/client.go index aec1450..0cd5277 100644 --- a/internal/api/client.go +++ b/internal/api/client.go @@ -77,10 +77,38 @@ func (c *Client) GetProject(projectID string) (*Notebook, error) { return nil, fmt.Errorf("get project: %w", err) } + // Debug: Print raw response before unmarshaling + if c.rpc.Config.Debug { + fmt.Fprintf(os.Stderr, "=== GetProject Raw Response ===\n") + fmt.Fprintf(os.Stderr, "Response length: %d bytes\n", len(resp)) + previewLen := 500 + if len(resp) < previewLen { + previewLen = len(resp) + } + fmt.Fprintf(os.Stderr, "Response preview: %s\n", string(resp[:previewLen])) + fmt.Fprintf(os.Stderr, "================================\n") + } + + // Sources nesting issue is now fixed in beprotojson package + var project pb.Project if err := beprotojson.Unmarshal(resp, &project); err != nil { return nil, fmt.Errorf("parse response: %w", err) } + + // Debug: Print parsed project after unmarshaling + if c.rpc.Config.Debug { + fmt.Fprintf(os.Stderr, "=== GetProject Parsed Result ===\n") + fmt.Fprintf(os.Stderr, "Project ID: '%s'\n", project.ProjectId) + fmt.Fprintf(os.Stderr, "Project Title: '%s'\n", project.Title) + fmt.Fprintf(os.Stderr, "Project Emoji: '%s'\n", project.Emoji) + fmt.Fprintf(os.Stderr, "Sources count: %d\n", len(project.Sources)) + if len(project.Sources) > 0 { + fmt.Fprintf(os.Stderr, "First source: %+v\n", project.Sources[0]) + } + fmt.Fprintf(os.Stderr, "=================================\n") + } + return &project, nil } diff --git a/internal/beprotojson/beprotojson.go b/internal/beprotojson/beprotojson.go index caf140b..86c0563 100644 --- a/internal/beprotojson/beprotojson.go +++ b/internal/beprotojson/beprotojson.go @@ -55,6 +55,14 @@ func (o UnmarshalOptions) Unmarshal(b []byte, m proto.Message) error { func (o UnmarshalOptions) populateMessage(arr []interface{}, m proto.Message) error { msg := m.ProtoReflect() fields := msg.Descriptor().Fields() + msgName := string(msg.Descriptor().FullName()) + + // Special handling for Project message: unwrap extra nesting from GetProject API + if msgName == "notebooklm.v1alpha1.Project" && len(arr) == 1 { + if innerArr, ok := arr[0].([]interface{}); ok { + arr = innerArr + } + } for i, value := range arr { if value == nil {