@charlie.act7/gemini-notebook-mcp 2.1.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +461 -434
- package/dist/auth/auth-manager.d.ts +2 -6
- package/dist/auth/auth-manager.d.ts.map +1 -1
- package/dist/auth/auth-manager.js +50 -58
- package/dist/auth/auth-manager.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -0
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +18 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +69 -6
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +101 -48
- package/dist/index.js.map +1 -1
- package/dist/library/notebook-library.d.ts +7 -3
- package/dist/library/notebook-library.d.ts.map +1 -1
- package/dist/library/notebook-library.js +190 -35
- package/dist/library/notebook-library.js.map +1 -1
- package/dist/library/types.d.ts +18 -0
- package/dist/library/types.d.ts.map +1 -1
- package/dist/notebooklm/artifact-store.d.ts +26 -0
- package/dist/notebooklm/artifact-store.d.ts.map +1 -0
- package/dist/notebooklm/artifact-store.js +102 -0
- package/dist/notebooklm/artifact-store.js.map +1 -0
- package/dist/notebooklm/audio.d.ts +3 -0
- package/dist/notebooklm/audio.d.ts.map +1 -1
- package/dist/notebooklm/audio.js +72 -39
- package/dist/notebooklm/audio.js.map +1 -1
- package/dist/notebooklm/chat.d.ts.map +1 -1
- package/dist/notebooklm/chat.js +22 -14
- package/dist/notebooklm/chat.js.map +1 -1
- package/dist/notebooklm/citations.d.ts +17 -22
- package/dist/notebooklm/citations.d.ts.map +1 -1
- package/dist/notebooklm/citations.js +148 -115
- package/dist/notebooklm/citations.js.map +1 -1
- package/dist/notebooklm/selectors.d.ts +54 -2
- package/dist/notebooklm/selectors.d.ts.map +1 -1
- package/dist/notebooklm/selectors.js +109 -2
- package/dist/notebooklm/selectors.js.map +1 -1
- package/dist/notebooklm/sources.d.ts +18 -3
- package/dist/notebooklm/sources.d.ts.map +1 -1
- package/dist/notebooklm/sources.js +128 -32
- package/dist/notebooklm/sources.js.map +1 -1
- package/dist/resources/resource-handlers.js +2 -2
- package/dist/resources/resource-handlers.js.map +1 -1
- package/dist/session/browser-session.d.ts +17 -10
- package/dist/session/browser-session.d.ts.map +1 -1
- package/dist/session/browser-session.js +165 -169
- package/dist/session/browser-session.js.map +1 -1
- package/dist/session/session-manager.d.ts +12 -7
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +120 -80
- package/dist/session/session-manager.js.map +1 -1
- package/dist/session/shared-context-manager.d.ts.map +1 -1
- package/dist/session/shared-context-manager.js +12 -10
- package/dist/session/shared-context-manager.js.map +1 -1
- package/dist/tools/definitions/ask-question.d.ts +4 -3
- package/dist/tools/definitions/ask-question.d.ts.map +1 -1
- package/dist/tools/definitions/ask-question.js +9 -109
- package/dist/tools/definitions/ask-question.js.map +1 -1
- package/dist/tools/definitions/notebook-management.d.ts.map +1 -1
- package/dist/tools/definitions/notebook-management.js +47 -4
- package/dist/tools/definitions/notebook-management.js.map +1 -1
- package/dist/tools/definitions/session-management.d.ts.map +1 -1
- package/dist/tools/definitions/session-management.js +2 -0
- package/dist/tools/definitions/session-management.js.map +1 -1
- package/dist/tools/definitions/sources.d.ts +8 -0
- package/dist/tools/definitions/sources.d.ts.map +1 -1
- package/dist/tools/definitions/sources.js +152 -15
- package/dist/tools/definitions/sources.js.map +1 -1
- package/dist/tools/definitions/system.d.ts.map +1 -1
- package/dist/tools/definitions/system.js +23 -19
- package/dist/tools/definitions/system.js.map +1 -1
- package/dist/tools/definitions.d.ts +3 -3
- package/dist/tools/definitions.d.ts.map +1 -1
- package/dist/tools/definitions.js +5 -9
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/handlers.d.ts +101 -14
- package/dist/tools/handlers.d.ts.map +1 -1
- package/dist/tools/handlers.js +280 -76
- package/dist/tools/handlers.js.map +1 -1
- package/dist/tools/validation.d.ts +6 -0
- package/dist/tools/validation.d.ts.map +1 -0
- package/dist/tools/validation.js +267 -0
- package/dist/tools/validation.js.map +1 -0
- package/dist/transport/http.d.ts +2 -0
- package/dist/transport/http.d.ts.map +1 -1
- package/dist/transport/http.js +6 -1
- package/dist/transport/http.js.map +1 -1
- package/dist/types.d.ts +15 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/cleanup-manager.d.ts +35 -115
- package/dist/utils/cleanup-manager.d.ts.map +1 -1
- package/dist/utils/cleanup-manager.js +179 -632
- package/dist/utils/cleanup-manager.js.map +1 -1
- package/dist/utils/disclaimer.d.ts +2 -1
- package/dist/utils/disclaimer.d.ts.map +1 -1
- package/dist/utils/disclaimer.js +3 -2
- package/dist/utils/disclaimer.js.map +1 -1
- package/dist/utils/logger.d.ts +26 -39
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +104 -50
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/operation.d.ts +8 -0
- package/dist/utils/operation.d.ts.map +1 -0
- package/dist/utils/operation.js +42 -0
- package/dist/utils/operation.js.map +1 -0
- package/dist/utils/page-utils.d.ts.map +1 -1
- package/dist/utils/page-utils.js +3 -3
- package/dist/utils/page-utils.js.map +1 -1
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +17 -0
- package/dist/version.js.map +1 -0
- package/docs/configuration.md +205 -179
- package/docs/implementation-plan.md +135 -0
- package/docs/tools.md +473 -412
- package/docs/troubleshooting.md +161 -159
- package/docs/usage-guide.md +282 -282
- package/package.json +4 -3
|
@@ -16,7 +16,7 @@ import type { Page } from "patchright";
|
|
|
16
16
|
import type { SharedContextManager } from "./shared-context-manager.js";
|
|
17
17
|
import type { AuthManager } from "../auth/auth-manager.js";
|
|
18
18
|
import { type SourceFormat, type ExtractCitationsResult } from "../notebooklm/citations.js";
|
|
19
|
-
import { type AddSourceInput, type AddSourceResult } from "../notebooklm/sources.js";
|
|
19
|
+
import { type AddSourceInput, type AddSourceResult, type SourceSummary } from "../notebooklm/sources.js";
|
|
20
20
|
import { type GenerateAudioOptions, type AudioGenerationResult, type DownloadAudioResult } from "../notebooklm/audio.js";
|
|
21
21
|
import type { SessionInfo, ProgressCallback } from "../types.js";
|
|
22
22
|
export declare class BrowserSession {
|
|
@@ -62,37 +62,44 @@ export declare class BrowserSession {
|
|
|
62
62
|
* Ask a question to NotebookLM
|
|
63
63
|
*/
|
|
64
64
|
private runExclusive;
|
|
65
|
-
ask(question: string, sendProgress?: ProgressCallback): Promise<string>;
|
|
66
|
-
askAndExtractCitations(question: string, format: SourceFormat, sendProgress?: ProgressCallback): Promise<ExtractCitationsResult>;
|
|
65
|
+
ask(question: string, sendProgress?: ProgressCallback, signal?: AbortSignal): Promise<string>;
|
|
66
|
+
askAndExtractCitations(question: string, format: SourceFormat, sendProgress?: ProgressCallback, signal?: AbortSignal): Promise<ExtractCitationsResult>;
|
|
67
67
|
private askUnlocked;
|
|
68
68
|
/**
|
|
69
69
|
* Add a new source (URL or pasted text) to the active notebook page
|
|
70
70
|
* (issue #25). Lazily initialises the session so the caller can use this
|
|
71
71
|
* without first running `ask()`.
|
|
72
72
|
*/
|
|
73
|
-
addSource(input: AddSourceInput): Promise<AddSourceResult>;
|
|
73
|
+
addSource(input: AddSourceInput, signal?: AbortSignal): Promise<AddSourceResult>;
|
|
74
74
|
private addSourceUnlocked;
|
|
75
|
+
listSources(signal?: AbortSignal): Promise<SourceSummary[]>;
|
|
76
|
+
getSource(selector: {
|
|
77
|
+
sourceId?: string;
|
|
78
|
+
name?: string;
|
|
79
|
+
}, signal?: AbortSignal): Promise<SourceSummary | null>;
|
|
75
80
|
/**
|
|
76
81
|
* Generate an Audio Overview for the active notebook (issue #11).
|
|
77
82
|
*/
|
|
78
|
-
generateAudio(options?: GenerateAudioOptions): Promise<AudioGenerationResult>;
|
|
83
|
+
generateAudio(options?: GenerateAudioOptions, signal?: AbortSignal): Promise<AudioGenerationResult>;
|
|
79
84
|
private generateAudioUnlocked;
|
|
80
85
|
/**
|
|
81
86
|
* Non-blocking probe for the current Audio Overview state (issue #11).
|
|
82
87
|
*/
|
|
83
|
-
getAudioStatus(): Promise<AudioGenerationResult>;
|
|
88
|
+
getAudioStatus(signal?: AbortSignal): Promise<AudioGenerationResult>;
|
|
84
89
|
private getAudioStatusUnlocked;
|
|
85
90
|
/**
|
|
86
91
|
* Download the most recent Audio Overview (issue #11).
|
|
87
92
|
*/
|
|
88
|
-
downloadAudio(destinationDir: string): Promise<DownloadAudioResult>;
|
|
93
|
+
downloadAudio(destinationDir: string, signal?: AbortSignal): Promise<DownloadAudioResult>;
|
|
89
94
|
private downloadAudioUnlocked;
|
|
95
|
+
private withAuthenticatedNotebookPage;
|
|
96
|
+
private dismissUnexpectedOverlays;
|
|
90
97
|
/**
|
|
91
98
|
* Pull DOM-level citations from the most recent answer on this session's
|
|
92
99
|
* page (issue #20). Must be called immediately after `ask()` — before any
|
|
93
100
|
* follow-up question disturbs the source panel.
|
|
94
101
|
*/
|
|
95
|
-
extractCitations(answer: string, format: SourceFormat): Promise<ExtractCitationsResult>;
|
|
102
|
+
extractCitations(answer: string, format: SourceFormat, signal?: AbortSignal): Promise<ExtractCitationsResult>;
|
|
96
103
|
private extractCitationsUnlocked;
|
|
97
104
|
/**
|
|
98
105
|
* Find the chat input element
|
|
@@ -108,7 +115,7 @@ export declare class BrowserSession {
|
|
|
108
115
|
* Detect if a rate limit error occurred
|
|
109
116
|
*
|
|
110
117
|
* Searches the page for error messages indicating rate limit/quota exhaustion.
|
|
111
|
-
*
|
|
118
|
+
* Account limits vary and can change; do not assume a fixed allowance.
|
|
112
119
|
*
|
|
113
120
|
* @returns true if rate limit error detected, false otherwise
|
|
114
121
|
*/
|
|
@@ -116,7 +123,7 @@ export declare class BrowserSession {
|
|
|
116
123
|
/**
|
|
117
124
|
* Reset the chat history (start a new conversation)
|
|
118
125
|
*/
|
|
119
|
-
reset(): Promise<void>;
|
|
126
|
+
reset(signal?: AbortSignal): Promise<void>;
|
|
120
127
|
private resetUnlocked;
|
|
121
128
|
/**
|
|
122
129
|
* Close the session
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-session.d.ts","sourceRoot":"","sources":["../../src/session/browser-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAkB,IAAI,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAI3D,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"browser-session.d.ts","sourceRoot":"","sources":["../../src/session/browser-session.ts"],"names":[],"mappings":"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"}
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { humanType, randomDelay, randomInt } from "../utils/stealth-utils.js";
|
|
16
16
|
import { waitForStableAnswer, snapshotPriorAnswers } from "../notebooklm/chat.js";
|
|
17
|
-
import { Selectors, joinAlt } from "../notebooklm/selectors.js";
|
|
17
|
+
import { Selectors, findVisibleSelector, joinAlt } from "../notebooklm/selectors.js";
|
|
18
18
|
import { extractCitations as extractCitationsFromPage, } from "../notebooklm/citations.js";
|
|
19
|
-
import { addSource as addSourceToPage, } from "../notebooklm/sources.js";
|
|
19
|
+
import { addSource as addSourceToPage, listSources as listSourcesOnPage, getSource as getSourceOnPage, } from "../notebooklm/sources.js";
|
|
20
20
|
import { generateAudioOverview as generateAudioOnPage, downloadAudioOverview as downloadAudioOnPage, getAudioStatusOnPage, } from "../notebooklm/audio.js";
|
|
21
21
|
import { getRuntimeConfig } from "../config.js";
|
|
22
|
-
import { log } from "../utils/logger.js";
|
|
23
|
-
import { RateLimitError } from "../errors.js";
|
|
22
|
+
import { hashLogValue, log } from "../utils/logger.js";
|
|
23
|
+
import { RateLimitError, UiChangedError } from "../errors.js";
|
|
24
|
+
import { runWithOperationBoundary, throwIfAborted, } from "../utils/operation.js";
|
|
24
25
|
export class BrowserSession {
|
|
25
26
|
sessionId;
|
|
26
27
|
notebookUrl;
|
|
@@ -41,7 +42,7 @@ export class BrowserSession {
|
|
|
41
42
|
this.createdAt = Date.now();
|
|
42
43
|
this.lastActivity = Date.now();
|
|
43
44
|
this.messageCount = 0;
|
|
44
|
-
log.info(`🆕 BrowserSession ${sessionId} created`);
|
|
45
|
+
log.info(`🆕 BrowserSession ${hashLogValue(sessionId)} created`);
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Initialize the session by creating a page and navigating to the notebook
|
|
@@ -49,10 +50,10 @@ export class BrowserSession {
|
|
|
49
50
|
async init() {
|
|
50
51
|
const config = getRuntimeConfig();
|
|
51
52
|
if (this.initialized) {
|
|
52
|
-
log.warning(`⚠️ Session ${this.sessionId} already initialized`);
|
|
53
|
+
log.warning(`⚠️ Session ${hashLogValue(this.sessionId)} already initialized`);
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
|
-
log.info(`🚀 Initializing session ${this.sessionId}...`);
|
|
56
|
+
log.info(`🚀 Initializing session ${hashLogValue(this.sessionId)}...`);
|
|
56
57
|
try {
|
|
57
58
|
// Ensure a valid shared context
|
|
58
59
|
this.context = await this.sharedContextManager.getOrCreateContext();
|
|
@@ -73,7 +74,7 @@ export class BrowserSession {
|
|
|
73
74
|
}
|
|
74
75
|
log.success(` ✅ Created new page`);
|
|
75
76
|
// Navigate to notebook
|
|
76
|
-
log.info(` 🌐 Navigating to
|
|
77
|
+
log.info(` 🌐 Navigating to configured notebook`);
|
|
77
78
|
await this.page.goto(this.notebookUrl, {
|
|
78
79
|
waitUntil: "domcontentloaded",
|
|
79
80
|
timeout: config.browserTimeout,
|
|
@@ -84,7 +85,7 @@ export class BrowserSession {
|
|
|
84
85
|
const cookiesAreValid = await this.authManager.validateCookiesExpiry(this.context);
|
|
85
86
|
const isAuthenticated = cookiesAreValid && !this.isAuthenticationPage();
|
|
86
87
|
if (!isAuthenticated) {
|
|
87
|
-
log.warning(` 🔑 Session ${this.sessionId} needs authentication`);
|
|
88
|
+
log.warning(` 🔑 Session ${hashLogValue(this.sessionId)} needs authentication`);
|
|
88
89
|
const loginSuccess = await this.ensureAuthenticated();
|
|
89
90
|
if (!loginSuccess) {
|
|
90
91
|
throw new Error("Failed to authenticate session");
|
|
@@ -118,10 +119,10 @@ export class BrowserSession {
|
|
|
118
119
|
await this.authManager.saveBrowserState(this.context, this.page);
|
|
119
120
|
this.initialized = true;
|
|
120
121
|
this.updateActivity();
|
|
121
|
-
log.success(`✅ Session ${this.sessionId} initialized successfully`);
|
|
122
|
+
log.success(`✅ Session ${hashLogValue(this.sessionId)} initialized successfully`);
|
|
122
123
|
}
|
|
123
124
|
catch (error) {
|
|
124
|
-
log.error(`❌ Failed to initialize session ${this.sessionId}: ${error}`);
|
|
125
|
+
log.error(`❌ Failed to initialize session ${hashLogValue(this.sessionId)}: ${error}`);
|
|
125
126
|
if (this.page) {
|
|
126
127
|
await this.page.close();
|
|
127
128
|
this.page = null;
|
|
@@ -144,29 +145,16 @@ export class BrowserSession {
|
|
|
144
145
|
throw new Error("Page not initialized");
|
|
145
146
|
}
|
|
146
147
|
try {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
state: "visible", // ONLY check visibility (NO disabled check!)
|
|
148
|
+
log.info(" ⏳ Waiting for a verified chat input...");
|
|
149
|
+
await this.page.waitForSelector(joinAlt(Selectors.chat.queryInput), {
|
|
150
|
+
timeout: 15_000,
|
|
151
|
+
state: "visible",
|
|
152
152
|
});
|
|
153
153
|
log.success(" ✅ Chat input ready!");
|
|
154
154
|
}
|
|
155
|
-
catch {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
log.info(" ⏳ Trying fallback selector (aria-label)...");
|
|
159
|
-
await this.page.waitForSelector('textarea[aria-label="Feld für Anfragen"]', {
|
|
160
|
-
timeout: 5000, // Python uses 5s for fallback
|
|
161
|
-
state: "visible",
|
|
162
|
-
});
|
|
163
|
-
log.success(" ✅ Chat input ready (fallback)!");
|
|
164
|
-
}
|
|
165
|
-
catch (error) {
|
|
166
|
-
log.error(` ❌ NotebookLM interface not ready: ${error}`);
|
|
167
|
-
throw new Error("Could not find NotebookLM chat input. " +
|
|
168
|
-
"Please ensure the notebook page has loaded correctly.", { cause: error });
|
|
169
|
-
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
log.diagnostic("chat.queryInput verification failure", String(error));
|
|
157
|
+
throw new UiChangedError("chat.queryInput");
|
|
170
158
|
}
|
|
171
159
|
}
|
|
172
160
|
isPageClosedSafe() {
|
|
@@ -202,7 +190,7 @@ export class BrowserSession {
|
|
|
202
190
|
if (!this.page) {
|
|
203
191
|
throw new Error("Page not initialized");
|
|
204
192
|
}
|
|
205
|
-
log.info(`🔑 Checking authentication for session ${this.sessionId}...`);
|
|
193
|
+
log.info(`🔑 Checking authentication for session ${hashLogValue(this.sessionId)}...`);
|
|
206
194
|
// Check cookie validity
|
|
207
195
|
const isValid = await this.authManager.validateCookiesExpiry(this.context);
|
|
208
196
|
if (isValid && !this.isAuthenticationPage()) {
|
|
@@ -315,44 +303,29 @@ export class BrowserSession {
|
|
|
315
303
|
/**
|
|
316
304
|
* Ask a question to NotebookLM
|
|
317
305
|
*/
|
|
318
|
-
runExclusive(operation) {
|
|
306
|
+
runExclusive(operation, signal) {
|
|
307
|
+
throwIfAborted(signal);
|
|
319
308
|
const result = this.operationTail.then(async () => {
|
|
309
|
+
throwIfAborted(signal);
|
|
320
310
|
this.updateActivity();
|
|
321
311
|
return await operation();
|
|
322
312
|
});
|
|
323
313
|
this.operationTail = result.then(() => undefined, () => undefined);
|
|
324
314
|
return result;
|
|
325
315
|
}
|
|
326
|
-
async ask(question, sendProgress) {
|
|
327
|
-
return await this.runExclusive(() => this.askUnlocked(question, sendProgress));
|
|
316
|
+
async ask(question, sendProgress, signal) {
|
|
317
|
+
return await this.runExclusive(() => this.askUnlocked(question, sendProgress, signal), signal);
|
|
328
318
|
}
|
|
329
|
-
async askAndExtractCitations(question, format, sendProgress) {
|
|
319
|
+
async askAndExtractCitations(question, format, sendProgress, signal) {
|
|
330
320
|
return await this.runExclusive(async () => {
|
|
331
|
-
const answer = await this.askUnlocked(question, sendProgress);
|
|
332
|
-
return await this.extractCitationsUnlocked(answer, format);
|
|
333
|
-
});
|
|
321
|
+
const answer = await this.askUnlocked(question, sendProgress, signal);
|
|
322
|
+
return await this.extractCitationsUnlocked(answer, format, signal);
|
|
323
|
+
}, signal);
|
|
334
324
|
}
|
|
335
|
-
async askUnlocked(question, sendProgress) {
|
|
325
|
+
async askUnlocked(question, sendProgress, signal) {
|
|
336
326
|
const config = getRuntimeConfig();
|
|
337
|
-
const askOnce = async () => {
|
|
338
|
-
|
|
339
|
-
log.warning(` ℹ️ Session not initialized or page missing → re-initializing...`);
|
|
340
|
-
await this.init();
|
|
341
|
-
}
|
|
342
|
-
log.info(`💬 [${this.sessionId}] Asking: "${question.substring(0, 100)}..."`);
|
|
343
|
-
const page = this.page;
|
|
344
|
-
// Ensure we're still authenticated
|
|
345
|
-
await sendProgress?.("Verifying authentication...", 2, 5);
|
|
346
|
-
const isAuth = (await this.authManager.validateCookiesExpiry(this.context)) &&
|
|
347
|
-
!this.isAuthenticationPage();
|
|
348
|
-
if (!isAuth) {
|
|
349
|
-
log.warning(` 🔑 Session expired, re-authenticating...`);
|
|
350
|
-
await sendProgress?.("Re-authenticating session...", 2, 5);
|
|
351
|
-
const reAuthSuccess = await this.ensureAuthenticated();
|
|
352
|
-
if (!reAuthSuccess) {
|
|
353
|
-
throw new Error("Failed to re-authenticate session");
|
|
354
|
-
}
|
|
355
|
-
}
|
|
327
|
+
const askOnce = async (page) => {
|
|
328
|
+
log.info(`💬 [${hashLogValue(this.sessionId)}] Asking question (${question.length} characters)`);
|
|
356
329
|
// Hydrate and snapshot existing responses BEFORE asking. The current
|
|
357
330
|
// NotebookLM UI virtualises history, so the textarea can be visible
|
|
358
331
|
// before prior chat cards have mounted.
|
|
@@ -362,8 +335,7 @@ export class BrowserSession {
|
|
|
362
335
|
// Find the chat input
|
|
363
336
|
const inputSelector = await this.findChatInput();
|
|
364
337
|
if (!inputSelector) {
|
|
365
|
-
throw new
|
|
366
|
-
"Please check if the notebook page has loaded correctly.");
|
|
338
|
+
throw new UiChangedError("chat.queryInput");
|
|
367
339
|
}
|
|
368
340
|
log.info(` ⌨️ Typing question with human-like behavior...`);
|
|
369
341
|
await sendProgress?.("Typing question with human-like behavior...", 2, 5);
|
|
@@ -416,110 +388,152 @@ export class BrowserSession {
|
|
|
416
388
|
// Check for rate limit errors AFTER receiving answer
|
|
417
389
|
log.info(` 🔍 Checking for rate limit errors...`);
|
|
418
390
|
if (await this.detectRateLimitError()) {
|
|
419
|
-
throw new RateLimitError("NotebookLM
|
|
391
|
+
throw new RateLimitError("NotebookLM reported a rate or quota limit");
|
|
420
392
|
}
|
|
421
393
|
// Update session stats
|
|
422
394
|
this.messageCount++;
|
|
423
395
|
this.updateActivity();
|
|
424
|
-
log.success(`✅ [${this.sessionId}] Received answer (${answer.length} chars, ${this.messageCount} total messages)`);
|
|
396
|
+
log.success(`✅ [${hashLogValue(this.sessionId)}] Received answer (${answer.length} chars, ${this.messageCount} total messages)`);
|
|
425
397
|
return answer;
|
|
426
398
|
};
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
if (/has been closed|Target .* closed|Browser has been closed|Context .* closed/i.test(msg)) {
|
|
433
|
-
log.warning(` ♻️ Detected closed page/context. Recovering session and retrying ask...`);
|
|
434
|
-
try {
|
|
435
|
-
this.initialized = false;
|
|
436
|
-
if (this.page) {
|
|
437
|
-
try {
|
|
438
|
-
await this.page.close();
|
|
439
|
-
}
|
|
440
|
-
catch {
|
|
441
|
-
/* page already gone */
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
this.page = null;
|
|
445
|
-
await this.init();
|
|
446
|
-
return await askOnce();
|
|
447
|
-
}
|
|
448
|
-
catch (e2) {
|
|
449
|
-
log.error(`❌ Recovery failed: ${e2}`);
|
|
450
|
-
throw e2;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
log.error(`❌ [${this.sessionId}] Failed to ask question: ${msg}`);
|
|
454
|
-
throw error;
|
|
455
|
-
}
|
|
399
|
+
await sendProgress?.("Verifying authentication...", 2, 5);
|
|
400
|
+
return await this.withAuthenticatedNotebookPage("ask_question", askOnce, {
|
|
401
|
+
signal,
|
|
402
|
+
timeoutMs: config.answerTimeoutMs + 60_000,
|
|
403
|
+
});
|
|
456
404
|
}
|
|
457
405
|
/**
|
|
458
406
|
* Add a new source (URL or pasted text) to the active notebook page
|
|
459
407
|
* (issue #25). Lazily initialises the session so the caller can use this
|
|
460
408
|
* without first running `ask()`.
|
|
461
409
|
*/
|
|
462
|
-
async addSource(input) {
|
|
463
|
-
return await this.runExclusive(() => this.addSourceUnlocked(input));
|
|
410
|
+
async addSource(input, signal) {
|
|
411
|
+
return await this.runExclusive(() => this.addSourceUnlocked(input, signal), signal);
|
|
464
412
|
}
|
|
465
|
-
async addSourceUnlocked(input) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
return await
|
|
413
|
+
async addSourceUnlocked(input, signal) {
|
|
414
|
+
return await this.withAuthenticatedNotebookPage("add_source", (page) => addSourceToPage(page, input), { signal, timeoutMs: 120_000 });
|
|
415
|
+
}
|
|
416
|
+
async listSources(signal) {
|
|
417
|
+
return await this.runExclusive(() => this.withAuthenticatedNotebookPage("list_sources", listSourcesOnPage, {
|
|
418
|
+
signal,
|
|
419
|
+
timeoutMs: 30_000,
|
|
420
|
+
}), signal);
|
|
421
|
+
}
|
|
422
|
+
async getSource(selector, signal) {
|
|
423
|
+
return await this.runExclusive(() => this.withAuthenticatedNotebookPage("get_source", (page) => getSourceOnPage(page, selector), { signal, timeoutMs: 30_000 }), signal);
|
|
470
424
|
}
|
|
471
425
|
/**
|
|
472
426
|
* Generate an Audio Overview for the active notebook (issue #11).
|
|
473
427
|
*/
|
|
474
|
-
async generateAudio(options = {}) {
|
|
475
|
-
return await this.runExclusive(() => this.generateAudioUnlocked(options));
|
|
428
|
+
async generateAudio(options = {}, signal) {
|
|
429
|
+
return await this.runExclusive(() => this.generateAudioUnlocked(options, signal), signal);
|
|
476
430
|
}
|
|
477
|
-
async generateAudioUnlocked(options = {}) {
|
|
478
|
-
|
|
479
|
-
await this.init();
|
|
480
|
-
}
|
|
481
|
-
return await generateAudioOnPage(this.page, options);
|
|
431
|
+
async generateAudioUnlocked(options = {}, signal) {
|
|
432
|
+
return await this.withAuthenticatedNotebookPage("generate_audio", (page) => generateAudioOnPage(page, options), { signal, timeoutMs: (options.timeoutMs ?? 600_000) + 30_000 });
|
|
482
433
|
}
|
|
483
434
|
/**
|
|
484
435
|
* Non-blocking probe for the current Audio Overview state (issue #11).
|
|
485
436
|
*/
|
|
486
|
-
async getAudioStatus() {
|
|
487
|
-
return await this.runExclusive(() => this.getAudioStatusUnlocked());
|
|
437
|
+
async getAudioStatus(signal) {
|
|
438
|
+
return await this.runExclusive(() => this.getAudioStatusUnlocked(signal), signal);
|
|
488
439
|
}
|
|
489
|
-
async getAudioStatusUnlocked() {
|
|
490
|
-
|
|
491
|
-
await this.init();
|
|
492
|
-
}
|
|
493
|
-
return await getAudioStatusOnPage(this.page);
|
|
440
|
+
async getAudioStatusUnlocked(signal) {
|
|
441
|
+
return await this.withAuthenticatedNotebookPage("get_audio_status", (page) => getAudioStatusOnPage(page), { signal, timeoutMs: 30_000 });
|
|
494
442
|
}
|
|
495
443
|
/**
|
|
496
444
|
* Download the most recent Audio Overview (issue #11).
|
|
497
445
|
*/
|
|
498
|
-
async downloadAudio(destinationDir) {
|
|
499
|
-
return await this.runExclusive(() => this.downloadAudioUnlocked(destinationDir));
|
|
446
|
+
async downloadAudio(destinationDir, signal) {
|
|
447
|
+
return await this.runExclusive(() => this.downloadAudioUnlocked(destinationDir, signal), signal);
|
|
448
|
+
}
|
|
449
|
+
async downloadAudioUnlocked(destinationDir, signal) {
|
|
450
|
+
return await this.withAuthenticatedNotebookPage("download_audio", (page) => downloadAudioOnPage(page, destinationDir), { signal, timeoutMs: 90_000 });
|
|
451
|
+
}
|
|
452
|
+
async withAuthenticatedNotebookPage(operationName, operation, options = {}) {
|
|
453
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
454
|
+
try {
|
|
455
|
+
return await runWithOperationBoundary(operationName, async () => {
|
|
456
|
+
if (!this.initialized ||
|
|
457
|
+
!this.page ||
|
|
458
|
+
this.isPageClosedSafe() ||
|
|
459
|
+
this.isAuthenticationPage()) {
|
|
460
|
+
if (this.page && !this.isPageClosedSafe()) {
|
|
461
|
+
await this.page.close().catch(() => undefined);
|
|
462
|
+
}
|
|
463
|
+
this.page = null;
|
|
464
|
+
this.initialized = false;
|
|
465
|
+
await this.init();
|
|
466
|
+
}
|
|
467
|
+
if (!this.page || this.isAuthenticationPage()) {
|
|
468
|
+
throw new Error("AUTH_REQUIRED: Google requested sign-in");
|
|
469
|
+
}
|
|
470
|
+
const cookiesAreValid = await this.authManager.validateCookiesExpiry(this.context);
|
|
471
|
+
if (!cookiesAreValid) {
|
|
472
|
+
const restored = await this.ensureAuthenticated();
|
|
473
|
+
if (!restored || !this.page || this.isAuthenticationPage()) {
|
|
474
|
+
throw new Error("AUTH_REQUIRED: Google requested sign-in");
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
await this.dismissUnexpectedOverlays();
|
|
478
|
+
if (!this.page) {
|
|
479
|
+
throw new Error("BROWSER_CRASHED: NotebookLM page is unavailable");
|
|
480
|
+
}
|
|
481
|
+
return await operation(this.page);
|
|
482
|
+
}, {
|
|
483
|
+
signal: options.signal,
|
|
484
|
+
timeoutMs: options.timeoutMs,
|
|
485
|
+
onInterrupt: async () => {
|
|
486
|
+
if (this.page && !this.isPageClosedSafe()) {
|
|
487
|
+
await this.page.close().catch(() => undefined);
|
|
488
|
+
}
|
|
489
|
+
this.page = null;
|
|
490
|
+
this.initialized = false;
|
|
491
|
+
},
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
if (attempt === 0 &&
|
|
496
|
+
options.retryRecoverable !== false &&
|
|
497
|
+
isRecoverableBrowserOperationError(error)) {
|
|
498
|
+
log.warning(` ♻️ Recovering browser before retrying ${operationName}`);
|
|
499
|
+
if (this.page && !this.isPageClosedSafe()) {
|
|
500
|
+
await this.page.close().catch(() => undefined);
|
|
501
|
+
}
|
|
502
|
+
this.page = null;
|
|
503
|
+
this.initialized = false;
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
throw error;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
throw new Error(`${operationName} failed after browser recovery`);
|
|
500
510
|
}
|
|
501
|
-
async
|
|
502
|
-
if (!this.
|
|
503
|
-
|
|
511
|
+
async dismissUnexpectedOverlays() {
|
|
512
|
+
if (!this.page)
|
|
513
|
+
return;
|
|
514
|
+
const dialog = this.page.locator(Selectors.chat.dialog).first();
|
|
515
|
+
if (await dialog.isVisible({ timeout: 250 }).catch(() => false)) {
|
|
516
|
+
await this.page.keyboard.press("Escape").catch(() => undefined);
|
|
517
|
+
await this.page.waitForTimeout(150).catch(() => undefined);
|
|
504
518
|
}
|
|
505
|
-
return await downloadAudioOnPage(this.page, destinationDir);
|
|
506
519
|
}
|
|
507
520
|
/**
|
|
508
521
|
* Pull DOM-level citations from the most recent answer on this session's
|
|
509
522
|
* page (issue #20). Must be called immediately after `ask()` — before any
|
|
510
523
|
* follow-up question disturbs the source panel.
|
|
511
524
|
*/
|
|
512
|
-
async extractCitations(answer, format) {
|
|
513
|
-
return await this.runExclusive(() => this.extractCitationsUnlocked(answer, format));
|
|
525
|
+
async extractCitations(answer, format, signal) {
|
|
526
|
+
return await this.runExclusive(() => this.extractCitationsUnlocked(answer, format, signal), signal);
|
|
514
527
|
}
|
|
515
|
-
async extractCitationsUnlocked(answer, format) {
|
|
528
|
+
async extractCitationsUnlocked(answer, format, signal) {
|
|
516
529
|
if (format === "none" || !this.page || this.isPageClosedSafe()) {
|
|
517
530
|
return { citations: [], formattedAnswer: answer };
|
|
518
531
|
}
|
|
519
532
|
try {
|
|
520
|
-
return await extractCitationsFromPage(this.page, answer, format);
|
|
533
|
+
return await extractCitationsFromPage(this.page, answer, format, { signal });
|
|
521
534
|
}
|
|
522
535
|
catch (err) {
|
|
536
|
+
throwIfAborted(signal);
|
|
523
537
|
log.warning(` ⚠️ Citation extraction failed: ${err}`);
|
|
524
538
|
return { citations: [], formattedAnswer: answer };
|
|
525
539
|
}
|
|
@@ -537,31 +551,8 @@ export class BrowserSession {
|
|
|
537
551
|
if (!this.page) {
|
|
538
552
|
return null;
|
|
539
553
|
}
|
|
540
|
-
const selectors = [
|
|
541
|
-
// Stable class — language-agnostic.
|
|
542
|
-
"textarea.query-box-input",
|
|
543
|
-
// Locale-bound aria-label fallbacks for older builds.
|
|
544
|
-
'textarea[aria-label="Feld für Anfragen"]',
|
|
545
|
-
'textarea[aria-label*="anfrag" i]',
|
|
546
|
-
'textarea[aria-label*="query" i]',
|
|
547
|
-
'textarea[aria-label*="zone de requete" i]',
|
|
548
|
-
'textarea[aria-label*="requete" i]',
|
|
549
|
-
'textarea[aria-label*="consulta" i]',
|
|
550
|
-
'textarea[aria-label*="domanda" i]',
|
|
551
|
-
];
|
|
552
554
|
const tryFind = async () => {
|
|
553
|
-
|
|
554
|
-
try {
|
|
555
|
-
const element = await this.page.$(selector);
|
|
556
|
-
if (element && (await element.isVisible())) {
|
|
557
|
-
return selector;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
catch {
|
|
561
|
-
continue;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
return null;
|
|
555
|
+
return await findVisibleSelector(this.page, "chat.queryInput", 300);
|
|
565
556
|
};
|
|
566
557
|
let hit = await tryFind();
|
|
567
558
|
if (hit) {
|
|
@@ -586,7 +577,7 @@ export class BrowserSession {
|
|
|
586
577
|
if (url.includes("addSource=true") || url.includes("?")) {
|
|
587
578
|
const cleanUrl = url.replace(/[?&]addSource=true/g, "").replace(/&$/, "");
|
|
588
579
|
if (cleanUrl !== url) {
|
|
589
|
-
log.
|
|
580
|
+
log.diagnostic("Cleaning NotebookLM URL state", `${url} -> ${cleanUrl}`);
|
|
590
581
|
await this.page
|
|
591
582
|
.goto(cleanUrl, { waitUntil: "domcontentloaded", timeout: 15_000 })
|
|
592
583
|
.catch(() => undefined);
|
|
@@ -620,7 +611,7 @@ export class BrowserSession {
|
|
|
620
611
|
* Detect if a rate limit error occurred
|
|
621
612
|
*
|
|
622
613
|
* Searches the page for error messages indicating rate limit/quota exhaustion.
|
|
623
|
-
*
|
|
614
|
+
* Account limits vary and can change; do not assume a fixed allowance.
|
|
624
615
|
*
|
|
625
616
|
* @returns true if rate limit error detected, false otherwise
|
|
626
617
|
*/
|
|
@@ -629,16 +620,6 @@ export class BrowserSession {
|
|
|
629
620
|
return false;
|
|
630
621
|
}
|
|
631
622
|
// Error message selectors (common patterns for error containers)
|
|
632
|
-
const errorSelectors = [
|
|
633
|
-
".error-message",
|
|
634
|
-
".error-container",
|
|
635
|
-
"[role='alert']",
|
|
636
|
-
".rate-limit-message",
|
|
637
|
-
"[data-error]",
|
|
638
|
-
".notification-error",
|
|
639
|
-
".alert-error",
|
|
640
|
-
".toast-error",
|
|
641
|
-
];
|
|
642
623
|
// Keywords that indicate rate limiting
|
|
643
624
|
const keywords = [
|
|
644
625
|
"rate limit",
|
|
@@ -653,7 +634,7 @@ export class BrowserSession {
|
|
|
653
634
|
"request limit",
|
|
654
635
|
];
|
|
655
636
|
// Check error containers for rate limit messages
|
|
656
|
-
for (const selector of
|
|
637
|
+
for (const selector of Selectors.chat.rateLimitContainers) {
|
|
657
638
|
try {
|
|
658
639
|
const elements = await this.page.$$(selector);
|
|
659
640
|
for (const el of elements) {
|
|
@@ -661,7 +642,8 @@ export class BrowserSession {
|
|
|
661
642
|
const text = await el.innerText();
|
|
662
643
|
const lower = text.toLowerCase();
|
|
663
644
|
if (keywords.some((k) => lower.includes(k))) {
|
|
664
|
-
log.error(`🚫 Rate limit detected
|
|
645
|
+
log.error(`🚫 Rate limit detected in NotebookLM UI`);
|
|
646
|
+
log.diagnostic("Rate-limit UI text", text.slice(0, 500));
|
|
665
647
|
return true;
|
|
666
648
|
}
|
|
667
649
|
}
|
|
@@ -676,7 +658,7 @@ export class BrowserSession {
|
|
|
676
658
|
}
|
|
677
659
|
// Also check if chat input is disabled (sometimes NotebookLM disables input when rate limited)
|
|
678
660
|
try {
|
|
679
|
-
const inputSelector =
|
|
661
|
+
const inputSelector = joinAlt(Selectors.chat.queryInput);
|
|
680
662
|
const input = await this.page.$(inputSelector);
|
|
681
663
|
if (input) {
|
|
682
664
|
const isDisabled = await input.evaluate((el) => {
|
|
@@ -710,15 +692,25 @@ export class BrowserSession {
|
|
|
710
692
|
/**
|
|
711
693
|
* Reset the chat history (start a new conversation)
|
|
712
694
|
*/
|
|
713
|
-
async reset() {
|
|
714
|
-
return await this.runExclusive(() => this.resetUnlocked()
|
|
695
|
+
async reset(signal) {
|
|
696
|
+
return await this.runExclusive(() => runWithOperationBoundary("reset_session", () => this.resetUnlocked(), {
|
|
697
|
+
signal,
|
|
698
|
+
timeoutMs: 60_000,
|
|
699
|
+
onInterrupt: async () => {
|
|
700
|
+
if (this.page && !this.isPageClosedSafe()) {
|
|
701
|
+
await this.page.close().catch(() => undefined);
|
|
702
|
+
}
|
|
703
|
+
this.page = null;
|
|
704
|
+
this.initialized = false;
|
|
705
|
+
},
|
|
706
|
+
}), signal);
|
|
715
707
|
}
|
|
716
708
|
async resetUnlocked() {
|
|
717
709
|
const resetOnce = async () => {
|
|
718
710
|
if (!this.initialized || !this.page || this.isPageClosedSafe()) {
|
|
719
711
|
await this.init();
|
|
720
712
|
}
|
|
721
|
-
log.info(`🔄 [${this.sessionId}] Resetting chat history...`);
|
|
713
|
+
log.info(`🔄 [${hashLogValue(this.sessionId)}] Resetting chat history...`);
|
|
722
714
|
const page = this.page;
|
|
723
715
|
// Reloading does not clear NotebookLM's server-side conversation. Use
|
|
724
716
|
// the actual "Clear chat history" action exposed by the current UI.
|
|
@@ -750,7 +742,7 @@ export class BrowserSession {
|
|
|
750
742
|
// Reset message count
|
|
751
743
|
this.messageCount = 0;
|
|
752
744
|
this.updateActivity();
|
|
753
|
-
log.success(`✅ [${this.sessionId}] Chat history reset`);
|
|
745
|
+
log.success(`✅ [${hashLogValue(this.sessionId)}] Chat history reset`);
|
|
754
746
|
};
|
|
755
747
|
try {
|
|
756
748
|
await resetOnce();
|
|
@@ -773,7 +765,7 @@ export class BrowserSession {
|
|
|
773
765
|
await resetOnce();
|
|
774
766
|
return;
|
|
775
767
|
}
|
|
776
|
-
log.error(`❌ [${this.sessionId}] Failed to reset: ${msg}`);
|
|
768
|
+
log.error(`❌ [${hashLogValue(this.sessionId)}] Failed to reset: ${msg}`);
|
|
777
769
|
throw error;
|
|
778
770
|
}
|
|
779
771
|
}
|
|
@@ -784,7 +776,7 @@ export class BrowserSession {
|
|
|
784
776
|
return await this.runExclusive(() => this.closeUnlocked());
|
|
785
777
|
}
|
|
786
778
|
async closeUnlocked() {
|
|
787
|
-
log.info(`🛑 Closing session ${this.sessionId}...`);
|
|
779
|
+
log.info(`🛑 Closing session ${hashLogValue(this.sessionId)}...`);
|
|
788
780
|
if (this.page) {
|
|
789
781
|
try {
|
|
790
782
|
await this.page.close();
|
|
@@ -796,7 +788,7 @@ export class BrowserSession {
|
|
|
796
788
|
}
|
|
797
789
|
}
|
|
798
790
|
this.initialized = false;
|
|
799
|
-
log.success(`✅ Session ${this.sessionId} closed`);
|
|
791
|
+
log.success(`✅ Session ${hashLogValue(this.sessionId)} closed`);
|
|
800
792
|
}
|
|
801
793
|
/**
|
|
802
794
|
* Update last activity timestamp
|
|
@@ -839,4 +831,8 @@ export class BrowserSession {
|
|
|
839
831
|
return this.initialized && this.page !== null;
|
|
840
832
|
}
|
|
841
833
|
}
|
|
834
|
+
function isRecoverableBrowserOperationError(error) {
|
|
835
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
836
|
+
return /has been closed|target .*closed|browser.*closed|context.*closed|page.*closed|crash/i.test(message);
|
|
837
|
+
}
|
|
842
838
|
//# sourceMappingURL=browser-session.js.map
|