mcp-scraper 0.92.0 → 0.93.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -1
- package/README.md +2 -2
- 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-ZJZMDWDI.js → chunk-35QGIWR6.js} +4 -4
- package/dist/{chunk-BMNXU4JL.js → chunk-4YLZR4OR.js} +1 -1
- package/dist/{chunk-F7V6HSN5.js → chunk-5KQO27NH.js} +1 -1
- package/dist/chunk-DT2FYN6N.js +1 -0
- package/dist/chunk-DUJ56SHU.js +1 -0
- package/dist/{chunk-IU3GN5SX.js → chunk-H3SJLJYM.js} +1 -1
- package/dist/{chunk-37WWXOZU.js → chunk-LBMRUR4E.js} +2 -2
- package/dist/{chunk-ZMNUI5LB.js → chunk-M5VZVMPC.js} +8 -8
- package/dist/{chunk-JM4MGP6E.js → chunk-PMOPJOSJ.js} +1 -1
- package/dist/chunk-RZEZJAID.js +1 -0
- package/dist/chunk-SH5KB4P7.js +1 -0
- package/dist/{chunk-XRWBQI3V.js → chunk-VRVO4OQ3.js} +300 -297
- package/dist/{chunk-JHMI6HEO.js → chunk-W2T4NTCE.js} +1 -1
- package/dist/chunk-XASDACRP.js +6 -0
- package/dist/chunk-Y6MKMSOC.js +1 -0
- package/dist/{extract-bundle-YHQPOGSU.js → extract-bundle-M2XM4BEW.js} +1 -1
- package/dist/{gmail-service-PKMSTKD5.js → gmail-service-EGATZIBE.js} +1 -1
- package/dist/index.cjs +45 -45
- package/dist/index.d.cts +153 -112
- package/dist/index.d.ts +153 -112
- package/dist/index.js +6 -6
- package/dist/{server-IV2GMCGQ.js → server-JLR2YJ7V.js} +464 -465
- package/dist/{site-extract-repository-DVMUVCKD.js → site-extract-repository-3NFFFPXQ.js} +1 -1
- package/dist/{stripe-event-worker-3EGRYJZP.js → stripe-event-worker-PUYXT5DS.js} +1 -1
- package/dist/worker-UG4OXZWR.js +1 -0
- package/package.json +1 -1
- package/dist/chunk-2TZBO52D.js +0 -1
- package/dist/chunk-4FROKQJN.js +0 -1
- package/dist/chunk-5WHYMZ3Z.js +0 -1
- package/dist/chunk-DDUZETZY.js +0 -1
- package/dist/chunk-MYSBUV4Y.js +0 -1
- package/dist/chunk-Q2FOIRK3.js +0 -1
- package/dist/chunk-RECKUOEF.js +0 -1
- package/dist/worker-KOCD6RZ3.js +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
declare const SERP_FEATURE_COMPLETENESS_STATES: readonly ["observed_present", "observed_absent", "incomplete", "not_requested", "unknown", "unsupported"];
|
|
4
|
+
type SerpFeatureCompletenessState = typeof SERP_FEATURE_COMPLETENESS_STATES[number];
|
|
5
|
+
|
|
6
|
+
interface SerpPreviewQuestion {
|
|
7
|
+
question: string;
|
|
8
|
+
answer: string | null;
|
|
9
|
+
url: string | null;
|
|
10
|
+
}
|
|
11
|
+
interface SerpFeatureItem {
|
|
12
|
+
title: string | null;
|
|
13
|
+
url: string | null;
|
|
14
|
+
description: string | null;
|
|
15
|
+
position: number | null;
|
|
16
|
+
}
|
|
17
|
+
interface SerpFeatureGroup {
|
|
18
|
+
name: string;
|
|
19
|
+
attributes: Record<string, string | number | boolean | null>;
|
|
20
|
+
items: SerpFeatureItem[];
|
|
21
|
+
}
|
|
22
|
+
interface FullSerpPageFeatures {
|
|
23
|
+
page: 1 | 2;
|
|
24
|
+
status: Record<string, SerpFeatureCompletenessState>;
|
|
25
|
+
paaPreview: SerpPreviewQuestion[];
|
|
26
|
+
additional: SerpFeatureGroup[];
|
|
27
|
+
localPack: LocalPackBusiness[];
|
|
28
|
+
forums: ForumResult[];
|
|
29
|
+
videos: VideoResult[];
|
|
30
|
+
whatPeopleSaying: WhatPeopleSayingCard[];
|
|
31
|
+
aiOverview: AIOverviewResult;
|
|
32
|
+
aiMode: AIModeResult;
|
|
33
|
+
entityIds: EntityIds;
|
|
34
|
+
}
|
|
35
|
+
interface FullSerpFeatures {
|
|
36
|
+
status: Record<string, SerpFeatureCompletenessState>;
|
|
37
|
+
paaPreview: SerpPreviewQuestion[];
|
|
38
|
+
additional: SerpFeatureGroup[];
|
|
39
|
+
pages: FullSerpPageFeatures[];
|
|
40
|
+
}
|
|
41
|
+
|
|
3
42
|
declare const HarvestOptionsSchema: z.ZodObject<{
|
|
4
43
|
query: z.ZodString;
|
|
5
44
|
location: z.ZodOptional<z.ZodString>;
|
|
@@ -57,75 +96,6 @@ declare const HarvestOptionsSchema: z.ZodObject<{
|
|
|
57
96
|
softDeadlineMs: z.ZodOptional<z.ZodNumber>;
|
|
58
97
|
}, z.core.$strip>;
|
|
59
98
|
|
|
60
|
-
type CanonicalLocationName = string;
|
|
61
|
-
type SerpDevice = 'desktop' | 'mobile';
|
|
62
|
-
type ProxyMode = 'location' | 'configured' | 'none';
|
|
63
|
-
interface \u004b\u0065\u0072\u006e\u0065\u006cLocationProxyTarget {
|
|
64
|
-
canonicalLocation: CanonicalLocationName;
|
|
65
|
-
level: 'zip' | 'city' | 'state';
|
|
66
|
-
country: 'US';
|
|
67
|
-
state: string;
|
|
68
|
-
city: string;
|
|
69
|
-
zip?: string;
|
|
70
|
-
cityCandidates: string[];
|
|
71
|
-
proxyName: string;
|
|
72
|
-
config: {
|
|
73
|
-
country: 'US';
|
|
74
|
-
state: string;
|
|
75
|
-
city?: string;
|
|
76
|
-
zip?: string;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
type \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionSource = 'disabled' | 'location_reused' | 'location_created' | 'isp_created' | 'backup_custom' | 'configured_fallback' | 'unavailable';
|
|
80
|
-
interface \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionDebug {
|
|
81
|
-
source: \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionSource;
|
|
82
|
-
proxyType: string;
|
|
83
|
-
proxyMode: ProxyMode;
|
|
84
|
-
proxyIdPresent: boolean;
|
|
85
|
-
proxyIdSuffix: string | null;
|
|
86
|
-
target: \u004b\u0065\u0072\u006e\u0065\u006cLocationProxyTarget | null;
|
|
87
|
-
error: string | null;
|
|
88
|
-
disposable?: boolean;
|
|
89
|
-
}
|
|
90
|
-
interface HarvestStats {
|
|
91
|
-
seed: string;
|
|
92
|
-
totalQuestions: number;
|
|
93
|
-
maxDepthReached: number;
|
|
94
|
-
durationMs: number;
|
|
95
|
-
errorCount: number;
|
|
96
|
-
}
|
|
97
|
-
type HarvestCompletionStatus = 'paa_found' | 'no_paa' | 'serp_only';
|
|
98
|
-
/**
|
|
99
|
-
* A completed browser attempt can still be unsuitable for programmatic use.
|
|
100
|
-
* This is deliberately separate from completionStatus so a valid no-PAA
|
|
101
|
-
* response with organic results is not confused with an unreadable SERP.
|
|
102
|
-
*/
|
|
103
|
-
type HarvestResultQuality = 'complete' | 'partial' | 'degraded';
|
|
104
|
-
type HarvestDegradationReason = 'empty_primary_serp';
|
|
105
|
-
type HarvestDiagnosticWarningCode = 'short_videos_captcha_skipped' | 'paa_partial';
|
|
106
|
-
type HarvestDiagnosticWarningSurface = 'short_videos' | 'paa';
|
|
107
|
-
interface HarvestDiagnosticWarning {
|
|
108
|
-
code: HarvestDiagnosticWarningCode;
|
|
109
|
-
surface: HarvestDiagnosticWarningSurface;
|
|
110
|
-
message: string;
|
|
111
|
-
retryable: boolean;
|
|
112
|
-
}
|
|
113
|
-
interface HarvestCompleteness {
|
|
114
|
-
paaWithoutAnswer: number;
|
|
115
|
-
paaWithoutSource: number;
|
|
116
|
-
paaAnswersRecovered: number;
|
|
117
|
-
aioShareCaptured: boolean | null;
|
|
118
|
-
paaRequested?: number;
|
|
119
|
-
paaReturned?: number;
|
|
120
|
-
paaUnique?: number;
|
|
121
|
-
}
|
|
122
|
-
type HarvestInterruptionCode = 'browser_session_interrupted' | 'request_aborted' | 'timeout';
|
|
123
|
-
type HarvestInterruptionReasonSource = 'client_runtime' | 'extractor';
|
|
124
|
-
interface HarvestInterruptionDiagnostic {
|
|
125
|
-
code: HarvestInterruptionCode;
|
|
126
|
-
reasonSource: HarvestInterruptionReasonSource;
|
|
127
|
-
message: string | null;
|
|
128
|
-
}
|
|
129
99
|
type PaaDiscoveryStatus = 'in_progress' | 'target_reached' | 'frontier_exhausted' | 'no_paa_observed' | 'interrupted' | 'recovery_exhausted';
|
|
130
100
|
type PaaTargetStatus = 'met' | 'not_met';
|
|
131
101
|
type PaaMaterialStatus = 'complete' | 'partial';
|
|
@@ -185,15 +155,6 @@ interface PaaInteractionObservation {
|
|
|
185
155
|
errorCode: 'click_failed' | 'click_ack_timeout' | 'control_missing' | 'confirmation_timeout' | null;
|
|
186
156
|
}
|
|
187
157
|
type PaaProgressPhase = 'serp_captured' | 'discovered' | 'click_observed' | 'answer_captured' | 'fill_incomplete' | 'expansion_finished' | 'attempt_ending';
|
|
188
|
-
/** Observed organic pagination outcome; page two never expands a separate PAA graph. */
|
|
189
|
-
interface HarvestPaginationDiagnostics {
|
|
190
|
-
requestedPages: 1 | 2;
|
|
191
|
-
capturedPages: 1 | 2;
|
|
192
|
-
page2Status: 'not_requested' | 'not_attempted' | 'captured' | 'unavailable' | 'failed';
|
|
193
|
-
page1OrganicCount: number;
|
|
194
|
-
page2OrganicCount: number;
|
|
195
|
-
failureCode?: 'missing_next' | 'invalid_next' | 'empty_page' | 'captcha' | 'timeout' | 'navigation_error' | 'unsupported_driver';
|
|
196
|
-
}
|
|
197
158
|
/** Material already observed before PAA expansion completes. It is checkpointed
|
|
198
159
|
* so a worker interruption cannot discard the SERP that led to the PAA graph. */
|
|
199
160
|
interface PaaProgressMaterial {
|
|
@@ -218,6 +179,119 @@ interface PaaProgressSnapshot {
|
|
|
218
179
|
material?: PaaProgressMaterial;
|
|
219
180
|
interactions?: PaaInteractionObservation[];
|
|
220
181
|
}
|
|
182
|
+
interface PaaSource extends SerpOutboundLink {
|
|
183
|
+
title: string | null;
|
|
184
|
+
site: string | null;
|
|
185
|
+
}
|
|
186
|
+
interface PAANode {
|
|
187
|
+
questionId: string;
|
|
188
|
+
googleLinkId: string | null;
|
|
189
|
+
googleEvidenceId: string | null;
|
|
190
|
+
question: string;
|
|
191
|
+
answer: string | null;
|
|
192
|
+
sourceTitle: string | null;
|
|
193
|
+
sourceSite: string | null;
|
|
194
|
+
sourceCite: string | null;
|
|
195
|
+
sources: PaaSource[];
|
|
196
|
+
depth: number;
|
|
197
|
+
parentQuestion: string | null;
|
|
198
|
+
children: PAANode[];
|
|
199
|
+
}
|
|
200
|
+
interface FlatRow {
|
|
201
|
+
seed_query: string;
|
|
202
|
+
question_id: string;
|
|
203
|
+
google_link_id: string;
|
|
204
|
+
google_evidence_id: string;
|
|
205
|
+
question: string;
|
|
206
|
+
answer: string;
|
|
207
|
+
source_title: string;
|
|
208
|
+
source_site: string;
|
|
209
|
+
source_cite: string;
|
|
210
|
+
sources: PaaSource[];
|
|
211
|
+
depth: number;
|
|
212
|
+
parent_question: string;
|
|
213
|
+
extracted_at: string;
|
|
214
|
+
}
|
|
215
|
+
type HarvestOptions = z.infer<typeof HarvestOptionsSchema>;
|
|
216
|
+
|
|
217
|
+
type CanonicalLocationName = string;
|
|
218
|
+
type SerpDevice = 'desktop' | 'mobile';
|
|
219
|
+
type ProxyMode = 'location' | 'configured' | 'none';
|
|
220
|
+
interface \u004b\u0065\u0072\u006e\u0065\u006cLocationProxyTarget {
|
|
221
|
+
canonicalLocation: CanonicalLocationName;
|
|
222
|
+
level: 'zip' | 'city' | 'state';
|
|
223
|
+
country: 'US';
|
|
224
|
+
state: string;
|
|
225
|
+
city: string;
|
|
226
|
+
zip?: string;
|
|
227
|
+
cityCandidates: string[];
|
|
228
|
+
proxyName: string;
|
|
229
|
+
config: {
|
|
230
|
+
country: 'US';
|
|
231
|
+
state: string;
|
|
232
|
+
city?: string;
|
|
233
|
+
zip?: string;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
type \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionSource = 'disabled' | 'location_reused' | 'location_created' | 'isp_created' | 'backup_custom' | 'configured_fallback' | 'unavailable';
|
|
237
|
+
interface \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionDebug {
|
|
238
|
+
source: \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionSource;
|
|
239
|
+
proxyType: string;
|
|
240
|
+
proxyMode: ProxyMode;
|
|
241
|
+
proxyIdPresent: boolean;
|
|
242
|
+
proxyIdSuffix: string | null;
|
|
243
|
+
target: \u004b\u0065\u0072\u006e\u0065\u006cLocationProxyTarget | null;
|
|
244
|
+
error: string | null;
|
|
245
|
+
disposable?: boolean;
|
|
246
|
+
}
|
|
247
|
+
interface HarvestStats {
|
|
248
|
+
seed: string;
|
|
249
|
+
totalQuestions: number;
|
|
250
|
+
maxDepthReached: number;
|
|
251
|
+
durationMs: number;
|
|
252
|
+
errorCount: number;
|
|
253
|
+
}
|
|
254
|
+
type HarvestCompletionStatus = 'paa_found' | 'no_paa' | 'serp_only';
|
|
255
|
+
/**
|
|
256
|
+
* A completed browser attempt can still be unsuitable for programmatic use.
|
|
257
|
+
* This is deliberately separate from completionStatus so a valid no-PAA
|
|
258
|
+
* response with organic results is not confused with an unreadable SERP.
|
|
259
|
+
*/
|
|
260
|
+
type HarvestResultQuality = 'complete' | 'partial' | 'degraded';
|
|
261
|
+
type HarvestDegradationReason = 'empty_primary_serp';
|
|
262
|
+
type HarvestDiagnosticWarningCode = 'short_videos_captcha_skipped' | 'paa_partial';
|
|
263
|
+
type HarvestDiagnosticWarningSurface = 'short_videos' | 'paa';
|
|
264
|
+
interface HarvestDiagnosticWarning {
|
|
265
|
+
code: HarvestDiagnosticWarningCode;
|
|
266
|
+
surface: HarvestDiagnosticWarningSurface;
|
|
267
|
+
message: string;
|
|
268
|
+
retryable: boolean;
|
|
269
|
+
}
|
|
270
|
+
interface HarvestCompleteness {
|
|
271
|
+
paaWithoutAnswer: number;
|
|
272
|
+
paaWithoutSource: number;
|
|
273
|
+
paaAnswersRecovered: number;
|
|
274
|
+
aioShareCaptured: boolean | null;
|
|
275
|
+
paaRequested?: number;
|
|
276
|
+
paaReturned?: number;
|
|
277
|
+
paaUnique?: number;
|
|
278
|
+
}
|
|
279
|
+
type HarvestInterruptionCode = 'browser_session_interrupted' | 'request_aborted' | 'timeout';
|
|
280
|
+
type HarvestInterruptionReasonSource = 'client_runtime' | 'extractor';
|
|
281
|
+
interface HarvestInterruptionDiagnostic {
|
|
282
|
+
code: HarvestInterruptionCode;
|
|
283
|
+
reasonSource: HarvestInterruptionReasonSource;
|
|
284
|
+
message: string | null;
|
|
285
|
+
}
|
|
286
|
+
/** Observed organic pagination outcome; page two never expands a separate PAA graph. */
|
|
287
|
+
interface HarvestPaginationDiagnostics {
|
|
288
|
+
requestedPages: 1 | 2;
|
|
289
|
+
capturedPages: 1 | 2;
|
|
290
|
+
page2Status: 'not_requested' | 'not_attempted' | 'captured' | 'unavailable' | 'failed';
|
|
291
|
+
page1OrganicCount: number;
|
|
292
|
+
page2OrganicCount: number;
|
|
293
|
+
failureCode?: 'missing_next' | 'invalid_next' | 'empty_page' | 'captcha' | 'timeout' | 'navigation_error' | 'unsupported_driver';
|
|
294
|
+
}
|
|
221
295
|
interface HarvestDiagnostics {
|
|
222
296
|
phaseTimings?: {
|
|
223
297
|
providerConnectMs?: number;
|
|
@@ -358,39 +432,6 @@ interface SerpOutboundLink {
|
|
|
358
432
|
linkType: SerpLinkType;
|
|
359
433
|
resolutionStatus: SerpLinkResolutionStatus;
|
|
360
434
|
}
|
|
361
|
-
interface PaaSource extends SerpOutboundLink {
|
|
362
|
-
title: string | null;
|
|
363
|
-
site: string | null;
|
|
364
|
-
}
|
|
365
|
-
interface PAANode {
|
|
366
|
-
questionId: string;
|
|
367
|
-
googleLinkId: string | null;
|
|
368
|
-
googleEvidenceId: string | null;
|
|
369
|
-
question: string;
|
|
370
|
-
answer: string | null;
|
|
371
|
-
sourceTitle: string | null;
|
|
372
|
-
sourceSite: string | null;
|
|
373
|
-
sourceCite: string | null;
|
|
374
|
-
sources: PaaSource[];
|
|
375
|
-
depth: number;
|
|
376
|
-
parentQuestion: string | null;
|
|
377
|
-
children: PAANode[];
|
|
378
|
-
}
|
|
379
|
-
interface FlatRow {
|
|
380
|
-
seed_query: string;
|
|
381
|
-
question_id: string;
|
|
382
|
-
google_link_id: string;
|
|
383
|
-
google_evidence_id: string;
|
|
384
|
-
question: string;
|
|
385
|
-
answer: string;
|
|
386
|
-
source_title: string;
|
|
387
|
-
source_site: string;
|
|
388
|
-
source_cite: string;
|
|
389
|
-
sources: PaaSource[];
|
|
390
|
-
depth: number;
|
|
391
|
-
parent_question: string;
|
|
392
|
-
extracted_at: string;
|
|
393
|
-
}
|
|
394
435
|
interface VideoResult {
|
|
395
436
|
type: 'video' | 'short_video';
|
|
396
437
|
title: string;
|
|
@@ -495,9 +536,9 @@ interface HarvestResult {
|
|
|
495
536
|
organicResults: OrganicResult[];
|
|
496
537
|
localPack: LocalPackBusiness[];
|
|
497
538
|
entityIds: EntityIds;
|
|
539
|
+
fullSerpFeatures?: FullSerpFeatures;
|
|
498
540
|
stats: HarvestStats;
|
|
499
541
|
}
|
|
500
|
-
type HarvestOptions = z.infer<typeof HarvestOptionsSchema>;
|
|
501
542
|
|
|
502
543
|
declare function harvest(rawOptions: unknown): Promise<HarvestResult>;
|
|
503
544
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
declare const SERP_FEATURE_COMPLETENESS_STATES: readonly ["observed_present", "observed_absent", "incomplete", "not_requested", "unknown", "unsupported"];
|
|
4
|
+
type SerpFeatureCompletenessState = typeof SERP_FEATURE_COMPLETENESS_STATES[number];
|
|
5
|
+
|
|
6
|
+
interface SerpPreviewQuestion {
|
|
7
|
+
question: string;
|
|
8
|
+
answer: string | null;
|
|
9
|
+
url: string | null;
|
|
10
|
+
}
|
|
11
|
+
interface SerpFeatureItem {
|
|
12
|
+
title: string | null;
|
|
13
|
+
url: string | null;
|
|
14
|
+
description: string | null;
|
|
15
|
+
position: number | null;
|
|
16
|
+
}
|
|
17
|
+
interface SerpFeatureGroup {
|
|
18
|
+
name: string;
|
|
19
|
+
attributes: Record<string, string | number | boolean | null>;
|
|
20
|
+
items: SerpFeatureItem[];
|
|
21
|
+
}
|
|
22
|
+
interface FullSerpPageFeatures {
|
|
23
|
+
page: 1 | 2;
|
|
24
|
+
status: Record<string, SerpFeatureCompletenessState>;
|
|
25
|
+
paaPreview: SerpPreviewQuestion[];
|
|
26
|
+
additional: SerpFeatureGroup[];
|
|
27
|
+
localPack: LocalPackBusiness[];
|
|
28
|
+
forums: ForumResult[];
|
|
29
|
+
videos: VideoResult[];
|
|
30
|
+
whatPeopleSaying: WhatPeopleSayingCard[];
|
|
31
|
+
aiOverview: AIOverviewResult;
|
|
32
|
+
aiMode: AIModeResult;
|
|
33
|
+
entityIds: EntityIds;
|
|
34
|
+
}
|
|
35
|
+
interface FullSerpFeatures {
|
|
36
|
+
status: Record<string, SerpFeatureCompletenessState>;
|
|
37
|
+
paaPreview: SerpPreviewQuestion[];
|
|
38
|
+
additional: SerpFeatureGroup[];
|
|
39
|
+
pages: FullSerpPageFeatures[];
|
|
40
|
+
}
|
|
41
|
+
|
|
3
42
|
declare const HarvestOptionsSchema: z.ZodObject<{
|
|
4
43
|
query: z.ZodString;
|
|
5
44
|
location: z.ZodOptional<z.ZodString>;
|
|
@@ -57,75 +96,6 @@ declare const HarvestOptionsSchema: z.ZodObject<{
|
|
|
57
96
|
softDeadlineMs: z.ZodOptional<z.ZodNumber>;
|
|
58
97
|
}, z.core.$strip>;
|
|
59
98
|
|
|
60
|
-
type CanonicalLocationName = string;
|
|
61
|
-
type SerpDevice = 'desktop' | 'mobile';
|
|
62
|
-
type ProxyMode = 'location' | 'configured' | 'none';
|
|
63
|
-
interface \u004b\u0065\u0072\u006e\u0065\u006cLocationProxyTarget {
|
|
64
|
-
canonicalLocation: CanonicalLocationName;
|
|
65
|
-
level: 'zip' | 'city' | 'state';
|
|
66
|
-
country: 'US';
|
|
67
|
-
state: string;
|
|
68
|
-
city: string;
|
|
69
|
-
zip?: string;
|
|
70
|
-
cityCandidates: string[];
|
|
71
|
-
proxyName: string;
|
|
72
|
-
config: {
|
|
73
|
-
country: 'US';
|
|
74
|
-
state: string;
|
|
75
|
-
city?: string;
|
|
76
|
-
zip?: string;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
type \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionSource = 'disabled' | 'location_reused' | 'location_created' | 'isp_created' | 'backup_custom' | 'configured_fallback' | 'unavailable';
|
|
80
|
-
interface \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionDebug {
|
|
81
|
-
source: \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionSource;
|
|
82
|
-
proxyType: string;
|
|
83
|
-
proxyMode: ProxyMode;
|
|
84
|
-
proxyIdPresent: boolean;
|
|
85
|
-
proxyIdSuffix: string | null;
|
|
86
|
-
target: \u004b\u0065\u0072\u006e\u0065\u006cLocationProxyTarget | null;
|
|
87
|
-
error: string | null;
|
|
88
|
-
disposable?: boolean;
|
|
89
|
-
}
|
|
90
|
-
interface HarvestStats {
|
|
91
|
-
seed: string;
|
|
92
|
-
totalQuestions: number;
|
|
93
|
-
maxDepthReached: number;
|
|
94
|
-
durationMs: number;
|
|
95
|
-
errorCount: number;
|
|
96
|
-
}
|
|
97
|
-
type HarvestCompletionStatus = 'paa_found' | 'no_paa' | 'serp_only';
|
|
98
|
-
/**
|
|
99
|
-
* A completed browser attempt can still be unsuitable for programmatic use.
|
|
100
|
-
* This is deliberately separate from completionStatus so a valid no-PAA
|
|
101
|
-
* response with organic results is not confused with an unreadable SERP.
|
|
102
|
-
*/
|
|
103
|
-
type HarvestResultQuality = 'complete' | 'partial' | 'degraded';
|
|
104
|
-
type HarvestDegradationReason = 'empty_primary_serp';
|
|
105
|
-
type HarvestDiagnosticWarningCode = 'short_videos_captcha_skipped' | 'paa_partial';
|
|
106
|
-
type HarvestDiagnosticWarningSurface = 'short_videos' | 'paa';
|
|
107
|
-
interface HarvestDiagnosticWarning {
|
|
108
|
-
code: HarvestDiagnosticWarningCode;
|
|
109
|
-
surface: HarvestDiagnosticWarningSurface;
|
|
110
|
-
message: string;
|
|
111
|
-
retryable: boolean;
|
|
112
|
-
}
|
|
113
|
-
interface HarvestCompleteness {
|
|
114
|
-
paaWithoutAnswer: number;
|
|
115
|
-
paaWithoutSource: number;
|
|
116
|
-
paaAnswersRecovered: number;
|
|
117
|
-
aioShareCaptured: boolean | null;
|
|
118
|
-
paaRequested?: number;
|
|
119
|
-
paaReturned?: number;
|
|
120
|
-
paaUnique?: number;
|
|
121
|
-
}
|
|
122
|
-
type HarvestInterruptionCode = 'browser_session_interrupted' | 'request_aborted' | 'timeout';
|
|
123
|
-
type HarvestInterruptionReasonSource = 'client_runtime' | 'extractor';
|
|
124
|
-
interface HarvestInterruptionDiagnostic {
|
|
125
|
-
code: HarvestInterruptionCode;
|
|
126
|
-
reasonSource: HarvestInterruptionReasonSource;
|
|
127
|
-
message: string | null;
|
|
128
|
-
}
|
|
129
99
|
type PaaDiscoveryStatus = 'in_progress' | 'target_reached' | 'frontier_exhausted' | 'no_paa_observed' | 'interrupted' | 'recovery_exhausted';
|
|
130
100
|
type PaaTargetStatus = 'met' | 'not_met';
|
|
131
101
|
type PaaMaterialStatus = 'complete' | 'partial';
|
|
@@ -185,15 +155,6 @@ interface PaaInteractionObservation {
|
|
|
185
155
|
errorCode: 'click_failed' | 'click_ack_timeout' | 'control_missing' | 'confirmation_timeout' | null;
|
|
186
156
|
}
|
|
187
157
|
type PaaProgressPhase = 'serp_captured' | 'discovered' | 'click_observed' | 'answer_captured' | 'fill_incomplete' | 'expansion_finished' | 'attempt_ending';
|
|
188
|
-
/** Observed organic pagination outcome; page two never expands a separate PAA graph. */
|
|
189
|
-
interface HarvestPaginationDiagnostics {
|
|
190
|
-
requestedPages: 1 | 2;
|
|
191
|
-
capturedPages: 1 | 2;
|
|
192
|
-
page2Status: 'not_requested' | 'not_attempted' | 'captured' | 'unavailable' | 'failed';
|
|
193
|
-
page1OrganicCount: number;
|
|
194
|
-
page2OrganicCount: number;
|
|
195
|
-
failureCode?: 'missing_next' | 'invalid_next' | 'empty_page' | 'captcha' | 'timeout' | 'navigation_error' | 'unsupported_driver';
|
|
196
|
-
}
|
|
197
158
|
/** Material already observed before PAA expansion completes. It is checkpointed
|
|
198
159
|
* so a worker interruption cannot discard the SERP that led to the PAA graph. */
|
|
199
160
|
interface PaaProgressMaterial {
|
|
@@ -218,6 +179,119 @@ interface PaaProgressSnapshot {
|
|
|
218
179
|
material?: PaaProgressMaterial;
|
|
219
180
|
interactions?: PaaInteractionObservation[];
|
|
220
181
|
}
|
|
182
|
+
interface PaaSource extends SerpOutboundLink {
|
|
183
|
+
title: string | null;
|
|
184
|
+
site: string | null;
|
|
185
|
+
}
|
|
186
|
+
interface PAANode {
|
|
187
|
+
questionId: string;
|
|
188
|
+
googleLinkId: string | null;
|
|
189
|
+
googleEvidenceId: string | null;
|
|
190
|
+
question: string;
|
|
191
|
+
answer: string | null;
|
|
192
|
+
sourceTitle: string | null;
|
|
193
|
+
sourceSite: string | null;
|
|
194
|
+
sourceCite: string | null;
|
|
195
|
+
sources: PaaSource[];
|
|
196
|
+
depth: number;
|
|
197
|
+
parentQuestion: string | null;
|
|
198
|
+
children: PAANode[];
|
|
199
|
+
}
|
|
200
|
+
interface FlatRow {
|
|
201
|
+
seed_query: string;
|
|
202
|
+
question_id: string;
|
|
203
|
+
google_link_id: string;
|
|
204
|
+
google_evidence_id: string;
|
|
205
|
+
question: string;
|
|
206
|
+
answer: string;
|
|
207
|
+
source_title: string;
|
|
208
|
+
source_site: string;
|
|
209
|
+
source_cite: string;
|
|
210
|
+
sources: PaaSource[];
|
|
211
|
+
depth: number;
|
|
212
|
+
parent_question: string;
|
|
213
|
+
extracted_at: string;
|
|
214
|
+
}
|
|
215
|
+
type HarvestOptions = z.infer<typeof HarvestOptionsSchema>;
|
|
216
|
+
|
|
217
|
+
type CanonicalLocationName = string;
|
|
218
|
+
type SerpDevice = 'desktop' | 'mobile';
|
|
219
|
+
type ProxyMode = 'location' | 'configured' | 'none';
|
|
220
|
+
interface \u004b\u0065\u0072\u006e\u0065\u006cLocationProxyTarget {
|
|
221
|
+
canonicalLocation: CanonicalLocationName;
|
|
222
|
+
level: 'zip' | 'city' | 'state';
|
|
223
|
+
country: 'US';
|
|
224
|
+
state: string;
|
|
225
|
+
city: string;
|
|
226
|
+
zip?: string;
|
|
227
|
+
cityCandidates: string[];
|
|
228
|
+
proxyName: string;
|
|
229
|
+
config: {
|
|
230
|
+
country: 'US';
|
|
231
|
+
state: string;
|
|
232
|
+
city?: string;
|
|
233
|
+
zip?: string;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
type \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionSource = 'disabled' | 'location_reused' | 'location_created' | 'isp_created' | 'backup_custom' | 'configured_fallback' | 'unavailable';
|
|
237
|
+
interface \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionDebug {
|
|
238
|
+
source: \u004b\u0065\u0072\u006e\u0065\u006cProxyResolutionSource;
|
|
239
|
+
proxyType: string;
|
|
240
|
+
proxyMode: ProxyMode;
|
|
241
|
+
proxyIdPresent: boolean;
|
|
242
|
+
proxyIdSuffix: string | null;
|
|
243
|
+
target: \u004b\u0065\u0072\u006e\u0065\u006cLocationProxyTarget | null;
|
|
244
|
+
error: string | null;
|
|
245
|
+
disposable?: boolean;
|
|
246
|
+
}
|
|
247
|
+
interface HarvestStats {
|
|
248
|
+
seed: string;
|
|
249
|
+
totalQuestions: number;
|
|
250
|
+
maxDepthReached: number;
|
|
251
|
+
durationMs: number;
|
|
252
|
+
errorCount: number;
|
|
253
|
+
}
|
|
254
|
+
type HarvestCompletionStatus = 'paa_found' | 'no_paa' | 'serp_only';
|
|
255
|
+
/**
|
|
256
|
+
* A completed browser attempt can still be unsuitable for programmatic use.
|
|
257
|
+
* This is deliberately separate from completionStatus so a valid no-PAA
|
|
258
|
+
* response with organic results is not confused with an unreadable SERP.
|
|
259
|
+
*/
|
|
260
|
+
type HarvestResultQuality = 'complete' | 'partial' | 'degraded';
|
|
261
|
+
type HarvestDegradationReason = 'empty_primary_serp';
|
|
262
|
+
type HarvestDiagnosticWarningCode = 'short_videos_captcha_skipped' | 'paa_partial';
|
|
263
|
+
type HarvestDiagnosticWarningSurface = 'short_videos' | 'paa';
|
|
264
|
+
interface HarvestDiagnosticWarning {
|
|
265
|
+
code: HarvestDiagnosticWarningCode;
|
|
266
|
+
surface: HarvestDiagnosticWarningSurface;
|
|
267
|
+
message: string;
|
|
268
|
+
retryable: boolean;
|
|
269
|
+
}
|
|
270
|
+
interface HarvestCompleteness {
|
|
271
|
+
paaWithoutAnswer: number;
|
|
272
|
+
paaWithoutSource: number;
|
|
273
|
+
paaAnswersRecovered: number;
|
|
274
|
+
aioShareCaptured: boolean | null;
|
|
275
|
+
paaRequested?: number;
|
|
276
|
+
paaReturned?: number;
|
|
277
|
+
paaUnique?: number;
|
|
278
|
+
}
|
|
279
|
+
type HarvestInterruptionCode = 'browser_session_interrupted' | 'request_aborted' | 'timeout';
|
|
280
|
+
type HarvestInterruptionReasonSource = 'client_runtime' | 'extractor';
|
|
281
|
+
interface HarvestInterruptionDiagnostic {
|
|
282
|
+
code: HarvestInterruptionCode;
|
|
283
|
+
reasonSource: HarvestInterruptionReasonSource;
|
|
284
|
+
message: string | null;
|
|
285
|
+
}
|
|
286
|
+
/** Observed organic pagination outcome; page two never expands a separate PAA graph. */
|
|
287
|
+
interface HarvestPaginationDiagnostics {
|
|
288
|
+
requestedPages: 1 | 2;
|
|
289
|
+
capturedPages: 1 | 2;
|
|
290
|
+
page2Status: 'not_requested' | 'not_attempted' | 'captured' | 'unavailable' | 'failed';
|
|
291
|
+
page1OrganicCount: number;
|
|
292
|
+
page2OrganicCount: number;
|
|
293
|
+
failureCode?: 'missing_next' | 'invalid_next' | 'empty_page' | 'captcha' | 'timeout' | 'navigation_error' | 'unsupported_driver';
|
|
294
|
+
}
|
|
221
295
|
interface HarvestDiagnostics {
|
|
222
296
|
phaseTimings?: {
|
|
223
297
|
providerConnectMs?: number;
|
|
@@ -358,39 +432,6 @@ interface SerpOutboundLink {
|
|
|
358
432
|
linkType: SerpLinkType;
|
|
359
433
|
resolutionStatus: SerpLinkResolutionStatus;
|
|
360
434
|
}
|
|
361
|
-
interface PaaSource extends SerpOutboundLink {
|
|
362
|
-
title: string | null;
|
|
363
|
-
site: string | null;
|
|
364
|
-
}
|
|
365
|
-
interface PAANode {
|
|
366
|
-
questionId: string;
|
|
367
|
-
googleLinkId: string | null;
|
|
368
|
-
googleEvidenceId: string | null;
|
|
369
|
-
question: string;
|
|
370
|
-
answer: string | null;
|
|
371
|
-
sourceTitle: string | null;
|
|
372
|
-
sourceSite: string | null;
|
|
373
|
-
sourceCite: string | null;
|
|
374
|
-
sources: PaaSource[];
|
|
375
|
-
depth: number;
|
|
376
|
-
parentQuestion: string | null;
|
|
377
|
-
children: PAANode[];
|
|
378
|
-
}
|
|
379
|
-
interface FlatRow {
|
|
380
|
-
seed_query: string;
|
|
381
|
-
question_id: string;
|
|
382
|
-
google_link_id: string;
|
|
383
|
-
google_evidence_id: string;
|
|
384
|
-
question: string;
|
|
385
|
-
answer: string;
|
|
386
|
-
source_title: string;
|
|
387
|
-
source_site: string;
|
|
388
|
-
source_cite: string;
|
|
389
|
-
sources: PaaSource[];
|
|
390
|
-
depth: number;
|
|
391
|
-
parent_question: string;
|
|
392
|
-
extracted_at: string;
|
|
393
|
-
}
|
|
394
435
|
interface VideoResult {
|
|
395
436
|
type: 'video' | 'short_video';
|
|
396
437
|
title: string;
|
|
@@ -495,9 +536,9 @@ interface HarvestResult {
|
|
|
495
536
|
organicResults: OrganicResult[];
|
|
496
537
|
localPack: LocalPackBusiness[];
|
|
497
538
|
entityIds: EntityIds;
|
|
539
|
+
fullSerpFeatures?: FullSerpFeatures;
|
|
498
540
|
stats: HarvestStats;
|
|
499
541
|
}
|
|
500
|
-
type HarvestOptions = z.infer<typeof HarvestOptionsSchema>;
|
|
501
542
|
|
|
502
543
|
declare function harvest(rawOptions: unknown): Promise<HarvestResult>;
|
|
503
544
|
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{w as z}from"./chunk-
|
|
1
|
+
import{w as z}from"./chunk-M5VZVMPC.js";import"./chunk-M5QHXNFZ.js";import"./chunk-SH5KB4P7.js";import{h as M}from"./chunk-2SP57VCG.js";import"./chunk-6DTXIZY2.js";import"./chunk-Y6MKMSOC.js";import"./chunk-WJ4XFLS4.js";import{execSync as ce}from"child_process";import{readFileSync as G,writeFileSync as _,unlinkSync as D,mkdirSync as Y}from"fs";import{tmpdir as W}from"os";import{join as l}from"path";import{fal as p}from"@fal-ai/client";var X="https://api.deepinfra.com/v1/openai/chat/completions",L="https://openrouter.ai/api/v1/chat/completions",A="Qwen/Qwen3.6-35B-A3B",Z=`You are a video prompt engineer for Seedance 2.0 text-to-video AI.
|
|
2
2
|
|
|
3
3
|
IMPORTANT TECHNICAL CONTEXT: Clip 2 will be generated using image-to-video, meaning it will start from the exact last frame of Clip 1. The two clips will be visually seamless \u2014 same location, same characters, continuous motion. You must write prompts that make this feel like one uninterrupted 16-second video.
|
|
4
4
|
|
|
@@ -20,17 +20,17 @@ Rules for visuals:
|
|
|
20
20
|
- Describe exactly what the camera sees
|
|
21
21
|
|
|
22
22
|
Respond with JSON only:
|
|
23
|
-
{"clip1": "...", "clip2": "...", "voiceover": "...", "audioMood": "..."}`;async function B(t,
|
|
23
|
+
{"clip1": "...", "clip2": "...", "voiceover": "...", "audioMood": "..."}`;async function B(i,t,e,o){let n=await fetch(t,{method:"POST",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"},body:JSON.stringify({model:A,temperature:.7,messages:[{role:"system",content:Z},{role:"user",content:`Question: ${e}
|
|
24
24
|
|
|
25
|
-
Answer: ${o.slice(0,500)}`}]})});if(!n.ok)throw new Error(`LLM call failed (${n.status}): ${await n.text()}`);let r=await n.json();
|
|
26
|
-
[1/7] Generating prompts via QWEN 3.6...`);let r=await T(
|
|
25
|
+
Answer: ${o.slice(0,500)}`}]})});if(!n.ok)throw new Error(`LLM call failed (${n.status}): ${await n.text()}`);let r=await n.json();t===L?M({vendor:"openrouter",model:A,units:r.usage?.cost??0,unitType:"usd"}):M({vendor:"deepinfra_qwen",model:A,units:r.usage?.completion_tokens??0,unitType:"tokens"});let a=r.choices[0]?.message?.content?.trim()??"",c=a.match(/\{[\s\S]*\}/);if(!c)throw new Error(`No JSON in QWEN response: ${a.slice(0,200)}`);let s=JSON.parse(c[0]);if(!s.clip1||!s.clip2||!s.voiceover||!s.audioMood)throw new Error(`QWEN response missing fields: ${a.slice(0,200)}`);return s}async function T(i,t){let e=process.env.DEEPINFRA_API_KEY,o=process.env.OPENROUTER_API_KEY;if(e)try{return await B(e,X,i,t)}catch(n){console.warn("[promptBuilder] DeepInfra failed, trying OpenRouter:",n.message)}if(o)return await B(o,L,i,t);throw new Error("No LLM key \u2014 set DEEPINFRA_API_KEY or OPENROUTER_API_KEY")}function V(i){if(!i.clip1||!i.clip2||!i.voiceover||!i.audioMood)throw new Error("Episode brief is missing prompt fields \u2014 run blog-to-video skill to regenerate");return{clip1:i.clip1,clip2:i.clip2,voiceover:i.voiceover,audioMood:i.audioMood}}import{writeFileSync as U,mkdirSync as ee}from"fs";import{join as F}from"path";import{tmpdir as oe}from"os";import{fal as x}from"@fal-ai/client";var te="fal-ai/mmaudio-v2",ie="fal-ai/elevenlabs/tts",re="fal-ai/google/gemini-2.5-flash-preview-tts";async function j(i){let t=await fetch(i);if(!t.ok)throw new Error(`Failed to download TTS audio (${t.status})`);return Buffer.from(await t.arrayBuffer())}async function O(i){console.log("[AudioGenerator] Generating voiceover...");let t=F(oe(),`tts-${Date.now()}`);ee(t,{recursive:!0});let e=F(t,"voiceover.mp3");try{let r=process.env.ELEVENLABS_VOICE_ID??"pNInz6obpgDQGcFmaJgB",a=await x.run(ie,{input:{text:i,voice_id:r,model_id:"eleven_v3"}});return U(e,await j(a.audio.url)),console.log("[AudioGenerator] TTS: ElevenLabs via fal"),e}catch(r){console.warn("[AudioGenerator] ElevenLabs via fal failed, trying Gemini:",r.message)}let o=process.env.GEMINI_TTS_VOICE??"Kore",n=await x.run(re,{input:{text:i,voice:o}});return U(e,await j(n.audio.url)),console.log("[AudioGenerator] TTS: Gemini via fal"),e}async function $(i,t,e){return console.log("[AudioGenerator] Adding background audio via MMAudio V2..."),(await x.run(te,{input:{video_url:i,prompt:t,negative_prompt:"speech, voice, talking, dialogue, narration, vocals, singing, human voice, conversation, words, lyrics, announcer, commentary",duration:e,cfg_strength:4.5}})).video.url}import{execSync as K}from"child_process";import{writeFileSync as ne,mkdirSync as ae}from"fs";import{join as u}from"path";import{fal as se}from"@fal-ai/client";async function I(i,t){let e=await fetch(i);if(!e.ok)throw new Error(`Download failed (${e.status}): ${i}`);ne(t,Buffer.from(await e.arrayBuffer()))}async function N(i,t,e){ae(e,{recursive:!0});let o=Date.now(),n=u(e,`clip1-${o}.mp4`),r=u(e,`clip2-${o}.mp4`),a=u(e,`combined-${o}.mp4`);return console.log("[VideoMixer] Downloading clips..."),await Promise.all([I(i,n),I(t,r)]),console.log("[VideoMixer] Concatenating..."),K(`ffmpeg -i "${n}" -i "${r}" -filter_complex "[0:v][1:v]concat=n=2:v=1:a=0[v]" -map "[v]" -y "${a}" -loglevel error`),a}async function b(i){let{readFileSync:t}=await import("fs"),e=new Blob([t(i)],{type:"video/mp4"}),o=await se.storage.upload(e);return console.log("[VideoMixer] Uploaded to fal:",o),o}async function R(i,t,e){let o=Date.now(),n=u(e,`voiceover-${o}.wav`),r=u(e,`final-${o}.mp4`);return console.log("[VideoMixer] Downloading voiceover..."),await I(t,n),console.log("[VideoMixer] Mixing voiceover over background audio..."),K(`ffmpeg -i "${i}" -i "${n}" -filter_complex "[0:a]volume=0.2[bg];[1:a]volume=1.0[vo];[bg][vo]amix=inputs=2:duration=first[a]" -map 0:v -map "[a]" -c:v copy -y "${r}" -loglevel error`),r}var q="bytedance/seedance-2.0/text-to-video",J="bytedance/seedance-2.0/image-to-video";function v(i,t,e,o){return{prompt:i,resolution:t.resolution??"720p",duration:t.clipDurationSeconds??8,aspect_ratio:t.aspectRatio??"16:9",generate_audio:!1,...e!==void 0?{seed:e}:{},...o!==void 0?{image_url:o}:{}}}async function w(i,t){let{request_id:e}=await p.queue.submit(i,{input:t});for(console.log(`[fal] submitted ${i} \u2192 ${e}`);;){await new Promise(r=>setTimeout(r,5e3));let o=await p.queue.status(i,{requestId:e,logs:!1});if(console.log(`[fal] ${e} \u2192 ${o.status}`),o.status==="FAILED")throw new Error(`Request ${e} failed`);if(o.status!=="COMPLETED")continue;return(await p.queue.result(i,{requestId:e})).data}}async function H(i,t){let e=Date.now(),o=l(t,`clip1-raw-${e}.mp4`),n=l(t,`last-frame-${e}.jpg`),r=await fetch(i);if(!r.ok)throw new Error(`Failed to download clip 1 (${r.status})`);_(o,Buffer.from(await r.arrayBuffer()));try{ce(`ffmpeg -sseof -0.1 -i "${o}" -vframes 1 -y "${n}" -loglevel error`)}finally{try{D(o)}catch{}}return n}var k=class{constructor(t){let e=t??process.env.FAL_KEY;if(!e)throw new Error("FAL_KEY is required");p.config({credentials:e})}async generateClipPair(t,e,o={}){let n=o.outputDir??l(W(),`paa-video-${Date.now()}`);Y(n,{recursive:!0}),console.log(`
|
|
26
|
+
[1/7] Generating prompts via QWEN 3.6...`);let r=await T(t,e);console.log(" Voiceover:",r.voiceover),console.log(" Audio mood:",r.audioMood),console.log(`
|
|
27
27
|
[2/7] Generating clip 1 (text-to-video)...`);let a=await w(q,v(r.clip1,o,o.seed));console.log(`
|
|
28
28
|
[3/7] Extracting last frame \u2192 clip 2 start...`);let c=await H(a.video.url,n),s=new Blob([G(c)],{type:"image/jpeg"}),h=await p.storage.upload(s);try{D(c)}catch{}console.log(`
|
|
29
29
|
[4/7] Generating clip 2 (image-to-video from last frame)...`);let d=o.seed!==void 0?o.seed+1:void 0,m=await w(J,v(r.clip2,o,d,h));console.log(`
|
|
30
30
|
[5/7] Concatenating clips + generating voiceover (parallel)...`);let[P,y]=await Promise.all([N(a.video.url,m.video.url,n),O(r.voiceover)]);console.log(`
|
|
31
31
|
[6/7] Adding background audio via MMAudio V2...`);let E=await b(P),S=(o.clipDurationSeconds??8)*2,g=await $(E,r.audioMood,S);console.log(`
|
|
32
|
-
[7/7] Overlaying voiceover on final video...`);let f=l(n,`with-bg-audio-${Date.now()}.mp4`),C=await fetch(g);_(f,Buffer.from(await C.arrayBuffer()));let Q=await R(f,y,n);return{clip1Url:a.video.url,clip2Url:m.video.url,finalVideoPath:Q,seed:a.seed,promptClip1:r.clip1,promptClip2:r.clip2,voiceover:r.voiceover,audioMood:r.audioMood}}async generateEpisode(
|
|
33
|
-
[Episode ${
|
|
32
|
+
[7/7] Overlaying voiceover on final video...`);let f=l(n,`with-bg-audio-${Date.now()}.mp4`),C=await fetch(g);_(f,Buffer.from(await C.arrayBuffer()));let Q=await R(f,y,n);return{clip1Url:a.video.url,clip2Url:m.video.url,finalVideoPath:Q,seed:a.seed,promptClip1:r.clip1,promptClip2:r.clip2,voiceover:r.voiceover,audioMood:r.audioMood}}async generateEpisode(t,e={}){let o=e.outputDir??l(W(),`episode-${t.episodeNumber}-${Date.now()}`);Y(o,{recursive:!0});let n=V(t);console.log(`
|
|
33
|
+
[Episode ${t.episodeNumber}/${t.episodeCount}] ${t.sectionTitle}`),console.log(" Voiceover:",n.voiceover),console.log(`
|
|
34
34
|
[2/7] Generating clip 1 (text-to-video)...`);let r=await w(q,v(n.clip1,e,e.seed));console.log(`
|
|
35
35
|
[3/7] Extracting last frame \u2192 clip 2 start...`);let a=await H(r.video.url,o),c=new Blob([G(a)],{type:"image/jpeg"}),s=await p.storage.upload(c);try{D(a)}catch{}console.log(`
|
|
36
36
|
[4/7] Generating clip 2 (image-to-video from last frame)...`);let h=e.seed!==void 0?e.seed+1:void 0,d=await w(J,v(n.clip2,e,h,s));console.log(`
|