session

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package session owns everything about a signed-in NotebookLM session: which host the account uses, the page tokens, cookies and their storage.

Index

Constants

View Source
const KeyringTimeout = 30 * time.Second

KeyringTimeout leaves time to answer the macOS "allow access" dialog.

Variables

View Source
var (
	ErrSignedOut      = errors.New("session: signed out")
	ErrCookieMismatch = errors.New("session: cookie mismatch (cookies bound to another client)")
	ErrPageDrift      = errors.New("session: page tokens not found (page layout changed)")
)
View Source
var ErrKeyringTimeout = errors.New("session: the OS keyring did not answer (is the keychain locked or missing?)")

ErrKeyringTimeout: the OS keyring did not answer within the timeout.

View Source
var ErrStaleRevision = errors.New("session: profile changed on disk since it was loaded")
View Source
var ErrUndecryptable = errors.New("session: profile cannot be decrypted")

ErrUndecryptable marks a profile file that its key cannot decrypt: the key does not match (it was replaced), or the file is damaged. Such a profile can never be read again. A keyring that cannot answer is not this error.

Functions

func DefaultDir

func DefaultDir() (string, error)

DefaultDir is <default config dir>/profiles.

func IsNotebookHost

func IsNotebookHost(u *url.URL) bool

IsNotebookHost is the only host check in the codebase. Upstreams that scattered host checks broke in five places on the rebrand.

func MigrateProfiles added in v0.3.2

func MigrateProfiles(oldDir, newDir string, kr Keyring) ([]string, error)

MigrateProfiles copies profiles from an old profiles folder into newDir. A profile is copied only when newDir has none of that name and the old one decrypts with its own key; the key goes along (key file, or keyring entry under newDir's scoped name). The old folder and its keyring entries are never changed, so nothing is lost. A profile that does not decrypt (it belongs to another view of the folder, or its key is gone) is skipped. It is cheap when there is nothing to do and safe to run on every start; it returns the names it copied.

Types

type Cookie struct {
	Name     string    `json:"name"`
	Value    string    `json:"value"`
	Domain   string    `json:"domain"`
	Path     string    `json:"path"`
	Expires  time.Time `json:"expires,omitzero"`
	Secure   bool      `json:"secure,omitempty"`
	HTTPOnly bool      `json:"httpOnly,omitempty"`
}

Cookie is a stored browser cookie. Domain starting with "." matches subdomains; otherwise it is host-only.

type DirEnv added in v0.3.2

type DirEnv struct {
	GOOS   string
	Home   func() (string, error) // os.UserHomeDir
	Config func() (string, error) // os.UserConfigDir
}

DirEnv resolves the default config folders. The lookups are functions so tests can point them at temp folders and never read the real home or %APPDATA%.

func OSDirEnv added in v0.3.2

func OSDirEnv() DirEnv

OSDirEnv is the real environment.

func (DirEnv) ConfigDir added in v0.3.2

func (e DirEnv) ConfigDir() (string, error)

ConfigDir is the default sourcebolt config folder: %USERPROFILE%\.sourcebolt on Windows, <user config dir>/sourcebolt elsewhere.

Windows moved out of %APPDATA% because a process started by a packaged (MSIX) app, such as Claude Desktop from the Microsoft Store, gets AppData file-system virtualization: its writes to %APPDATA% land in a private copy, so two apps on one PC saw two different profile files. The user profile folder outside AppData is not virtualized.

func (DirEnv) LegacyConfigDir added in v0.3.2

func (e DirEnv) LegacyConfigDir() string

LegacyConfigDir is the folder versions up to 0.3.1 used on Windows (%APPDATA%\sourcebolt), or "" when there is none to migrate from.

type Host

type Host string

Host is a NotebookLM web host, optionally with a port (tests).

const HostDefault Host = "notebook.google.com"

HostDefault is where rebranded accounts land since July 2026.

func (Host) Origin

func (h Host) Origin() string

Origin returns "https://<host>".

type HostRedirectError

type HostRedirectError struct{ To Host }

HostRedirectError means the account was redirected to another notebook host.

func (*HostRedirectError) Error

func (e *HostRedirectError) Error() string

type Jar

type Jar struct {
	// contains filtered or unexported fields
}

Jar is a concurrency-safe cookie jar that implements http.CookieJar and merges Set-Cookie responses so rotated cookies are never lost.

func ImportHeader

func ImportHeader(s string, h Host) (*Jar, error)

ImportHeader parses a raw "Cookie:" header, a bare "a=b; c=d" list or a cURL command copied from browser dev tools.

func ImportJSON

func ImportJSON(r io.Reader) (*Jar, error)

ImportJSON parses an array of cookie objects (browser-extension exports). Expiry may be in seconds or milliseconds.

func ImportNetscape

func ImportNetscape(r io.Reader) (*Jar, error)

ImportNetscape parses a Netscape cookies.txt export.

func NewJar

func NewJar() *Jar

func ParseExport added in v0.3.2

func ParseExport(raw []byte, format string, h Host) (*Jar, error)

ParseExport reads a cookie export in format "netscape", "json" or "header". An empty format is detected: a leading "[" is JSON, a tab is Netscape, anything else is a Cookie header.

func (*Jar) Add

func (j *Jar) Add(c Cookie)

Add inserts or replaces the cookie with the same name, domain and path.

func (*Jar) All

func (j *Jar) All() []Cookie

All returns a copy of every stored cookie.

func (*Jar) Cookies

func (j *Jar) Cookies(u *url.URL) []*http.Cookie

Cookies implements http.CookieJar.

func (*Jar) Has

func (j *Jar) Has(names ...string) bool

Has reports whether a live cookie exists for every name.

func (*Jar) HeaderFor

func (j *Jar) HeaderFor(h Host) string

HeaderFor builds the Cookie header value for requests to host h.

func (*Jar) Merge

func (j *Jar) Merge(resp *http.Response)

Merge stores every Set-Cookie of resp.

func (*Jar) Missing

func (j *Jar) Missing() []string

Missing lists the required cookies the jar lacks, for error messages.

func (*Jar) Replace

func (j *Jar) Replace(cs []Cookie)

Replace swaps the jar contents in place, so every holder of the jar pointer sees the new session (a fresh login picked up by a running server).

func (*Jar) SetCookies

func (j *Jar) SetCookies(u *url.URL, cs []*http.Cookie)

SetCookies implements http.CookieJar.

func (*Jar) Valid

func (j *Jar) Valid() bool

Valid applies the minimum cookie set NotebookLM accepts: SID + __Secure-1PSIDTS, plus OSID or APISID+SAPISID.

type Keyring

type Keyring interface {
	Get(service, user string) (string, error)
	Set(service, user, value string) error
	Delete(service, user string) error
}

Keyring is the subset of an OS keyring the store needs.

type OSKeyring

type OSKeyring struct{}

OSKeyring uses the platform keyring (Windows Credential Manager, macOS Keychain, Linux Secret Service). Only a 32-byte key goes there: Windows limits entries to 2,560 bytes, too small for a cookie jar.

Every call gives up after KeyringTimeout: on macOS the keyring is the `security` tool, which waits forever on a locked or missing keychain when nobody can unlock it (ssh, CI, a headless Mac). A new profile's key then goes to the key file instead.

func (OSKeyring) Delete

func (OSKeyring) Delete(s, u string) error

func (OSKeyring) Get

func (OSKeyring) Get(s, u string) (string, error)

func (OSKeyring) Set

func (OSKeyring) Set(s, u, v string) error

type Profile

type Profile struct {
	Name      string
	Host      Host
	Jar       *Jar
	Rev       int64 // revision on disk; Save fails if someone else saved since Load
	Updated   time.Time
	KeyInFile bool // the encryption key lives in a 0600 file (no OS keyring)
}

Profile is one signed-in Google account.

type Store

type Store interface {
	Load(name string) (*Profile, error)
	Save(p *Profile) error
	Delete(name string) error
	List() ([]string, error)
}

Store persists profiles.

func NewFileStore

func NewFileStore(dir string, kr Keyring) Store

NewFileStore stores each profile as an AES-256-GCM encrypted file in dir.

type TimeoutKeyring added in v0.3.0

type TimeoutKeyring struct {
	Inner   Keyring
	Timeout time.Duration
}

TimeoutKeyring returns ErrKeyringTimeout when Inner does not answer within Timeout. The abandoned call keeps running in the background.

func (TimeoutKeyring) Delete added in v0.3.0

func (k TimeoutKeyring) Delete(s, u string) error

func (TimeoutKeyring) Get added in v0.3.0

func (k TimeoutKeyring) Get(s, u string) (string, error)

func (TimeoutKeyring) Set added in v0.3.0

func (k TimeoutKeyring) Set(s, u, v string) error

type Tokens

type Tokens struct {
	AT      string // SNlM0e, CSRF token sent as "at"
	FSID    string // FdrFJe, sent as "f.sid"
	BL      string // cfb2h, build label sent as "bl"
	HL      string // <html lang>, sent as "hl"
	Email   string // oPEP7c
	Fetched time.Time
}

Tokens are the per-page values every RPC needs.

func Bootstrap

func Bootstrap(ctx context.Context, c *http.Client, h Host) (Tokens, error)

Bootstrap fetches https://<h>/ with the client's cookies and extracts tokens. Redirects are never followed: a redirect to accounts.google.com means the session is gone, and following it would hide that.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL