diff --git a/notebooklm/audio_prompt_proto_test.go b/notebooklm/audio_prompt_proto_test.go new file mode 100644 index 00000000..20fabc94 --- /dev/null +++ b/notebooklm/audio_prompt_proto_test.go @@ -0,0 +1,61 @@ +package notebooklm + +import ( + "encoding/json" + "reflect" + "testing" + + pb "github.com/tmc/nlm/gen/notebooklm/v1alpha1" + "github.com/tmc/nlm/internal/beprotojson" +) + +// TestUniversalAudioDetailsPromptRoundTrip pins the wire position of the audio +// steer. Custom instructions for an Audio Overview travel in +// UniversalAudioDetails.prompt (field 1) on CreateUniversalArtifact; the legacy +// CreateAudioOverviewRequest.custom_instructions path is rejected by the server. +// If prompt ever stops encoding at index 0, instructions are silently dropped and +// the audio is generated with default treatment, which is not an observable error. +func TestUniversalAudioDetailsPromptRoundTrip(t *testing.T) { + wire := []interface{}{ + "fabricated audio steer", + float64(1), + nil, + nil, + "en", + nil, + float64(2), + } + data, err := json.Marshal(wire) + if err != nil { + t.Fatal(err) + } + + var got pb.UniversalAudioDetails + if err := beprotojson.Unmarshal(data, &got); err != nil { + t.Fatal(err) + } + if got.GetPrompt() != "fabricated audio steer" { + t.Fatalf("prompt = %q, want %q", got.GetPrompt(), "fabricated audio steer") + } + if got.GetStyle() != 1 { + t.Fatalf("style = %d, want 1", got.GetStyle()) + } + if got.GetLanguage() != "en" { + t.Fatalf("language = %q, want %q", got.GetLanguage(), "en") + } + if got.GetEnabled() != 2 { + t.Fatalf("enabled = %d, want 2", got.GetEnabled()) + } + + encoded, err := beprotojson.Marshal(&got) + if err != nil { + t.Fatal(err) + } + var roundTrip interface{} + if err := json.Unmarshal(encoded, &roundTrip); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(roundTrip, wire) { + t.Fatalf("round trip = %#v, want %#v", roundTrip, wire) + } +} diff --git a/notebooklm/client_audio.go b/notebooklm/client_audio.go index ddda08fe..72afafb2 100644 --- a/notebooklm/client_audio.go +++ b/notebooklm/client_audio.go @@ -49,7 +49,11 @@ func (c *Client) CreateAudioOverviewWithOptions(ctx context.Context, projectID s if len(sourceIDs) == 0 { return nil, fmt.Errorf("project has no sources - add sources before creating audio overview") } - if opts.Instructions == "" && opts.AudioType == pb.AudioType_AUDIO_TYPE_DEEP_DIVE && + // Custom instructions travel in UniversalAudioDetails.prompt. The legacy + // CreateAudioOverviewRequest.custom_instructions path below is rejected by + // the server (InvalidInput on R7cb6c), so instructions must not divert the + // request away from CreateUniversalArtifact. + if opts.AudioType == pb.AudioType_AUDIO_TYPE_DEEP_DIVE && opts.Length == pb.AudioLength_AUDIO_LENGTH_DEFAULT && opts.Language == "en" { audioSources := make([]*pb.SourceIdList, 0, len(sourceIDs)) for _, sourceID := range sourceIDs { @@ -62,6 +66,7 @@ func (c *Client) CreateAudioOverviewWithOptions(ctx context.Context, projectID s Kind: 1, SourceGroups: universalArtifactSourceGroups(sourceIDs), Audio: &pb.UniversalAudioOptions{Details: &pb.UniversalAudioDetails{ + Prompt: opts.Instructions, Style: int32(opts.Length), Sources: audioSources, Language: opts.Language,