@egdesk/next-api-plugin 1.5.14 → 1.5.15

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,209 @@ 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
+ /**
3214
+ * Publish an Instagram post via Playwright (login + create). Requires a local
3215
+ * imagePath (absolute path on the EGDesk machine) and caption. Records publish history.
3216
+ */
3217
+ export async function createInstagramPost(options: {
3218
+ connectionId: string;
3219
+ caption: string;
3220
+ /** Absolute path to an image on the EGDesk machine */
3221
+ imagePath: string;
3222
+ /** Ms to wait after Share (default 8000) */
3223
+ waitAfterShare?: number;
3224
+ }) {
3225
+ return callInstagramTool('instagram_create_post', options);
3226
+ }
3227
+
3228
+ /** Debug publish: post fixed/default caption with ~/Downloads/cat.png (or imagePath). No Gemini. */
3229
+ export async function debugInstagramPost(options: {
3230
+ connectionId: string;
3231
+ caption?: string;
3232
+ imagePath?: string;
3233
+ }) {
3234
+ return callInstagramTool('instagram_debug_post', options);
3235
+ }
3236
+
3237
+ export type InstagramSchedule = {
3238
+ id: string;
3239
+ title: string;
3240
+ connectionId: string;
3241
+ connectionName: string;
3242
+ connectionType: string;
3243
+ enabled: boolean;
3244
+ frequencyType: string;
3245
+ frequencyValue: unknown;
3246
+ scheduledTime: string;
3247
+ nextRun?: string | null;
3248
+ lastRun?: string | null;
3249
+ runCount?: number;
3250
+ successCount?: number;
3251
+ failureCount?: number;
3252
+ topics?: unknown;
3253
+ };
3254
+
3255
+ /** List Instagram scheduled posts for a connection, or all Instagram schedules when omitted. */
3256
+ export async function listInstagramSchedules(connectionId?: string): Promise<{
3257
+ success: boolean;
3258
+ schedules: InstagramSchedule[];
3259
+ }> {
3260
+ return callInstagramTool('instagram_list_schedules', connectionId ? { connectionId } : {});
3261
+ }
3047
3262
  `;
3048
3263
  fs.writeFileSync(helperPath, helperContent.replace(/\r?\n/g, os.EOL), 'utf-8');
3049
3264
  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, and __instagram_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();
@@ -458,7 +480,7 @@ export const config = {
458
480
  matcher: [
459
481
  /*
460
482
  * 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
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
462
484
  */
463
485
  '/:path*',
464
486
  ],
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.15",
4
4
  "description": "Next.js plugin for EGDesk database proxy integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",