@egdesk/next-api-plugin 1.5.14 → 1.5.19

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.
@@ -2936,10 +2936,22 @@ export async function listPhoneDevices() {
2936
2936
  return callPhoneTool('phone_list_devices', {});
2937
2937
  }
2938
2938
 
2939
- export async function createPhoneDevice(options: { label: string; id?: string }) {
2939
+ export async function createPhoneDevice(options: {
2940
+ label: string;
2941
+ id?: string;
2942
+ googleProfileName?: string;
2943
+ }) {
2940
2944
  return callPhoneTool('phone_create_device', options);
2941
2945
  }
2942
2946
 
2947
+ export async function updatePhoneDevice(options: {
2948
+ deviceId: string;
2949
+ label?: string;
2950
+ googleProfileName?: string | null;
2951
+ }) {
2952
+ return callPhoneTool('phone_update_device', options);
2953
+ }
2954
+
2943
2955
  export async function deletePhoneDevice(deviceId: string) {
2944
2956
  return callPhoneTool('phone_delete_device', { deviceId });
2945
2957
  }
@@ -3044,6 +3056,784 @@ export async function createPhoneConsentLink(options: {
3044
3056
  export async function syncPhoneConsentEvents(snapshotId: string) {
3045
3057
  return callPhoneTool('phone_consent_events_sync', { snapshotId });
3046
3058
  }
3059
+
3060
+ // ==========================================
3061
+ // INSTAGRAM (MCP)
3062
+ // ==========================================
3063
+ //
3064
+ // Login model: each connection stores a login id (email/username) + password
3065
+ // (or a shared googleProfileName), plus an optional public @handle used for
3066
+ // profile URLs. Posting and stats sync drive real Instagram via Playwright,
3067
+ // so they are slower (~seconds to ~1-2 min) than plain data reads.
3068
+
3069
+ /**
3070
+ * Call EGDesk Instagram MCP tool.
3071
+ *
3072
+ * - Server: \`POST {apiUrl}/instagram/tools/call\`
3073
+ * - Client: \`POST /__instagram_proxy\` (see proxy.ts / middleware)
3074
+ */
3075
+ export async function callInstagramTool(
3076
+ toolName: string,
3077
+ args: Record<string, any> = {}
3078
+ ): Promise<any> {
3079
+ const body = JSON.stringify({ tool: toolName, arguments: args });
3080
+
3081
+ const isServer = typeof window === 'undefined';
3082
+
3083
+ let response: Response;
3084
+ if (isServer) {
3085
+ const apiUrl =
3086
+ (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
3087
+ EGDESK_CONFIG.apiUrl;
3088
+ response = await fetch(\`\${apiUrl}/instagram/tools/call\`, {
3089
+ method: 'POST',
3090
+ headers: buildServerEgdeskHeaders(),
3091
+ body
3092
+ });
3093
+ } else {
3094
+ response = await apiFetch('/__instagram_proxy', {
3095
+ method: 'POST',
3096
+ headers: { 'Content-Type': 'application/json' },
3097
+ body
3098
+ });
3099
+ }
3100
+
3101
+ return parseEgdeskMcpToolResponse(response);
3102
+ }
3103
+
3104
+ export type InstagramConnection = {
3105
+ id: string;
3106
+ name: string;
3107
+ username: string;
3108
+ /** Public @handle (no leading @) used for profile URLs, or null. */
3109
+ handle: string | null;
3110
+ hasPassword: boolean;
3111
+ hasAccessToken: boolean;
3112
+ createdAt: string;
3113
+ updatedAt: string;
3114
+ };
3115
+
3116
+ /** List Instagram connections saved in EGDesk. Passwords are never returned. */
3117
+ export async function listInstagramConnections(): Promise<{
3118
+ success: boolean;
3119
+ connections: InstagramConnection[];
3120
+ }> {
3121
+ return callInstagramTool('instagram_list_connections', {});
3122
+ }
3123
+
3124
+ /** Save a new Instagram connection, or update an existing one by (username or id). */
3125
+ export async function saveInstagramConnection(options: {
3126
+ name: string;
3127
+ /** Login id (email, phone, or username) */
3128
+ username: string;
3129
+ password: string;
3130
+ /** Public Instagram @handle (not email) */
3131
+ handle?: string;
3132
+ /** Optional existing connection id */
3133
+ id?: string;
3134
+ }) {
3135
+ return callInstagramTool('instagram_save_connection', options);
3136
+ }
3137
+
3138
+ /** Update fields on an Instagram connection (name, login, password, handle). */
3139
+ export async function updateInstagramConnection(options: {
3140
+ connectionId: string;
3141
+ name?: string;
3142
+ username?: string;
3143
+ password?: string;
3144
+ handle?: string;
3145
+ }) {
3146
+ return callInstagramTool('instagram_update_connection', options);
3147
+ }
3148
+
3149
+ /** Delete an Instagram connection by id. */
3150
+ export async function deleteInstagramConnection(connectionId: string) {
3151
+ return callInstagramTool('instagram_delete_connection', { connectionId });
3152
+ }
3153
+
3154
+ export type InstagramPublishHistorySource = 'schedule' | 'debug' | 'manual';
3155
+
3156
+ export type InstagramPublishHistoryEntry = {
3157
+ id: string;
3158
+ source: InstagramPublishHistorySource;
3159
+ status: 'success' | 'failure';
3160
+ connectionId?: string | null;
3161
+ connectionName?: string | null;
3162
+ username?: string | null;
3163
+ scheduleId?: string | null;
3164
+ scheduleTitle?: string | null;
3165
+ title?: string | null;
3166
+ caption?: string | null;
3167
+ imagePath?: string | null;
3168
+ postUrl?: string | null;
3169
+ shortcode?: string | null;
3170
+ likes?: number | null;
3171
+ comments?: number | null;
3172
+ views?: number | null;
3173
+ statsScrapedAt?: string | null;
3174
+ errorMessage?: string | null;
3175
+ startedAt: string;
3176
+ completedAt: string;
3177
+ durationMs?: number;
3178
+ };
3179
+
3180
+ /** List Instagram publish history (scheduled runs + debug/manual posts) with likes/comments when synced. */
3181
+ export async function listInstagramHistory(options: {
3182
+ connectionId?: string;
3183
+ /** 'success' | 'failure' */
3184
+ status?: string;
3185
+ /** Max rows (default 100, max 500) */
3186
+ limit?: number;
3187
+ } = {}): Promise<{ success: boolean; total: number; history: InstagramPublishHistoryEntry[] }> {
3188
+ return callInstagramTool('instagram_list_history', options);
3189
+ }
3190
+
3191
+ /**
3192
+ * Login (headed, background window) and scrape recent posts for likes/comments;
3193
+ * merge into publish history. Slow (~1-2 min).
3194
+ */
3195
+ export async function syncInstagramPostStats(options: {
3196
+ connectionId: string;
3197
+ /** Max posts to open (default 12, max 24) */
3198
+ limit?: number;
3199
+ /** Parallel tabs (default 8, max 8) */
3200
+ concurrency?: number;
3201
+ }) {
3202
+ return callInstagramTool('instagram_sync_post_stats', options);
3203
+ }
3204
+
3205
+ /** Alias of syncInstagramPostStats — scrape recent posts with engagement. */
3206
+ export async function fetchInstagramPosts(options: {
3207
+ connectionId: string;
3208
+ limit?: number;
3209
+ }) {
3210
+ return callInstagramTool('instagram_fetch_posts', options);
3211
+ }
3212
+
3213
+ export type GenerateInstagramContentOptions = {
3214
+ topic?: string;
3215
+ /** Alias for topic; used to resolve a BI catalog product */
3216
+ productName?: string;
3217
+ /** BI snapshot for brand identity + product grounding */
3218
+ biSnapshotId?: string;
3219
+ /** Override the auto-built content goal */
3220
+ contentGoal?: string;
3221
+ /** Guidance for the generated image */
3222
+ visualBrief?: string;
3223
+ /** Hashtags to bias the AI toward */
3224
+ preferredHashtags?: string[];
3225
+ /** Preferred call-to-action */
3226
+ cta?: string;
3227
+ language?: string;
3228
+ extraInstructions?: string;
3229
+ textModel?: string;
3230
+ imageModel?: string;
3231
+ /** Default true — set false to skip image generation and only return the caption */
3232
+ generateImage?: boolean;
3233
+ };
3234
+
3235
+ export type GeneratedInstagramContentResult = {
3236
+ success: boolean;
3237
+ topic: string;
3238
+ productName: string | null;
3239
+ biSnapshotId: string | null;
3240
+ content: {
3241
+ caption: string;
3242
+ hook: string;
3243
+ body: string;
3244
+ cta: string;
3245
+ hashtags: string[];
3246
+ altText?: string;
3247
+ imagePrompt?: string;
3248
+ notes?: string[];
3249
+ };
3250
+ textModel: string | null;
3251
+ image?: { filePath: string; fileName: string; mimeType: string; size: number };
3252
+ imageWarning?: string;
3253
+ imageError?: string;
3254
+ hint?: string;
3255
+ };
3256
+
3257
+ /**
3258
+ * Generate an Instagram caption + image WITHOUT logging in or publishing.
3259
+ * Pass topic, or biSnapshotId (+ optional productName) to ground on a Business Identity product.
3260
+ * Returns content.caption and image.filePath — pass both to createInstagramPost() to publish afterwards.
3261
+ */
3262
+ export async function generateInstagramContent(
3263
+ options: GenerateInstagramContentOptions = {}
3264
+ ): Promise<GeneratedInstagramContentResult> {
3265
+ return callInstagramTool('instagram_generate_content', options);
3266
+ }
3267
+
3268
+ /**
3269
+ * Publish an Instagram post via Playwright (login + create). Requires a local
3270
+ * imagePath (absolute path on the EGDesk machine) and caption. Records publish history.
3271
+ */
3272
+ export async function createInstagramPost(options: {
3273
+ connectionId: string;
3274
+ caption: string;
3275
+ /** Absolute path to an image on the EGDesk machine */
3276
+ imagePath: string;
3277
+ /** Ms to wait after Share (default 8000) */
3278
+ waitAfterShare?: number;
3279
+ }) {
3280
+ return callInstagramTool('instagram_create_post', options);
3281
+ }
3282
+
3283
+ /** Debug publish: post fixed/default caption with ~/Downloads/cat.png (or imagePath). No Gemini. */
3284
+ export async function debugInstagramPost(options: {
3285
+ connectionId: string;
3286
+ caption?: string;
3287
+ imagePath?: string;
3288
+ }) {
3289
+ return callInstagramTool('instagram_debug_post', options);
3290
+ }
3291
+
3292
+ export type InstagramSchedule = {
3293
+ id: string;
3294
+ title: string;
3295
+ connectionId: string;
3296
+ connectionName: string;
3297
+ connectionType: string;
3298
+ enabled: boolean;
3299
+ frequencyType: string;
3300
+ frequencyValue: unknown;
3301
+ scheduledTime: string;
3302
+ nextRun?: string | null;
3303
+ lastRun?: string | null;
3304
+ runCount?: number;
3305
+ successCount?: number;
3306
+ failureCount?: number;
3307
+ topics?: unknown;
3308
+ };
3309
+
3310
+ /** List Instagram scheduled posts for a connection, or all Instagram schedules when omitted. */
3311
+ export async function listInstagramSchedules(connectionId?: string): Promise<{
3312
+ success: boolean;
3313
+ schedules: InstagramSchedule[];
3314
+ }> {
3315
+ return callInstagramTool('instagram_list_schedules', connectionId ? { connectionId } : {});
3316
+ }
3317
+
3318
+ // ==========================================
3319
+ // BLOG (MCP) — WordPress / Naver
3320
+ // ==========================================
3321
+ //
3322
+ // Path A: schedule auto-generate + publish posts (blog_schedule_create + runNow / blog_schedule_run_now).
3323
+ // Path B: generate a draft, inspect it, then publish separately (generateBlogContent → publishBlogDraft).
3324
+ // Path C: publish title + HTML + images in one call (publishBlogContent).
3325
+
3326
+ /**
3327
+ * Call EGDesk Blog MCP tool.
3328
+ *
3329
+ * - Server: \`POST {apiUrl}/blog/tools/call\`
3330
+ * - Client: \`POST /__blog_proxy\` (see proxy.ts / middleware)
3331
+ */
3332
+ export async function callBlogTool(
3333
+ toolName: string,
3334
+ args: Record<string, any> = {}
3335
+ ): Promise<any> {
3336
+ const body = JSON.stringify({ tool: toolName, arguments: args });
3337
+
3338
+ const isServer = typeof window === 'undefined';
3339
+
3340
+ let response: Response;
3341
+ if (isServer) {
3342
+ const apiUrl =
3343
+ (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
3344
+ EGDESK_CONFIG.apiUrl;
3345
+ response = await fetch(\`\${apiUrl}/blog/tools/call\`, {
3346
+ method: 'POST',
3347
+ headers: buildServerEgdeskHeaders(),
3348
+ body
3349
+ });
3350
+ } else {
3351
+ response = await apiFetch('/__blog_proxy', {
3352
+ method: 'POST',
3353
+ headers: { 'Content-Type': 'application/json' },
3354
+ body
3355
+ });
3356
+ }
3357
+
3358
+ return parseEgdeskMcpToolResponse(response);
3359
+ }
3360
+
3361
+ export type BlogConnection = {
3362
+ id: string;
3363
+ name: string;
3364
+ type: 'wordpress' | 'naver';
3365
+ url?: string;
3366
+ };
3367
+
3368
+ /** List WordPress and Naver Blog connections available for scheduling/publishing. */
3369
+ export async function listBlogConnections(): Promise<{ connections: BlogConnection[] }> {
3370
+ return callBlogTool('blog_list_connections', {});
3371
+ }
3372
+
3373
+ /**
3374
+ * Add a new blog account connection (WordPress or Naver). Returns connectionId for
3375
+ * schedule/publish tools. Updates existing Naver by username or WordPress by url.
3376
+ */
3377
+ export async function addBlogConnection(options: {
3378
+ type: 'naver' | 'wordpress';
3379
+ /** Defaults to username or site URL */
3380
+ name?: string;
3381
+ /** Naver ID or WordPress username */
3382
+ username: string;
3383
+ /** Naver password or WordPress application password */
3384
+ password: string;
3385
+ /** WordPress site URL (required when type=wordpress) */
3386
+ url?: string;
3387
+ /** Optional proxy URL for Naver automation */
3388
+ proxyUrl?: string;
3389
+ }) {
3390
+ return callBlogTool('blog_add_connection', options);
3391
+ }
3392
+
3393
+ export type CreateBlogScheduleOptions = {
3394
+ title: string;
3395
+ connectionId: string;
3396
+ /** manual topics or rotate BI products */
3397
+ topicSource?: 'manual' | 'bi_products';
3398
+ /** Required when topicSource is bi_products */
3399
+ biSnapshotId?: string;
3400
+ /** Manual topics or product names when using bi_products */
3401
+ topics?: string[];
3402
+ /** HH:MM (24h). Default 09:00 */
3403
+ scheduledTime?: string;
3404
+ frequencyType?: 'daily' | 'weekly' | 'monthly' | 'custom';
3405
+ frequencyValue?: number;
3406
+ /** 0=Sunday … 6=Saturday (weekly) */
3407
+ weeklyDay?: number;
3408
+ /** 1-31 (monthly) */
3409
+ monthlyDay?: number;
3410
+ aiKeyId?: string;
3411
+ textModel?: string;
3412
+ imageModel?: string;
3413
+ /** Default true */
3414
+ enabled?: boolean;
3415
+ /** If true, immediately generate + publish after creating the schedule. May take several minutes. */
3416
+ runNow?: boolean;
3417
+ };
3418
+
3419
+ /**
3420
+ * Create a recurring blog schedule. Use topicSource='bi_products' with biSnapshotId +
3421
+ * product name topics for auto-generation from the BI catalog.
3422
+ */
3423
+ export async function createBlogSchedule(options: CreateBlogScheduleOptions) {
3424
+ return callBlogTool('blog_schedule_create', options);
3425
+ }
3426
+
3427
+ /** List scheduled blog posts (optional connectionId filter). */
3428
+ export async function listBlogSchedules(connectionId?: string) {
3429
+ return callBlogTool('blog_schedule_list', connectionId ? { connectionId } : {});
3430
+ }
3431
+
3432
+ /** Enable or disable a scheduled blog post. */
3433
+ export async function toggleBlogSchedule(scheduleId: string, enabled: boolean) {
3434
+ return callBlogTool('blog_schedule_toggle', { scheduleId, enabled });
3435
+ }
3436
+
3437
+ /** Immediately generate and publish for a schedule (full auto path). May take several minutes. */
3438
+ export async function runBlogScheduleNow(scheduleId: string) {
3439
+ return callBlogTool('blog_schedule_run_now', { scheduleId });
3440
+ }
3441
+
3442
+ export type BlogPublishHistoryEntry = {
3443
+ id: string;
3444
+ source: 'mcp' | 'schedule';
3445
+ status: 'success' | 'failure';
3446
+ connectionId?: string | null;
3447
+ connectionName?: string | null;
3448
+ connectionType?: string | null;
3449
+ scheduleId?: string | null;
3450
+ scheduleTitle?: string | null;
3451
+ draftId?: string | null;
3452
+ title?: string | null;
3453
+ postUrl?: string | null;
3454
+ /** Naver logNo / WordPress post id when known */
3455
+ postId?: string | null;
3456
+ errorMessage?: string | null;
3457
+ imageCount?: number;
3458
+ topics?: string[];
3459
+ startedAt: string;
3460
+ completedAt: string;
3461
+ durationMs?: number;
3462
+ };
3463
+
3464
+ /**
3465
+ * Fetch posted-blog history: scheduled executions + MCP one-off publishes (title, postUrl,
3466
+ * postId, status, connection, timestamps). Naver postId is the logNo for
3467
+ * blog.stat.naver.com/blog/download/article/{postId}.
3468
+ */
3469
+ export async function listBlogHistory(options: {
3470
+ /** Filter to one schedule */
3471
+ scheduleId?: string;
3472
+ /** Filter by blog connection */
3473
+ connectionId?: string;
3474
+ status?: 'success' | 'failure';
3475
+ /** Max rows (default 100, max 500) */
3476
+ limit?: number;
3477
+ } = {}): Promise<{ total: number; history: BlogPublishHistoryEntry[] }> {
3478
+ return callBlogTool('blog_list_history', options);
3479
+ }
3480
+
3481
+ export type BlogDraftImage = {
3482
+ uuid?: string;
3483
+ description?: string;
3484
+ altText?: string;
3485
+ caption?: string;
3486
+ placement?: string;
3487
+ filePath?: string;
3488
+ url?: string;
3489
+ mimeType?: string;
3490
+ };
3491
+
3492
+ export type BlogDraftSummary = {
3493
+ draftId: string;
3494
+ topic: string;
3495
+ biSnapshotId: string | null;
3496
+ productName: string | null;
3497
+ title: string;
3498
+ excerpt: string | null;
3499
+ tags: string[] | string;
3500
+ imageCount: number;
3501
+ images: Array<{
3502
+ index: number;
3503
+ uuid: string | null;
3504
+ description: string | null;
3505
+ placement: string | null;
3506
+ filePath: string | null;
3507
+ url: string | null;
3508
+ }>;
3509
+ markerCount: number;
3510
+ wordCount: number;
3511
+ createdAt: string;
3512
+ updatedAt: string;
3513
+ };
3514
+
3515
+ /**
3516
+ * Generate blog content without publishing. Returns draftId, image filePaths, and preview.
3517
+ * Use productName + biSnapshotId to apply product tone/images. Pass draftId (or
3518
+ * title+content+images) to publishBlogDraft() / publishBlogContent().
3519
+ */
3520
+ export async function generateBlogContent(options: {
3521
+ topic?: string;
3522
+ productName?: string;
3523
+ biSnapshotId?: string;
3524
+ textModel?: string;
3525
+ imageModel?: string;
3526
+ aiKeyId?: string;
3527
+ /** Affects image handling. Default naver (local files). */
3528
+ platform?: 'wordpress' | 'naver';
3529
+ /** Optional WordPress connection for image upload during generation */
3530
+ connectionId?: string;
3531
+ /** If true, include full HTML body in the response */
3532
+ includeContent?: boolean;
3533
+ } = {}): Promise<
3534
+ BlogDraftSummary & { success: true; hint: string; content?: string; markers?: unknown[] }
3535
+ > {
3536
+ return callBlogTool('blog_generate_content', options);
3537
+ }
3538
+
3539
+ /** Fetch a generated draft. includeContent=true returns full HTML + images metadata. */
3540
+ export async function getBlogDraft(
3541
+ draftId: string,
3542
+ includeContent?: boolean
3543
+ ): Promise<{ summary: BlogDraftSummary; draft?: unknown }> {
3544
+ return callBlogTool('blog_get_draft', { draftId, includeContent });
3545
+ }
3546
+
3547
+ /**
3548
+ * Publish to WordPress or Naver in one call. Prefer draftId, OR pass title + content HTML
3549
+ * (with [IMAGE:description:placement] markers) + images[] together. images items accept
3550
+ * filePath, dataBase64/data URL, or url — order must match markers.
3551
+ */
3552
+ export async function publishBlog(options: {
3553
+ connectionId: string;
3554
+ /** Publish a previously generated draft (images come from the draft unless overridden) */
3555
+ draftId?: string;
3556
+ /** Inline title when not using draftId */
3557
+ title?: string;
3558
+ /** HTML body with [IMAGE:description:placement] markers at insert positions */
3559
+ content?: string;
3560
+ /** Images in marker order */
3561
+ images?: BlogDraftImage[];
3562
+ tags?: string | string[];
3563
+ excerpt?: string;
3564
+ }): Promise<{
3565
+ success: boolean;
3566
+ postUrl: string;
3567
+ postId: string | null;
3568
+ connectionType: string;
3569
+ draftId?: string;
3570
+ }> {
3571
+ return callBlogTool('blog_publish', options);
3572
+ }
3573
+
3574
+ /**
3575
+ * Sync fresh Naver article stats for one or many posts from blog.stat.naver.com (Excel
3576
+ * CV/LIKE/COMMENT/REFERER/DEMO + live 누적 조회수/공감/댓글). Pass postIds for multiple logNos,
3577
+ * or fromHistory=true to sync recent published posts.
3578
+ */
3579
+ export async function getBlogArticleStats(options: {
3580
+ /** Naver blog connection id */
3581
+ connectionId: string;
3582
+ /** Single Naver logNo / article id (optional if postIds or fromHistory) */
3583
+ postId?: string;
3584
+ /** Multiple Naver logNo / article ids to sync in one call (preferred for batch) */
3585
+ postIds?: string[];
3586
+ /** If true (and no postId/postIds), sync recent successful publish-history posts that have postId */
3587
+ fromHistory?: boolean;
3588
+ metric?: 'CV' | 'LIKE' | 'COMMENT' | 'REFERER' | 'DEMO';
3589
+ /** YYYY-MM-DD filter for returned series */
3590
+ dateFrom?: string;
3591
+ /** YYYY-MM-DD filter for returned series */
3592
+ dateTo?: string;
3593
+ /** Max posts when fromHistory=true (default 20, max 100) */
3594
+ limit?: number;
3595
+ /** Include download snapshot metadata (default true) */
3596
+ includeSnapshots?: boolean;
3597
+ }) {
3598
+ return callBlogTool('blog_article_stats', options);
3599
+ }
3600
+
3601
+ // ==========================================
3602
+ // YOUTUBE SHORTS (MCP)
3603
+ // ==========================================
3604
+ //
3605
+ // Login model: connections use a shared Chrome profile (chromeUserDataDir +
3606
+ // chromeExecutablePath, recommended to avoid CAPTCHA) or username+password.
3607
+ // Generation and upload drive real YouTube via Playwright, so schedule_run_now /
3608
+ // generateVideo=true / debug_post are slower (seconds to several minutes).
3609
+
3610
+ /**
3611
+ * Call EGDesk YouTube Shorts MCP tool.
3612
+ *
3613
+ * - Server: \`POST {apiUrl}/youtube/tools/call\`
3614
+ * - Client: \`POST /__youtube_proxy\` (see proxy.ts / middleware)
3615
+ */
3616
+ export async function callYouTubeTool(
3617
+ toolName: string,
3618
+ args: Record<string, any> = {}
3619
+ ): Promise<any> {
3620
+ const body = JSON.stringify({ tool: toolName, arguments: args });
3621
+
3622
+ const isServer = typeof window === 'undefined';
3623
+
3624
+ let response: Response;
3625
+ if (isServer) {
3626
+ const apiUrl =
3627
+ (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
3628
+ EGDESK_CONFIG.apiUrl;
3629
+ response = await fetch(\`\${apiUrl}/youtube/tools/call\`, {
3630
+ method: 'POST',
3631
+ headers: buildServerEgdeskHeaders(),
3632
+ body
3633
+ });
3634
+ } else {
3635
+ response = await apiFetch('/__youtube_proxy', {
3636
+ method: 'POST',
3637
+ headers: { 'Content-Type': 'application/json' },
3638
+ body
3639
+ });
3640
+ }
3641
+
3642
+ return parseEgdeskMcpToolResponse(response);
3643
+ }
3644
+
3645
+ export type YouTubeConnection = {
3646
+ id: string;
3647
+ name: string;
3648
+ username: string | null;
3649
+ hasPassword: boolean;
3650
+ googleProfileName: string | null;
3651
+ chromeUserDataDir: string | null;
3652
+ chromeExecutablePath: string | null;
3653
+ channelId: string | null;
3654
+ hasAccessToken: boolean;
3655
+ createdAt: string;
3656
+ updatedAt: string;
3657
+ };
3658
+
3659
+ /** List YouTube connections saved in EGDesk (id, name, chrome profile path). Passwords are never returned. */
3660
+ export async function listYouTubeConnections(): Promise<{
3661
+ success: boolean;
3662
+ connections: YouTubeConnection[];
3663
+ }> {
3664
+ return callYouTubeTool('youtube_list_connections', {});
3665
+ }
3666
+
3667
+ /**
3668
+ * Save or update a YouTube connection. Prefer chromeUserDataDir + chromeExecutablePath
3669
+ * to avoid CAPTCHA; username+password also accepted.
3670
+ */
3671
+ export async function saveYouTubeConnection(options: {
3672
+ name: string;
3673
+ /** Google / YouTube login */
3674
+ username?: string;
3675
+ password?: string;
3676
+ chromeUserDataDir?: string;
3677
+ chromeExecutablePath?: string;
3678
+ channelId?: string;
3679
+ /** Optional existing connection id */
3680
+ id?: string;
3681
+ }) {
3682
+ return callYouTubeTool('youtube_save_connection', options);
3683
+ }
3684
+
3685
+ /** Update fields on a YouTube connection. */
3686
+ export async function updateYouTubeConnection(options: {
3687
+ connectionId: string;
3688
+ name?: string;
3689
+ username?: string;
3690
+ password?: string;
3691
+ chromeUserDataDir?: string;
3692
+ chromeExecutablePath?: string;
3693
+ channelId?: string;
3694
+ }) {
3695
+ return callYouTubeTool('youtube_update_connection', options);
3696
+ }
3697
+
3698
+ /** Delete a YouTube connection by id. */
3699
+ export async function deleteYouTubeConnection(connectionId: string) {
3700
+ return callYouTubeTool('youtube_delete_connection', { connectionId });
3701
+ }
3702
+
3703
+ export type CreateYouTubeScheduleOptions = {
3704
+ title: string;
3705
+ connectionId: string;
3706
+ /** manual topics or rotate BI products */
3707
+ topicSource?: 'manual' | 'bi_products';
3708
+ /** BI snapshot for product grounding + brand face / spokesperson */
3709
+ biSnapshotId?: string;
3710
+ /** Manual topics or product names when using bi_products */
3711
+ topics?: string[];
3712
+ /** HH:MM (24h). Default 09:00 */
3713
+ scheduledTime?: string;
3714
+ frequencyType?: 'daily' | 'weekly' | 'monthly' | 'custom';
3715
+ frequencyValue?: number;
3716
+ /** 0=Sunday … 6=Saturday (weekly) */
3717
+ weeklyDay?: number;
3718
+ /** 1-31 (monthly) */
3719
+ monthlyDay?: number;
3720
+ aiKeyId?: string;
3721
+ /** Shorts script model (default gemini-3.5-flash) */
3722
+ textModel?: string;
3723
+ /** Veo video model (default veo-3.1-generate-preview) */
3724
+ videoModel?: string;
3725
+ /** Default true */
3726
+ enabled?: boolean;
3727
+ /** If true, immediately generate + upload Shorts after creating the schedule. May take several minutes. */
3728
+ runNow?: boolean;
3729
+ };
3730
+
3731
+ /**
3732
+ * Create a recurring YouTube Shorts schedule. Use topicSource='bi_products' with
3733
+ * biSnapshotId (+ product name topics) for product-grounded Shorts with brand face.
3734
+ */
3735
+ export async function createYouTubeSchedule(options: CreateYouTubeScheduleOptions) {
3736
+ return callYouTubeTool('youtube_schedule_create', options);
3737
+ }
3738
+
3739
+ /** List YouTube Shorts scheduled posts (optional connectionId filter). */
3740
+ export async function listYouTubeSchedules(connectionId?: string) {
3741
+ return callYouTubeTool('youtube_list_schedules', connectionId ? { connectionId } : {});
3742
+ }
3743
+
3744
+ /** Enable or disable a YouTube Shorts schedule. */
3745
+ export async function toggleYouTubeSchedule(scheduleId: string, enabled: boolean) {
3746
+ return callYouTubeTool('youtube_schedule_toggle', { scheduleId, enabled });
3747
+ }
3748
+
3749
+ /**
3750
+ * Immediately generate script + Veo Shorts + upload for a schedule (full auto path).
3751
+ * Uses preferred brand face when biSnapshotId is set. May take several minutes.
3752
+ */
3753
+ export async function runYouTubeScheduleNow(scheduleId: string) {
3754
+ return callYouTubeTool('youtube_schedule_run_now', { scheduleId });
3755
+ }
3756
+
3757
+ export type GenerateYouTubeContentOptions = {
3758
+ /** Topic or product name for the Short */
3759
+ topic?: string;
3760
+ /** Alias for topic; used to resolve BI catalog product */
3761
+ productName?: string;
3762
+ /** BI snapshot for product tone + brand face */
3763
+ biSnapshotId?: string;
3764
+ textModel?: string;
3765
+ videoModel?: string;
3766
+ /** Caption language (default ko) */
3767
+ language?: string;
3768
+ extraInstructions?: string;
3769
+ /** If true, run Veo clip → overlay → outro and return local finalPath */
3770
+ generateVideo?: boolean;
3771
+ /** Skip brand outro stitch when generateVideo=true */
3772
+ skipOutro?: boolean;
3773
+ };
3774
+
3775
+ export type GeneratedYouTubeContentResult = {
3776
+ success: boolean;
3777
+ topic: string;
3778
+ productName: string;
3779
+ biSnapshotId: string | null;
3780
+ spokesperson: { name: string; role?: string } | null;
3781
+ content: {
3782
+ title: string;
3783
+ description: string;
3784
+ tags: string[];
3785
+ script: unknown;
3786
+ veoScenes: unknown;
3787
+ veoPrompt?: string;
3788
+ thumbnailPrompt?: string;
3789
+ notes?: string[];
3790
+ };
3791
+ textModel: string;
3792
+ videoModel: string;
3793
+ video?: {
3794
+ finalPath: string;
3795
+ composedPath: string;
3796
+ rawClipPath: string;
3797
+ sceneClipPaths: string[];
3798
+ durationSec: number;
3799
+ outroVariantId?: string;
3800
+ };
3801
+ hint: string;
3802
+ };
3803
+
3804
+ /**
3805
+ * Generate YouTube Shorts content (title/description/script/veoScenes) WITHOUT uploading.
3806
+ * Pass biSnapshotId to ground on a BI product + preferred brand face. Set generateVideo=true
3807
+ * to also render a local mp4 via the Shorts pipeline (pass the returned video.finalPath to
3808
+ * debugYouTubePost() to upload).
3809
+ */
3810
+ export async function generateYouTubeContent(
3811
+ options: GenerateYouTubeContentOptions = {}
3812
+ ): Promise<GeneratedYouTubeContentResult> {
3813
+ return callYouTubeTool('youtube_generate_content', options);
3814
+ }
3815
+
3816
+ /** Debug upload: login + upload a local Shorts mp4 (no Gemini). Defaults to ~/Downloads/shorts-test.mp4. */
3817
+ export async function debugYouTubePost(options: {
3818
+ connectionId: string;
3819
+ /** Absolute local file path to an mp4 already saved on this machine */
3820
+ videoPath?: string;
3821
+ title?: string;
3822
+ description?: string;
3823
+ }) {
3824
+ return callYouTubeTool('youtube_debug_post', options);
3825
+ }
3826
+
3827
+ /** List YouTube Shorts publish/execution history (scheduled runs) with post URLs when available. */
3828
+ export async function listYouTubeHistory(options: {
3829
+ scheduleId?: string;
3830
+ connectionId?: string;
3831
+ status?: 'success' | 'failure';
3832
+ /** Max rows (default 100, max 500) */
3833
+ limit?: number;
3834
+ } = {}) {
3835
+ return callYouTubeTool('youtube_list_history', options);
3836
+ }
3047
3837
  `;
3048
3838
  fs.writeFileSync(helperPath, helperContent.replace(/\r?\n/g, os.EOL), 'utf-8');
3049
3839
  console.log(`✅ Generated ${helperPath}`);
@@ -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, and __phone_proxy requests
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
@@ -406,6 +406,28 @@ export async function proxy(request: NextRequest) {
406
406
  }
407
407
  }
408
408
 
409
+ if (pathname.includes('__instagram_proxy')) {
410
+ try {
411
+ const body = await request.text();
412
+ const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
413
+
414
+ const response = await fetch(\`\${apiUrl}/instagram/tools/call\`, {
415
+ method: 'POST',
416
+ headers: buildEgdeskHeaders(),
417
+ body,
418
+ });
419
+
420
+ const result = await response.json();
421
+
422
+ return NextResponse.json(result, { status: response.status });
423
+ } catch (error: any) {
424
+ return NextResponse.json(
425
+ { error: 'Proxy error', message: error.message },
426
+ { status: 500 }
427
+ );
428
+ }
429
+ }
430
+
409
431
  if (pathname.includes('__egdesk_config_proxy')) {
410
432
  try {
411
433
  const body = await request.text();
@@ -450,6 +472,72 @@ export async function proxy(request: NextRequest) {
450
472
  }
451
473
  }
452
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
+
453
541
  // Continue to next proxy or route
454
542
  return NextResponse.next();
455
543
  }
@@ -458,7 +546,7 @@ export const config = {
458
546
  matcher: [
459
547
  /*
460
548
  * Match all paths except static assets
461
- * 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
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
462
550
  */
463
551
  '/:path*',
464
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.28";
11
+ export declare const COMPATIBLE_APP_VERSION = "1.4.32";
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.28';
49
+ exports.COMPATIBLE_APP_VERSION = '1.4.32';
50
50
  const fs = __importStar(require("fs"));
51
51
  const path = __importStar(require("path"));
52
52
  const setup_userdata_1 = require("./setup-userdata");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egdesk/next-api-plugin",
3
- "version": "1.5.14",
3
+ "version": "1.5.19",
4
4
  "description": "Next.js plugin for EGDesk database proxy integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",