Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/python-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@ async with NotebookLMClient.from_storage(rate_limit_max_retries=0) as client:
| `get_summary(notebook_id)` | `notebook_id: str` | `str` | Get raw summary text |
| `get_share_url(notebook_id, artifact_id=None)` | `notebook_id: str, str \| None` | `str` | Get a share URL |
| `suggest_next_steps(notebook_id, *, source_ids=None)` | `str, list[str] \| None` | `list[NextStepSuggestion]` | Grounded follow-up **questions** for the notebook (`NextStepSuggestions`) — the block a chat answer carries as `AskResult.next_steps`, without needing a prior conversation. `source_ids=None` lets the server use all sources (no `GET_NOTEBOOK` round-trip). Distinct from `suggest_prompts`, which returns `(title, prompt)` steering pairs. |
| `get_toolset_preferences(notebook_id)` | `notebook_id: str` | `list[ToolsetPreference]` | Read per-notebook Connected Apps / toolset preferences (`ToolManagementService.ListNotebookToolsetPreferences` / `EEr8Nb`), such as `google-drive` (`("Search Drive", "Read Drive file")`). Web-only; Android raises `UnsupportedOperationError`. |
| `remove_from_recent(notebook_id)` | `notebook_id: str` | `None` | Remove from recently viewed |
| `get_raw(notebook_id)` | `notebook_id: str` | `Any` | Get raw API response data. Web: batchexecute list. Android: known-field **dict** (`message_to_known_dict`), not a protobuf message. See [Web vs Android inventory](web-android-public-behavior.md). |

Expand Down
1 change: 1 addition & 0 deletions docs/rpc-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ typed namespaces. For Android gRPC method contracts, start with the
| `mKDdke` | COPY_ARTIFACTS | Copy Studio artifacts into another notebook (full new rows inline) | `_web/artifacts.py` |
| `OcvKNc` | SUGGEST_NEXT_STEPS | Grounded follow-up questions (the chat `next_steps` block, standalone) | `_web/notebooks.py` |
| `sqTeoe` | GET_CUSTOMIZATION_CHOICES | Studio "Customize" option tables (account-level) | `_web/artifacts.py` |
| `EEr8Nb` | LIST_TOOLSET_PREFERENCES | Read per-notebook Connected Apps / toolset preferences (`ToolManagementService.ListNotebookToolsetPreferences`, Web-only) | `_web/notebooks.py`, `_web/rows/notebooks.py` |

### Content Type Codes (ArtifactTypeCode)

Expand Down
1 change: 1 addition & 0 deletions docs/web-android-public-behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ program. Explicitly out of scope for this page:
| `artifacts.generate_report` with `ReportFormat.CONCEPT_EXPLANATION` | Android supports concept-explanation reports; Web rejects this format as unsupported. | Capability metadata — keep | `tests/unit/test_creation_conformance.py` (`test_android_concept_report_support_is_not_fabricated_on_web`) |
| Interactive mind-map `instructions` | Web omits a whitespace-only prompt and preserves nonblank text. Android preserves the supplied text, including whitespace. | Deliberate policy — keep | `tests/unit/test_creation_conformance.py` (`test_interactive_domain_normalization_and_language_encoding`) |
| `sources.add_file` for `.csv`, `.docx`, `.pptx` | Web exposes `Source.kind` as `CSV`, `DOCX`, or `POWERPOINT`. Android stages these formats through Drive and exposes the Drive type (`GOOGLE_DRIVE`, wire code 14); captured ingestion has content parity, not type parity. Code 14 can be disambiguated for other MIME types such as Sheets and PDF. | Projection difference — preserve the actual source kind | `tests/unit/android/test_source_upload.py` (`test_every_drive_staged_extension_routes_through_drive`); `tests/unit/test_types.py` (source-kind mappings); [captured Web/Android upload matrix](android/web-compat-seam-closure.md#source-type-does-not-survive-any-android-upload-route) |
| `notebooks.get_toolset_preferences` | Web reads per-notebook Connected Apps / toolset preferences via `ToolManagementService.ListNotebookToolsetPreferences` (`EEr8Nb`). Android has no `ToolManagementService` gRPC surface and raises `UnsupportedOperationError`. | Capability metadata — Web-only service | `tests/unit/test_toolset_preferences.py` (`test_calls_eer8nb_with_notebook_source_path_and_allow_null`, `test_raises_unsupported_operation_error_without_transport_call`) |

The live Android notes conformance probe is opt-in and destructive only to the
uniquely prefixed resources it creates; this inventory cites it as the
Expand Down
1 change: 1 addition & 0 deletions scripts/check_rpc_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ def get_test_params(method: RPCMethod, notebook_id: str | None) -> list[Any] | N
RPCMethod.GET_NOTEBOOK,
RPCMethod.GET_SOURCE_GUIDE,
RPCMethod.GET_SHARE_STATUS,
RPCMethod.LIST_TOOLSET_PREFERENCES,
RPCMethod.REMOVE_RECENTLY_VIEWED,
):
return [notebook_id]
Expand Down
2 changes: 2 additions & 0 deletions src/notebooklm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
SuggestedTopic,
TableCell,
TextSpan,
ToolsetPreference,
UnknownArtifactUserState,
# Warnings
UnknownTypeWarning,
Expand Down Expand Up @@ -293,6 +294,7 @@
"Notebook",
"PremiumFeatureInfo",
"ChatSession",
"ToolsetPreference",
"ChatSessionStatus",
"NotebookDescription",
"NotebookMetadata",
Expand Down
11 changes: 11 additions & 0 deletions src/notebooklm/_android/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
RateLimitError,
RPCError,
ServerError,
UnsupportedOperationError,
ValidationError,
)
from ..outcomes import CommitState
Expand All @@ -30,6 +31,7 @@
NotebookDescription,
PromptSuggestion,
SharePermission,
ToolsetPreference,
)
from .epoch import bind_workflow_epoch, reset_workflow_epoch
from .session import AndroidSession
Expand Down Expand Up @@ -507,6 +509,15 @@ async def remove_from_recent(self, notebook_id: str) -> None:
notebook_id,
)

async def get_toolset_preferences(self, notebook_id: str) -> builtins.list[ToolsetPreference]:
"""Raise ``UnsupportedOperationError`` on Android (``ToolManagementService`` is Web-only)."""
if not isinstance(notebook_id, str) or not notebook_id.strip():
raise ValidationError("notebook_id must be a non-empty string")
raise UnsupportedOperationError(
"get_toolset_preferences is not supported on the Android backend "
"(ToolManagementService is Web-only)"
)


__all__ = [
"AndroidNotebooksAPI",
Expand Down
5 changes: 5 additions & 0 deletions src/notebooklm/_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
NotebookDescription,
NotebookMetadata,
PromptSuggestion,
ToolsetPreference,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -257,6 +258,10 @@ async def get_description(self, notebook_id: str) -> NotebookDescription:
async def remove_from_recent(self, notebook_id: str) -> None:
"""Remove a notebook from the recently viewed list."""

@abstractmethod
async def get_toolset_preferences(self, notebook_id: str) -> builtins.list[ToolsetPreference]:
"""Return per-notebook Connected Apps / toolset preferences."""

@abstractmethod
async def get_raw(self, notebook_id: str) -> Any:
"""Get undecoded notebook data from the backend."""
Expand Down
22 changes: 22 additions & 0 deletions src/notebooklm/_types/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ class ChatSession:
id: str


@dataclass(frozen=True)
class ToolsetPreference:
"""Per-notebook Connected Apps / toolset preference returned by ``EEr8Nb``.

Returned by :meth:`~notebooklm._notebooks.NotebooksAPI.get_toolset_preferences`
(``ToolManagementService.ListNotebookToolsetPreferences`` on the Web backend).

Attributes:
toolset_id: Stable backend toolset identifier (e.g. ``"google-drive"``).
display_name: Human-readable toolset label (e.g. ``"Google Drive"``),
or ``None`` when omitted.
enabled: Whether this toolset is enabled for the notebook.
tools: Display labels of tools surfaced under this toolset
(e.g. ``("Search Drive", "Read Drive file")``).
"""

toolset_id: str
display_name: str | None = None
enabled: bool = False
tools: tuple[str, ...] = ()


@dataclass
class Notebook:
"""Represents a NotebookLM notebook."""
Expand Down
33 changes: 33 additions & 0 deletions src/notebooklm/_web/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
NotebookDescription,
PromptSuggestion,
SuggestedTopic,
ToolsetPreference,
)
from .contracts import RpcCaller
from .params.notebooks import (
Expand All @@ -45,12 +46,14 @@
build_get_notebook_params,
build_next_step_suggestions_params,
build_prompt_suggestions_params,
build_toolset_preferences_params,
build_update_notebook_params,
)
from .rows.chat import NextStepSuggestionRow
from .rows.notebooks import (
PromptSuggestionRow,
decode_notebook,
decode_toolset_preferences,
unwrap_next_step_suggestions,
unwrap_prompt_suggestions,
)
Expand Down Expand Up @@ -967,6 +970,36 @@ async def remove_from_recent(self, notebook_id: str) -> None:
allow_null=True,
)

async def get_toolset_preferences(self, notebook_id: str) -> builtins.list[ToolsetPreference]:
"""Get per-notebook Connected Apps / toolset preferences (``EEr8Nb``).

Queries ``ToolManagementService.ListNotebookToolsetPreferences`` for the
Connected Apps configured on ``notebook_id`` (for example ``google-drive``
with its ``Search Drive`` and ``Read Drive file`` tools).

Args:
notebook_id: The notebook ID.

Returns:
List of :class:`ToolsetPreference` entries (empty when no toolsets are
returned for the notebook).

Raises:
ValidationError: If ``notebook_id`` is empty or whitespace-only.
DecodingError: If a non-empty response deviates from the expected row layout.
"""
try:
params = build_toolset_preferences_params(notebook_id)
except ValueError as exc:
raise ValidationError(str(exc)) from exc
result = await self._rpc.rpc_call(
RPCMethod.LIST_TOOLSET_PREFERENCES,
params,
source_path=f"/notebook/{notebook_id}",
allow_null=True,
)
return decode_toolset_preferences(result)

async def get_raw(self, notebook_id: str) -> Any:
"""Get raw notebook data from API.

Expand Down
14 changes: 14 additions & 0 deletions src/notebooklm/_web/params/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,17 @@ def build_next_step_suggestions_params(
if source_ids:
params.append(nest_source_ids(list(source_ids), 2))
return params


def build_toolset_preferences_params(notebook_id: str) -> list[Any]:
"""Build ``LIST_TOOLSET_PREFERENCES`` (``EEr8Nb``) params.

``ToolManagementService.ListNotebookToolsetPreferences`` takes a single
notebook ID at field 1: ``[notebook_id]``.

Raises:
ValueError: if ``notebook_id`` is not a non-blank string.
"""
if not isinstance(notebook_id, str) or not notebook_id.strip():
raise ValueError("notebook_id must be a non-empty string")
return [notebook_id]
4 changes: 4 additions & 0 deletions src/notebooklm/_web/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,10 @@ def register_default_policies(registry: IdempotencyRegistry) -> None:
"read-only studio customization table; replay does not mutate any state"
),
RPCMethod.GET_SHARE_STATUS: "read-only share status fetch; replay does not mutate ACL state",
RPCMethod.LIST_TOOLSET_PREFERENCES: (
"read-only per-notebook Connected Apps / toolset preference fetch; "
"replay does not mutate notebook state"
),
RPCMethod.REMOVE_RECENTLY_VIEWED: (
"remove notebook from recents is idempotent; replay leaves it absent"
),
Expand Down
139 changes: 137 additions & 2 deletions src/notebooklm/_web/rows/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@

from ..._types.common import _datetime_from_timestamp
from ..._types.enums import ChatGoal, ChatResponseLength, SharePermission
from ...exceptions import UnknownRPCMethodError
from ...exceptions import DecodingError, UnknownRPCMethodError
from ...rpc import RPCMethod, safe_index

if TYPE_CHECKING:
from ..._types.notebooks import Notebook
from ..._types.notebooks import Notebook, ToolsetPreference

logger = logging.getLogger("notebooklm._types.notebooks")

__all__ = [
"PromptSuggestionRow",
"ProjectRow",
"ToolsetPreferenceRow",
"decode_notebook",
"decode_toolset_preferences",
"unwrap_next_step_suggestions",
"unwrap_prompt_suggestions",
]
Expand Down Expand Up @@ -411,3 +413,136 @@ def prompt(self) -> str:
into ``chat_ask`` without leaking a bullet-dash as the question (#1909).
"""
return _strip_leading_list_marker(self._str_at(self._PROMPT_POS))


_LIST_TOOLSET_PREFERENCES_METHOD_ID = RPCMethod.LIST_TOOLSET_PREFERENCES.value
_TOOLSET_PREFERENCES_ROWS_POS = 0


@dataclass(frozen=True)
class ToolsetPreferenceRow:
"""Typed view of one raw ``ListNotebookToolsetPreferences`` (``EEr8Nb``) row.

Wire layout (live-captured from ``ToolManagementService.ListNotebookToolsetPreferences``):

===== ============================================================
Index Meaning
===== ============================================================
0 toolset_id (str, e.g. ``"google-drive"``)
1 display_name (str | None, e.g. ``"Google Drive"``)
2 enabled (bool)
3 tools (list of ``[tool_label, ...]`` sub-rows)
===== ============================================================
"""

_raw: Any = field(repr=False)

_ID_POS: ClassVar[int] = 0
_DISPLAY_NAME_POS: ClassVar[int] = 1
_ENABLED_POS: ClassVar[int] = 2
_TOOLS_POS: ClassVar[int] = 3
_TOOL_LABEL_POS: ClassVar[int] = 0

@property
def toolset_id(self) -> str | None:
"""Toolset identifier at slot 0, or ``None`` when absent/malformed."""
if not isinstance(self._raw, list) or len(self._raw) <= self._ID_POS:
return None
value = self._raw[self._ID_POS]
return value if isinstance(value, str) and value.strip() else None

@property
def display_name(self) -> str | None:
"""Human-readable display name at slot 1, or ``None`` when omitted."""
if not isinstance(self._raw, list) or len(self._raw) <= self._DISPLAY_NAME_POS:
return None
value = self._raw[self._DISPLAY_NAME_POS]
return value if isinstance(value, str) and value else None

@property
def enabled(self) -> bool:
"""Boolean enabled flag at slot 2 (``False`` when omitted or non-bool)."""
if not isinstance(self._raw, list) or len(self._raw) <= self._ENABLED_POS:
return False
value = self._raw[self._ENABLED_POS]
return value if isinstance(value, bool) else False

@property
def tools(self) -> tuple[str, ...]:
"""Tuple of tool display labels extracted from nested ``[label]`` entries."""
if not isinstance(self._raw, list) or len(self._raw) <= self._TOOLS_POS:
return ()
raw_tools = self._raw[self._TOOLS_POS]
if raw_tools is None:
return ()
if not isinstance(raw_tools, list):
return ()
labels: list[str] = []
for item in raw_tools:
if isinstance(item, list) and len(item) > self._TOOL_LABEL_POS:
label = item[self._TOOL_LABEL_POS]
if isinstance(label, str) and label:
labels.append(label)
return tuple(labels)


def decode_toolset_preferences(
result: Any,
*,
source: str = "NotebooksAPI.get_toolset_preferences",
) -> list[ToolsetPreference]:
"""Decode a ``ListNotebookToolsetPreferences`` (``EEr8Nb``) response.

An empty response (``None``, ``[]``, or ``[None]`` / ``[[]]``) yields ``[]``.
A non-list outer envelope, non-list inner container, or malformed row missing
a non-empty string ``toolset_id`` raises :class:`DecodingError`.
"""
from ..._types.notebooks import ToolsetPreference

if result is None or result == []:
return []
if not isinstance(result, list):
raise DecodingError(
f"{source}: expected outer list envelope, got {type(result).__name__}",
method_id=_LIST_TOOLSET_PREFERENCES_METHOD_ID,
raw_response=reprlib.repr(result),
)
inner = safe_index(
result,
_TOOLSET_PREFERENCES_ROWS_POS,
method_id=_LIST_TOOLSET_PREFERENCES_METHOD_ID,
source=source,
)
if inner is None:
return []
if not isinstance(inner, list):
raise DecodingError(
f"{source}: expected list of toolset rows at index 0, got {type(inner).__name__}",
method_id=_LIST_TOOLSET_PREFERENCES_METHOD_ID,
raw_response=reprlib.repr(result),
)

preferences: list[ToolsetPreference] = []
for index, raw_row in enumerate(inner):
if not isinstance(raw_row, list):
raise DecodingError(
f"{source}: expected list row at index {index}, got {type(raw_row).__name__}",
method_id=_LIST_TOOLSET_PREFERENCES_METHOD_ID,
raw_response=reprlib.repr(raw_row),
)
row = ToolsetPreferenceRow(raw_row)
if row.toolset_id is None:
raise DecodingError(
f"{source}: toolset row at index {index} missing non-empty string toolset_id",
method_id=_LIST_TOOLSET_PREFERENCES_METHOD_ID,
raw_response=reprlib.repr(raw_row),
)
preferences.append(
ToolsetPreference(
toolset_id=row.toolset_id,
display_name=row.display_name,
enabled=row.enabled,
tools=row.tools,
)
)
return preferences
3 changes: 3 additions & 0 deletions src/notebooklm/rpc/_identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ class RPCMethod(str, Enum):

# Additional notebook operations
REMOVE_RECENTLY_VIEWED = "fejl7e" # -> RemoveRecentlyViewedProject
# -> ToolManagementService.ListNotebookToolsetPreferences. Web-only Connected Apps /
# toolset preference read (e.g. Google Drive search & file read tools).
LIST_TOOLSET_PREFERENCES = "EEr8Nb"

# User settings
# -> GetOrCreateAccount (account-level; may create the account on first call)
Expand Down
Loading
Loading