@charlie.act7/gemini-notebook-mcp 2.0.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.
Files changed (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +435 -0
  3. package/dist/auth/account-switcher.d.ts +21 -0
  4. package/dist/auth/account-switcher.d.ts.map +1 -0
  5. package/dist/auth/account-switcher.js +54 -0
  6. package/dist/auth/account-switcher.js.map +1 -0
  7. package/dist/auth/auth-manager.d.ts +139 -0
  8. package/dist/auth/auth-manager.d.ts.map +1 -0
  9. package/dist/auth/auth-manager.js +1006 -0
  10. package/dist/auth/auth-manager.js.map +1 -0
  11. package/dist/browser/chromium-fallback.d.ts +24 -0
  12. package/dist/browser/chromium-fallback.d.ts.map +1 -0
  13. package/dist/browser/chromium-fallback.js +53 -0
  14. package/dist/browser/chromium-fallback.js.map +1 -0
  15. package/dist/browser/watchdog.d.ts +35 -0
  16. package/dist/browser/watchdog.d.ts.map +1 -0
  17. package/dist/browser/watchdog.js +74 -0
  18. package/dist/browser/watchdog.js.map +1 -0
  19. package/dist/config.d.ts +99 -0
  20. package/dist/config.d.ts.map +1 -0
  21. package/dist/config.js +255 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/errors.d.ts +26 -0
  24. package/dist/errors.d.ts.map +1 -0
  25. package/dist/errors.js +41 -0
  26. package/dist/errors.js.map +1 -0
  27. package/dist/index.d.ts +32 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +558 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/library/metadata.d.ts +14 -0
  32. package/dist/library/metadata.d.ts.map +1 -0
  33. package/dist/library/metadata.js +33 -0
  34. package/dist/library/metadata.js.map +1 -0
  35. package/dist/library/notebook-library.d.ts +70 -0
  36. package/dist/library/notebook-library.d.ts.map +1 -0
  37. package/dist/library/notebook-library.js +311 -0
  38. package/dist/library/notebook-library.js.map +1 -0
  39. package/dist/library/types.d.ts +67 -0
  40. package/dist/library/types.d.ts.map +1 -0
  41. package/dist/library/types.js +8 -0
  42. package/dist/library/types.js.map +1 -0
  43. package/dist/notebooklm/audio.d.ts +67 -0
  44. package/dist/notebooklm/audio.d.ts.map +1 -0
  45. package/dist/notebooklm/audio.js +275 -0
  46. package/dist/notebooklm/audio.js.map +1 -0
  47. package/dist/notebooklm/chat.d.ts +79 -0
  48. package/dist/notebooklm/chat.d.ts.map +1 -0
  49. package/dist/notebooklm/chat.js +631 -0
  50. package/dist/notebooklm/chat.js.map +1 -0
  51. package/dist/notebooklm/citations.d.ts +35 -0
  52. package/dist/notebooklm/citations.d.ts.map +1 -0
  53. package/dist/notebooklm/citations.js +173 -0
  54. package/dist/notebooklm/citations.js.map +1 -0
  55. package/dist/notebooklm/selectors.d.ts +168 -0
  56. package/dist/notebooklm/selectors.d.ts.map +1 -0
  57. package/dist/notebooklm/selectors.js +435 -0
  58. package/dist/notebooklm/selectors.js.map +1 -0
  59. package/dist/notebooklm/sources.d.ts +61 -0
  60. package/dist/notebooklm/sources.d.ts.map +1 -0
  61. package/dist/notebooklm/sources.js +324 -0
  62. package/dist/notebooklm/sources.js.map +1 -0
  63. package/dist/notebooklm/url.d.ts +7 -0
  64. package/dist/notebooklm/url.d.ts.map +1 -0
  65. package/dist/notebooklm/url.js +36 -0
  66. package/dist/notebooklm/url.js.map +1 -0
  67. package/dist/resources/resource-handlers.d.ts +22 -0
  68. package/dist/resources/resource-handlers.d.ts.map +1 -0
  69. package/dist/resources/resource-handlers.js +220 -0
  70. package/dist/resources/resource-handlers.js.map +1 -0
  71. package/dist/session/browser-session.d.ts +147 -0
  72. package/dist/session/browser-session.d.ts.map +1 -0
  73. package/dist/session/browser-session.js +838 -0
  74. package/dist/session/browser-session.js.map +1 -0
  75. package/dist/session/session-manager.d.ts +80 -0
  76. package/dist/session/session-manager.d.ts.map +1 -0
  77. package/dist/session/session-manager.js +294 -0
  78. package/dist/session/session-manager.js.map +1 -0
  79. package/dist/session/shared-context-manager.d.ts +107 -0
  80. package/dist/session/shared-context-manager.d.ts.map +1 -0
  81. package/dist/session/shared-context-manager.js +465 -0
  82. package/dist/session/shared-context-manager.js.map +1 -0
  83. package/dist/tools/definitions/ask-question.d.ts +8 -0
  84. package/dist/tools/definitions/ask-question.d.ts.map +1 -0
  85. package/dist/tools/definitions/ask-question.js +244 -0
  86. package/dist/tools/definitions/ask-question.js.map +1 -0
  87. package/dist/tools/definitions/notebook-management.d.ts +9 -0
  88. package/dist/tools/definitions/notebook-management.d.ts.map +1 -0
  89. package/dist/tools/definitions/notebook-management.js +263 -0
  90. package/dist/tools/definitions/notebook-management.js.map +1 -0
  91. package/dist/tools/definitions/session-management.d.ts +12 -0
  92. package/dist/tools/definitions/session-management.d.ts.map +1 -0
  93. package/dist/tools/definitions/session-management.js +82 -0
  94. package/dist/tools/definitions/session-management.js.map +1 -0
  95. package/dist/tools/definitions/sources.d.ts +14 -0
  96. package/dist/tools/definitions/sources.d.ts.map +1 -0
  97. package/dist/tools/definitions/sources.js +200 -0
  98. package/dist/tools/definitions/sources.js.map +1 -0
  99. package/dist/tools/definitions/system.d.ts +9 -0
  100. package/dist/tools/definitions/system.d.ts.map +1 -0
  101. package/dist/tools/definitions/system.js +152 -0
  102. package/dist/tools/definitions/system.js.map +1 -0
  103. package/dist/tools/definitions.d.ts +12 -0
  104. package/dist/tools/definitions.d.ts.map +1 -0
  105. package/dist/tools/definitions.js +28 -0
  106. package/dist/tools/definitions.js.map +1 -0
  107. package/dist/tools/handlers.d.ts +274 -0
  108. package/dist/tools/handlers.d.ts.map +1 -0
  109. package/dist/tools/handlers.js +840 -0
  110. package/dist/tools/handlers.js.map +1 -0
  111. package/dist/tools/index.d.ts +8 -0
  112. package/dist/tools/index.d.ts.map +1 -0
  113. package/dist/tools/index.js +8 -0
  114. package/dist/tools/index.js.map +1 -0
  115. package/dist/transport/http.d.ts +38 -0
  116. package/dist/transport/http.d.ts.map +1 -0
  117. package/dist/transport/http.js +231 -0
  118. package/dist/transport/http.js.map +1 -0
  119. package/dist/types.d.ts +101 -0
  120. package/dist/types.d.ts.map +1 -0
  121. package/dist/types.js +5 -0
  122. package/dist/types.js.map +1 -0
  123. package/dist/utils/cleanup-manager.d.ts +133 -0
  124. package/dist/utils/cleanup-manager.d.ts.map +1 -0
  125. package/dist/utils/cleanup-manager.js +671 -0
  126. package/dist/utils/cleanup-manager.js.map +1 -0
  127. package/dist/utils/cli-handler.d.ts +16 -0
  128. package/dist/utils/cli-handler.d.ts.map +1 -0
  129. package/dist/utils/cli-handler.js +105 -0
  130. package/dist/utils/cli-handler.js.map +1 -0
  131. package/dist/utils/disclaimer.d.ts +31 -0
  132. package/dist/utils/disclaimer.d.ts.map +1 -0
  133. package/dist/utils/disclaimer.js +43 -0
  134. package/dist/utils/disclaimer.js.map +1 -0
  135. package/dist/utils/logger.d.ts +61 -0
  136. package/dist/utils/logger.d.ts.map +1 -0
  137. package/dist/utils/logger.js +92 -0
  138. package/dist/utils/logger.js.map +1 -0
  139. package/dist/utils/page-utils.d.ts +25 -0
  140. package/dist/utils/page-utils.d.ts.map +1 -0
  141. package/dist/utils/page-utils.js +51 -0
  142. package/dist/utils/page-utils.js.map +1 -0
  143. package/dist/utils/settings-manager.d.ts +37 -0
  144. package/dist/utils/settings-manager.d.ts.map +1 -0
  145. package/dist/utils/settings-manager.js +141 -0
  146. package/dist/utils/settings-manager.js.map +1 -0
  147. package/dist/utils/stealth-utils.d.ts +135 -0
  148. package/dist/utils/stealth-utils.d.ts.map +1 -0
  149. package/dist/utils/stealth-utils.js +399 -0
  150. package/dist/utils/stealth-utils.js.map +1 -0
  151. package/docs/configuration.md +181 -0
  152. package/docs/tools.md +417 -0
  153. package/docs/troubleshooting.md +171 -0
  154. package/docs/usage-guide.md +284 -0
  155. package/package.json +71 -0
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Settings Manager
3
+ *
4
+ * Handles persistent configuration for the NotebookLM MCP Server.
5
+ * Manages profiles, disabled tools, and environment variable overrides.
6
+ */
7
+ import fs from "fs/promises";
8
+ import { existsSync, mkdirSync, readFileSync } from "fs";
9
+ import path from "path";
10
+ import { CONFIG } from "../config.js";
11
+ import { log } from "./logger.js";
12
+ import { z } from "zod";
13
+ const DEFAULT_SETTINGS = {
14
+ profile: "full",
15
+ disabledTools: [],
16
+ };
17
+ const settingsSchema = z.object({
18
+ profile: z.enum(["minimal", "standard", "full"]).default("full"),
19
+ disabledTools: z.array(z.string()).default([]),
20
+ customSettings: z.record(z.unknown()).optional(),
21
+ });
22
+ function isProfileName(value) {
23
+ return value === "minimal" || value === "standard" || value === "full";
24
+ }
25
+ const PROFILES = {
26
+ minimal: [
27
+ "ask_question",
28
+ "get_health",
29
+ "list_notebooks",
30
+ "select_notebook",
31
+ "get_notebook", // Added as it is read-only and useful
32
+ ],
33
+ standard: [
34
+ "ask_question",
35
+ "get_health",
36
+ "list_notebooks",
37
+ "select_notebook",
38
+ "get_notebook",
39
+ "setup_auth",
40
+ "list_sessions",
41
+ "add_notebook",
42
+ "update_notebook",
43
+ "search_notebooks",
44
+ ],
45
+ full: ["*"], // All tools
46
+ };
47
+ export class SettingsManager {
48
+ settingsPath;
49
+ settings;
50
+ constructor() {
51
+ // Use the config directory from env-paths defined in config.ts
52
+ this.settingsPath = path.join(CONFIG.configDir, "settings.json");
53
+ this.settings = this.loadSettings();
54
+ }
55
+ /**
56
+ * Load settings from file, falling back to defaults
57
+ */
58
+ loadSettings() {
59
+ try {
60
+ // Ensure config dir exists
61
+ if (!existsSync(CONFIG.configDir)) {
62
+ mkdirSync(CONFIG.configDir, { recursive: true });
63
+ }
64
+ if (existsSync(this.settingsPath)) {
65
+ // Synchronous read keeps the constructor simple — settings are tiny
66
+ // and we need them before any tool dispatch can happen.
67
+ const data = readFileSync(this.settingsPath, "utf-8");
68
+ return settingsSchema.parse({ ...DEFAULT_SETTINGS, ...JSON.parse(data) });
69
+ }
70
+ }
71
+ catch (error) {
72
+ log.warning(`⚠️ Failed to load settings: ${error}. Using defaults.`);
73
+ }
74
+ return { ...DEFAULT_SETTINGS };
75
+ }
76
+ /**
77
+ * Save current settings to file
78
+ */
79
+ async saveSettings(newSettings) {
80
+ const previousSettings = this.settings;
81
+ const nextSettings = settingsSchema.parse({ ...this.settings, ...newSettings });
82
+ const temporaryPath = `${this.settingsPath}.${process.pid}.tmp`;
83
+ try {
84
+ await fs.writeFile(temporaryPath, JSON.stringify(nextSettings, null, 2), {
85
+ encoding: "utf-8",
86
+ mode: 0o600,
87
+ });
88
+ await fs.rename(temporaryPath, this.settingsPath);
89
+ this.settings = nextSettings;
90
+ }
91
+ catch (error) {
92
+ this.settings = previousSettings;
93
+ await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
94
+ throw new Error(`Failed to save settings: ${error}`, { cause: error });
95
+ }
96
+ }
97
+ /**
98
+ * Get effective configuration (merging File settings with Env Vars)
99
+ */
100
+ getEffectiveSettings() {
101
+ const envProfileRaw = process.env.NOTEBOOKLM_PROFILE;
102
+ const envProfile = isProfileName(envProfileRaw) ? envProfileRaw : undefined;
103
+ const envDisabled = process.env.NOTEBOOKLM_DISABLED_TOOLS;
104
+ const effectiveProfile = envProfile ?? this.settings.profile;
105
+ let effectiveDisabled = [...this.settings.disabledTools];
106
+ if (envDisabled) {
107
+ const envDisabledList = envDisabled.split(",").map((t) => t.trim());
108
+ effectiveDisabled = [...new Set([...effectiveDisabled, ...envDisabledList])];
109
+ }
110
+ return {
111
+ profile: effectiveProfile,
112
+ disabledTools: effectiveDisabled,
113
+ customSettings: this.settings.customSettings,
114
+ };
115
+ }
116
+ /**
117
+ * Filter tools based on effective configuration
118
+ */
119
+ filterTools(allTools) {
120
+ const { profile, disabledTools } = this.getEffectiveSettings();
121
+ const allowedTools = PROFILES[profile];
122
+ return allTools.filter((tool) => {
123
+ // 1. Check if allowed by profile (unless profile is full/wildcard)
124
+ if (!allowedTools.includes("*") && !allowedTools.includes(tool.name)) {
125
+ return false;
126
+ }
127
+ // 2. Check if explicitly disabled
128
+ if (disabledTools.includes(tool.name)) {
129
+ return false;
130
+ }
131
+ return true;
132
+ });
133
+ }
134
+ getSettingsPath() {
135
+ return this.settingsPath;
136
+ }
137
+ getProfiles() {
138
+ return PROFILES;
139
+ }
140
+ }
141
+ //# sourceMappingURL=settings-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings-manager.js","sourceRoot":"","sources":["../../src/utils/settings-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,MAAM,gBAAgB,GAAa;IACjC,OAAO,EAAE,MAAM;IACf,aAAa,EAAE,EAAE;CAClB,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IAChE,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IAC9C,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;CACjD,CAAC,CAAC;AAEH,SAAS,aAAa,CAAC,KAAyB;IAC9C,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,MAAM,CAAC;AACzE,CAAC;AAED,MAAM,QAAQ,GAAkC;IAC9C,OAAO,EAAE;QACP,cAAc;QACd,YAAY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C;IAED,WAAW;QACT,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Stealth utilities for human-like browser behavior
3
+ *
4
+ * This module provides functions to simulate realistic human interactions:
5
+ * - Human-like typing (speed configurable via CONFIG.typingWpmMin/Max)
6
+ * - Realistic mouse movements (Bezier curves with jitter)
7
+ * - Random delays (normal distribution)
8
+ * - Smooth scrolling
9
+ * - Reading pauses
10
+ *
11
+ * Based on the Python implementation from stealth_utils.py
12
+ */
13
+ import type { Page } from "patchright";
14
+ /**
15
+ * Sleep for specified milliseconds
16
+ */
17
+ export declare function sleep(ms: number): Promise<void>;
18
+ /**
19
+ * Generate random integer between min and max (inclusive)
20
+ */
21
+ export declare function randomInt(min: number, max: number): number;
22
+ /**
23
+ * Generate random float between min and max
24
+ */
25
+ export declare function randomFloat(min: number, max: number): number;
26
+ /**
27
+ * Generate random character (for typos)
28
+ */
29
+ export declare function randomChar(): string;
30
+ /**
31
+ * Generate Gaussian (normal) distributed random number
32
+ * Uses Box-Muller transform
33
+ */
34
+ export declare function gaussian(mean: number, stdDev: number): number;
35
+ /**
36
+ * Add a random delay to simulate human thinking/reaction time
37
+ * Uses normal distribution for more realistic delays
38
+ *
39
+ * @param minMs Minimum delay in milliseconds (default: from CONFIG)
40
+ * @param maxMs Maximum delay in milliseconds (default: from CONFIG)
41
+ */
42
+ export declare function randomDelay(minMs?: number, maxMs?: number): Promise<void>;
43
+ /**
44
+ * Type text in a human-like manner with variable speed and optional typos
45
+ *
46
+ * Simulates realistic typing patterns:
47
+ * - Variable speed (45-65 WPM by default)
48
+ * - Occasional typos (2% chance)
49
+ * - Longer pauses after punctuation
50
+ * - Realistic character delays
51
+ *
52
+ * @param page Playwright page instance
53
+ * @param selector CSS selector of input element
54
+ * @param text Text to type
55
+ * @param options Typing options (wpm, withTypos)
56
+ */
57
+ export declare function humanType(page: Page, selector: string, text: string, options?: {
58
+ wpm?: number;
59
+ withTypos?: boolean;
60
+ }): Promise<void>;
61
+ /**
62
+ * Move mouse in a realistic curved path to target coordinates
63
+ * Uses Bezier-like curves with jitter for natural movement
64
+ *
65
+ * @param page Playwright page instance
66
+ * @param targetX Target X coordinate (default: random)
67
+ * @param targetY Target Y coordinate (default: random)
68
+ * @param steps Number of steps in movement (default: random 10-25)
69
+ */
70
+ export declare function randomMouseMovement(page: Page, targetX?: number, targetY?: number, steps?: number): Promise<void>;
71
+ /**
72
+ * Click an element with realistic human behavior
73
+ * Includes mouse movement, pause, and click
74
+ *
75
+ * @param page Playwright page instance
76
+ * @param selector CSS selector of element to click
77
+ * @param withMouseMovement Whether to move mouse first (default: true)
78
+ */
79
+ export declare function realisticClick(page: Page, selector: string, withMouseMovement?: boolean): Promise<void>;
80
+ /**
81
+ * Scroll the page smoothly like a human
82
+ * Uses multiple small steps for smooth animation
83
+ *
84
+ * @param page Playwright page instance
85
+ * @param amount Scroll amount in pixels (default: random 100-400)
86
+ * @param direction Scroll direction ("down" or "up")
87
+ */
88
+ export declare function smoothScroll(page: Page, amount?: number, direction?: "up" | "down"): Promise<void>;
89
+ /**
90
+ * Pause as if reading text, based on length
91
+ * Calculates realistic reading time based on text length and WPM
92
+ *
93
+ * @param textLength Number of characters to "read"
94
+ * @param wpm Reading speed in words per minute (default: random 200-250)
95
+ */
96
+ export declare function readingPause(textLength: number, wpm?: number): Promise<void>;
97
+ /**
98
+ * Add small random mouse movements to simulate natural fidgeting
99
+ *
100
+ * @param page Playwright page instance
101
+ * @param iterations Number of small movements (default: 3)
102
+ */
103
+ export declare function randomMouseJitter(page: Page, iterations?: number): Promise<void>;
104
+ /**
105
+ * Hover over an element with realistic mouse movement
106
+ *
107
+ * @param page Playwright page instance
108
+ * @param selector CSS selector of element to hover
109
+ */
110
+ export declare function hoverElement(page: Page, selector: string): Promise<void>;
111
+ /**
112
+ * Simulate reading a page with scrolling and pauses
113
+ * Adds realistic behavior of scrolling and reading content
114
+ *
115
+ * @param page Playwright page instance
116
+ */
117
+ export declare function simulateReadingPage(page: Page): Promise<void>;
118
+ declare const _default: {
119
+ sleep: typeof sleep;
120
+ randomInt: typeof randomInt;
121
+ randomFloat: typeof randomFloat;
122
+ randomChar: typeof randomChar;
123
+ gaussian: typeof gaussian;
124
+ randomDelay: typeof randomDelay;
125
+ humanType: typeof humanType;
126
+ randomMouseMovement: typeof randomMouseMovement;
127
+ realisticClick: typeof realisticClick;
128
+ smoothScroll: typeof smoothScroll;
129
+ readingPause: typeof readingPause;
130
+ randomMouseJitter: typeof randomMouseJitter;
131
+ hoverElement: typeof hoverElement;
132
+ simulateReadingPage: typeof simulateReadingPage;
133
+ };
134
+ export default _default;
135
+ //# sourceMappingURL=stealth-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stealth-utils.d.ts","sourceRoot":"","sources":["../../src/utils/stealth-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAOvC;;GAEG;AACH,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAGnC;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAK7D;AAMD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAuB/E;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAs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@ -0,0 +1,399 @@
1
+ /**
2
+ * Stealth utilities for human-like browser behavior
3
+ *
4
+ * This module provides functions to simulate realistic human interactions:
5
+ * - Human-like typing (speed configurable via CONFIG.typingWpmMin/Max)
6
+ * - Realistic mouse movements (Bezier curves with jitter)
7
+ * - Random delays (normal distribution)
8
+ * - Smooth scrolling
9
+ * - Reading pauses
10
+ *
11
+ * Based on the Python implementation from stealth_utils.py
12
+ */
13
+ import { getRuntimeConfig } from "../config.js";
14
+ // ============================================================================
15
+ // Helper Functions
16
+ // ============================================================================
17
+ /**
18
+ * Sleep for specified milliseconds
19
+ */
20
+ export async function sleep(ms) {
21
+ return new Promise((resolve) => setTimeout(resolve, ms));
22
+ }
23
+ /**
24
+ * Generate random integer between min and max (inclusive)
25
+ */
26
+ export function randomInt(min, max) {
27
+ return Math.floor(Math.random() * (max - min + 1)) + min;
28
+ }
29
+ /**
30
+ * Generate random float between min and max
31
+ */
32
+ export function randomFloat(min, max) {
33
+ return Math.random() * (max - min) + min;
34
+ }
35
+ /**
36
+ * Generate random character (for typos)
37
+ */
38
+ export function randomChar() {
39
+ const chars = "qwertyuiopasdfghjklzxcvbnm";
40
+ return chars[randomInt(0, chars.length - 1)];
41
+ }
42
+ /**
43
+ * Generate Gaussian (normal) distributed random number
44
+ * Uses Box-Muller transform
45
+ */
46
+ export function gaussian(mean, stdDev) {
47
+ const u1 = Math.random();
48
+ const u2 = Math.random();
49
+ const z0 = Math.sqrt(-2.0 * Math.log(u1)) * Math.cos(2.0 * Math.PI * u2);
50
+ return z0 * stdDev + mean;
51
+ }
52
+ // ============================================================================
53
+ // Random Delays
54
+ // ============================================================================
55
+ /**
56
+ * Add a random delay to simulate human thinking/reaction time
57
+ * Uses normal distribution for more realistic delays
58
+ *
59
+ * @param minMs Minimum delay in milliseconds (default: from CONFIG)
60
+ * @param maxMs Maximum delay in milliseconds (default: from CONFIG)
61
+ */
62
+ export async function randomDelay(minMs, maxMs) {
63
+ const config = getRuntimeConfig();
64
+ minMs = minMs ?? config.minDelayMs;
65
+ maxMs = maxMs ?? config.maxDelayMs;
66
+ if (!config.stealthEnabled || !config.stealthRandomDelays) {
67
+ // Fixed delay (average)
68
+ const target = minMs === maxMs ? minMs : (minMs + maxMs) / 2;
69
+ if (target > 0) {
70
+ await sleep(target);
71
+ }
72
+ return;
73
+ }
74
+ // Use normal distribution for more realistic delays
75
+ // Mean at 60% of range, standard deviation of 20% of range
76
+ const mean = minMs + (maxMs - minMs) * 0.6;
77
+ const stdDev = (maxMs - minMs) * 0.2;
78
+ let delay = gaussian(mean, stdDev);
79
+ delay = Math.max(minMs, Math.min(maxMs, delay)); // Clamp to range
80
+ await sleep(delay);
81
+ }
82
+ // ============================================================================
83
+ // Human Typing
84
+ // ============================================================================
85
+ /**
86
+ * Type text in a human-like manner with variable speed and optional typos
87
+ *
88
+ * Simulates realistic typing patterns:
89
+ * - Variable speed (45-65 WPM by default)
90
+ * - Occasional typos (2% chance)
91
+ * - Longer pauses after punctuation
92
+ * - Realistic character delays
93
+ *
94
+ * @param page Playwright page instance
95
+ * @param selector CSS selector of input element
96
+ * @param text Text to type
97
+ * @param options Typing options (wpm, withTypos)
98
+ */
99
+ export async function humanType(page, selector, text, options = {}) {
100
+ const config = getRuntimeConfig();
101
+ if (!config.stealthEnabled || !config.stealthHumanTyping) {
102
+ // Fast typing without stealth
103
+ await page.fill(selector, text);
104
+ return;
105
+ }
106
+ const wpm = options.wpm ?? randomInt(config.typingWpmMin, config.typingWpmMax);
107
+ const withTypos = options.withTypos ?? true;
108
+ // Calculate average delay per character (in ms)
109
+ // WPM = (characters / 5) / minutes
110
+ // Average word length ~5 characters
111
+ const charsPerMinute = wpm * 5;
112
+ const avgDelayMs = (60 * 1000) / charsPerMinute;
113
+ // Clear existing text first
114
+ await page.fill(selector, "");
115
+ await randomDelay(30, 80);
116
+ // Click to focus
117
+ await page.click(selector);
118
+ await randomDelay(20, 60);
119
+ // Type each character
120
+ for (let i = 0; i < text.length; i++) {
121
+ const char = text[i];
122
+ // Simulate very rare typo (0.3% chance) and shorter correction
123
+ if (withTypos && Math.random() < 0.003 && i > 0) {
124
+ // Type wrong character
125
+ const wrongChar = randomChar();
126
+ await page.keyboard.insertText(wrongChar);
127
+ // Shorter notice window for faster typing
128
+ const noticeDelay = randomFloat(avgDelayMs * 0.6, avgDelayMs * 1.1);
129
+ await sleep(noticeDelay);
130
+ // Backspace
131
+ await page.keyboard.press("Backspace");
132
+ await randomDelay(20, 60);
133
+ }
134
+ // Type correct character
135
+ await page.keyboard.insertText(char);
136
+ // Variable delay between characters – tuned for faster but still human-like typing
137
+ let delay;
138
+ if (char === "." || char === "!" || char === "?") {
139
+ delay = randomFloat(avgDelayMs * 1.05, avgDelayMs * 1.4);
140
+ }
141
+ else if (char === " ") {
142
+ delay = randomFloat(avgDelayMs * 0.5, avgDelayMs * 0.9);
143
+ }
144
+ else if (char === ",") {
145
+ delay = randomFloat(avgDelayMs * 0.9, avgDelayMs * 1.2);
146
+ }
147
+ else {
148
+ // Normal character
149
+ const variation = randomFloat(0.5, 0.9);
150
+ delay = avgDelayMs * variation;
151
+ }
152
+ await sleep(delay);
153
+ }
154
+ // Small delay after finishing typing
155
+ await randomDelay(50, 120);
156
+ }
157
+ // ============================================================================
158
+ // Mouse Movement
159
+ // ============================================================================
160
+ /**
161
+ * Move mouse in a realistic curved path to target coordinates
162
+ * Uses Bezier-like curves with jitter for natural movement
163
+ *
164
+ * @param page Playwright page instance
165
+ * @param targetX Target X coordinate (default: random)
166
+ * @param targetY Target Y coordinate (default: random)
167
+ * @param steps Number of steps in movement (default: random 10-25)
168
+ */
169
+ export async function randomMouseMovement(page, targetX, targetY, steps) {
170
+ const config = getRuntimeConfig();
171
+ if (!config.stealthEnabled || !config.stealthMouseMovements) {
172
+ return;
173
+ }
174
+ const viewport = page.viewportSize() || config.viewport;
175
+ targetX = targetX ?? randomInt(100, viewport.width - 100);
176
+ targetY = targetY ?? randomInt(100, viewport.height - 100);
177
+ steps = steps ?? randomInt(10, 25);
178
+ // Start from a random position (we don't know current position)
179
+ const startX = randomInt(0, viewport.width);
180
+ const startY = randomInt(0, viewport.height);
181
+ // Generate curved path using Bezier-like curve
182
+ for (let step = 0; step < steps; step++) {
183
+ const progress = step / steps;
184
+ // Add some randomness to create a natural curve
185
+ const curveOffsetX = Math.sin(progress * Math.PI) * randomInt(-50, 50);
186
+ const curveOffsetY = Math.cos(progress * Math.PI) * randomInt(-30, 30);
187
+ let currentX = startX + (targetX - startX) * progress + curveOffsetX;
188
+ let currentY = startY + (targetY - startY) * progress + curveOffsetY;
189
+ // Add micro-jitter (humans never move in perfectly straight lines)
190
+ const jitterX = randomFloat(-3, 3);
191
+ const jitterY = randomFloat(-3, 3);
192
+ currentX = Math.max(0, Math.min(viewport.width, currentX + jitterX));
193
+ currentY = Math.max(0, Math.min(viewport.height, currentY + jitterY));
194
+ await page.mouse.move(currentX, currentY);
195
+ // Variable delay between movements (faster in middle, slower at ends)
196
+ const delay = 10 + 20 * Math.abs(0.5 - progress);
197
+ await sleep(delay);
198
+ }
199
+ }
200
+ // ============================================================================
201
+ // Realistic Click
202
+ // ============================================================================
203
+ /**
204
+ * Click an element with realistic human behavior
205
+ * Includes mouse movement, pause, and click
206
+ *
207
+ * @param page Playwright page instance
208
+ * @param selector CSS selector of element to click
209
+ * @param withMouseMovement Whether to move mouse first (default: true)
210
+ */
211
+ export async function realisticClick(page, selector, withMouseMovement = true) {
212
+ const config = getRuntimeConfig();
213
+ if (!config.stealthEnabled || !config.stealthMouseMovements) {
214
+ await page.click(selector);
215
+ return;
216
+ }
217
+ if (withMouseMovement) {
218
+ // Move mouse to element
219
+ const element = await page.$(selector);
220
+ if (element) {
221
+ const box = await element.boundingBox();
222
+ if (box) {
223
+ // Don't click exactly in center (humans are imperfect)
224
+ const offsetX = randomFloat(-box.width * 0.2, box.width * 0.2);
225
+ const offsetY = randomFloat(-box.height * 0.2, box.height * 0.2);
226
+ const targetX = box.x + box.width / 2 + offsetX;
227
+ const targetY = box.y + box.height / 2 + offsetY;
228
+ await randomMouseMovement(page, targetX, targetY);
229
+ }
230
+ }
231
+ }
232
+ // Small pause before clicking
233
+ await randomDelay(100, 300);
234
+ // Click
235
+ await page.click(selector);
236
+ // Small pause after clicking
237
+ await randomDelay(150, 400);
238
+ }
239
+ // ============================================================================
240
+ // Smooth Scrolling
241
+ // ============================================================================
242
+ /**
243
+ * Scroll the page smoothly like a human
244
+ * Uses multiple small steps for smooth animation
245
+ *
246
+ * @param page Playwright page instance
247
+ * @param amount Scroll amount in pixels (default: random 100-400)
248
+ * @param direction Scroll direction ("down" or "up")
249
+ */
250
+ export async function smoothScroll(page, amount, direction = "down") {
251
+ amount = amount ?? randomInt(100, 400);
252
+ amount = Math.abs(amount);
253
+ if (direction === "up") {
254
+ amount = -amount;
255
+ }
256
+ const config = getRuntimeConfig();
257
+ if (!config.stealthEnabled || !config.stealthMouseMovements) {
258
+ await page.evaluate((scrollAmount) => {
259
+ window.scrollBy({ top: scrollAmount, behavior: "auto" });
260
+ }, amount);
261
+ return;
262
+ }
263
+ // Scroll in multiple small steps for smoothness
264
+ const steps = randomInt(8, 15);
265
+ const stepAmount = amount / steps;
266
+ for (let i = 0; i < steps; i++) {
267
+ await page.evaluate((step) => {
268
+ window.scrollBy({ top: step, behavior: "smooth" });
269
+ }, stepAmount);
270
+ await sleep(randomFloat(20, 50));
271
+ }
272
+ // Pause after scrolling (humans look at content)
273
+ await randomDelay(300, 800);
274
+ }
275
+ // ============================================================================
276
+ // Reading Simulation
277
+ // ============================================================================
278
+ /**
279
+ * Pause as if reading text, based on length
280
+ * Calculates realistic reading time based on text length and WPM
281
+ *
282
+ * @param textLength Number of characters to "read"
283
+ * @param wpm Reading speed in words per minute (default: random 200-250)
284
+ */
285
+ export async function readingPause(textLength, wpm) {
286
+ const config = getRuntimeConfig();
287
+ if (!config.stealthEnabled || !config.stealthRandomDelays) {
288
+ return;
289
+ }
290
+ wpm = wpm ?? randomInt(200, 250);
291
+ // Calculate reading time
292
+ // Average word length ~5 characters
293
+ const wordCount = textLength / 5;
294
+ const minutes = wordCount / wpm;
295
+ let seconds = minutes * 60;
296
+ // Add some randomness (humans don't read at constant speed)
297
+ seconds *= randomFloat(0.8, 1.2);
298
+ // Cap at reasonable maximum (3 seconds)
299
+ seconds = Math.min(seconds, 3.0);
300
+ await sleep(seconds * 1000);
301
+ }
302
+ // ============================================================================
303
+ // Random Mouse Jitter
304
+ // ============================================================================
305
+ /**
306
+ * Add small random mouse movements to simulate natural fidgeting
307
+ *
308
+ * @param page Playwright page instance
309
+ * @param iterations Number of small movements (default: 3)
310
+ */
311
+ export async function randomMouseJitter(page, iterations = 3) {
312
+ const config = getRuntimeConfig();
313
+ if (!config.stealthEnabled || !config.stealthMouseMovements) {
314
+ return;
315
+ }
316
+ const viewport = page.viewportSize() || config.viewport;
317
+ for (let i = 0; i < iterations; i++) {
318
+ const targetX = randomInt(0, viewport.width);
319
+ const targetY = randomInt(0, viewport.height);
320
+ await page.mouse.move(targetX, targetY, { steps: randomInt(2, 4) });
321
+ await sleep(randomFloat(100, 300));
322
+ }
323
+ }
324
+ // ============================================================================
325
+ // Hover Element
326
+ // ============================================================================
327
+ /**
328
+ * Hover over an element with realistic mouse movement
329
+ *
330
+ * @param page Playwright page instance
331
+ * @param selector CSS selector of element to hover
332
+ */
333
+ export async function hoverElement(page, selector) {
334
+ const config = getRuntimeConfig();
335
+ if (!config.stealthEnabled || !config.stealthMouseMovements) {
336
+ await page.hover(selector);
337
+ return;
338
+ }
339
+ const element = await page.$(selector);
340
+ if (element) {
341
+ const box = await element.boundingBox();
342
+ if (box) {
343
+ // Move to center of element
344
+ const targetX = box.x + box.width / 2;
345
+ const targetY = box.y + box.height / 2;
346
+ await randomMouseMovement(page, targetX, targetY);
347
+ await page.hover(selector);
348
+ await randomDelay(200, 500);
349
+ }
350
+ }
351
+ }
352
+ // ============================================================================
353
+ // Simulate Reading Page
354
+ // ============================================================================
355
+ /**
356
+ * Simulate reading a page with scrolling and pauses
357
+ * Adds realistic behavior of scrolling and reading content
358
+ *
359
+ * @param page Playwright page instance
360
+ */
361
+ export async function simulateReadingPage(page) {
362
+ const config = getRuntimeConfig();
363
+ if (!config.stealthEnabled || !config.stealthRandomDelays) {
364
+ return;
365
+ }
366
+ // Random number of scroll actions
367
+ const scrollCount = randomInt(1, 3);
368
+ for (let i = 0; i < scrollCount; i++) {
369
+ // Scroll down
370
+ await smoothScroll(page, undefined, "down");
371
+ // "Read" the visible content
372
+ await randomDelay(800, 1500);
373
+ // Sometimes scroll up a bit (humans do this)
374
+ if (Math.random() < 0.3) {
375
+ await smoothScroll(page, randomInt(50, 150), "up");
376
+ await randomDelay(400, 800);
377
+ }
378
+ }
379
+ }
380
+ // ============================================================================
381
+ // Exports
382
+ // ============================================================================
383
+ export default {
384
+ sleep,
385
+ randomInt,
386
+ randomFloat,
387
+ randomChar,
388
+ gaussian,
389
+ randomDelay,
390
+ humanType,
391
+ randomMouseMovement,
392
+ realisticClick,
393
+ smoothScroll,
394
+ readingPause,
395
+ randomMouseJitter,
396
+ hoverElement,
397
+ simulateReadingPage,
398
+ };
399
+ //# sourceMappingURL=stealth-utils.js.map