@egdesk/next-api-plugin 1.5.15 → 1.5.20
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/dist/generate-helpers.js +637 -3
- package/dist/generate-proxy.js +68 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/generate-helpers.js
CHANGED
|
@@ -2449,14 +2449,69 @@ export type AiCallerCallResult = {
|
|
|
2449
2449
|
};
|
|
2450
2450
|
|
|
2451
2451
|
/**
|
|
2452
|
-
* Call Gemini and log token usage. Returns the AI response plus a usage summary.
|
|
2453
|
-
* Supports images, filePaths, and inline files (documents, text, video frames).
|
|
2452
|
+
* Call Gemini for TEXT generation and log token usage. Returns the AI response plus a usage summary.
|
|
2453
|
+
* Supports images, filePaths, and inline files (documents, text, video frames) as INPUT context.
|
|
2454
2454
|
* Omit \`maxOutputTokens\` to auto-use the selected model's maximum from the Gemini API.
|
|
2455
|
+
*
|
|
2456
|
+
* Do NOT pass an image-generation model (gemini-*-image, imagen-*) here — it cannot return image
|
|
2457
|
+
* bytes and will throw. Use \`generateAiCallerImage\` instead.
|
|
2455
2458
|
*/
|
|
2456
2459
|
export async function callAiCaller(prompt: string, options: AiCallerCallOptions = {}): Promise<AiCallerCallResult> {
|
|
2457
2460
|
return callAiCallerTool('ai_caller_call', { prompt, ...options });
|
|
2458
2461
|
}
|
|
2459
2462
|
|
|
2463
|
+
export type AiCallerGenerateImageOptions = {
|
|
2464
|
+
/** Image model id (e.g. gemini-3.1-flash-image, imagen-4.0-generate-001). Defaults to the preferred image model from AI Keys. */
|
|
2465
|
+
model?: string;
|
|
2466
|
+
/** Number of images to generate (default: 1) */
|
|
2467
|
+
count?: number;
|
|
2468
|
+
/** Optional reference images (base64, raw or data URLs) to ground generation */
|
|
2469
|
+
images?: string[];
|
|
2470
|
+
/** Aspect ratio (Imagen only; default 1:1) */
|
|
2471
|
+
aspectRatio?: '1:1' | '16:9' | '9:16' | '4:3' | '3:4';
|
|
2472
|
+
/** Output resolution (Imagen only; default 1K) */
|
|
2473
|
+
imageSize?: '1K' | '2K';
|
|
2474
|
+
/** Output MIME type (Imagen only; default image/png) */
|
|
2475
|
+
outputMimeType?: 'image/jpeg' | 'image/png';
|
|
2476
|
+
/** Optional absolute directory (on the EGDesk host) to also save generated images to disk */
|
|
2477
|
+
outputDir?: string;
|
|
2478
|
+
/** Gemini image model to fall back to if the primary (usually Imagen) model fails */
|
|
2479
|
+
fallbackModel?: string;
|
|
2480
|
+
caller?: string;
|
|
2481
|
+
/** Select a specific Google API key by name (as saved in EGDesk AI Keys Manager). Leave empty to use the default key. */
|
|
2482
|
+
keyName?: ${(options.apiKeyNames ?? []).length > 0
|
|
2483
|
+
? (options.apiKeyNames.map(n => `'${n}'`).join(' | ') + ' | (string & {})')
|
|
2484
|
+
: 'string'};
|
|
2485
|
+
};
|
|
2486
|
+
|
|
2487
|
+
export type AiCallerGeneratedImage = {
|
|
2488
|
+
fileName: string;
|
|
2489
|
+
mimeType: string;
|
|
2490
|
+
/** Base64-encoded image data */
|
|
2491
|
+
data: string;
|
|
2492
|
+
size: number;
|
|
2493
|
+
/** Local path on the EGDesk host, only set when outputDir was provided */
|
|
2494
|
+
filePath: string | null;
|
|
2495
|
+
};
|
|
2496
|
+
|
|
2497
|
+
export type AiCallerGenerateImageResult = {
|
|
2498
|
+
model: string;
|
|
2499
|
+
count: number;
|
|
2500
|
+
images: AiCallerGeneratedImage[];
|
|
2501
|
+
};
|
|
2502
|
+
|
|
2503
|
+
/**
|
|
2504
|
+
* Generate image(s) with Gemini image models or Imagen and log token usage.
|
|
2505
|
+
* Returns base64 image data (and a local filePath when \`outputDir\` is set).
|
|
2506
|
+
* Use this instead of \`callAiCaller\` for any image-generation model.
|
|
2507
|
+
*/
|
|
2508
|
+
export async function generateAiCallerImage(
|
|
2509
|
+
prompt: string,
|
|
2510
|
+
options: AiCallerGenerateImageOptions = {}
|
|
2511
|
+
): Promise<AiCallerGenerateImageResult> {
|
|
2512
|
+
return callAiCallerTool('ai_caller_generate_image', { prompt, ...options });
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2460
2515
|
export type AiCallerUsageOptions = {
|
|
2461
2516
|
caller?: string;
|
|
2462
2517
|
model?: string;
|
|
@@ -2490,11 +2545,15 @@ export type AiCallerModelsResult = {
|
|
|
2490
2545
|
models: string[];
|
|
2491
2546
|
defaultModel: string;
|
|
2492
2547
|
modelDetails?: AiCallerModelDetails[];
|
|
2548
|
+
/** Image-generation model ids — pass these to generateAiCallerImage, NOT callAiCaller */
|
|
2549
|
+
imageModels: string[];
|
|
2550
|
+
defaultImageModel: string;
|
|
2493
2551
|
};
|
|
2494
2552
|
|
|
2495
2553
|
/**
|
|
2496
2554
|
* List Gemini models available for text generation, fetched live from the Google API via EGDesk.
|
|
2497
|
-
* Includes per-model input/output token limits when available
|
|
2555
|
+
* Includes per-model input/output token limits when available, plus separate image-generation
|
|
2556
|
+
* model ids (for use with generateAiCallerImage).
|
|
2498
2557
|
*/
|
|
2499
2558
|
export async function listAiCallerModels(): Promise<AiCallerModelsResult> {
|
|
2500
2559
|
return callAiCallerTool('ai_caller_list_models', {});
|
|
@@ -3210,6 +3269,61 @@ export async function fetchInstagramPosts(options: {
|
|
|
3210
3269
|
return callInstagramTool('instagram_fetch_posts', options);
|
|
3211
3270
|
}
|
|
3212
3271
|
|
|
3272
|
+
export type GenerateInstagramContentOptions = {
|
|
3273
|
+
topic?: string;
|
|
3274
|
+
/** Alias for topic; used to resolve a BI catalog product */
|
|
3275
|
+
productName?: string;
|
|
3276
|
+
/** BI snapshot for brand identity + product grounding */
|
|
3277
|
+
biSnapshotId?: string;
|
|
3278
|
+
/** Override the auto-built content goal */
|
|
3279
|
+
contentGoal?: string;
|
|
3280
|
+
/** Guidance for the generated image */
|
|
3281
|
+
visualBrief?: string;
|
|
3282
|
+
/** Hashtags to bias the AI toward */
|
|
3283
|
+
preferredHashtags?: string[];
|
|
3284
|
+
/** Preferred call-to-action */
|
|
3285
|
+
cta?: string;
|
|
3286
|
+
language?: string;
|
|
3287
|
+
extraInstructions?: string;
|
|
3288
|
+
textModel?: string;
|
|
3289
|
+
imageModel?: string;
|
|
3290
|
+
/** Default true — set false to skip image generation and only return the caption */
|
|
3291
|
+
generateImage?: boolean;
|
|
3292
|
+
};
|
|
3293
|
+
|
|
3294
|
+
export type GeneratedInstagramContentResult = {
|
|
3295
|
+
success: boolean;
|
|
3296
|
+
topic: string;
|
|
3297
|
+
productName: string | null;
|
|
3298
|
+
biSnapshotId: string | null;
|
|
3299
|
+
content: {
|
|
3300
|
+
caption: string;
|
|
3301
|
+
hook: string;
|
|
3302
|
+
body: string;
|
|
3303
|
+
cta: string;
|
|
3304
|
+
hashtags: string[];
|
|
3305
|
+
altText?: string;
|
|
3306
|
+
imagePrompt?: string;
|
|
3307
|
+
notes?: string[];
|
|
3308
|
+
};
|
|
3309
|
+
textModel: string | null;
|
|
3310
|
+
image?: { filePath: string; fileName: string; mimeType: string; size: number };
|
|
3311
|
+
imageWarning?: string;
|
|
3312
|
+
imageError?: string;
|
|
3313
|
+
hint?: string;
|
|
3314
|
+
};
|
|
3315
|
+
|
|
3316
|
+
/**
|
|
3317
|
+
* Generate an Instagram caption + image WITHOUT logging in or publishing.
|
|
3318
|
+
* Pass topic, or biSnapshotId (+ optional productName) to ground on a Business Identity product.
|
|
3319
|
+
* Returns content.caption and image.filePath — pass both to createInstagramPost() to publish afterwards.
|
|
3320
|
+
*/
|
|
3321
|
+
export async function generateInstagramContent(
|
|
3322
|
+
options: GenerateInstagramContentOptions = {}
|
|
3323
|
+
): Promise<GeneratedInstagramContentResult> {
|
|
3324
|
+
return callInstagramTool('instagram_generate_content', options);
|
|
3325
|
+
}
|
|
3326
|
+
|
|
3213
3327
|
/**
|
|
3214
3328
|
* Publish an Instagram post via Playwright (login + create). Requires a local
|
|
3215
3329
|
* imagePath (absolute path on the EGDesk machine) and caption. Records publish history.
|
|
@@ -3259,6 +3373,526 @@ export async function listInstagramSchedules(connectionId?: string): Promise<{
|
|
|
3259
3373
|
}> {
|
|
3260
3374
|
return callInstagramTool('instagram_list_schedules', connectionId ? { connectionId } : {});
|
|
3261
3375
|
}
|
|
3376
|
+
|
|
3377
|
+
// ==========================================
|
|
3378
|
+
// BLOG (MCP) — WordPress / Naver
|
|
3379
|
+
// ==========================================
|
|
3380
|
+
//
|
|
3381
|
+
// Path A: schedule auto-generate + publish posts (blog_schedule_create + runNow / blog_schedule_run_now).
|
|
3382
|
+
// Path B: generate a draft, inspect it, then publish separately (generateBlogContent → publishBlogDraft).
|
|
3383
|
+
// Path C: publish title + HTML + images in one call (publishBlogContent).
|
|
3384
|
+
|
|
3385
|
+
/**
|
|
3386
|
+
* Call EGDesk Blog MCP tool.
|
|
3387
|
+
*
|
|
3388
|
+
* - Server: \`POST {apiUrl}/blog/tools/call\`
|
|
3389
|
+
* - Client: \`POST /__blog_proxy\` (see proxy.ts / middleware)
|
|
3390
|
+
*/
|
|
3391
|
+
export async function callBlogTool(
|
|
3392
|
+
toolName: string,
|
|
3393
|
+
args: Record<string, any> = {}
|
|
3394
|
+
): Promise<any> {
|
|
3395
|
+
const body = JSON.stringify({ tool: toolName, arguments: args });
|
|
3396
|
+
|
|
3397
|
+
const isServer = typeof window === 'undefined';
|
|
3398
|
+
|
|
3399
|
+
let response: Response;
|
|
3400
|
+
if (isServer) {
|
|
3401
|
+
const apiUrl =
|
|
3402
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
3403
|
+
EGDESK_CONFIG.apiUrl;
|
|
3404
|
+
response = await fetch(\`\${apiUrl}/blog/tools/call\`, {
|
|
3405
|
+
method: 'POST',
|
|
3406
|
+
headers: buildServerEgdeskHeaders(),
|
|
3407
|
+
body
|
|
3408
|
+
});
|
|
3409
|
+
} else {
|
|
3410
|
+
response = await apiFetch('/__blog_proxy', {
|
|
3411
|
+
method: 'POST',
|
|
3412
|
+
headers: { 'Content-Type': 'application/json' },
|
|
3413
|
+
body
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
|
|
3417
|
+
return parseEgdeskMcpToolResponse(response);
|
|
3418
|
+
}
|
|
3419
|
+
|
|
3420
|
+
export type BlogConnection = {
|
|
3421
|
+
id: string;
|
|
3422
|
+
name: string;
|
|
3423
|
+
type: 'wordpress' | 'naver';
|
|
3424
|
+
url?: string;
|
|
3425
|
+
};
|
|
3426
|
+
|
|
3427
|
+
/** List WordPress and Naver Blog connections available for scheduling/publishing. */
|
|
3428
|
+
export async function listBlogConnections(): Promise<{ connections: BlogConnection[] }> {
|
|
3429
|
+
return callBlogTool('blog_list_connections', {});
|
|
3430
|
+
}
|
|
3431
|
+
|
|
3432
|
+
/**
|
|
3433
|
+
* Add a new blog account connection (WordPress or Naver). Returns connectionId for
|
|
3434
|
+
* schedule/publish tools. Updates existing Naver by username or WordPress by url.
|
|
3435
|
+
*/
|
|
3436
|
+
export async function addBlogConnection(options: {
|
|
3437
|
+
type: 'naver' | 'wordpress';
|
|
3438
|
+
/** Defaults to username or site URL */
|
|
3439
|
+
name?: string;
|
|
3440
|
+
/** Naver ID or WordPress username */
|
|
3441
|
+
username: string;
|
|
3442
|
+
/** Naver password or WordPress application password */
|
|
3443
|
+
password: string;
|
|
3444
|
+
/** WordPress site URL (required when type=wordpress) */
|
|
3445
|
+
url?: string;
|
|
3446
|
+
/** Optional proxy URL for Naver automation */
|
|
3447
|
+
proxyUrl?: string;
|
|
3448
|
+
}) {
|
|
3449
|
+
return callBlogTool('blog_add_connection', options);
|
|
3450
|
+
}
|
|
3451
|
+
|
|
3452
|
+
export type CreateBlogScheduleOptions = {
|
|
3453
|
+
title: string;
|
|
3454
|
+
connectionId: string;
|
|
3455
|
+
/** manual topics or rotate BI products */
|
|
3456
|
+
topicSource?: 'manual' | 'bi_products';
|
|
3457
|
+
/** Required when topicSource is bi_products */
|
|
3458
|
+
biSnapshotId?: string;
|
|
3459
|
+
/** Manual topics or product names when using bi_products */
|
|
3460
|
+
topics?: string[];
|
|
3461
|
+
/** HH:MM (24h). Default 09:00 */
|
|
3462
|
+
scheduledTime?: string;
|
|
3463
|
+
frequencyType?: 'daily' | 'weekly' | 'monthly' | 'custom';
|
|
3464
|
+
frequencyValue?: number;
|
|
3465
|
+
/** 0=Sunday … 6=Saturday (weekly) */
|
|
3466
|
+
weeklyDay?: number;
|
|
3467
|
+
/** 1-31 (monthly) */
|
|
3468
|
+
monthlyDay?: number;
|
|
3469
|
+
aiKeyId?: string;
|
|
3470
|
+
textModel?: string;
|
|
3471
|
+
imageModel?: string;
|
|
3472
|
+
/** Default true */
|
|
3473
|
+
enabled?: boolean;
|
|
3474
|
+
/** If true, immediately generate + publish after creating the schedule. May take several minutes. */
|
|
3475
|
+
runNow?: boolean;
|
|
3476
|
+
};
|
|
3477
|
+
|
|
3478
|
+
/**
|
|
3479
|
+
* Create a recurring blog schedule. Use topicSource='bi_products' with biSnapshotId +
|
|
3480
|
+
* product name topics for auto-generation from the BI catalog.
|
|
3481
|
+
*/
|
|
3482
|
+
export async function createBlogSchedule(options: CreateBlogScheduleOptions) {
|
|
3483
|
+
return callBlogTool('blog_schedule_create', options);
|
|
3484
|
+
}
|
|
3485
|
+
|
|
3486
|
+
/** List scheduled blog posts (optional connectionId filter). */
|
|
3487
|
+
export async function listBlogSchedules(connectionId?: string) {
|
|
3488
|
+
return callBlogTool('blog_schedule_list', connectionId ? { connectionId } : {});
|
|
3489
|
+
}
|
|
3490
|
+
|
|
3491
|
+
/** Enable or disable a scheduled blog post. */
|
|
3492
|
+
export async function toggleBlogSchedule(scheduleId: string, enabled: boolean) {
|
|
3493
|
+
return callBlogTool('blog_schedule_toggle', { scheduleId, enabled });
|
|
3494
|
+
}
|
|
3495
|
+
|
|
3496
|
+
/** Immediately generate and publish for a schedule (full auto path). May take several minutes. */
|
|
3497
|
+
export async function runBlogScheduleNow(scheduleId: string) {
|
|
3498
|
+
return callBlogTool('blog_schedule_run_now', { scheduleId });
|
|
3499
|
+
}
|
|
3500
|
+
|
|
3501
|
+
export type BlogPublishHistoryEntry = {
|
|
3502
|
+
id: string;
|
|
3503
|
+
source: 'mcp' | 'schedule';
|
|
3504
|
+
status: 'success' | 'failure';
|
|
3505
|
+
connectionId?: string | null;
|
|
3506
|
+
connectionName?: string | null;
|
|
3507
|
+
connectionType?: string | null;
|
|
3508
|
+
scheduleId?: string | null;
|
|
3509
|
+
scheduleTitle?: string | null;
|
|
3510
|
+
draftId?: string | null;
|
|
3511
|
+
title?: string | null;
|
|
3512
|
+
postUrl?: string | null;
|
|
3513
|
+
/** Naver logNo / WordPress post id when known */
|
|
3514
|
+
postId?: string | null;
|
|
3515
|
+
errorMessage?: string | null;
|
|
3516
|
+
imageCount?: number;
|
|
3517
|
+
topics?: string[];
|
|
3518
|
+
startedAt: string;
|
|
3519
|
+
completedAt: string;
|
|
3520
|
+
durationMs?: number;
|
|
3521
|
+
};
|
|
3522
|
+
|
|
3523
|
+
/**
|
|
3524
|
+
* Fetch posted-blog history: scheduled executions + MCP one-off publishes (title, postUrl,
|
|
3525
|
+
* postId, status, connection, timestamps). Naver postId is the logNo for
|
|
3526
|
+
* blog.stat.naver.com/blog/download/article/{postId}.
|
|
3527
|
+
*/
|
|
3528
|
+
export async function listBlogHistory(options: {
|
|
3529
|
+
/** Filter to one schedule */
|
|
3530
|
+
scheduleId?: string;
|
|
3531
|
+
/** Filter by blog connection */
|
|
3532
|
+
connectionId?: string;
|
|
3533
|
+
status?: 'success' | 'failure';
|
|
3534
|
+
/** Max rows (default 100, max 500) */
|
|
3535
|
+
limit?: number;
|
|
3536
|
+
} = {}): Promise<{ total: number; history: BlogPublishHistoryEntry[] }> {
|
|
3537
|
+
return callBlogTool('blog_list_history', options);
|
|
3538
|
+
}
|
|
3539
|
+
|
|
3540
|
+
export type BlogDraftImage = {
|
|
3541
|
+
uuid?: string;
|
|
3542
|
+
description?: string;
|
|
3543
|
+
altText?: string;
|
|
3544
|
+
caption?: string;
|
|
3545
|
+
placement?: string;
|
|
3546
|
+
filePath?: string;
|
|
3547
|
+
url?: string;
|
|
3548
|
+
mimeType?: string;
|
|
3549
|
+
};
|
|
3550
|
+
|
|
3551
|
+
export type BlogDraftSummary = {
|
|
3552
|
+
draftId: string;
|
|
3553
|
+
topic: string;
|
|
3554
|
+
biSnapshotId: string | null;
|
|
3555
|
+
productName: string | null;
|
|
3556
|
+
title: string;
|
|
3557
|
+
excerpt: string | null;
|
|
3558
|
+
tags: string[] | string;
|
|
3559
|
+
imageCount: number;
|
|
3560
|
+
images: Array<{
|
|
3561
|
+
index: number;
|
|
3562
|
+
uuid: string | null;
|
|
3563
|
+
description: string | null;
|
|
3564
|
+
placement: string | null;
|
|
3565
|
+
filePath: string | null;
|
|
3566
|
+
url: string | null;
|
|
3567
|
+
}>;
|
|
3568
|
+
markerCount: number;
|
|
3569
|
+
wordCount: number;
|
|
3570
|
+
createdAt: string;
|
|
3571
|
+
updatedAt: string;
|
|
3572
|
+
};
|
|
3573
|
+
|
|
3574
|
+
/**
|
|
3575
|
+
* Generate blog content without publishing. Returns draftId, image filePaths, and preview.
|
|
3576
|
+
* Use productName + biSnapshotId to apply product tone/images. Pass draftId (or
|
|
3577
|
+
* title+content+images) to publishBlogDraft() / publishBlogContent().
|
|
3578
|
+
*/
|
|
3579
|
+
export async function generateBlogContent(options: {
|
|
3580
|
+
topic?: string;
|
|
3581
|
+
productName?: string;
|
|
3582
|
+
biSnapshotId?: string;
|
|
3583
|
+
textModel?: string;
|
|
3584
|
+
imageModel?: string;
|
|
3585
|
+
aiKeyId?: string;
|
|
3586
|
+
/** Affects image handling. Default naver (local files). */
|
|
3587
|
+
platform?: 'wordpress' | 'naver';
|
|
3588
|
+
/** Optional WordPress connection for image upload during generation */
|
|
3589
|
+
connectionId?: string;
|
|
3590
|
+
/** If true, include full HTML body in the response */
|
|
3591
|
+
includeContent?: boolean;
|
|
3592
|
+
} = {}): Promise<
|
|
3593
|
+
BlogDraftSummary & { success: true; hint: string; content?: string; markers?: unknown[] }
|
|
3594
|
+
> {
|
|
3595
|
+
return callBlogTool('blog_generate_content', options);
|
|
3596
|
+
}
|
|
3597
|
+
|
|
3598
|
+
/** Fetch a generated draft. includeContent=true returns full HTML + images metadata. */
|
|
3599
|
+
export async function getBlogDraft(
|
|
3600
|
+
draftId: string,
|
|
3601
|
+
includeContent?: boolean
|
|
3602
|
+
): Promise<{ summary: BlogDraftSummary; draft?: unknown }> {
|
|
3603
|
+
return callBlogTool('blog_get_draft', { draftId, includeContent });
|
|
3604
|
+
}
|
|
3605
|
+
|
|
3606
|
+
/**
|
|
3607
|
+
* Publish to WordPress or Naver in one call. Prefer draftId, OR pass title + content HTML
|
|
3608
|
+
* (with [IMAGE:description:placement] markers) + images[] together. images items accept
|
|
3609
|
+
* filePath, dataBase64/data URL, or url — order must match markers.
|
|
3610
|
+
*/
|
|
3611
|
+
export async function publishBlog(options: {
|
|
3612
|
+
connectionId: string;
|
|
3613
|
+
/** Publish a previously generated draft (images come from the draft unless overridden) */
|
|
3614
|
+
draftId?: string;
|
|
3615
|
+
/** Inline title when not using draftId */
|
|
3616
|
+
title?: string;
|
|
3617
|
+
/** HTML body with [IMAGE:description:placement] markers at insert positions */
|
|
3618
|
+
content?: string;
|
|
3619
|
+
/** Images in marker order */
|
|
3620
|
+
images?: BlogDraftImage[];
|
|
3621
|
+
tags?: string | string[];
|
|
3622
|
+
excerpt?: string;
|
|
3623
|
+
}): Promise<{
|
|
3624
|
+
success: boolean;
|
|
3625
|
+
postUrl: string;
|
|
3626
|
+
postId: string | null;
|
|
3627
|
+
connectionType: string;
|
|
3628
|
+
draftId?: string;
|
|
3629
|
+
}> {
|
|
3630
|
+
return callBlogTool('blog_publish', options);
|
|
3631
|
+
}
|
|
3632
|
+
|
|
3633
|
+
/**
|
|
3634
|
+
* Sync fresh Naver article stats for one or many posts from blog.stat.naver.com (Excel
|
|
3635
|
+
* CV/LIKE/COMMENT/REFERER/DEMO + live 누적 조회수/공감/댓글). Pass postIds for multiple logNos,
|
|
3636
|
+
* or fromHistory=true to sync recent published posts.
|
|
3637
|
+
*/
|
|
3638
|
+
export async function getBlogArticleStats(options: {
|
|
3639
|
+
/** Naver blog connection id */
|
|
3640
|
+
connectionId: string;
|
|
3641
|
+
/** Single Naver logNo / article id (optional if postIds or fromHistory) */
|
|
3642
|
+
postId?: string;
|
|
3643
|
+
/** Multiple Naver logNo / article ids to sync in one call (preferred for batch) */
|
|
3644
|
+
postIds?: string[];
|
|
3645
|
+
/** If true (and no postId/postIds), sync recent successful publish-history posts that have postId */
|
|
3646
|
+
fromHistory?: boolean;
|
|
3647
|
+
metric?: 'CV' | 'LIKE' | 'COMMENT' | 'REFERER' | 'DEMO';
|
|
3648
|
+
/** YYYY-MM-DD filter for returned series */
|
|
3649
|
+
dateFrom?: string;
|
|
3650
|
+
/** YYYY-MM-DD filter for returned series */
|
|
3651
|
+
dateTo?: string;
|
|
3652
|
+
/** Max posts when fromHistory=true (default 20, max 100) */
|
|
3653
|
+
limit?: number;
|
|
3654
|
+
/** Include download snapshot metadata (default true) */
|
|
3655
|
+
includeSnapshots?: boolean;
|
|
3656
|
+
}) {
|
|
3657
|
+
return callBlogTool('blog_article_stats', options);
|
|
3658
|
+
}
|
|
3659
|
+
|
|
3660
|
+
// ==========================================
|
|
3661
|
+
// YOUTUBE SHORTS (MCP)
|
|
3662
|
+
// ==========================================
|
|
3663
|
+
//
|
|
3664
|
+
// Login model: connections use a shared Chrome profile (chromeUserDataDir +
|
|
3665
|
+
// chromeExecutablePath, recommended to avoid CAPTCHA) or username+password.
|
|
3666
|
+
// Generation and upload drive real YouTube via Playwright, so schedule_run_now /
|
|
3667
|
+
// generateVideo=true / debug_post are slower (seconds to several minutes).
|
|
3668
|
+
|
|
3669
|
+
/**
|
|
3670
|
+
* Call EGDesk YouTube Shorts MCP tool.
|
|
3671
|
+
*
|
|
3672
|
+
* - Server: \`POST {apiUrl}/youtube/tools/call\`
|
|
3673
|
+
* - Client: \`POST /__youtube_proxy\` (see proxy.ts / middleware)
|
|
3674
|
+
*/
|
|
3675
|
+
export async function callYouTubeTool(
|
|
3676
|
+
toolName: string,
|
|
3677
|
+
args: Record<string, any> = {}
|
|
3678
|
+
): Promise<any> {
|
|
3679
|
+
const body = JSON.stringify({ tool: toolName, arguments: args });
|
|
3680
|
+
|
|
3681
|
+
const isServer = typeof window === 'undefined';
|
|
3682
|
+
|
|
3683
|
+
let response: Response;
|
|
3684
|
+
if (isServer) {
|
|
3685
|
+
const apiUrl =
|
|
3686
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
3687
|
+
EGDESK_CONFIG.apiUrl;
|
|
3688
|
+
response = await fetch(\`\${apiUrl}/youtube/tools/call\`, {
|
|
3689
|
+
method: 'POST',
|
|
3690
|
+
headers: buildServerEgdeskHeaders(),
|
|
3691
|
+
body
|
|
3692
|
+
});
|
|
3693
|
+
} else {
|
|
3694
|
+
response = await apiFetch('/__youtube_proxy', {
|
|
3695
|
+
method: 'POST',
|
|
3696
|
+
headers: { 'Content-Type': 'application/json' },
|
|
3697
|
+
body
|
|
3698
|
+
});
|
|
3699
|
+
}
|
|
3700
|
+
|
|
3701
|
+
return parseEgdeskMcpToolResponse(response);
|
|
3702
|
+
}
|
|
3703
|
+
|
|
3704
|
+
export type YouTubeConnection = {
|
|
3705
|
+
id: string;
|
|
3706
|
+
name: string;
|
|
3707
|
+
username: string | null;
|
|
3708
|
+
hasPassword: boolean;
|
|
3709
|
+
googleProfileName: string | null;
|
|
3710
|
+
chromeUserDataDir: string | null;
|
|
3711
|
+
chromeExecutablePath: string | null;
|
|
3712
|
+
channelId: string | null;
|
|
3713
|
+
hasAccessToken: boolean;
|
|
3714
|
+
createdAt: string;
|
|
3715
|
+
updatedAt: string;
|
|
3716
|
+
};
|
|
3717
|
+
|
|
3718
|
+
/** List YouTube connections saved in EGDesk (id, name, chrome profile path). Passwords are never returned. */
|
|
3719
|
+
export async function listYouTubeConnections(): Promise<{
|
|
3720
|
+
success: boolean;
|
|
3721
|
+
connections: YouTubeConnection[];
|
|
3722
|
+
}> {
|
|
3723
|
+
return callYouTubeTool('youtube_list_connections', {});
|
|
3724
|
+
}
|
|
3725
|
+
|
|
3726
|
+
/**
|
|
3727
|
+
* Save or update a YouTube connection. Prefer chromeUserDataDir + chromeExecutablePath
|
|
3728
|
+
* to avoid CAPTCHA; username+password also accepted.
|
|
3729
|
+
*/
|
|
3730
|
+
export async function saveYouTubeConnection(options: {
|
|
3731
|
+
name: string;
|
|
3732
|
+
/** Google / YouTube login */
|
|
3733
|
+
username?: string;
|
|
3734
|
+
password?: string;
|
|
3735
|
+
chromeUserDataDir?: string;
|
|
3736
|
+
chromeExecutablePath?: string;
|
|
3737
|
+
channelId?: string;
|
|
3738
|
+
/** Optional existing connection id */
|
|
3739
|
+
id?: string;
|
|
3740
|
+
}) {
|
|
3741
|
+
return callYouTubeTool('youtube_save_connection', options);
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3744
|
+
/** Update fields on a YouTube connection. */
|
|
3745
|
+
export async function updateYouTubeConnection(options: {
|
|
3746
|
+
connectionId: string;
|
|
3747
|
+
name?: string;
|
|
3748
|
+
username?: string;
|
|
3749
|
+
password?: string;
|
|
3750
|
+
chromeUserDataDir?: string;
|
|
3751
|
+
chromeExecutablePath?: string;
|
|
3752
|
+
channelId?: string;
|
|
3753
|
+
}) {
|
|
3754
|
+
return callYouTubeTool('youtube_update_connection', options);
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
/** Delete a YouTube connection by id. */
|
|
3758
|
+
export async function deleteYouTubeConnection(connectionId: string) {
|
|
3759
|
+
return callYouTubeTool('youtube_delete_connection', { connectionId });
|
|
3760
|
+
}
|
|
3761
|
+
|
|
3762
|
+
export type CreateYouTubeScheduleOptions = {
|
|
3763
|
+
title: string;
|
|
3764
|
+
connectionId: string;
|
|
3765
|
+
/** manual topics or rotate BI products */
|
|
3766
|
+
topicSource?: 'manual' | 'bi_products';
|
|
3767
|
+
/** BI snapshot for product grounding + brand face / spokesperson */
|
|
3768
|
+
biSnapshotId?: string;
|
|
3769
|
+
/** Manual topics or product names when using bi_products */
|
|
3770
|
+
topics?: string[];
|
|
3771
|
+
/** HH:MM (24h). Default 09:00 */
|
|
3772
|
+
scheduledTime?: string;
|
|
3773
|
+
frequencyType?: 'daily' | 'weekly' | 'monthly' | 'custom';
|
|
3774
|
+
frequencyValue?: number;
|
|
3775
|
+
/** 0=Sunday … 6=Saturday (weekly) */
|
|
3776
|
+
weeklyDay?: number;
|
|
3777
|
+
/** 1-31 (monthly) */
|
|
3778
|
+
monthlyDay?: number;
|
|
3779
|
+
aiKeyId?: string;
|
|
3780
|
+
/** Shorts script model (default gemini-3.5-flash) */
|
|
3781
|
+
textModel?: string;
|
|
3782
|
+
/** Veo video model (default veo-3.1-generate-preview) */
|
|
3783
|
+
videoModel?: string;
|
|
3784
|
+
/** Default true */
|
|
3785
|
+
enabled?: boolean;
|
|
3786
|
+
/** If true, immediately generate + upload Shorts after creating the schedule. May take several minutes. */
|
|
3787
|
+
runNow?: boolean;
|
|
3788
|
+
};
|
|
3789
|
+
|
|
3790
|
+
/**
|
|
3791
|
+
* Create a recurring YouTube Shorts schedule. Use topicSource='bi_products' with
|
|
3792
|
+
* biSnapshotId (+ product name topics) for product-grounded Shorts with brand face.
|
|
3793
|
+
*/
|
|
3794
|
+
export async function createYouTubeSchedule(options: CreateYouTubeScheduleOptions) {
|
|
3795
|
+
return callYouTubeTool('youtube_schedule_create', options);
|
|
3796
|
+
}
|
|
3797
|
+
|
|
3798
|
+
/** List YouTube Shorts scheduled posts (optional connectionId filter). */
|
|
3799
|
+
export async function listYouTubeSchedules(connectionId?: string) {
|
|
3800
|
+
return callYouTubeTool('youtube_list_schedules', connectionId ? { connectionId } : {});
|
|
3801
|
+
}
|
|
3802
|
+
|
|
3803
|
+
/** Enable or disable a YouTube Shorts schedule. */
|
|
3804
|
+
export async function toggleYouTubeSchedule(scheduleId: string, enabled: boolean) {
|
|
3805
|
+
return callYouTubeTool('youtube_schedule_toggle', { scheduleId, enabled });
|
|
3806
|
+
}
|
|
3807
|
+
|
|
3808
|
+
/**
|
|
3809
|
+
* Immediately generate script + Veo Shorts + upload for a schedule (full auto path).
|
|
3810
|
+
* Uses preferred brand face when biSnapshotId is set. May take several minutes.
|
|
3811
|
+
*/
|
|
3812
|
+
export async function runYouTubeScheduleNow(scheduleId: string) {
|
|
3813
|
+
return callYouTubeTool('youtube_schedule_run_now', { scheduleId });
|
|
3814
|
+
}
|
|
3815
|
+
|
|
3816
|
+
export type GenerateYouTubeContentOptions = {
|
|
3817
|
+
/** Topic or product name for the Short */
|
|
3818
|
+
topic?: string;
|
|
3819
|
+
/** Alias for topic; used to resolve BI catalog product */
|
|
3820
|
+
productName?: string;
|
|
3821
|
+
/** BI snapshot for product tone + brand face */
|
|
3822
|
+
biSnapshotId?: string;
|
|
3823
|
+
textModel?: string;
|
|
3824
|
+
videoModel?: string;
|
|
3825
|
+
/** Caption language (default ko) */
|
|
3826
|
+
language?: string;
|
|
3827
|
+
extraInstructions?: string;
|
|
3828
|
+
/** If true, run Veo clip → overlay → outro and return local finalPath */
|
|
3829
|
+
generateVideo?: boolean;
|
|
3830
|
+
/** Skip brand outro stitch when generateVideo=true */
|
|
3831
|
+
skipOutro?: boolean;
|
|
3832
|
+
};
|
|
3833
|
+
|
|
3834
|
+
export type GeneratedYouTubeContentResult = {
|
|
3835
|
+
success: boolean;
|
|
3836
|
+
topic: string;
|
|
3837
|
+
productName: string;
|
|
3838
|
+
biSnapshotId: string | null;
|
|
3839
|
+
spokesperson: { name: string; role?: string } | null;
|
|
3840
|
+
content: {
|
|
3841
|
+
title: string;
|
|
3842
|
+
description: string;
|
|
3843
|
+
tags: string[];
|
|
3844
|
+
script: unknown;
|
|
3845
|
+
veoScenes: unknown;
|
|
3846
|
+
veoPrompt?: string;
|
|
3847
|
+
thumbnailPrompt?: string;
|
|
3848
|
+
notes?: string[];
|
|
3849
|
+
};
|
|
3850
|
+
textModel: string;
|
|
3851
|
+
videoModel: string;
|
|
3852
|
+
video?: {
|
|
3853
|
+
finalPath: string;
|
|
3854
|
+
composedPath: string;
|
|
3855
|
+
rawClipPath: string;
|
|
3856
|
+
sceneClipPaths: string[];
|
|
3857
|
+
durationSec: number;
|
|
3858
|
+
outroVariantId?: string;
|
|
3859
|
+
};
|
|
3860
|
+
hint: string;
|
|
3861
|
+
};
|
|
3862
|
+
|
|
3863
|
+
/**
|
|
3864
|
+
* Generate YouTube Shorts content (title/description/script/veoScenes) WITHOUT uploading.
|
|
3865
|
+
* Pass biSnapshotId to ground on a BI product + preferred brand face. Set generateVideo=true
|
|
3866
|
+
* to also render a local mp4 via the Shorts pipeline (pass the returned video.finalPath to
|
|
3867
|
+
* debugYouTubePost() to upload).
|
|
3868
|
+
*/
|
|
3869
|
+
export async function generateYouTubeContent(
|
|
3870
|
+
options: GenerateYouTubeContentOptions = {}
|
|
3871
|
+
): Promise<GeneratedYouTubeContentResult> {
|
|
3872
|
+
return callYouTubeTool('youtube_generate_content', options);
|
|
3873
|
+
}
|
|
3874
|
+
|
|
3875
|
+
/** Debug upload: login + upload a local Shorts mp4 (no Gemini). Defaults to ~/Downloads/shorts-test.mp4. */
|
|
3876
|
+
export async function debugYouTubePost(options: {
|
|
3877
|
+
connectionId: string;
|
|
3878
|
+
/** Absolute local file path to an mp4 already saved on this machine */
|
|
3879
|
+
videoPath?: string;
|
|
3880
|
+
title?: string;
|
|
3881
|
+
description?: string;
|
|
3882
|
+
}) {
|
|
3883
|
+
return callYouTubeTool('youtube_debug_post', options);
|
|
3884
|
+
}
|
|
3885
|
+
|
|
3886
|
+
/** List YouTube Shorts publish/execution history (scheduled runs) with post URLs when available. */
|
|
3887
|
+
export async function listYouTubeHistory(options: {
|
|
3888
|
+
scheduleId?: string;
|
|
3889
|
+
connectionId?: string;
|
|
3890
|
+
status?: 'success' | 'failure';
|
|
3891
|
+
/** Max rows (default 100, max 500) */
|
|
3892
|
+
limit?: number;
|
|
3893
|
+
} = {}) {
|
|
3894
|
+
return callYouTubeTool('youtube_list_history', options);
|
|
3895
|
+
}
|
|
3262
3896
|
`;
|
|
3263
3897
|
fs.writeFileSync(helperPath, helperContent.replace(/\r?\n/g, os.EOL), 'utf-8');
|
|
3264
3898
|
console.log(`✅ Generated ${helperPath}`);
|
package/dist/generate-proxy.js
CHANGED
|
@@ -75,7 +75,7 @@ import type { NextRequest } from 'next/server';
|
|
|
75
75
|
/**
|
|
76
76
|
* EGDesk Database Proxy (Next.js 16+)
|
|
77
77
|
*
|
|
78
|
-
* Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, __company_research_proxy, __ai_center_proxy, __korean_law_proxy, __seo_proxy, __ssl_proxy, __local_agent_proxy, __pageindex_proxy, __drive_proxy, __knowledge_wiki_proxy, __egdesk_config_proxy, __ai_caller_proxy, __kakao_proxy, __phone_proxy, and
|
|
78
|
+
* Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, __company_research_proxy, __ai_center_proxy, __korean_law_proxy, __seo_proxy, __ssl_proxy, __local_agent_proxy, __pageindex_proxy, __drive_proxy, __knowledge_wiki_proxy, __egdesk_config_proxy, __ai_caller_proxy, __kakao_proxy, __phone_proxy, __instagram_proxy, __financehub_proxy, __blog_proxy, and __youtube_proxy requests
|
|
79
79
|
* and forwards them to the EGDesk MCP HTTP server. This avoids CORS in local and tunneled environments.
|
|
80
80
|
*
|
|
81
81
|
* Generated by @egdesk/next-api-plugin
|
|
@@ -472,6 +472,72 @@ export async function proxy(request: NextRequest) {
|
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
+
if (pathname.includes('__financehub_proxy')) {
|
|
476
|
+
try {
|
|
477
|
+
const body = await request.text();
|
|
478
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
479
|
+
|
|
480
|
+
const response = await fetch(\`\${apiUrl}/financehub/tools/call\`, {
|
|
481
|
+
method: 'POST',
|
|
482
|
+
headers: buildEgdeskHeaders(),
|
|
483
|
+
body,
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
const result = await response.json();
|
|
487
|
+
|
|
488
|
+
return NextResponse.json(result, { status: response.status });
|
|
489
|
+
} catch (error: any) {
|
|
490
|
+
return NextResponse.json(
|
|
491
|
+
{ error: 'Proxy error', message: error.message },
|
|
492
|
+
{ status: 500 }
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (pathname.includes('__blog_proxy')) {
|
|
498
|
+
try {
|
|
499
|
+
const body = await request.text();
|
|
500
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
501
|
+
|
|
502
|
+
const response = await fetch(\`\${apiUrl}/blog/tools/call\`, {
|
|
503
|
+
method: 'POST',
|
|
504
|
+
headers: buildEgdeskHeaders(),
|
|
505
|
+
body,
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
const result = await response.json();
|
|
509
|
+
|
|
510
|
+
return NextResponse.json(result, { status: response.status });
|
|
511
|
+
} catch (error: any) {
|
|
512
|
+
return NextResponse.json(
|
|
513
|
+
{ error: 'Proxy error', message: error.message },
|
|
514
|
+
{ status: 500 }
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if (pathname.includes('__youtube_proxy')) {
|
|
520
|
+
try {
|
|
521
|
+
const body = await request.text();
|
|
522
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
523
|
+
|
|
524
|
+
const response = await fetch(\`\${apiUrl}/youtube/tools/call\`, {
|
|
525
|
+
method: 'POST',
|
|
526
|
+
headers: buildEgdeskHeaders(),
|
|
527
|
+
body,
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
const result = await response.json();
|
|
531
|
+
|
|
532
|
+
return NextResponse.json(result, { status: response.status });
|
|
533
|
+
} catch (error: any) {
|
|
534
|
+
return NextResponse.json(
|
|
535
|
+
{ error: 'Proxy error', message: error.message },
|
|
536
|
+
{ status: 500 }
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
475
541
|
// Continue to next proxy or route
|
|
476
542
|
return NextResponse.next();
|
|
477
543
|
}
|
|
@@ -480,7 +546,7 @@ export const config = {
|
|
|
480
546
|
matcher: [
|
|
481
547
|
/*
|
|
482
548
|
* Match all paths except static assets
|
|
483
|
-
* The proxy function filters for __user_data_proxy / __browser_recording_proxy / __internal_knowledge_proxy / __company_research_proxy / __ai_center_proxy / __korean_law_proxy / __seo_proxy / __ssl_proxy / __local_agent_proxy / __pageindex_proxy / __drive_proxy / __knowledge_wiki_proxy / __egdesk_config_proxy / __ai_caller_proxy / __kakao_proxy / __phone_proxy / __instagram_proxy
|
|
549
|
+
* The proxy function filters for __user_data_proxy / __browser_recording_proxy / __internal_knowledge_proxy / __company_research_proxy / __ai_center_proxy / __korean_law_proxy / __seo_proxy / __ssl_proxy / __local_agent_proxy / __pageindex_proxy / __drive_proxy / __knowledge_wiki_proxy / __egdesk_config_proxy / __ai_caller_proxy / __kakao_proxy / __phone_proxy / __instagram_proxy / __financehub_proxy / __blog_proxy / __youtube_proxy
|
|
484
550
|
*/
|
|
485
551
|
'/:path*',
|
|
486
552
|
],
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* The minimum EGDesk app version this plugin version is compatible with.
|
|
9
9
|
* The app checks this at setup time and warns on mismatch.
|
|
10
10
|
*/
|
|
11
|
-
export declare const COMPATIBLE_APP_VERSION = "1.4.
|
|
11
|
+
export declare const COMPATIBLE_APP_VERSION = "1.4.33";
|
|
12
12
|
export interface SetupOptions {
|
|
13
13
|
egdeskUrl?: string;
|
|
14
14
|
/** Production EGDesk server URL — written to .env.production.local. Falls back to egdeskUrl. */
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ exports.setupNextApiPlugin = setupNextApiPlugin;
|
|
|
46
46
|
* The minimum EGDesk app version this plugin version is compatible with.
|
|
47
47
|
* The app checks this at setup time and warns on mismatch.
|
|
48
48
|
*/
|
|
49
|
-
exports.COMPATIBLE_APP_VERSION = '1.4.
|
|
49
|
+
exports.COMPATIBLE_APP_VERSION = '1.4.33';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|