mcp-scraper 0.93.1 → 0.93.2
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/CHANGELOG.md +31 -25
- package/README.md +3 -3
- package/dist/bin/api-server.js +1 -1
- package/dist/bin/mcp-scraper-cli.js +1 -1
- package/dist/bin/mcp-scraper-core.js +1 -1
- package/dist/bin/mcp-scraper-install.js +1 -1
- package/dist/bin/mcp-stdio-server.js +1 -1
- package/dist/bin/paa-harvest.js +1 -1
- package/dist/chunk-2SP57VCG.js +15 -15
- package/dist/{chunk-5QYW4CSJ.js → chunk-5VB3I7UX.js} +5 -5
- package/dist/chunk-73LAMUS5.js +6 -0
- package/dist/{chunk-X6RD3Y4W.js → chunk-CG2FHIBA.js} +1 -1
- package/dist/chunk-DT2FYN6N.js +1 -1
- package/dist/{chunk-XG6GCEUE.js → chunk-EWR7BPPD.js} +1 -1
- package/dist/{chunk-IK5BG7MO.js → chunk-KPDNM7E7.js} +1 -1
- package/dist/{chunk-M5VZVMPC.js → chunk-MJ2OICVY.js} +3 -3
- package/dist/chunk-ORB4RHCK.js +4 -4
- package/dist/{chunk-OD2WLHEN.js → chunk-QWSWHUOK.js} +4 -4
- package/dist/chunk-SH5KB4P7.js +1 -1
- package/dist/{chunk-M5QHXNFZ.js → chunk-VVG7LFFF.js} +3 -3
- package/dist/chunk-WJ4XFLS4.js +15 -15
- package/dist/chunk-XJ6PJWT5.js +1 -0
- package/dist/chunk-Y6MKMSOC.js +1 -1
- package/dist/{extract-bundle-C3N6E6V7.js → extract-bundle-MQOAKQDV.js} +1 -1
- package/dist/index.cjs +21 -21
- package/dist/index.d.cts +14 -14
- package/dist/index.d.ts +14 -14
- package/dist/index.js +1 -1
- package/dist/{server-KWGXYWYO.js → server-GRB6VNT6.js} +42 -42
- package/dist/{worker-ASXALAY7.js → worker-US6CTFYG.js} +1 -1
- package/package.json +136 -17
- package/THIRD_PARTY_NOTICES.html +0 -203
- package/dist/chunk-AYQSKD7D.js +0 -1
- package/dist/chunk-KPQM4UDJ.js +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.93.2] - 2026-09-24
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Show Google Search and other provider costs in the CEO report with separate calculated, actual-or-measured, and unresolved receipt coverage. Failed queries now stop the report, missing Bright Data SERP rates leave an explicit delivered-but-unpriced receipt, and historical cost rows no longer imply a margin from subscription MRR.
|
|
12
|
+
|
|
7
13
|
## [0.93.1] - 2026-09-24
|
|
8
14
|
|
|
9
15
|
### Fixed
|
|
@@ -101,7 +107,7 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
101
107
|
|
|
102
108
|
- Retire the inactive Personal Assistant from server startup, HTTP and MCP routing, web navigation, Scheduler transitions, generated contracts, and Memory tool registration while preserving its source history, persisted data, secrets, and provider resources behind the verified archive branch.
|
|
103
109
|
- Make two-page SERP capture perform a distinct page-two request, preserve page provenance and query/location intent, and report local-pack evidence as present, absent, incomplete, or unknown instead of silently claiming completeness.
|
|
104
|
-
- Make Maps retries follow one immutable egress plan, retain location intent, close every browser/proxy attempt, and treat an already-gone
|
|
110
|
+
- Make Maps retries follow one immutable egress plan, retain location intent, close every browser/proxy attempt, and treat an already-gone Kernel session as successful cleanup.
|
|
105
111
|
|
|
106
112
|
### Fixed
|
|
107
113
|
|
|
@@ -115,13 +121,13 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
115
121
|
|
|
116
122
|
- Add the fixture-tested operation, attempt, provider-receipt, reconciliation, and billing-link foundation needed to trace failed and retried SERP, PAA, Maps, extraction, and transcription work without treating missing provider cost as zero.
|
|
117
123
|
- Add a generated MCP cost-coverage manifest and release gate that tracks every hosted input flag plus each named execution method's retry, timeout, billing, and cost-accounting owner.
|
|
118
|
-
- Trace direct
|
|
119
|
-
- Add a protected four-cell PAA benchmark runner for
|
|
124
|
+
- Trace direct Bright Data SERP requests and Bright Data/Kernel browser attempts into the shared operation timeline, including provider identities, retry or fallback causality, immediate estimates, hourly due-gated Browser API reconciliation, and customer billing links.
|
|
125
|
+
- Add a protected four-cell PAA benchmark runner for Kernel and Bright Data at 20 and 40 complete questions, with a dry-run contract gate, one paid attempt per cell, sanitized provider evidence, and no automatic replacement run.
|
|
120
126
|
- Add a once-daily due-gated purge of raw provider identifiers and verbose diagnostic errors after 30 days while preserving normalized cost facts and hashed correlation keys.
|
|
121
127
|
|
|
122
128
|
### Fixed
|
|
123
129
|
|
|
124
|
-
- Skip
|
|
130
|
+
- Skip Kernel proxy resolution when the active attempt uses Bright Data Browser, removing avoidable Kernel API traffic from Bright Data-first SERP and PAA work.
|
|
125
131
|
|
|
126
132
|
## [0.90.4] - 2026-09-22
|
|
127
133
|
|
|
@@ -133,21 +139,21 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
133
139
|
|
|
134
140
|
### Fixed
|
|
135
141
|
|
|
136
|
-
- Route ordinary
|
|
142
|
+
- Route ordinary Bright Data SERP searches through the zone's native parsed proxy, returning Google results within the existing bounded deadline while preserving the REST endpoint as a configuration fallback.
|
|
137
143
|
- Keep Browser API credentials and interactive PAA behavior independent from the native SERP transport, with one provider request and no hidden retry or browser fallback.
|
|
138
144
|
|
|
139
145
|
## [0.90.2] - 2026-09-21
|
|
140
146
|
|
|
141
147
|
### Fixed
|
|
142
148
|
|
|
143
|
-
- Unwrap
|
|
149
|
+
- Unwrap Bright Data's object-valued REST response body before mapping parsed SERP fields, so successful direct searches return their organic results instead of an empty collection.
|
|
144
150
|
|
|
145
151
|
## [0.90.1] - 2026-09-21
|
|
146
152
|
|
|
147
153
|
### Changed
|
|
148
154
|
|
|
149
|
-
- Route ordinary `search_serp` calls through one parsed
|
|
150
|
-
- Keep saved SERP identities on their existing
|
|
155
|
+
- Route ordinary `search_serp` calls through one parsed Bright Data SERP API request when the dedicated production zone is configured, avoiding browser startup and cleanup while leaving interactive PAA on Browser API.
|
|
156
|
+
- Keep saved SERP identities on their existing Kernel-backed path and retain the browser path as the configuration fallback for local and unconfigured environments.
|
|
151
157
|
|
|
152
158
|
### Fixed
|
|
153
159
|
|
|
@@ -190,7 +196,7 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
190
196
|
|
|
191
197
|
### Changed
|
|
192
198
|
|
|
193
|
-
- Cap every
|
|
199
|
+
- Cap every Kernel browser session at a ten-minute absolute lifetime and move expired-session reconciliation from the minute root cron to a dedicated hourly audit.
|
|
194
200
|
- Disable the inactive Personal Assistant reminder, reconciliation, and inbound cron schedules while preserving their routes and implementation.
|
|
195
201
|
- Disable the inactive Personal Memory heartbeat and weekly rollup registrations in the production scheduler while preserving their implementation.
|
|
196
202
|
- Pause twice-daily automatic memory optimization while preserving the workflow for deliberate use, preventing all-vault fan-out from consuming background execution capacity.
|
|
@@ -199,10 +205,10 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
199
205
|
|
|
200
206
|
### Fixed
|
|
201
207
|
|
|
202
|
-
- Treat
|
|
208
|
+
- Treat Kernel's not-found response during legacy session deletion as successful cleanup, preventing already-closed sessions from retrying forever.
|
|
203
209
|
- Show browser sessions awaiting provider cleanup separately in the CTO report instead of hiding them behind a non-null close timestamp.
|
|
204
210
|
- Cast the analytics pruning clock before PostgreSQL interval arithmetic so the root cron no longer fails every minute while pruning scheduled occurrences.
|
|
205
|
-
- Explicitly delete
|
|
211
|
+
- Explicitly delete Kernel screenshot sessions after capture, including when closing the browser connection fails.
|
|
206
212
|
|
|
207
213
|
## [0.89.7] - 2026-09-18
|
|
208
214
|
|
|
@@ -321,7 +327,7 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
321
327
|
|
|
322
328
|
### Fixed
|
|
323
329
|
|
|
324
|
-
- Give each `reddit_thread` retrieval a 300-second end-to-end deadline, with two 60-second
|
|
330
|
+
- Give each `reddit_thread` retrieval a 300-second end-to-end deadline, with two 60-second Kernel attempts and two 60-second managed-browser backup attempts, instead of exhausting the full retry ladder in about 50 seconds. The MCP client now waits long enough to receive the endpoint's structured terminal result.
|
|
325
331
|
|
|
326
332
|
## [0.88.2] - 2026-09-02
|
|
327
333
|
|
|
@@ -358,19 +364,19 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
358
364
|
|
|
359
365
|
### Fixed
|
|
360
366
|
|
|
361
|
-
- Kept
|
|
367
|
+
- Kept Bright Data telemetry lookup off the Reddit response critical path and reallocated the saved time to 17-second backup attempts, so all four provider attempts can finish before production ends the request.
|
|
362
368
|
|
|
363
369
|
## [0.86.4] - 2026-09-02
|
|
364
370
|
|
|
365
371
|
### Fixed
|
|
366
372
|
|
|
367
|
-
- Kept the complete two-primary, two-backup Reddit retry ladder inside the production request window by limiting
|
|
373
|
+
- Kept the complete two-primary, two-backup Reddit retry ladder inside the production request window by limiting Kernel attempts to 8 seconds, Bright Data attempts to 14 seconds, and browser cleanup to 1 second.
|
|
368
374
|
|
|
369
375
|
## [0.86.3] - 2026-09-02
|
|
370
376
|
|
|
371
377
|
### Fixed
|
|
372
378
|
|
|
373
|
-
- Applied 45-second
|
|
379
|
+
- Applied 45-second Kernel and 35-second Bright Data deadlines to the complete Reddit browser-attempt lifecycle, and made known-thread primary attempts find and click the target through DuckDuckGo before the residential landing.
|
|
374
380
|
|
|
375
381
|
## [0.86.2] - 2026-09-02
|
|
376
382
|
|
|
@@ -519,13 +525,13 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
519
525
|
|
|
520
526
|
### Added
|
|
521
527
|
|
|
522
|
-
- Added a
|
|
523
|
-
- Added a bounded managed-browser backup for Reddit thread hydration after the primary
|
|
528
|
+
- Added a Kernel-only Reddit workflow that searches DuckDuckGo with a `site:reddit.com` query, switches the same browser to a residential proxy before clicking the selected result, and reads modern Reddit posts plus bounded rendered-comment expansion through dedicated search, thread, and combined REST endpoints.
|
|
529
|
+
- Added a bounded managed-browser backup for Reddit thread hydration after the primary Kernel attempt fails or returns fewer than the semantic target, capped at 25 comments with measured bandwidth, duration, CAPTCHA, closure, and provider-cost telemetry.
|
|
524
530
|
|
|
525
531
|
### Changed
|
|
526
532
|
|
|
527
|
-
- Routed the production `reddit_thread` and `reddit_trending` MCP tools through modern Reddit on
|
|
528
|
-
- Cost probes now include Reddit
|
|
533
|
+
- Routed the production `reddit_thread` and `reddit_trending` MCP tools through modern Reddit on Kernel residential sessions, with DuckDuckGo site search for trend discovery; removed Google and old Reddit from their active execution path while preserving tool names, billing rates, bounded partial results, and refunds.
|
|
534
|
+
- Cost probes now include Reddit Kernel sessions and any managed-browser fallback bytes and cost in the same request receipt, and identify when the backup contributed to total cost.
|
|
529
535
|
|
|
530
536
|
### Fixed
|
|
531
537
|
|
|
@@ -570,7 +576,7 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
570
576
|
|
|
571
577
|
### Fixed
|
|
572
578
|
|
|
573
|
-
- Persisted per-control PAA dispatch and 0.7/1.0/1.4-second confirmation telemetry in durable checkpoints, exposed recent interaction and attempt correlation through MCP status, attached
|
|
579
|
+
- Persisted per-control PAA dispatch and 0.7/1.0/1.4-second confirmation telemetry in durable checkpoints, exposed recent interaction and attempt correlation through MCP status, attached Bright Data session IDs immediately after browser launch, and finalized dangling attempt rows during lease recovery without blocking customer settlement.
|
|
574
580
|
- Prevented inline style, script, and hidden DOM text inside Google answer containers from falsely confirming that PAA answer material loaded.
|
|
575
581
|
- Routed canonical `/assistant` page loads to the web app and the redacted private Assistant readiness endpoint to the main API function, preventing production 404s after the 0.79.1 launch.
|
|
576
582
|
|
|
@@ -594,7 +600,7 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
594
600
|
- Added Scheduling as the canonical Personal Assistant setup surface, with connection readiness for Gmail, Calendar, Zoom, browser profiles, Memory, SMS, and email; exact schedule confirmation; approval and spend review; run history; and explicit watch/takeover states.
|
|
595
601
|
- Added owner-scoped browser profiles that can hold multiple independently verified login bindings, while every browser schedule grant selects one exact profile, login, domain, and action set.
|
|
596
602
|
- Added immutable schedule revisions, readiness receipts, append-only activation records, additive legacy schedule projection, and single-owner occurrence transition receipts so migration cannot silently infer browser authority or double-dispatch work.
|
|
597
|
-
- Added
|
|
603
|
+
- Added Kernel and private-Mac browser runtime boundaries with collision-resistant tenant namespaces, per-owner concurrency ceilings, bounded sessions, explicit and timeout cleanup, owner-qualified account deletion, and provider deletion readback.
|
|
598
604
|
- Added an owner-controlled Personal Assistant that brings SMS/MMS, Gmail, Google Calendar, Zoom, browser work, reminders, and Memory context packets into one governed workflow with immutable plans, approval checkpoints, spend limits, and durable receipts.
|
|
599
605
|
- Added Twilio number discovery, owned-number attachment, purchase and registration previews, Messaging Service readiness, signed inbound and delivery webhooks, safe MMS ingestion, deterministic opt-out handling, single and reviewed bulk messaging, and reconciliation for unknown provider outcomes.
|
|
600
606
|
- Added immutable, revisioned Memory context packets with source and attachment provenance, Gmail full-message imports, MMS media metadata, lifecycle controls, and readback verification against the selected vault.
|
|
@@ -631,7 +637,7 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
631
637
|
- Made `maxQuestions` an explicit target count rather than a traversal-depth control, with separate discovery and material-completeness diagnostics.
|
|
632
638
|
- Preserved complete People Also Ask, AI Overview, and organic-result link provenance in JSON, structured MCP output, and CSV while classifying plain links and Google redirect links explicitly.
|
|
633
639
|
- Resolved opaque Google `/goto` targets through bounded concurrent manual-redirect requests with active-browser interception as a fallback, without following publisher destinations and without dropping unresolved material.
|
|
634
|
-
- Aligned the bounded PAA production-provider canary with the public `maxQuestions` contract and made
|
|
640
|
+
- Aligned the bounded PAA production-provider canary with the public `maxQuestions` contract and made Bright Data the default test provider.
|
|
635
641
|
|
|
636
642
|
### Fixed
|
|
637
643
|
|
|
@@ -839,7 +845,7 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
839
845
|
|
|
840
846
|
- Added portable `harvest_paa_start` and `harvest_paa_status` tools for durable long-running PAA research, with stable idempotency recovery, progress, attempt provenance, completeness, billing state, and bounded provider telemetry.
|
|
841
847
|
- Added progressive PAA checkpoints that preserve and merge the best unique rows across browser retries and stale-job recovery instead of losing already captured questions when a provider session or caller is interrupted.
|
|
842
|
-
- Added exact
|
|
848
|
+
- Added exact Bright Data browser-session identity, sanitized Session Logs enrichment, disconnect attribution, bandwidth usage telemetry, and retryable reconciliation without making provider telemetry a prerequisite for result delivery.
|
|
843
849
|
|
|
844
850
|
### Changed
|
|
845
851
|
|
|
@@ -1572,7 +1578,7 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
1572
1578
|
|
|
1573
1579
|
### Changed
|
|
1574
1580
|
|
|
1575
|
-
- PAA browser work now uses
|
|
1581
|
+
- PAA browser work now uses Kernel's co-located Playwright execution with stealth mode's default managed proxy and native browser metadata. Location is expressed only through Google UULE, CAPTCHA solver waiting is capped at 60 seconds, and a fresh session is allowed once only when no useful data was captured.
|
|
1576
1582
|
- PAA invocations stop browser work at 250 seconds inside the 280-second application budget, reserving 30 seconds for persistence, cleanup, and settlement. The legacy cron worker no longer claims Inngest-owned PAA jobs.
|
|
1577
1583
|
|
|
1578
1584
|
### Fixed
|
|
@@ -1808,7 +1814,7 @@ All notable changes to MCP Scraper are documented here. The format is based on [
|
|
|
1808
1814
|
|
|
1809
1815
|
### Changed
|
|
1810
1816
|
|
|
1811
|
-
- `maps_search` now applies a transport ladder across its retry attempts so it can recover from Google soft-blocks instead of only retrying the same way. The first attempt is unchanged (
|
|
1817
|
+
- `maps_search` now applies a transport ladder across its retry attempts so it can recover from Google soft-blocks instead of only retrying the same way. The first attempt is unchanged (Kernel's default stealth ISP proxy, direct navigation). Subsequent retries switch to direct egress and arrive at Google through a cross-site redirect (the combination that measurably clears blocks a cold navigation triggers); the final escalation attempt uses direct egress without the redirect and accepts any egress country. This only affects the `proxyMode: 'none'` default path and only its retries — a first-attempt success behaves exactly as before.
|
|
1812
1818
|
|
|
1813
1819
|
## [0.32.1] - 2026-07-22
|
|
1814
1820
|
|
package/README.md
CHANGED
|
@@ -175,7 +175,7 @@ Build the branded one-click bundle:
|
|
|
175
175
|
npm run build:mcpb
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
The generated bundle is written to `build/mcpb/mcp-scraper-<version>.mcpb` and copied to `public/downloads/` for the hosted download. The current public bundle is `https://mcpscraper.dev/downloads/mcp-scraper.mcpb` (`0.93.
|
|
178
|
+
The generated bundle is written to `build/mcpb/mcp-scraper-<version>.mcpb` and copied to `public/downloads/` for the hosted download. The current public bundle is `https://mcpscraper.dev/downloads/mcp-scraper.mcpb` (`0.93.2`, SHA-256 `1c52ef996152bed5e17ba731f90a883cb4e1ad840826764d62d2e193a91d0a38`). Install it by opening or dragging it into Claude Desktop. Claude displays the `MCP Scraper` install card, icon, API-key configuration field, and manually curated current-release message from the bundle manifest.
|
|
179
179
|
|
|
180
180
|
The MCPB install exposes every tool — web-intelligence plus all `browser_*` tools — through the one `mcp-scraper` server.
|
|
181
181
|
|
|
@@ -366,8 +366,8 @@ The `mcp-scraper` NPX stdio server also exposes saved reports as MCP resources:
|
|
|
366
366
|
- `MCP_SCRAPER_OUTPUT_DIR` is optional and defaults to `~/Downloads/mcp-scraper`.
|
|
367
367
|
- `MCP_SCRAPER_SAVE_REPORTS=false` disables automatic Markdown report files.
|
|
368
368
|
- `MCP_SCRAPER_KEY_PATH` is optional. When no API key env var is set, the server also reads `~/.mcp-scraper-key` for compatibility with older installs.
|
|
369
|
-
- `BROWSER_AGENT_PROFILE_NAME` is optional and sets the default saved hosted browser profile for `mcp-scraper` stdio sessions. Aliases: `BROWSER_SERVICE_PROFILE_NAME`, `
|
|
370
|
-
- `BROWSER_AGENT_PROFILE_SAVE_CHANGES=true` is optional hosted setup behavior. It persists cookies and storage back to the named profile when `browser_close` deletes the hosted browser session. Aliases: `BROWSER_SERVICE_PROFILE_SAVE_CHANGES`, `
|
|
369
|
+
- `BROWSER_AGENT_PROFILE_NAME` is optional and sets the default saved hosted browser profile for `mcp-scraper` stdio sessions. Aliases: `BROWSER_SERVICE_PROFILE_NAME`, `KERNEL_BROWSER_PROFILE_NAME`, `KERNEL_PROFILE_NAME`.
|
|
370
|
+
- `BROWSER_AGENT_PROFILE_SAVE_CHANGES=true` is optional hosted setup behavior. It persists cookies and storage back to the named profile when `browser_close` deletes the hosted browser session. Aliases: `BROWSER_SERVICE_PROFILE_SAVE_CHANGES`, `KERNEL_BROWSER_PROFILE_SAVE_CHANGES`, `KERNEL_PROFILE_SAVE_CHANGES`.
|
|
371
371
|
|
|
372
372
|
Hosted operators can isolate authorization state in a dedicated Turso/libSQL database without changing the public MCP tool catalog or API-key authentication. The secured store uses atomic authorization-code exchange and refresh rotation, keyed secret lookup, bounded encrypted replay receipts, authority epochs, and fail-closed maintenance behavior. Production migration and rollback are controlled data moves, not ordinary mode flips; see [MCP OAuth operations](docs/operations/mcp-oauth-runbook.md). Existing client setup and reconnect behavior are unchanged in Phase 1.
|
|
373
373
|
|
package/dist/bin/api-server.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{readFileSync as s}from"fs";function c(){try{for(let r of s(".env","utf8").split(`
|
|
3
|
-
`)){let o=r.indexOf("=");if(o<1||r.trimStart().startsWith("#"))continue;let e=r.slice(0,o).trim();process.env[e]||(process.env[e]=r.slice(o+1).trim())}}catch{}}c();async function a(){let[{serve:r},{app:o},{startWorker:e},{migrate:i}]=await Promise.all([import("@hono/node-server"),import("../server-
|
|
3
|
+
`)){let o=r.indexOf("=");if(o<1||r.trimStart().startsWith("#"))continue;let e=r.slice(0,o).trim();process.env[e]||(process.env[e]=r.slice(o+1).trim())}}catch{}}c();async function a(){let[{serve:r},{app:o},{startWorker:e},{migrate:i}]=await Promise.all([import("@hono/node-server"),import("../server-GRB6VNT6.js"),import("../worker-US6CTFYG.js"),import("../db-B5XJTOGN.js")]),n=parseInt(process.env.PORT??"3001");try{if(await i(),process.env.ANALYTICS_DATABASE_URL){let{migrateAnalytics:t}=await import("../analytics-repository-IHOFBSUV.js");await t()}e(),r({fetch:o.fetch,port:n},t=>{console.log(`[server] http://localhost:${t.port}`),console.log(`[server] admin auth: ${process.env.ADMIN_KEY?"configured":"not configured"}`)})}catch(t){console.error("[startup] server preflight failed",t instanceof Error?t.name:"unknown_error"),process.exit(1)}}a();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{b as E,c as N,d as M,e as L,f as T,j as U}from"../chunk-W2T4NTCE.js";import"../chunk-KJQXUZ4Y.js";import"../chunk-Y6MKMSOC.js";import{g as v,j as b,k as D,l as K,m as H}from"../chunk-WO3N5FH2.js";import"../chunk-HE45FFBU.js";import{a as P}from"../chunk-
|
|
2
|
+
import{b as E,c as N,d as M,e as L,f as T,j as U}from"../chunk-W2T4NTCE.js";import"../chunk-KJQXUZ4Y.js";import"../chunk-Y6MKMSOC.js";import{g as v,j as b,k as D,l as K,m as H}from"../chunk-WO3N5FH2.js";import"../chunk-HE45FFBU.js";import{a as P}from"../chunk-XJ6PJWT5.js";import{Command as he}from"commander";import{spawn as ne}from"child_process";import{mkdir as ke,writeFile as Pe}from"fs/promises";import{basename as Ce,join as Z}from"path";function se(e){return e.apiKey?.trim()||"sk_live_your_key"}function ce(e){return e.packageSpec?.trim()||"mcp-scraper@latest"}function A(e={}){return["-y","--package",ce(e),"mcp-scraper"]}function pe(e){let n={MCP_SCRAPER_API_KEY:se(e)},c=e.browserProfileName?.trim();return c&&(n.BROWSER_AGENT_PROFILE_NAME=c),e.browserProfileSaveChanges===!0&&(n.BROWSER_AGENT_PROFILE_SAVE_CHANGES="true"),n}function q(){return["mcp","remove","mcp-scraper","-s","user"]}function J(){return["mcp","get","mcp-scraper"]}function B(e){let n=e.match(/^\s*Command:\s*(.+?)\s*$/m)?.[1];if(!n)return null;let c=e.match(/^\s*Args:\s*(.*?)\s*$/m)?.[1]??"",i=c.length?c.split(/\s+/):[],p={},u=e.split(/^\s*Environment:\s*$/m)[1];if(u)for(let a of u.split(`
|
|
3
3
|
`)){let l=a.match(/^\s{2,}([A-Za-z_][A-Za-z0-9_]*)=(.*)$/);if(!l){if(a.trim().length&&!/^\s{2,}/.test(a))break;continue}p[l[1]]=l[2]}return{command:n,args:i,env:p}}function j(e){let n=["mcp","add","mcp-scraper","--scope","user"];for(let[c,i]of Object.entries(e.env))n.push("--env",`${c}=${i}`);return n.push("--",e.command,...e.args),n}function G(e={}){let n=["mcp","add","mcp-scraper","--scope","user"];for(let[c,i]of Object.entries(pe(e)))n.push("--env",`${c}=${i}`);return n.push("--","npx",...A(e)),n}function O(e){if(e==="claude-code")return"claude";if(e==="claude"||D.hosts.some(n=>n.id===e))return e;throw new Error('Unknown host "'+e+'". Use: codex, claude, claude-code, claude-desktop, cursor, windsurf, cline, or user-action-only')}function ue(e){return K(e==="claude"?"claude-code":e)}function W(e,n={}){let c=O(e),i=ue(c),p="Restart the MCP client so it starts a fresh npx process.",u='MCP_SCRAPER_API_KEY="$MCP_SCRAPER_API_KEY" npx -y -p mcp-scraper@latest mcp-scraper-cli agent install claude --apply',a=`X-Ray install protocol: ${v} (${b})`;return c==="codex"?["# Codex MCP config",a,i.exactConfig,"",`Continuation: ${i.continuation}`,`Rollback: ${i.rollback}`,"",p].join(`
|
|
4
4
|
`):c==="claude"?["# Claude Code command",a,i.exactConfig,"","# One-command Claude Code setup",u,"",`Continuation: ${i.continuation}`,`Rollback: ${i.rollback}`,"",p].join(`
|
|
5
5
|
`):c==="claude-desktop"?["# Claude Desktop config",a,i.exactConfig,"","Desktop Extension: https://mcpscraper.dev/downloads/mcp-scraper.mcpb",`Continuation: ${i.continuation}`,`Rollback: ${i.rollback}`,p].join(`
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as e}from"../chunk-
|
|
2
|
+
import{a as e}from"../chunk-CG2FHIBA.js";import"../chunk-QWSWHUOK.js";import"../chunk-DT2FYN6N.js";import"../chunk-W2BVJ7S2.js";import"../chunk-RK2VCTZI.js";import"../chunk-ORB4RHCK.js";import"../chunk-TMB56NCA.js";import"../chunk-HUV2WTRW.js";import"../chunk-YGBTTW5D.js";import"../chunk-UN6FVDJQ.js";import"../chunk-SH5KB4P7.js";import"../chunk-2SP57VCG.js";import"../chunk-6DTXIZY2.js";import"../chunk-5VB3I7UX.js";import"../chunk-WO3N5FH2.js";import"../chunk-HE45FFBU.js";import"../chunk-XJ6PJWT5.js";import"../chunk-WJ4XFLS4.js";var _=["harvest_paa","search_serp","extract_url","diff_page","map_site_urls","map_wayback_snapshots","extract_site","analyze_site_similarity","audit_site","check_site_export","site_export_read","site_export_image","archive_read","youtube_harvest","youtube_transcribe","facebook_page_intel","facebook_ad_search","reddit_thread","reddit_trending","video_frame_analysis","video_frame_analysis_status","facebook_ad_transcribe","google_ads_search","google_ads_page_intel","google_ads_transcribe","facebook_video_transcribe","instagram_profile_content","instagram_media_download","maps_place_intel","maps_search","trustpilot_reviews","g2_reviews","capture_serp_snapshot","capture_serp_page_snapshots"];e({toolsets:new Set(["paa","serp"]),allowedToolNames:_});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as s}from"../chunk-
|
|
2
|
+
import{a as s}from"../chunk-5VB3I7UX.js";import{a as e}from"../chunk-XJ6PJWT5.js";var r=process.argv.includes("--no-color")||process.env.NO_COLOR!==void 0||process.env.FORCE_COLOR==="0"||!process.stdout.isTTY,n=process.argv.includes("--help")||process.argv.includes("-h");n&&(process.stdout.write(["Usage: mcp-scraper-install [--no-color]","","Prints the branded MCP Scraper terminal install card and copyable install commands.","mcp-scraper prints the same card in a human terminal and runs as the MCP stdio server in clients.",""].join(`
|
|
3
3
|
`)),process.exit(0));process.stdout.write(s({version:e,color:!r,apiKeyConfigured:!!process.env.MCP_SCRAPER_API_KEY?.trim()}));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as r}from"../chunk-
|
|
2
|
+
import{a as r}from"../chunk-CG2FHIBA.js";import"../chunk-QWSWHUOK.js";import"../chunk-DT2FYN6N.js";import"../chunk-W2BVJ7S2.js";import"../chunk-RK2VCTZI.js";import"../chunk-ORB4RHCK.js";import"../chunk-TMB56NCA.js";import"../chunk-HUV2WTRW.js";import"../chunk-YGBTTW5D.js";import"../chunk-UN6FVDJQ.js";import"../chunk-SH5KB4P7.js";import"../chunk-2SP57VCG.js";import"../chunk-6DTXIZY2.js";import"../chunk-5VB3I7UX.js";import"../chunk-WO3N5FH2.js";import"../chunk-HE45FFBU.js";import"../chunk-XJ6PJWT5.js";import"../chunk-WJ4XFLS4.js";r();
|
package/dist/bin/paa-harvest.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{w as t}from"../chunk-
|
|
2
|
+
import{w as t}from"../chunk-MJ2OICVY.js";import"../chunk-VVG7LFFF.js";import{b as r}from"../chunk-SH5KB4P7.js";import"../chunk-2SP57VCG.js";import"../chunk-6DTXIZY2.js";import"../chunk-Y6MKMSOC.js";import"../chunk-WJ4XFLS4.js";import{Command as s,Option as a}from"commander";var i=new s;i.name("paa-harvest").description("Recursively extract Google People Also Ask questions").requiredOption("-q, --query <query>","Seed query").option("-l, --location <location>",'Location name (e.g. "austin" or "Austin,Texas,United States")').option("--gl <gl>","Google country code","us").option("--hl <hl>","Google language code","en").option("-d, --depth <depth>","BFS depth (1-30)","3").option("-m, --max-questions <n>","Max questions to harvest","100").option("-o, --output <dir>","Output directory","./paa-output").option("-f, --format <format>","Output format: json, csv, or both","both").option("--headless","Run browser in headless mode",!1).option("--profile <dir>","Persistent browser profile directory").option("--proxy <url>","Proxy server URL").option("--browser-api-key <key>","Browser service API key (or set BROWSER_SERVICE_API_KEY env var)").addOption(new a("--kernel-api-key <key>").hideHelp()).action(async e=>{try{let o=await t({query:e.query,location:e.location,gl:e.gl,hl:e.hl,depth:parseInt(e.depth,10),maxQuestions:parseInt(e.maxQuestions,10),outputDir:e.output,format:e.format,headless:e.headless,profileDir:e.profile,proxy:e.proxy,kernelApiKey:e.browserApiKey??e.kernelApiKey??r()});console.log(JSON.stringify({totalQuestions:o.totalQuestions,outputDir:o.stats.seed}))}catch(o){console.error(o instanceof Error?o.message:String(o)),process.exit(1)}});async function n(){await i.parseAsync()}n();
|
package/dist/chunk-2SP57VCG.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import{c as l}from"./chunk-6DTXIZY2.js";import{t as _}from"./chunk-WJ4XFLS4.js";var c=166667e-10,N=.0001333336,I=new Set(["serp","fb_search","fb_ad","instagram"]),p=.00111,L=4,R=4e-4;function o(e,r){let t=process.env[e]?.trim();if(!t)return r;let s=Number(t);return Number.isFinite(s)&&s>=0?s:r}var A=o("NANGO_USD_PER_CONNECTION_MONTH",1),U=o("NANGO_USD_PER_FUNCTION_RUN",1e-4),m=o("NANGO_USD_PER_PROXY_REQUEST",1e-4),g=o("NANGO_USD_PER_COMPUTE_SEC",2e-4),O=o("
|
|
1
|
+
import{c as l}from"./chunk-6DTXIZY2.js";import{t as _}from"./chunk-WJ4XFLS4.js";var c=166667e-10,N=.0001333336,I=new Set(["serp","fb_search","fb_ad","instagram"]),p=.00111,L=4,R=4e-4;function o(e,r){let t=process.env[e]?.trim();if(!t)return r;let s=Number(t);return Number.isFinite(s)&&s>=0?s:r}var A=o("NANGO_USD_PER_CONNECTION_MONTH",1),U=o("NANGO_USD_PER_FUNCTION_RUN",1e-4),m=o("NANGO_USD_PER_PROXY_REQUEST",1e-4),g=o("NANGO_USD_PER_COMPUTE_SEC",2e-4),O=o("BRIGHTDATA_BROWSER_USD_PER_GB",8),D=o("BRIGHTDATA_SERP_USD_PER_REQUEST",.002836168);function u(e,r){return Math.max(0,e)/1e3*(r?N:c)}function d(e,r){return e==="fal_wizper"?Math.max(0,r)/L*p:e==="deepinfra_qwen"?Math.max(0,r)/1e3*R:e==="openrouter"||e==="mcp_memory_video"||e==="mcp_memory_ai"?Math.max(0,r):e==="nango_connection"?Math.max(0,r)*A:e==="nango_function_run"?Math.max(0,r)*U:e==="nango_proxy_request"?Math.max(0,r)*m:e==="nango_compute"?Math.max(0,r)*g:e==="brightdata_browser_api"?Math.max(0,r)/1e9*O:0}import{randomUUID as i}from"crypto";var E=!1,n=null;async function T(){if(!E)return n||(n=S().finally(()=>{n=null}),n)}async function S(){let e=_(),r=await e.execute(`
|
|
2
2
|
SELECT
|
|
3
|
-
(SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name IN ('
|
|
4
|
-
AND (SELECT COUNT(*) FROM pragma_table_info('
|
|
3
|
+
(SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name IN ('kernel_session_log', 'vendor_usage_log', 'cost_probe_runs')) = 3
|
|
4
|
+
AND (SELECT COUNT(*) FROM pragma_table_info('kernel_session_log') WHERE name IN ('proxy_source', 'proxy_type', 'method')) = 3
|
|
5
5
|
AND (SELECT COUNT(*) FROM pragma_table_info('vendor_usage_log') WHERE name IN ('method', 'source_key', 'provider_duration_ms', 'provider_captcha', 'provider_status')) = 5
|
|
6
6
|
AND (SELECT COUNT(*) FROM sqlite_master WHERE type = 'index' AND name = 'vendor_usage_log_vendor_source_key') = 1
|
|
7
7
|
AND (SELECT COUNT(*) FROM pragma_table_info('cost_probe_runs') WHERE name IN ('units', 'unit_type', 'mode')) = 3
|
|
8
8
|
AS ready
|
|
9
9
|
`);if(Number(r.rows[0]?.ready??0)===1){E=!0;return}await e.execute(`
|
|
10
|
-
CREATE TABLE IF NOT EXISTS
|
|
10
|
+
CREATE TABLE IF NOT EXISTS kernel_session_log (
|
|
11
11
|
id TEXT PRIMARY KEY,
|
|
12
|
-
|
|
12
|
+
kernel_session_id TEXT,
|
|
13
13
|
op TEXT,
|
|
14
14
|
source TEXT NOT NULL,
|
|
15
15
|
probe_run_id TEXT,
|
|
@@ -26,7 +26,7 @@ import{c as l}from"./chunk-6DTXIZY2.js";import{t as _}from"./chunk-WJ4XFLS4.js";
|
|
|
26
26
|
error TEXT,
|
|
27
27
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
28
28
|
)
|
|
29
|
-
`),await e.execute("CREATE INDEX IF NOT EXISTS
|
|
29
|
+
`),await e.execute("CREATE INDEX IF NOT EXISTS kernel_session_log_op ON kernel_session_log(op)"),await e.execute("CREATE INDEX IF NOT EXISTS kernel_session_log_probe ON kernel_session_log(probe_run_id)"),await e.execute("CREATE INDEX IF NOT EXISTS kernel_session_log_created ON kernel_session_log(created_at)");try{await e.execute("ALTER TABLE kernel_session_log ADD COLUMN proxy_source TEXT")}catch{}try{await e.execute("ALTER TABLE kernel_session_log ADD COLUMN proxy_type TEXT")}catch{}try{await e.execute("ALTER TABLE kernel_session_log ADD COLUMN method TEXT")}catch{}await e.execute(`
|
|
30
30
|
CREATE TABLE IF NOT EXISTS vendor_usage_log (
|
|
31
31
|
id TEXT PRIMARY KEY,
|
|
32
32
|
op TEXT,
|
|
@@ -54,20 +54,20 @@ import{c as l}from"./chunk-6DTXIZY2.js";import{t as _}from"./chunk-WJ4XFLS4.js";
|
|
|
54
54
|
success INTEGER NOT NULL DEFAULT 0,
|
|
55
55
|
error TEXT,
|
|
56
56
|
http_only INTEGER NOT NULL DEFAULT 0,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
kernel_used INTEGER NOT NULL DEFAULT 0,
|
|
58
|
+
kernel_sessions INTEGER NOT NULL DEFAULT 0,
|
|
59
|
+
kernel_seconds_total REAL NOT NULL DEFAULT 0,
|
|
60
|
+
kernel_tier_observed TEXT,
|
|
61
|
+
est_kernel_cost_usd_headless REAL NOT NULL DEFAULT 0,
|
|
62
|
+
est_kernel_cost_usd_headful REAL NOT NULL DEFAULT 0,
|
|
63
63
|
vendor_cost_usd REAL NOT NULL DEFAULT 0,
|
|
64
64
|
charged_credits REAL NOT NULL DEFAULT 0,
|
|
65
65
|
margin_usd_headless_starter REAL NOT NULL DEFAULT 0,
|
|
66
66
|
margin_usd_headful_starter REAL NOT NULL DEFAULT 0,
|
|
67
67
|
notes TEXT
|
|
68
68
|
)
|
|
69
|
-
`),await e.execute("CREATE INDEX IF NOT EXISTS cost_probe_runs_tool ON cost_probe_runs(tool)");try{await e.execute("ALTER TABLE cost_probe_runs ADD COLUMN units REAL")}catch{}try{await e.execute("ALTER TABLE cost_probe_runs ADD COLUMN unit_type TEXT")}catch{}try{await e.execute("ALTER TABLE cost_probe_runs ADD COLUMN mode TEXT")}catch{}E=!0}async function f(e){try{await T();let r=l(),t=Math.max(0,e.closedAtMs-e.openedAtMs);await _().execute({sql:`INSERT INTO
|
|
70
|
-
(id,
|
|
71
|
-
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,args:[i(),e
|
|
69
|
+
`),await e.execute("CREATE INDEX IF NOT EXISTS cost_probe_runs_tool ON cost_probe_runs(tool)");try{await e.execute("ALTER TABLE cost_probe_runs ADD COLUMN units REAL")}catch{}try{await e.execute("ALTER TABLE cost_probe_runs ADD COLUMN unit_type TEXT")}catch{}try{await e.execute("ALTER TABLE cost_probe_runs ADD COLUMN mode TEXT")}catch{}E=!0}async function f(e){try{await T();let r=l(),t=Math.max(0,e.closedAtMs-e.openedAtMs);await _().execute({sql:`INSERT INTO kernel_session_log
|
|
70
|
+
(id, kernel_session_id, op, source, probe_run_id, user_id, stealth, headless_sent, proxy_used, proxy_source, proxy_type, fallback, opened_at, closed_at, duration_ms, est_cost_usd_headless, est_cost_usd_headful, error, method)
|
|
71
|
+
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,args:[i(),e.kernelSessionId??null,r?.op??null,e.source,r?.probeRunId??null,r?.userId??null,a(e.stealth),a(e.headlessSent),a(e.proxyUsed),e.proxySource??null,e.proxyType??null,e.fallback?1:0,new Date(e.openedAtMs).toISOString(),new Date(e.closedAtMs).toISOString(),t,u(t,!1),u(t,!0),e.error??null,r?.subOp??null]})}catch(r){console.warn("[cost-telemetry] recordKernelSession failed:",r instanceof Error?r.message:String(r))}}async function v(e){try{await T();let r=l();return(await _().execute({sql:`INSERT OR IGNORE INTO vendor_usage_log
|
|
72
72
|
(id, op, probe_run_id, user_id, vendor, model, units, unit_type, est_cost_usd, error, method, source_key, provider_duration_ms, provider_captcha, provider_status)
|
|
73
73
|
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`,args:[i(),e.op??r?.op??null,e.probeRunId??r?.probeRunId??null,e.userId??r?.userId??null,e.vendor,e.model??null,e.units,e.unitType,d(e.vendor,e.units),e.error??null,e.method??r?.subOp??null,e.sourceKey??null,e.providerDurationMs??null,a(e.providerCaptcha),e.providerStatus??null]})).rowsAffected===1}catch(r){return console.warn("[cost-telemetry] recordVendorUsage failed:",r instanceof Error?r.message:String(r)),!1}}function a(e){return e==null?null:e?1:0}export{c as a,N as b,I as c,u as d,d as e,T as f,f as g,v as h};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var s={message:"
|
|
1
|
+
var s={message:"Google Search now preserves delivery evidence for provider-cost reporting even when an upstream billing rate is unavailable. Search inputs, results, and customer prices are unchanged."};var _={reset:"\x1B[0m",cyan:"\x1B[36m",lime:"\x1B[32m",amber:"\x1B[33m",red:"\x1B[31m",muted:"\x1B[90m",bold:"\x1B[1m"};function r(t,e,n){return n?`${_[e]}${t}${_.reset}`:t}function o(t,e,n){let a=t.padEnd(9," ");return` ${r(a,"muted",n)} ${e.join(r(" . ","muted",n))}`}function p(t){let e=t.color??!0,n=t.apiKeyConfigured?"$MCP_SCRAPER_API_KEY":"sk_live_your_key",a=String.raw`
|
|
2
2
|
__ __ ____ ____
|
|
3
3
|
| \/ |/ ___| _ \
|
|
4
4
|
| |\/| | | | |_) |
|
|
@@ -10,7 +10,7 @@ var s={message:"search_serp light mode returns organic Google positions, URLs, t
|
|
|
10
10
|
\___ \| | | |_) | / _ \ | |_) | _| | |_) |
|
|
11
11
|
___) | |___| _ < / ___ \| __/| |___| _ <
|
|
12
12
|
|____/ \____|_| \_\/_/ \_\_| |_____|_| \_\
|
|
13
|
-
`,
|
|
14
|
-
`),
|
|
15
|
-
`);return[r(`mcp-scraper v${t.version}`,"bold",e),r("> mcp-scraper-install","muted",e),r(
|
|
16
|
-
`)}export{
|
|
13
|
+
`,c=[`MCP_SCRAPER_API_KEY=${n} npx -y -p mcp-scraper@latest \\`," mcp-scraper-cli agent install claude --apply"].join(`
|
|
14
|
+
`),i=["[mcp_servers.mcp-scraper]",'command = "npx"','args = ["-y", "-p", "mcp-scraper@latest", "mcp-scraper"]',`env = { MCP_SCRAPER_API_KEY = "${n}" }`].join(`
|
|
15
|
+
`);return[r(`mcp-scraper v${t.version}`,"bold",e),r("> mcp-scraper-install","muted",e),r(a,"amber",e),`${r("MCP Scraper Agent","cyan",e)} . v${t.version} . mcpscraper.dev`,"1/1 install surfaces ready",r(`Newest in v${t.version}: ${s.message}`,"lime",e),"",`${r("Tools","cyan",e)} ${r("(362 MCP tools)","muted",e)}`,o("search",["harvest_paa","search_serp","maps_search","maps_place_intel"],e),o("extract",["extract_url","map_site_urls","extract_site","audit_site","directory_workflow"],e),o("build",["create_editorial_reading_room","rank_tracker_workflow","portable HTML"],e),o("media",["youtube_harvest","youtube_transcribe","facebook_reels_inventory","facebook_ad_search","facebook_page_intel","facebook_ad_transcribe","facebook_video_transcribe","tiktok_video_transcribe","instagram_profile_content","instagram_media_download","reddit_thread"],e),o("browser",["serp_identity_create","serp_identity_list","browser_open","browser_profile_connect","browser_profile_list","browser_close","browser_screenshot","browser_read","browser_locate","browser_replay_mark","browser_replay_annotate"],e),o("connect",["list_service_connections","describe_service_connection_tool","import_service_connection_to_memory","export_connected_service_data","renew_connected_data_download","read_service_connection","call_service_connection_action"],e),o("commons",["commons_search_entities","commons_get_entity_linkset","commons_prepare_entity","commons_submit_entity","commons_prepare_publication","commons_claim_publication","commons_publish_editorial","commons_get_publication"],e),o("account",["credits_info","reports","MCP resources"],e),o("memory",["memory-put","memory-get","memory-search","list-vaults","record-fact","list-scheduled-actions"],e),`${r("Workflows","cyan",e)} ${r("(MCP + CLI + API)","muted",e)}`,o("route",["workflow_list","workflow_suggest","workflow_run","workflow_step","workflow_status","workflow_artifact_read"],e),o("seo",["directory","agent-packet","competitive audit","map/serp comparison","PAA/AIO briefs","scheduled runs"],e),"",r("Usage tips:","amber",e),"Run mcp-scraper-install for this visible card. Run mcp-scraper-cli for setup utilities and subcommands.","Run mcp-scraper in a human terminal to print this card; MCP clients get the same command as a silent stdio server.","Explicit card command: npx -y -p mcp-scraper@latest mcp-scraper-install","Hosted browser sessions use direct/no-proxy egress by default.","Customer auth setup: run browser_profile_connect, send the watch_url, let the user sign in, then call browser_profile_list until AUTHENTICATED.","Connected account ranges: call export_connected_service_data once. It handles Gmail, Calendar, Zoom, and Resend pagination; do not loop read_service_connection over individual records.","Connected account RAG: call import_service_connection_to_memory for one bounded approved read. It writes a redacted, untrusted snapshot to a stable Memory path and embeds it for search.","Stack logins / reconnect: run browser_profile_connect again with the same profile name and another domain to add accounts or refresh a login.","Start with workflow_suggest for broad jobs like market analysis, ICP research, CRO audits, brand briefs, content gaps, and AI visibility.","For MCP clients, use mcp-scraper so one install can mix SERP, Maps, browser, reports, and saved MCP resources.","If you hit the concurrency limit, add 2 browsers for $5/month with mcp-scraper-cli billing concurrency checkout.","",`${r("Ready.","lime",e)} Install the combined MCP server with one command:`,"",r("Setup doctor","amber",e),"npx -y -p mcp-scraper@latest mcp-scraper-cli doctor","",r("Hosted profile setup","amber",e),'In your MCP client, call browser_profile_connect with email="seo@example.com" and domain="chatgpt.com".',"Give the returned watch_url to the user. After they sign in, call browser_profile_list, then browser_open with the returned profile. Add more logins by calling browser_profile_connect again with the same profile and a new domain.","",r("Claude Code one-command setup","amber",e),c,"Then fully exit Claude Code and open a new Claude terminal. Check with: claude mcp list","",r("Codex config","amber",e),i,"",r("Claude Desktop Extension","amber",e),"Download: https://mcpscraper.dev/downloads/mcp-scraper.mcpb","",r("Safety note:","muted",e),"mcp-scraper prints this card only when stdin/stdout are an interactive TTY. In MCP clients it writes only JSON-RPC to stdout.","Use --stdio or MCP_SCRAPER_FORCE_STDIO=1 to force server mode from a terminal.",""].join(`
|
|
16
|
+
`)}export{p as a};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as Tt}from"./chunk-EWR7BPPD.js";import{l as Rt,m as At,w as Pt}from"./chunk-MJ2OICVY.js";import{a as G,c as Ie,d as L,e as V,f as ie,j as Ce,k as Ct}from"./chunk-DT2FYN6N.js";import{b as Et,c as kt,d as $,f as z,g as H,h as U,i as le,k as B,n as Ot,q as It}from"./chunk-ORB4RHCK.js";import{a as Te,b as xe,g as Me}from"./chunk-UN6FVDJQ.js";import{a as lt,b as ut}from"./chunk-SH5KB4P7.js";import{a as wt,b as vt,d as St}from"./chunk-2SP57VCG.js";import{b as _t,c as bt}from"./chunk-6DTXIZY2.js";import{c as it}from"./chunk-Y6MKMSOC.js";import{Nb as ae,Rb as ke,Tb as Oe,Va as Pe,b as Re,g as N,h as ct,hb as yt,ia as gt,j as dt,ja as ft,jb as Ee,la as ht,m as pt,o as mt,oa as Ae}from"./chunk-WJ4XFLS4.js";import{request as br}from"https";import{HttpsProxyAgent as wr}from"https-proxy-agent";var ue={source:"https://brightdata.com/users/zone/premium_domains",retrievedAt:"2026-09-23T20:14:30.483Z",includedStatuses:["premium","remove_candidate"],domains:["advanceautoparts.com","affitto.it","agoda.cn","albertsons.com","allpeople.com","autozone.com","bestbuy.com","bestwestern.com","billiger.de","bottlerover.com","carousell.com","carousell.com.hk","carousell.com.my","carousell.ph","carousell.sg","carsales.com.au","cdiscount.com","chewy.com","costco.com","cvs.com","despegar.com.mx","dickssportinggoods.com","dynos.es","emaxme.com","familytreenow.com","feuvert.fr","flooranddecor.com","foodlion.com","footlocker.co.uk","footlocker.com","giantfoodstores.com","gopuff.com","gplay.bg","hermes.com","hyatt.com","idealo.de","immobilienscout24.de","ingatlan.com","instacart.com","intersport.fr","joann.com","kroger.com","lazada.co.id","lazada.co.th","lazada.com.my","lazada.com.ph","lazada.sg","lazada.vn","lowes.ca","lowes.com","mcmaster.com","mediamarkt.de","mediamarkt.es","medline.com","mscdirect.com","napaonline.com","nofrills.ca","peoplefinders.com","platt.com","publicdatausa.com","realcanadiansuperstore.ca","realestate.com.au","restaurantguru.com","searchpeoplefree.com","shopee.cl","shopee.co.id","shopee.co.th","shopee.com.br","shopee.com.co","shopee.com.mx","shopee.com.my","shopee.ph","shopee.sg","shopee.tw","shopee.vn","similarweb.com","skyscanner.co.kr","skyscanner.net","stopandshop.com","target.com","temu.com","ticketmaster.com","totalwine.com","tractorsupply.com","walmart.com.mx","wayfair.com","weismarkets.com","wizzair.com","worten.pt"]};var Xr=ue.source,xt=ue.retrievedAt,yr=new Set(ue.domains);function Z(e){let t=new URL(e).hostname.toLowerCase().replace(/\.$/,"");for(let n of yr)if(t===n||t.endsWith(`.${n}`))return"premium";return"standard"}function ce(e){for(let t of["providerProduct","billingTier","billableEvent","unitType","source","policyVersion","effectiveAt"])if(!e[t]?.trim())throw new Error(`Provider rate ${t} is required`);if(!Number.isSafeInteger(e.numeratorUsdNanos)||e.numeratorUsdNanos<0)throw new Error("Provider rate numerator must be a non-negative safe integer");if(!Number.isSafeInteger(e.denominatorUnits)||e.denominatorUnits<1)throw new Error("Provider rate denominator must be a positive safe integer");if(Number.isNaN(Date.parse(e.effectiveAt)))throw new Error("Provider rate effectiveAt must be a date");return e}function de(e,t){if(ce(e),!Number.isSafeInteger(t)||t<0)throw new Error("Billable units must be a non-negative safe integer");let n=BigInt(e.numeratorUsdNanos)*BigInt(t),r=BigInt(e.denominatorUnits),o=(n*2n+r)/(r*2n);if(o>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Provider amount exceeds safe integer range");return Number(o)}function Mt(e=process.env){let t=e.BRIGHTDATA_SERP_CONTRACT_USD_PER_1000?.trim(),n=e.BRIGHTDATA_SERP_RATE_SOURCE?.trim(),r=e.BRIGHTDATA_SERP_RATE_POLICY_VERSION?.trim(),o=e.BRIGHTDATA_SERP_RATE_EFFECTIVE_AT?.trim();if(!t&&!n&&!r&&!o)return null;if(!t||!n||!r||!o)throw new Error("Bright Data SERP contract rate requires amount, source, policy version, and effective date");let a=Number(t);if(!Number.isFinite(a)||a<0)throw new Error("Invalid Bright Data SERP contract amount");return ce({providerProduct:"brightdata_serp_api",billingTier:"payg",billableEvent:"successful_delivery",unitType:"request",numeratorUsdNanos:Math.round(a*1e9),denominatorUnits:1e3,source:n,policyVersion:r,effectiveAt:o})}function _r(e){return ce({providerProduct:"brightdata_browser_api",billingTier:e,billableEvent:"transferred_byte",unitType:"byte",numeratorUsdNanos:(e==="premium"?11:8)*1e9,denominatorUnits:1e9,source:`owner_confirmed_payg_2026-09-23;brightdata_domain_snapshot_${xt}`,policyVersion:"brightdata-browser-domain-tier-2026-09-23",effectiveAt:"2026-09-23T00:00:00Z"})}function to(e){return _r(Z(e))}function Nt(){return ce({providerProduct:"apify_google_serp_scraperlink",billingTier:"store_pay_per_event",billableEvent:"serp_page",unitType:"page",numeratorUsdNanos:5e8,denominatorUnits:1e3,source:"https://apify.com/scraperlink/google-search-results-serp-scraper",policyVersion:"scraperlink-listing-2026-09-24",effectiveAt:"2026-09-24T00:00:00Z"})}var vr="https://api.brightdata.com/request",Sr=8e3,Rr="brd.superproxy.io",Ar="44445",Pr=10*1024*1024;async function Er(e,t){let n=new URL(`http://${t.host}:${t.port}`);n.username=t.username,n.password=t.password;let r=new wr(n);try{return await new Promise((o,a)=>{let s=br(e,{agent:r,headers:{"x-unblock-data-format":"parsed"},rejectUnauthorized:!1,signal:t.signal},i=>{let l=[],u=0;i.on("data",c=>{let p=Buffer.isBuffer(c)?c:Buffer.from(c);if(u+=p.length,u>Pr){s.destroy(new Error("Bright Data SERP response exceeded the maximum size"));return}l.push(p)}),i.on("end",()=>o({ok:(i.statusCode??500)>=200&&(i.statusCode??500)<300,status:i.statusCode??500,rawText:Buffer.concat(l).toString("utf8"),providerRequestId:typeof i.headers["x-response-id"]=="string"?i.headers["x-response-id"]:typeof i.headers["x-request-id"]=="string"?i.headers["x-request-id"]:null}))});s.on("error",()=>a(new Error("Bright Data native SERP request failed"))),s.end()})}finally{r.destroy()}}function zt(e=process.env){let t=!!(e.BRIGHTDATA_SERP_PROXY_USERNAME?.trim()&&e.BRIGHTDATA_SERP_PROXY_PASSWORD?.trim()),n=!!((e.BRIGHTDATA_SERP_API_KEY||e.BRIGHTDATA_API_KEY)?.trim()&&e.BRIGHTDATA_SERP_ZONE?.trim());return t||n}function m(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)?e:null}function D(e){return Array.isArray(e)?e:[]}function De(e){return typeof e=="string"&&e.trim()?e.trim():null}function A(e){return typeof e=="number"&&Number.isFinite(e)?e:typeof e=="string"&&e.trim()&&Number.isFinite(Number(e))?Number(e):null}function g(e,t){for(let n of t){let r=De(e[n]);if(r)return r}return null}function J(e){try{return new URL(e).hostname.replace(/^www\./,"")}catch{return""}}function Kt(e){return{rawUrl:e,resolvedUrl:e,linkType:"plain",resolutionStatus:"not_needed"}}function kr(e){let t=e;if(typeof t=="string")try{t=JSON.parse(t)}catch{throw new Error("Bright Data SERP API returned invalid JSON")}let n=m(t);if(!n)throw new Error("Bright Data SERP API returned an invalid payload");if(typeof n.body=="string")try{let o=JSON.parse(n.body);if(m(o))return m(o)}catch{}let r=m(n.body);return r?m(r.result)??m(r.data)??r:m(n.result)??m(n.data)??n}function j(e,t){for(let r of t){let o=D(e[r]);if(o.length)return o}let n=m(e.results);if(n)for(let r of t){let o=D(n[r]);if(o.length)return o}return[]}function K(e,t){let n=[e,m(e.results)].filter(r=>!!r);for(let r of n)for(let o of t)if(Object.prototype.hasOwnProperty.call(r,o))return{observed:!0,rawShapeValid:Array.isArray(r[o]),rawCount:D(r[o]).length};return{observed:!1,rawShapeValid:!1,rawCount:0}}function Ne(e,t){let n=[e,m(e.results)].filter(r=>!!r);for(let r of n)for(let o of t){if(!Object.prototype.hasOwnProperty.call(r,o))continue;let a=m(r[o]);return{observed:!0,rawShapeValid:a!==null,rawCount:a&&Object.keys(a).length>0?1:0}}return{observed:!1,rawShapeValid:!1,rawCount:0}}function Dt(e){return j(e,["organic","organic_results","organicResults"]).flatMap((t,n)=>{let r=m(t);if(!r)return[];let o=g(r,["link","url","href"]),a=g(r,["title","name"]);if(!o||!a)return[];let s=m(r.rating)??m(r.inline_rating);return[{position:Math.max(1,Math.trunc(A(r.global_rank)??A(r.rank)??A(r.position)??n+1)),title:a,url:o,...Kt(o),domain:J(o),cite:g(r,["display_link","displayLink","cite"]),snippet:g(r,["description","snippet","text"]),isRedditStyle:J(o)==="reddit.com",inlineRating:s?{value:String(s.value??s.rating??""),count:String(s.count??s.reviews??"")}:null}]}).sort((t,n)=>t.position-n.position)}function qt(e){return j(e,["snack_pack","local","local_results","local_pack","localPack"]).flatMap((t,n)=>{let r=m(t);if(!r)return[];let o=g(r,["title","name"]);if(!o)return[];let a=D(r.extensions??r.metadata).map(De).filter(s=>!!s);return[{position:Math.max(1,Math.trunc(A(r.global_rank)??A(r.rank)??A(r.position)??n+1)),name:o,cid:g(r,["cid"]),rating:g(r,["rating"])??(A(r.rating)!=null?String(A(r.rating)):null),reviewCount:g(r,["reviews_cnt","reviews","review_count","reviewCount"])??(A(r.reviews_cnt)!=null?String(A(r.reviews_cnt)):A(r.reviews)!=null?String(A(r.reviews)):null),metadata:a,websiteUrl:g(r,["website","website_url","link"]),directionsUrl:g(r,["directions","directions_url"])}]})}function Jt(e){let t=m(e);return D(t?.citations??t?.sources??t?.references).flatMap(n=>{let r=m(n);if(!r)return[];let o=g(r,["link","url","href"]);return o?[{text:g(r,["title","text","name"])??J(o),href:o,...Kt(o)}]:[]})}function ge(e,t=0){if(t>4)return[];if(Array.isArray(e))return e.flatMap(a=>ge(a,t+1));let n=m(e);if(!n)return[];let r=g(n,["snippet","text","answer"]),o=ge(n.texts??n.list??n.items,t+1);return[...r?[r]:[],...o]}function Ht(e,t){if(!t)return{detected:!1,text:null,citations:[]};let n=m(e.ai_overview)??m(e.aiOverview)??m(e.overview);if(!n)return{detected:!1,text:null,citations:[]};let r=g(n,["text","answer","description"])??(ge(n.texts).join(`
|
|
2
|
+
|
|
3
|
+
`).slice(0,5e4)||null),o=Jt(n);return{detected:!!(r||o.length),text:r,citations:o}}function Ut(e,t){if(!t)return{detected:!1,text:null,citations:[]};let n=m(e.ai_mode)??m(e.aiMode);if(!n)return{detected:!1,text:null,citations:[]};let r=g(n,["text","answer","description"])??(ge(n.texts).join(`
|
|
4
|
+
|
|
5
|
+
`).slice(0,5e4)||null),o=Jt(n);return{detected:!!(r||o.length),text:r,citations:o}}function Bt(e,t){return t?[...j(e,["videos","video_results"]),...j(e,["short_videos","shorts"])].flatMap(n=>{let r=m(n);if(!r)return[];let o=g(r,["link","url"]),a=g(r,["title","name"]);return!o||!a?[]:[{type:"video",title:a,channel:g(r,["channel","source"])??"",platform:J(o),duration:g(r,["duration"])??"",url:o}]}):[]}function Ft(e,t){if(!t)return[];let n=m(e.forums);return[...j(e,["discussions","forums","forum_results"]),...D(n?.items)].flatMap(r=>{let o=m(r);if(!o)return[];let a=g(o,["link","url"]),s=g(o,["title","name"]);return!a||!s?[]:[{title:s,source:g(o,["source"])??J(a),url:a}]})}function Gt(e,t){return t?j(e,["what_people_are_saying","whatPeopleSaying"]).flatMap(n=>{let r=m(n);if(!r)return[];let o=g(r,["link","url"]),a=g(r,["title","name"]);if(!o||!a)return[];let s=g(r,["platform","source"])??J(o),i=s.toLowerCase();return[{type:i.includes("reddit")?"reddit":i.includes("facebook")?"facebook":i.includes("instagram")?"instagram":i.includes("tiktok")?"tiktok":i.includes("youtube")?"youtube":i.includes("news")?"news":"unknown",title:a,url:o,source:s,platform:s,popularComment:g(r,["comment","popular_comment"]),engagement:g(r,["engagement"])??"",date:g(r,["date"])??"",duration:g(r,["duration"]),authorNote:g(r,["author_note"])}]}):[]}var Or={featuredSnippets:["featured_snippets","featured_snippet","featuredSnippet"],knowledgePanel:["knowledge","knowledge_graph","knowledgeGraph"],topStories:["top_stories","topStories"],news:["news","news_results"],images:["images","image_results"],shopping:["shopping","shopping_results"],relatedSearches:["related","related_searches","relatedSearches"],recipes:["recipes","recipe_results"],jobs:["jobs","job_results"],topAds:["top_ads"],bottomAds:["bottom_ads"],topProducts:["top_pla"],bottomProducts:["bottom_pla"],jackpotProducts:["jackpot_pla"],shortVideos:["short_videos","shorts"],localMap:["snack_pack_map"],flights:["flights"],hotels:["hotels_selection"],popularProducts:["popular_products"],weather:["weather"],currencyExchange:["currency_exchange"],latestPosts:["latest_posts"],perspectives:["perspectives"],navigation:["navigation"],chips:["chips"],spelling:["spelling"]};function pe(e,t){for(let n of[e,m(e.results)])if(n){for(let r of t)if(Object.prototype.hasOwnProperty.call(n,r))return{observed:!0,value:n[r]}}return{observed:!1,value:null}}function me(e,t,n){return e?t==null||Array.isArray(t)&&t.length===0?"observed_absent":Array.isArray(t)?n>0?"observed_present":"incomplete":m(t)?n>0?"observed_present":Object.keys(m(t)).length===0?"observed_absent":"incomplete":"incomplete":"unknown"}function Ir(e,t){let n={},r=[["localPack",["snack_pack","local","local_results","local_pack","localPack"],t.localPack],["forums",["discussions","forums","forum_results"],t.forums],["videos",["videos","video_results","short_videos","shorts"],t.videos],["aiOverview",["ai_overview","aiOverview","overview"],t.aiOverview],["whatPeopleSaying",["what_people_are_saying","whatPeopleSaying"],t.whatPeopleSaying],["entityIds",["knowledge","knowledge_graph","knowledgeGraph"],t.entityIds]];for(let[l,u,c]of r){let p=pe(e,u);n[l]=me(p.observed,p.value,c)}let o=pe(e,["ai_mode","aiMode"]);n.aiMode=me(o.observed,o.value,t.aiMode);let a=pe(e,["people_also_ask","peopleAlsoAsk","related_questions","paa"]),s=D(a.value).slice(0,30).flatMap(l=>{let u=m(l);if(!u)return[];let c=g(u,["question","title"]);return c?[{question:c.slice(0,1e3),answer:g(u,["answer","snippet","text"])?.slice(0,1e4)??null,url:g(u,["link","url"])??null}]:[]});n.paaPreview=me(a.observed,a.value,s.length);let i=[];for(let[l,u]of Object.entries(Or)){let c=pe(e,u);if(!c.observed)continue;let p=m(c.value),w=(Array.isArray(c.value)?c.value:p&&(Array.isArray(p.items)||Array.isArray(p.posts))?[...D(p.items),...D(p.posts)]:[c.value]).slice(0,20).flatMap(S=>{let y=m(S);if(!y)return[];let C=g(y,["title","name","heading"]),k=g(y,["link","url","website"]),q=g(y,["description","snippet","text","summary","story"]);return!C&&!k&&!q?[]:[{title:C?.slice(0,1e3)??null,url:k,description:q?.slice(0,1e4)??null,position:A(y.global_rank)??A(y.rank)??A(y.position)??null}]});n[l]=me(c.observed,c.value,w.length);let R=Object.fromEntries(Object.entries(p??{}).slice(0,30).flatMap(([S,y])=>/^[a-zA-Z0-9_]{1,80}$/.test(S)&&(y===null||["string","number","boolean"].includes(typeof y))?[[S,typeof y=="string"?y.slice(0,2e3):y]]:[]));i.push({name:l,attributes:R,items:w})}return{status:n,paaPreview:s,additional:i}}function Lt(e,t){let n=new Set,r=new Set(t.map(s=>s.cid).filter(s=>!!s)),o=new Set,a=(s,i=0)=>{if(i>6||s==null)return;if(Array.isArray(s)){for(let u of s)a(u,i+1);return}let l=m(s);if(l)for(let[u,c]of Object.entries(l)){let p=u.toLowerCase().replace(/[^a-z]/g,""),_=De(c);_&&(p==="kgid"||p==="kgmid"||p==="mid")?n.add(_):_&&p==="cid"?r.add(_):_&&p==="gcid"?o.add(_):typeof c=="object"&&a(c,i+1)}};return a(e),{entities:[],kgIds:[...n],cids:[...r],gcids:[...o]}}function Vt(e,t){let n=e instanceof Error?e.message:String(e);return t.aborted||/timeout|timed out/i.test(n)?"timeout":/captcha|recaptcha|unusual traffic|google\.com\/sorry|blocked/i.test(n)?"captcha":/invalid (?:json|payload)/i.test(n)?"invalid_payload":"provider_error"}function $t(e){return e==="invalid_payload"?"invalid_payload":e==="captcha"?"serp_readiness":e==="timeout"||e==="provider_error"?"provider_transport":"pagination"}async function qe(e,t=process.env,n=fetch,r=Er,o){if(e.pages!==1)throw new Error("Bright Data SERP supports one page only; use Apify for two pages");let a=(t.BRIGHTDATA_SERP_API_KEY||t.BRIGHTDATA_API_KEY)?.trim(),s=t.BRIGHTDATA_SERP_ZONE?.trim(),i=t.BRIGHTDATA_SERP_PROXY_USERNAME?.trim(),l=t.BRIGHTDATA_SERP_PROXY_PASSWORD?.trim(),u=!!(i&&l);if(!u&&(!a||!s))throw new Error("Direct SERP API is not configured");let c=Date.now(),p=bt(),_=null,w=e.location?At(e.location):null;if(e.location&&!w?.canonical)throw new G("query_integrity","location_unresolved",`SERP location could not be resolved without changing the query (candidates: ${w?.ambiguousCandidates??0})`);let R=w?.canonical?Rt(w.canonical):null,S=AbortSignal.timeout(e.includeAllSerpFeatures?33e3:Sr),y=e.signal?AbortSignal.any([e.signal,S]):S,C=1,k=[],q=[],Ke=0,Je=async d=>{let O=Date.now(),b=u?"brightdata_serp_native_proxy":"brightdata_serp_rest",I=null,x=null,Q=!1,W=!1,F=null,Y=null;if(p?.operationRunId&&(d===1||_))try{I=await $({runId:p.operationRunId,attemptNumber:o?o.attemptNumber+d-1:d,method:b,provider:"brightdata",...d===2?{parentAttemptId:_,edgeKind:"next_phase"}:o?{parentAttemptId:o.parentAttemptId,edgeKind:"provider_fallback",retryKind:"provider_fallback"}:{},normalizedFlags:{page:d,device:e.device,hasLocation:!!e.location}}),d===1&&(_=I),x=(await H({attemptId:I,provider:"brightdata",providerProduct:"brightdata_serp_api",accountScope:p.operationAccountScope??"production-default",method:b,providerStatus:"started"})).id}catch(h){throw console.warn(JSON.stringify({event:"direct_serp_telemetry_start_failed",page:d,message:h instanceof Error?h.message:String(h)})),h}let P=new URLSearchParams({q:e.query,gl:e.gl,hl:e.hl,pws:"0",num:"10",...d===2?{start:"10"}:{}}),se=it(e.recency);se&&P.set("tbs",se),e.device==="mobile"&&P.set("brd_mobile","1"),(e.includeAiOverview||e.includeAllSerpFeatures)&&P.set("brd_ai_overview","2"),R&&P.set("uule",R),u&&P.set("brd_json","1"),Ke+=1;let M;try{if(u){let E=t.BRIGHTDATA_SERP_PROXY_HOST?.trim()||Rr,X=t.BRIGHTDATA_SERP_PROXY_PORT?.trim()||Ar;M=await r(`https://www.google.com/search?${P}`,{username:i,password:l,host:E,port:X,signal:y})}else{let E=await n(vr,{method:"POST",headers:{Authorization:`Bearer ${a}`,"Content-Type":"application/json"},body:JSON.stringify({zone:s,url:`https://www.google.com/search?${P}`,format:"json",data_format:"parsed"}),signal:y});M={ok:E.ok,status:E.status,rawText:await E.text(),providerRequestId:E.headers.get("x-response-id")??E.headers.get("x-request-id")}}if(Y=`http_${M.status}`,x&&M.providerRequestId&&await U(x,M.providerRequestId),!M.ok)throw new Error(`Bright Data SERP API failed with HTTP ${M.status}`);Q=!0;let h;try{h=kr(JSON.parse(M.rawText))}catch(E){let X=E instanceof Error&&E.message!=="Unexpected end of JSON input"?E.message:"Bright Data SERP API returned invalid JSON";throw new G("invalid_payload","invalid_provider_payload",X)}let f=Dt(h);return k.push({page:d,attempted:!0,captured:f.length>0,resultCount:f.length,requestOffset:d===2?10:0,providerRequestIdObserved:!!M.providerRequestId,...f.length===0?{failureCode:"empty_page"}:{}}),W=!0,h}catch(h){F=h;let f=Vt(h,y);if(k.some(X=>X.page===d)||k.push({page:d,attempted:!0,captured:!1,resultCount:0,requestOffset:d===2?10:0,providerRequestIdObserved:!1,failureCode:f}),d===2)throw h;let E=h instanceof G?h.stage:$t(f);throw h instanceof G?h:new G(E,f,h instanceof Error?h.message:String(h))}finally{let h=null;if(x&&Q)try{let f=Mt(t);f?await B({receiptId:x,costState:"measured",units:1,unitType:"request",amountUsdNanos:de(f,1),rateSource:f.source,providerProduct:f.providerProduct,billingTier:f.billingTier,billableEvent:f.billableEvent,measurementSource:"provider_http_delivery",rateNumerator:f.numeratorUsdNanos,rateDenominator:f.denominatorUnits,ratePolicyVersion:f.policyVersion,rateEffectiveAt:f.effectiveAt,providerStatus:Y??"delivered",providerDurationMs:Date.now()-O}):await le({receiptId:x,units:1,unitType:"request",providerStatus:"delivered_rate_unconfigured"})}catch(f){console.warn(JSON.stringify({event:"direct_serp_receipt_finalize_failed",page:d,message:f instanceof Error?f.message:String(f)})),h=f}if(I&&await z({attemptId:I,status:W?"succeeded":y.aborted?"timed_out":"failed",errorCode:F?Vt(F,y):null,durationMs:Date.now()-O}).catch(f=>console.warn(JSON.stringify({event:"direct_serp_attempt_finish_failed",page:d,message:f instanceof Error?f.message:String(f)}))),h)throw h}};try{q.push({page:1,payload:await Je(1)})}catch(d){throw d}let je=null;if(C===2)try{q.push({page:2,payload:await Je(2)})}catch(d){je=d}let ir=Date.now()-c,lr=Date.now(),v=q[0].payload,ur=q.flatMap(({page:d,payload:O})=>Dt(O).map(b=>({...b,position:d===2&&b.position<=10?b.position+10:b.position,sourcePage:d}))).filter((d,O,b)=>b.findIndex(I=>Ie(I.url)===Ie(d.url))===O),Qe=e.includeLocalPack||e.includeAllSerpFeatures,_e=Qe?qt(v):[],be=K(v,["snack_pack","local","local_results","local_pack","localPack"]),cr=V({requested:Qe,moduleObserved:be.observed,rawCount:be.rawCount,mappedCount:_e.length,rawShapeValid:be.rawShapeValid}),We=e.includeAiOverview||e.includeAllSerpFeatures,Ye=Ht(v,We),Xe=e.includeForums||e.includeAllSerpFeatures,Ze=Ft(v,Xe),et=e.includeVideos||e.includeAllSerpFeatures,tt=Bt(v,et),rt=e.includeWhatPeopleSaying||e.includeAllSerpFeatures,ot=Gt(v,rt),we=m(v.forums),ve=we&&Array.isArray(we.items)?{observed:!0,rawCount:we.items.length,rawShapeValid:!0}:K(v,["discussions","forums","forum_results"]),Se=K(v,["videos","video_results","short_videos","shorts"]),nt={localPack:cr,forums:V({requested:Xe,moduleObserved:ve.observed,rawCount:ve.rawCount,mappedCount:Ze.length,rawShapeValid:ve.rawShapeValid}),videos:V({requested:et,moduleObserved:Se.observed,rawCount:Se.rawCount,mappedCount:tt.length,rawShapeValid:Se.rawShapeValid}),aiOverview:V({requested:We,moduleObserved:Ne(v,["ai_overview","aiOverview","overview"]).observed,rawCount:Ne(v,["ai_overview","aiOverview","overview"]).rawCount,mappedCount:Ye.detected?1:0,rawShapeValid:Ne(v,["ai_overview","aiOverview","overview"]).rawShapeValid}),whatPeopleSaying:V({requested:rt,moduleObserved:K(v,["what_people_are_saying","whatPeopleSaying"]).observed,rawCount:K(v,["what_people_are_saying","whatPeopleSaying"]).rawCount,mappedCount:ot.length,rawShapeValid:K(v,["what_people_are_saying","whatPeopleSaying"]).rawShapeValid})},dr=L(1,k),pr=k.find(d=>d.page===1)?.resultCount??0,oe=k.find(d=>d.page===2)?.resultCount??0,mr=ie({query:e.query,finalQuery:e.query,canonicalLocation:w?.canonical??null,locationResolutionSource:w?.source??"not_requested",locationAmbiguousCandidates:w?.ambiguousCandidates??0,uule:R,outboundProviderMethod:u?"brightdata_serp_native_proxy":"brightdata_serp_rest"}),ne=je?$t(k.find(d=>d.page===2)?.failureCode??"provider_error"):Object.values(nt).some(d=>d==="incomplete"||d==="unknown")?"optional_feature_parsing":null,gr={pagination:{...dr,providerRequestCount:Ke},features:nt,queryIntegrity:mr,failureStage:ne},st=e.includeAllSerpFeatures?(()=>{let d=q.map(({page:O,payload:b})=>{let I=qt(b),x=Ft(b,!0),Q=Bt(b,!0),W=Gt(b,!0),F=Ht(b,!0),Y=Ut(b,!0),P=Lt(b,I),se=Ir(b,{localPack:I.length,forums:x.length,videos:Q.length,aiOverview:F.detected?1:0,aiMode:Y.detected?1:0,whatPeopleSaying:W.length,entityIds:P.entities.length+P.kgIds.length+P.cids.length+P.gcids.length});return{page:O,...se,localPack:I,forums:x,videos:Q,whatPeopleSaying:W,aiOverview:F,aiMode:Y,entityIds:P}});return{status:d[0].status,paaPreview:d.flatMap(O=>O.paaPreview),additional:d.flatMap(O=>O.additional),pages:d}})():void 0,fr=new Date().toISOString(),at=Date.now()-c;return{seed:e.query,location:e.location??null,extractedAt:fr,diagnostics:{phaseTimings:{providerConnectMs:ir,serpParseMs:Date.now()-lr,totalServerMs:at},pagination:{requestedPages:C,capturedPages:C===2&&oe>0?2:1,page2Status:C===2?oe>0?"captured":"failed":"not_requested",page1OrganicCount:pr,page2OrganicCount:oe,...C===2&&oe===0?{failureCode:k.find(d=>d.page===2)?.failureCode==="captcha"?"captcha":k.find(d=>d.page===2)?.failureCode==="timeout"?"timeout":"empty_page"}:{}},completionStatus:"serp_only",problem:null,resultQuality:ne?"partial":"complete",degradedResult:!!ne,degradationReasons:[],retryRecommended:!!ne,serpCompleteness:gr},totalQuestions:0,surface:"web",aiOverview:Ye,aiMode:Ut(v,e.includeAllSerpFeatures),...st?{fullSerpFeatures:st}:{},whatPeopleSaying:ot,tree:[],flat:[],videos:tt,forums:Ze,organicResults:ur,localPack:_e,entityIds:Lt(v,_e),stats:{seed:e.query,totalQuestions:0,maxDepthReached:0,durationMs:at,errorCount:0}}}var Cr="scraperlink~google-search-results-serp-scraper",ee="https://api.apify.com/v2";var T=class extends Error{constructor(n,r=null,o=!1,a=null){super(n);this.runId=r;this.retrySafe=o;this.terminalStatus=a;this.name="ApifyGoogleRunError"}runId;retrySafe;terminalStatus};function te(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}function re(e){return typeof e=="string"&&e.trim()?e.trim():null}function Tr(e){try{return["http:","https:"].includes(new URL(e).protocol)}catch{return!1}}function xr(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{throw new Error("Apify searchResults is not valid JSON")}}function jt(e,t){if(!Array.isArray(e)||e.length===0)throw new Error("Apify dataset contains no search results");let n=[];for(let[a,s]of e.entries()){let i=te(s);if(!i)throw new Error("Apify dataset contains an invalid row");let l=xr(i.searchResults??i),u=te(l),c=Array.isArray(l)?l:Array.isArray(u?.results)?u.results:Array.isArray(u?.organicResults)?u.organicResults:Array.isArray(u?.organic)?u.organic:u&&(u.position!==void 0||u.title!==void 0)?[u]:null;if(!c)throw new Error("Apify dataset search result shape is unsupported");let p=Number(i.page_number??u?.page_number??a+1);if(!Number.isInteger(p)||p<1||p>t)throw new Error("Apify dataset has an unexpected page number");n.push(...c.map(_=>({row:_,page:p})))}let r=n.map(({row:a,page:s},i)=>{let l=te(a),u=l?.position,c=re(l?.title),p=re(l?.url??l?.link);if(!l||!c||!p||!Tr(p)||u!==void 0&&(!Number.isInteger(u)||u<1))throw new Error(`Apify search result ${i+1} is missing a valid position, URL, or title`);let _=re(l.description??l.snippet),w=typeof u=="number"?u:i%10+1;return{position:s>1&&w<=10?w+(s-1)*10:w,url:p,title:c,description:_}});if(r.length>t*10)throw new Error("Apify returned more results than requested");let o={page1:r.filter(a=>a.position<=10).length,page2:r.filter(a=>a.position>10).length};if(o.page1===0)throw new Error("Apify did not return the first result page");return{results:r,pageResultCounts:o}}async function fe(e,t,n,r){let o=await n(e,{headers:{Authorization:`Bearer ${t}`},signal:r});if(!o.ok)throw new Error(`Apify API returned HTTP ${o.status}`);return o.json()}function He(e){let t=te(te(e)?.data),n=re(t?.id),r=re(t?.status);if(!n||!r)throw new Error("Apify returned an invalid run receipt");return{id:n,status:r}}async function Mr(e,t=fetch){let n=performance.now(),r=AbortSignal.timeout(9e4),o=e.signal?AbortSignal.any([e.signal,r]):r,a=e.runId,s=!1,i=null;try{if(!/^[A-Za-z0-9]+$/.test(a))throw new Error("Invalid Apify run ID");let l=He(await fe(`${ee}/actor-runs/${a}?waitForFinish=30`,e.token,t,o));for(;["READY","RUNNING","TIMING-OUT","ABORTING"].includes(l.status);)l=He(await fe(`${ee}/actor-runs/${a}?waitForFinish=30`,e.token,t,o));if(s=!0,i=l.status,l.status!=="SUCCEEDED")throw new Error(`Apify run ended with status ${l.status}`);let u=e.pages??1,c=await fe(`${ee}/actor-runs/${a}/dataset/items?format=json`,e.token,t,o);return{query:e.query,...jt(c,u),requestedPages:u,runId:a,elapsedMs:Math.round(performance.now()-n)}}catch(l){throw new T(l instanceof Error?l.message:String(l),a,s,i)}}async function Qt(e,t,n=fetch){let r=performance.now(),o=e.query.trim(),a=e.pages??1;if(!o||o.includes(`
|
|
6
|
+
`))throw new Error("Apify search requires one nonempty query");if(a!==1&&a!==2)throw new Error("Apify search supports one or two pages");let s=t.token.trim();if(!s)throw new Error("Apify API token is required");let i=t.maxChargeUsd??.01;if(!Number.isFinite(i)||i<=0)throw new Error("Invalid Apify charge cap");let l=AbortSignal.timeout(9e4),u=e.signal?AbortSignal.any([e.signal,l]):l,c=`${ee}/actors/${Cr}/runs?maxTotalChargeUsd=${i}&restartOnError=false&waitForFinish=30`,p=null,_=!1,w=null;try{let R=await n(c,{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify({keyword:o,limit:a===2?"20":"10",page:1,proxy_location:"us",include_merged:!1}),signal:u});if(!R.ok)throw new Error(`Apify run start returned HTTP ${R.status}`);let S=He(await R.json());if(p=S.id,_=!["READY","RUNNING","TIMING-OUT","ABORTING"].includes(S.status),_&&(w=S.status),S.status!=="SUCCEEDED"&&S.status!=="READY"&&S.status!=="RUNNING")throw new Error(`Apify run ended with status ${S.status}`);if(S.status==="SUCCEEDED"){let C=await fe(`${ee}/actor-runs/${p}/dataset/items?format=json`,s,n,u);return{query:o,...jt(C,a),requestedPages:a,runId:p,elapsedMs:Math.round(performance.now()-r)}}return{...await Mr({runId:p,query:o,token:s,pages:a,signal:u},n),elapsedMs:Math.round(performance.now()-r)}}catch(R){throw R instanceof T?R:new T(R instanceof Error?R.message:String(R),p,_,w)}}var Wt="apify_google_serp",Yt="apify",Nr="apify_google_serp_scraperlink";async function Xt(e,t,n,r){let o=Nt();await B({receiptId:e,costState:"estimated",units:t,unitType:o.unitType,amountUsdNanos:de(o,t),rateSource:o.source,providerProduct:o.providerProduct,billingTier:o.billingTier,billableEvent:o.billableEvent,measurementSource:"actor_run_succeeded",rateNumerator:o.numeratorUsdNanos,rateDenominator:o.denominatorUnits,ratePolicyVersion:o.policyVersion,rateEffectiveAt:o.effectiveAt,providerStatus:r,providerDurationMs:n})}async function Zt(e){let t=performance.now(),n=await $({runId:e.operationRunId,attemptNumber:e.attemptNumber,method:Wt,provider:Yt,parentAttemptId:e.parentAttemptId,edgeKind:e.edgeKind,retryKind:e.retryKind,normalizedFlags:{page:1,pages:e.options.pages??1,proxyLocation:"us"}}),r=await H({attemptId:n,provider:Yt,providerProduct:Nr,billingTier:"store_pay_per_event",accountScope:e.accountScope,method:Wt,providerStatus:"before_actor_start"}),o=null,a=null;try{return o=await Qt(e.options,{token:e.token},e.fetchImpl),await U(r.id,o.runId),await Xt(r.id,o.requestedPages,o.elapsedMs,"succeeded_estimated"),{...o,attemptId:n}}catch(s){throw a=s,o?Object.assign(new T("Apify cost tracking failed after run completion",o.runId),{attemptId:n}):(s instanceof T&&s.runId&&(await U(r.id,s.runId),s.terminalStatus==="SUCCEEDED"?await Xt(r.id,e.options.pages??1,Math.round(performance.now()-t),"succeeded_dataset_unavailable"):await le({receiptId:r.id,units:e.options.pages??1,unitType:"page",providerStatus:"run_outcome_or_cost_pending"})),Object.assign(s instanceof Error?s:new Error(String(s)),{attemptId:n}))}finally{await z({attemptId:n,status:a?e.options.signal?.aborted?"timed_out":"failed":"succeeded",errorCode:a?"apify_search_failed":null,durationMs:Math.round(performance.now()-t)})}}function er(e,t=e.requestedPages){let n=e.results.map(s=>{let i=new URL(s.url).hostname.replace(/^www\./,"");return{position:s.position,title:s.title,url:s.url,rawUrl:s.url,resolvedUrl:s.url,linkType:"plain",resolutionStatus:"not_needed",domain:i,cite:null,snippet:s.description,isRedditStyle:i==="reddit.com",inlineRating:null}}),r=t===2&&e.pageResultCounts.page2>0?2:1,o=t===2&&r===1,a=L(t,[{page:1,attempted:!0,captured:!0,resultCount:e.pageResultCounts.page1,requestOffset:0,providerRequestIdObserved:!0},...t===2?[{page:2,attempted:!0,captured:!o,resultCount:e.pageResultCounts.page2,requestOffset:10,providerRequestIdObserved:!0,...o?{failureCode:"empty_page"}:{}}]:[]]);return{seed:e.query,location:null,extractedAt:new Date().toISOString(),diagnostics:{phaseTimings:{providerConnectMs:e.elapsedMs,totalServerMs:e.elapsedMs},pagination:{requestedPages:t,capturedPages:r,page2Status:t===2?o?"failed":"captured":"not_requested",page1OrganicCount:e.pageResultCounts.page1,page2OrganicCount:e.pageResultCounts.page2},completionStatus:"serp_only",problem:null,resultQuality:o?"partial":"complete",degradedResult:o,degradationReasons:o?["page_two_missing"]:[],retryRecommended:!1,serpCompleteness:{pagination:a,features:{localPack:"not_requested",forums:"not_requested",videos:"not_requested",aiOverview:"not_requested",whatPeopleSaying:"not_requested"},queryIntegrity:ie({query:e.query,finalQuery:e.query,locationResolutionSource:"not_requested",outboundProviderMethod:"default_search"}),failureStage:null}},totalQuestions:0,surface:"web",aiOverview:{detected:!1,text:null,citations:[],shareUrl:null},aiMode:{detected:!1,text:null,citations:[]},whatPeopleSaying:[],tree:[],flat:[],videos:[],forums:[],organicResults:n,localPack:[],entityIds:{entities:[],kgIds:[],cids:[],gcids:[]},stats:{seed:e.query,totalQuestions:0,maxDepthReached:0,durationMs:e.elapsedMs,errorCount:0}}}var Dr=12e3;async function Ue(e){if(e.mode==="full")return Hr(e);if(!e.token)throw new Error("Apify search is not configured");let t=performance.now(),n;for(let o=1;o<=2;o++){let a=AbortSignal.any([e.signal,AbortSignal.timeout(Dr)]),s=e.pages===2&&o===2?1:e.pages;try{let i=await Zt({options:{query:e.query,pages:s,signal:a},token:e.token,operationRunId:e.operationRunId,accountScope:e.accountScope,attemptNumber:o,...n?{parentAttemptId:n,edgeKind:"same_method_retry",retryKind:"same_method"}:{}});console.info(JSON.stringify({event:"serp_provider_succeeded",provider:"apify",operationRunId:e.operationRunId,attemptNumber:o,durationMs:i.elapsedMs,resultCount:i.results.length,requestedPages:e.pages,providerRequestedPages:i.requestedPages,deliveredPages:i.pageResultCounts.page2>0?2:1,runId:i.runId}));let l=er(i,e.pages);return l.stats.durationMs=Math.round(performance.now()-t),l.diagnostics.phaseTimings&&(l.diagnostics.phaseTimings.totalServerMs=l.stats.durationMs),{result:l,mode:"light",deliveryProvider:"apify",deliveredPages:i.pageResultCounts.page2>0?2:1}}catch(i){n=i&&typeof i=="object"&&"attemptId"in i?String(i.attemptId):void 0;let l=i instanceof T?i:null;if(console.warn(JSON.stringify({event:"serp_provider_failed",provider:"apify",operationRunId:e.operationRunId,attemptNumber:o,runId:l?.runId??null,requestedPages:e.pages,attemptPages:s,retrySafe:l?.retrySafe===!0,error:i instanceof Error?i.message:String(i)})),e.signal.aborted||!n||l?.retrySafe!==!0)throw i}}if(!n)throw new Error("Search attempt receipt is missing");let r={query:e.query,gl:"us",hl:"en",device:"desktop",pages:1,includeAllSerpFeatures:!1,includeLocalPack:!1,includeForums:!1,includeVideos:!1,includeAiOverview:!1,includeWhatPeopleSaying:!1,signal:e.signal};console.info(JSON.stringify({event:"serp_provider_fallback",provider:"brightdata",operationRunId:e.operationRunId,attemptNumber:3,requestedPages:e.pages,providerRequestedPages:1}));try{let o=await qe(r,process.env,fetch,void 0,{attemptNumber:3,parentAttemptId:n});if(o.organicResults.length===0)throw new Error("Search returned no organic results");return e.pages===2&&qr(o),o.stats.durationMs=Math.round(performance.now()-t),o.diagnostics.phaseTimings&&(o.diagnostics.phaseTimings.totalServerMs=o.stats.durationMs),console.info(JSON.stringify({event:"serp_provider_succeeded",provider:"brightdata",operationRunId:e.operationRunId,attemptNumber:3,durationMs:o.stats.durationMs,resultCount:o.organicResults.length,requestedPages:e.pages,providerRequestedPages:1,deliveredPages:1,resultQuality:o.diagnostics.resultQuality})),{result:o,mode:"light",deliveryProvider:"brightdata",deliveredPages:1}}catch(o){throw console.warn(JSON.stringify({event:"serp_provider_failed",provider:"brightdata",operationRunId:e.operationRunId,attemptNumber:3,error:o instanceof Error?o.message:String(o)})),o}}function qr(e){let t=e.organicResults.length,n=e.diagnostics.pagination;n&&(n.requestedPages=2,n.capturedPages=1,n.page2Status="failed",n.page2OrganicCount=0),e.diagnostics.resultQuality="partial",e.diagnostics.degradedResult=!0,e.diagnostics.degradationReasons=["page_two_missing"];let r=e.diagnostics;if(r.serpCompleteness){let o=r.serpCompleteness.pagination.evidence.find(a=>a.page===1);r.serpCompleteness.pagination={...L(2,[{page:1,attempted:!0,captured:!0,resultCount:t,requestOffset:0,providerRequestIdObserved:o?.providerRequestIdObserved??!1},{page:2,attempted:!0,captured:!1,resultCount:0,requestOffset:10,providerRequestIdObserved:!1,failureCode:"provider_error"}]),providerRequestCount:r.serpCompleteness.pagination.providerRequestCount}}}async function Hr(e){if(e.pages===2){let o=await Ue({...e,mode:"light",pages:2}),a=Object.fromEntries(["localPack","forums","videos","aiOverview","aiMode","whatPeopleSaying","entityIds","paaPreview","topStories"].map(i=>[i,"unsupported"]));o.result.fullSerpFeatures={status:a,paaPreview:[],additional:[],pages:[]};let s=o.result.diagnostics;return s.serpCompleteness&&(s.serpCompleteness.features={localPack:"unsupported",forums:"unsupported",videos:"unsupported",aiOverview:"unsupported",whatPeopleSaying:"unsupported"}),{...o,mode:"full"}}let t=performance.now(),n={query:e.query,gl:"us",hl:"en",device:"desktop",pages:1,includeAllSerpFeatures:!0,includeLocalPack:!0,includeForums:!0,includeVideos:!0,includeAiOverview:!0,includeWhatPeopleSaying:!0,signal:e.signal},r=await qe(n);if(r.organicResults.length===0)throw new Error("Full Search returned no organic results");return r.stats.durationMs=Math.round(performance.now()-t),r.diagnostics.phaseTimings&&(r.diagnostics.phaseTimings.totalServerMs=r.stats.durationMs),{result:r,mode:"full",deliveryProvider:"brightdata",deliveredPages:r.diagnostics.pagination?.capturedPages===2?2:1}}async function Be(e,t,n=3){for(let r=1;r<=n;r++){try{let o=await fetch(e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t),signal:AbortSignal.timeout(1e4)});if(o.ok)return;console.warn(`[webhook] attempt ${r} \u2192 ${o.status} from ${e}`)}catch(o){console.warn(`[webhook] attempt ${r} failed:`,o instanceof Error?o.message:o)}r<n&&await new Promise(o=>setTimeout(o,1e3*r*2))}console.error(`[webhook] gave up after ${n} attempts for ${e}`)}function Ur(e){return e instanceof Error?e.message:String(e)}function Br(e,t){return e instanceof DOMException&&(e.name==="TimeoutError"||e.name==="AbortError")?!0:/timeout|timed out|Timeout \d+ms exceeded|deadline/i.test(t)}function Fr(e){return/captcha|recaptcha|unusual traffic|google\.com\/sorry|blocked/i.test(e)}function Gr(e){return/ERR_TUNNEL_CONNECTION_FAILED|ERR_PROXY_CONNECTION_FAILED|ERR_SOCKS_CONNECTION_FAILED|tunnel connection failed|proxy connection failed|transport error: proxy/i.test(e)}function Lr(e){return/proxy unavailable|proxy_unavailable|connection_test_failed|did not return a proxy id|configured fallback/i.test(e)}function Vr(e){return/(?:spending|billing|organization|account).{0,80}(?:cap|limit|blocked|disabled)|(?:quota|capacity).{0,40}(?:reached|exceeded)|https?:\/\/\S*dashboard/i.test(e)}function $r(e){return/browser (?:has been )?closed|context (?:has been )?closed|target page, context or browser has been closed|session closed|page has been closed/i.test(e)}function Fe(e){let t=Ur(e);return e instanceof pt?{error_code:"request_aborted",error_type:"request_aborted",message:N("request_aborted"),retryable:!0,httpStatus:408,terminalStatus:"cancelled"}:e instanceof dt||Fr(t)?{error_code:"captcha_exhausted",error_type:"captcha",message:N("captcha_exhausted"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:Tt(e,t)?{error_code:"vendor_unavailable",error_type:"service_unavailable",message:N("vendor_unavailable"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:e instanceof mt?{error_code:"location_mismatch",error_type:"location_mismatch",message:N("location_mismatch"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:Gr(t)?{error_code:"proxy_tunnel_failed",error_type:"connection",message:N("proxy_tunnel_failed"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:Lr(t)?{error_code:"proxy_unavailable",error_type:"connection",message:N("proxy_unavailable"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:$r(t)?{error_code:"browser_session_interrupted",error_type:"extraction",message:N("browser_session_interrupted"),retryable:!0,httpStatus:503,terminalStatus:"failed"}:Br(e,t)?{error_code:"harvest_timeout",error_type:"timeout",message:N("harvest_timeout"),retryable:!0,httpStatus:504,terminalStatus:"failed"}:Vr(t)?{error_code:"service_unavailable",error_type:"service_unavailable",message:Re,retryable:!0,httpStatus:503,terminalStatus:"failed"}:{error_code:"extraction_failed",error_type:"extraction",message:Re,retryable:!1,httpStatus:500,terminalStatus:"failed"}}function Ge(e){return JSON.stringify({error_code:e.error_code,error_type:e.error_type,message:e.message,retryable:e.retryable})}function he(e,t={}){let n=ct({errorCode:e.error_code,errorType:e.error_type,retryable:e.retryable,retryAfterSeconds:t.retryAfterSeconds,chargeStatus:t.chargeStatus,details:t.details});return{error:n.message,...n}}function Le(e,t={}){let{error:n,...r}=he(e,t);return r}function Io(e,t={}){let n=Fe(e);return{body:he(n,t),status:n.httpStatus}}import{createHash as zr}from"crypto";var Kr=1e9;function Jr(e){return zr("sha256").update(JSON.stringify(e)).digest("hex")}function ye(e){return`harvest:${e}`}async function Do(e){let t=ye(e.jobId);try{return(await Et({id:t,userId:e.userId,ownerScope:`user:${e.userId}`,tool:e.tool,normalizedFlags:e.normalizedFlags,idempotencyKey:`job:${e.jobId}`,requestFingerprint:Jr(e.normalizedFlags),jobId:e.jobId,requestId:e.requestId??null,deploymentCommit:process.env.VERCEL_GIT_COMMIT_SHA?.trim()||process.env.GIT_COMMIT_SHA?.trim()||null})).id}catch(n){return console.warn(JSON.stringify({event:"operation_run_start_failed",job_id:e.jobId,tool:e.tool,message:n instanceof Error?n.message:String(n)})),null}}async function $e(e,t,n){if(e)try{await kt({runId:e,status:t,failureClass:n})}catch(r){console.warn(JSON.stringify({event:"operation_run_finish_failed",operation_run_id:e,message:r instanceof Error?r.message:String(r)}))}}async function qo(e,t,n,r){if(!(!e||!t))try{await Ot({runId:e,billingTable:"billing_debits",billingKey:t,relation:n,amountMc:r})}catch(o){console.warn(JSON.stringify({event:"operation_billing_link_failed",operation_run_id:e,relation:n,message:o instanceof Error?o.message:String(o)}))}}function Ve(e){return e==="timeout"?"timed_out":e==="request_aborted"?"cancelled":e==="browser_session_interrupted"?"interrupted":e==="captcha"||e==="proxy_tunnel_failed"||e==="proxy_unavailable"||e==="location_mismatch"||e==="error"?"failed":"succeeded"}function jr(e){return e==="bright_data_browser_api"?"brightdata":"kernel"}function tr(e,t,n=0){let r=new Map,o=null;return async a=>{if(e)try{if(a.type==="started"){let i=n+a.attemptNumber;if(i>1&&!o){let p=(await It(e))?.attempts.at(-1);o=p?.id==null?null:String(p.id)}let l=await $({runId:e,attemptNumber:i,method:a.method,provider:a.provider,parentAttemptId:i===1?null:o,edgeKind:i===1?null:n>0&&a.attemptNumber===1?"durable_resume":a.retryKind==="provider_fallback"?"provider_fallback":"same_method_retry",retryKind:i===1?null:n>0&&a.attemptNumber===1?"durable_resume":a.retryKind,retryReason:i===1?null:n>0&&a.attemptNumber===1?"durable_worker_resume":a.retryReason,retryOwner:i===1?null:n>0&&a.attemptNumber===1?"durable_reconciler":"harvest",normalizedFlags:{maxAttempts:a.maxAttempts,maxQuestions:a.maxQuestions,hasLocation:!!a.location,plannedProvider:a.provider,planReason:a.planReason??null,planTimeoutMs:a.planTimeoutMs??null},startedAt:a.startedAt}),u=await H({attemptId:l,provider:a.provider,providerProduct:a.provider==="brightdata"?"brightdata_browser_api":"kernel_browser",billingTier:a.provider==="brightdata"?Z("https://www.google.com/search"):null,accountScope:t,method:a.method,providerStatus:"started"});r.set(a.attemptNumber,{attemptId:l,receiptId:u.id,plannedProvider:a.provider,observedProvider:null,providerMismatch:!1,method:a.method,startedAtMs:Date.parse(a.startedAt),billingMode:null}),o=l;return}let s=r.get(a.attemptNumber);if(!s)throw new Error(`Missing operation attempt state for attempt ${a.attemptNumber}`);if(a.type==="provider_session_started"){let i=jr(a.provider);if(s.observedProvider=i,s.billingMode=a.billingMode??null,i!==s.plannedProvider){s.providerMismatch=!0,await B({receiptId:s.receiptId,costState:"unavailable",providerStatus:"provider_mismatch",errorCode:"provider_mismatch",errorMessage:`Planned ${s.plannedProvider}; observed ${i}`,finalizedAt:a.observedAt});let l=i==="brightdata"?"brightdata_browser":"kernel_browser",u=await H({attemptId:s.attemptId,provider:i,providerProduct:i==="brightdata"?"brightdata_browser_api":"kernel_browser",billingTier:i==="brightdata"?Z("https://www.google.com/search"):null,accountScope:t,method:l,providerStatus:"observed_provider_mismatch"});s.receiptId=u.id,s.method=l}await U(s.receiptId,a.providerSessionId);return}if(await z({attemptId:s.attemptId,status:s.providerMismatch?"failed":Ve(a.outcome),errorCode:s.providerMismatch?"provider_mismatch":Ve(a.outcome)==="succeeded"?null:a.outcome,errorMessage:a.error,durationMs:a.durationMs,endedAt:a.completedAt}),(s.observedProvider??s.plannedProvider)==="kernel"){let i=s.billingMode==="headful",l=s.billingMode==="headless"||s.billingMode==="headful"?St(a.durationMs,i):null;await B({receiptId:s.receiptId,costState:"estimated",units:a.durationMs/1e3,unitType:"wall_open_second",amountUsdNanos:l==null?null:Math.round(l*Kr),providerProduct:"kernel_browser",billingTier:s.billingMode,billableEvent:"provider_active_gb_second",measurementSource:"wall_open_time_proxy",rateSource:l!=null?`kernel_${s.billingMode}_usd_per_second:${i?vt:wt}`:null,providerStatus:s.providerMismatch?"provider_mismatch":a.outcome,providerDurationMs:a.durationMs,errorCode:s.providerMismatch?"provider_mismatch":Ve(a.outcome)==="succeeded"?null:a.outcome,errorMessage:a.error,finalizedAt:a.completedAt})}}catch(s){console.warn(JSON.stringify({event:"operation_attempt_telemetry_failed",operation_run_id:e,attempt_number:a.attemptNumber,message:s instanceof Error?s.message:String(s)}))}}}function rr(e,t,n=null,r="production-default",o=0){let a=tr(n,r,o);return async s=>{if(await a(s),s.type==="started"){await gt({jobId:e,userId:t,attemptNumber:s.attemptNumber,maxAttempts:s.maxAttempts,query:s.query,location:s.location,maxQuestions:s.maxQuestions,startedAt:s.startedAt});return}if(s.type==="provider_session_started"){await ft({jobId:e,attemptNumber:s.attemptNumber,browserProvider:s.provider,providerSessionId:s.providerSessionId,observedAt:s.observedAt});return}await ht({jobId:e,attemptNumber:s.attemptNumber,outcome:s.outcome,kernelSessionId:s.kernelSessionId,questionCount:s.questionCount,durationMs:s.durationMs,error:s.error,willRetry:s.willRetry,kernelDeleteStarted:s.cleanup.kernelDeleteStarted,kernelDeleteSucceeded:s.cleanup.kernelDeleteSucceeded,kernelDeleteError:s.cleanup.kernelDeleteError,browserCloseSucceeded:s.cleanup.browserCloseSucceeded,browserCloseError:s.cleanup.browserCloseError,browserProvider:s.cleanup.provider??null,providerSessionId:s.cleanup.providerSessionId??null,providerLookupStatus:s.cleanup.providerSessionId?"pending":"not_applicable",providerErrorCode:s.cleanup.providerDisconnectObserved?"browser_session_interrupted":null,providerErrorMessage:s.cleanup.providerDisconnectMessage??null,providerReasonSource:s.cleanup.providerDisconnectObserved?"client_runtime":null,providerDisconnectObserved:s.cleanup.providerDisconnectObserved??!1,providerDisconnectMessage:s.cleanup.providerDisconnectMessage??null,debug:s.debug,completedAt:s.completedAt})}}var or=2,ze=0;function nr(e){if(!e||typeof e!="object")return 0;let t=e;return typeof t.totalQuestions=="number"?t.totalQuestions:Array.isArray(t.flat)?t.flat.length:0}function sr(e){return Te.paa_base+Math.max(1,e)*Te.paa}async function ar(e){ze++;try{let t=typeof e.options=="string"?JSON.parse(e.options):e.options,n={value:null},r=null,o=t.serpOnly&&!t.serpIdentity,a=ye(e.id),s=process.env.APIFY_API_TOKEN?.trim();if(o&&(t.pages===2?!s:!zt()||t.mode!=="full"&&!s))throw new Error("Search providers are not configured");let i=await _t({op:t.serpOnly?"serp":"paa",userId:Number(e.user_id),headlessSentOut:n,operationRunId:a,operationAccountScope:"production-default"},()=>o?Ue({query:t.query??e.query,pages:t.pages===2?2:1,token:s,mode:t.mode,operationRunId:a,accountScope:"production-default",signal:AbortSignal.timeout(lt(t.maxQuestions??30,!0,t.mode,t.pages).serverMs)}).then(u=>(r=u,u.result)):Pt({...t,kernelApiKey:ut(),headless:!0,format:"json",outputDir:"/tmp/paa-output-api",onAttemptEvent:rr(e.id,e.user_id,a)}));if(o&&!r)throw new Error("Search provider billing receipt is missing");await yt(e.id,i),await $e(a,"succeeded");let l=await Ae(e.id,e.user_id);if(typeof t.billingHoldMc=="number"&&t.billingDebitKey){let u=t.serpOnly?o?Me(r.deliveredPages,r.deliveryProvider):xe(n.value):sr(nr(i));await Oe(Number(e.user_id),t.billingDebitKey,u,t.serpOnly?"serp_refund":"paa_refund",t.serpOnly?"SERP search settlement":"PAA harvest settlement",t.serpOnly?"serp_search":"paa_harvest")}else if(!t.serpOnly&&typeof t.billingHoldMc=="number"){let u=sr(nr(i)),c=t.billingHoldMc-u;c>0?await ae(e.user_id,c,"paa_refund","overestimate refund"):c<0&&await ke(e.user_id,-c,"paa",t.query??e.query)}else if(t.serpOnly&&typeof t.billingHoldMc=="number"){let u=o?Me(r.deliveredPages,r.deliveryProvider):xe(n.value),c=t.billingHoldMc-u;c>0?await ae(e.user_id,c,"serp_refund","headless-mode pricing settle"):c<0&&await ke(e.user_id,-c,"serp",t.query??e.query)}e.callback_url&&await Be(e.callback_url,{job_id:e.id,status:"done",result:Ct(i),attempts:Ce(l)})}catch(t){console.error("[harvest/worker] failed",{jobId:e.id,error:t instanceof Error?t.message:String(t)});let n=Fe(t);await $e(ye(e.id),n.error_code==="harvest_timeout"?"timed_out":n.terminalStatus,n.error_code);let r=typeof e.options=="string"?JSON.parse(e.options):e.options,o=typeof r.billingHoldMc=="number"&&r.billingHoldMc>0;await Ee(e.id,Ge(n),Le(n,{chargeStatus:o?"refund_pending":"not_charged"}));let a=await Ae(e.id,e.user_id);try{o&&(r.billingDebitKey?await Oe(Number(e.user_id),r.billingDebitKey,0,r.serpOnly?"serp_refund":"paa_refund","failed call",r.serpOnly?"serp_search":"paa_harvest"):await ae(e.user_id,r.billingHoldMc,"refund","failed call"),await Ee(e.id,Ge(n),Le(n,{chargeStatus:"refunded"})))}catch{}e.callback_url&&await Be(e.callback_url,{job_id:e.id,status:"failed",...he(n),attempts:Ce(a)})}finally{ze--}}async function Qr(){let e=await Pe();if(!e)return{claimed:!1};let t=Date.now();return await ar(e),{claimed:!0,jobId:e.id,completed:!0,durationMs:Date.now()-t}}async function en(e){let t=[];for(let n=0;n<e.maxJobs&&!(Date.now()>=e.deadlineMs);n++){let r=await Qr();if(t.push(r),!r.claimed)break}return t}function tn(){setInterval(async()=>{if(ze>=or)return;let e=await Pe();e&&ar(e)},2e3),console.log(`[worker] started \u2014 polling every 2s, max ${or} concurrent`)}export{Z as a,de as b,_r as c,to as d,zt as e,Ue as f,Fe as g,Ge as h,he as i,Le as j,Io as k,ye as l,Do as m,$e as n,qo as o,rr as p,Be as q,Qr as r,en as s,tn as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{A as f,Ga as T,Ia as h,Ja as w,Ka as _,La as y,Ma as C,ga as g,ia as S,va as R,wa as E,ya as v,z as u}from"./chunk-
|
|
1
|
+
import{A as f,Ga as T,Ia as h,Ja as w,Ka as _,La as y,Ma as C,ga as g,ia as S,va as R,wa as E,ya as v,z as u}from"./chunk-QWSWHUOK.js";import{a as P}from"./chunk-5VB3I7UX.js";import{a as m}from"./chunk-XJ6PJWT5.js";import{readFileSync as N}from"fs";import{homedir as I}from"os";import{join as A}from"path";import{serveStdio as b}from"@modelcontextprotocol/server/stdio";import{McpServer as k}from"@modelcontextprotocol/server";var x=new Map(w.map(r=>[r.upstreamName,r.id]));function O(r){let s=r.split(`
|
|
2
2
|
`).filter(o=>o.startsWith("data:")).map(o=>o.slice(5).trim()).filter(Boolean);if(!s.length)return JSON.parse(r);for(let o of s){let e=JSON.parse(o);if(e.result||e.error)return e}throw new Error("hosted MCP returned no JSON-RPC result")}function a(r){return{content:[{type:"text",text:JSON.stringify({ok:!1,error:r})}],isError:!0}}var c=class{baseUrl;apiKey;constructor(s,o){this.baseUrl=s.replace(/\/$/,""),this.apiKey=o}async callMemoryTool(s,o){let e=x.get(s);if(!e)return a(`unknown memory tool: ${s}`);try{let n=await fetch(`${this.baseUrl}/mcp`,{method:"POST",headers:{"content-type":"application/json",accept:"application/json, text/event-stream","x-api-key":this.apiKey},body:JSON.stringify({jsonrpc:"2.0",id:`memory:${e}`,method:"tools/call",params:{name:e,arguments:o}})}),l=await n.text();if(!n.ok)return a(`hosted memory ${e} failed (HTTP ${n.status})`);let t=O(l);return t.error?a(t.error.message??`hosted memory ${e} failed`):t.result??a(`hosted memory ${e} returned no result`)}catch(n){return a(n instanceof Error?n.message:`hosted memory ${e} call failed`)}}};function M(r,s){if(s.length===0)throw new Error("Restricted MCP tool allowlist must contain at least one tool name");let o=new Set;for(let t of s){if(typeof t!="string"||t.trim()!==t||t.length===0)throw new Error("Restricted MCP tool allowlist contains a malformed tool name");if(o.has(t))throw new Error(`Restricted MCP tool allowlist contains duplicate tool name: ${t}`);o.add(t)}let e=new Set,n=r,l=n.registerTool.bind(r);return n.registerTool=(t,i,p)=>{if(o.has(t))return e.add(t),l(t,i,p)},{assertComplete(){let t=[...o].filter(i=>!e.has(i));if(t.length>0)throw new Error(`Restricted MCP tool allowlist contains unknown or unavailable tool names: ${t.join(", ")}`)},registeredToolNames(){return[...e]}}}var L=new Set(["paa","serp","browser-agent","scheduled-results","memory"]);function $(){let s=[process.env.MCP_SCRAPER_KEY_PATH?.trim(),A(I(),".mcp-scraper-key")].filter(Boolean);for(let o of s)try{let e=N(o,"utf8").trim();if(e)return e}catch{}}function Y(r,s={}){let o=s.toolsets??L,e=process.env.MCP_SCRAPER_BASE_URL?.trim()||process.env.MCP_BASE_URL?.trim()||"https://mcpscraper.dev",n=g(),l=S({deploymentProfile:n,transportProfile:"stdio",baseUrl:e,explicitlyEnabled:process.env.MCP_SCRAPER_ALLOW_PRIVATE_NETWORK==="1"}),t=process.env.BROWSER_AGENT_CONSOLE_URL?.trim()||e,i=new k({name:"mcp-scraper",version:m},{instructions:u,cacheHints:{"server/discover":{ttlMs:3e5,cacheScope:"private"},"tools/list":{ttlMs:3e5,cacheScope:"private"},"prompts/list":{ttlMs:3e5,cacheScope:"private"},"resources/list":{ttlMs:3e5,cacheScope:"private"},"resources/templates/list":{ttlMs:3e5,cacheScope:"private"},"resources/read":{ttlMs:6e4,cacheScope:"private"}}});f(i);let p=s.allowedToolNames?M(i,s.allowedToolNames):void 0,d=s.httpExecutor??new T(e,r,{localNetworkAccess:l});return o.has("paa")&&v(i,d,{ownerId:R(r),deploymentProfile:n,transportProfile:"stdio",baseUrl:e,localNetworkAccess:l,taskHandleSecret:r}),o.has("serp")&&E(i,d,{exposeDevelopmentDiagnostics:n==="development"||n==="test"}),o.has("browser-agent")&&h(i,{baseUrl:e,apiKey:r,consoleBaseUrl:t}),o.has("scheduled-results")&&C(i,new y(e,r)),o.has("memory")&&_(i,new c(e,r)),p?.assertComplete(),i}function se(r={}){let s=process.argv.includes("--stdio")||process.env.MCP_SCRAPER_FORCE_STDIO==="1",o=!!(process.stdin.isTTY&&process.stdout.isTTY),e=process.argv.includes("--help")||process.argv.includes("-h");if(!s&&(o||e)){let l=process.argv.includes("--no-color")||process.env.NO_COLOR!==void 0||process.env.FORCE_COLOR==="0"||!process.stdout.isTTY;process.stdout.write(P({version:m,color:!l,apiKeyConfigured:!!process.env.MCP_SCRAPER_API_KEY?.trim()})),process.exit(0)}let n=(process.env.MCP_SCRAPER_API_KEY??process.env.MCP_SCRAPER_KEY??process.env.MCP_API_KEY??$())?.trim();n||(process.stderr.write(`MCP_SCRAPER_API_KEY env var or ~/.mcp-scraper-key is required
|
|
3
3
|
`),process.exit(1)),b(()=>Y(n,r),{legacy:"serve",onerror(l){process.stderr.write(`${l.message}
|
|
4
4
|
`)}})}export{se as a};
|