@egdesk/next-api-plugin 1.5.60 → 1.5.64
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 +169 -54
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/generate-helpers.js
CHANGED
|
@@ -218,6 +218,8 @@ export type WorkspaceVisitorCallOptions = {
|
|
|
218
218
|
visitorSessionId?: string;
|
|
219
219
|
/** Origin the visitor logged in from. Required on the server (no window). */
|
|
220
220
|
visitorOrigin?: string;
|
|
221
|
+
/** Owner MCP: use personal Google login before service account when both are configured. */
|
|
222
|
+
preferOAuth?: boolean;
|
|
221
223
|
};
|
|
222
224
|
|
|
223
225
|
function getBrowserVisitorSessionId(): string | null {
|
|
@@ -276,8 +278,10 @@ function withVisitorToolArgs(
|
|
|
276
278
|
args: Record<string, any>,
|
|
277
279
|
options: WorkspaceVisitorCallOptions = {},
|
|
278
280
|
): Record<string, any> {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
+
const out = { ...args };
|
|
282
|
+
if (options.asVisitor) out.asVisitor = true;
|
|
283
|
+
if (options.preferOAuth !== undefined) out.preferOAuth = options.preferOAuth;
|
|
284
|
+
return out;
|
|
281
285
|
}
|
|
282
286
|
|
|
283
287
|
async function callWorkspaceMcpTool(
|
|
@@ -315,7 +319,30 @@ async function callWorkspaceMcpTool(
|
|
|
315
319
|
|
|
316
320
|
/**
|
|
317
321
|
* Parse EGDesk MCP \`/tools/call\` JSON so \`error\` is shown even when HTTP status is 500.
|
|
322
|
+
* Envelope \`success: true\` is not enough — add_account uses accountAdded.
|
|
318
323
|
*/
|
|
324
|
+
function finalizeEgdeskMcpPayload(parsed: any): any {
|
|
325
|
+
const pending =
|
|
326
|
+
parsed &&
|
|
327
|
+
typeof parsed === 'object' &&
|
|
328
|
+
(parsed.requiresConfirmation === true ||
|
|
329
|
+
(Array.isArray(parsed.needs_more_fields) && parsed.needs_more_fields.length > 0));
|
|
330
|
+
if (
|
|
331
|
+
parsed &&
|
|
332
|
+
typeof parsed === 'object' &&
|
|
333
|
+
parsed.accountAdded === false &&
|
|
334
|
+
!pending
|
|
335
|
+
) {
|
|
336
|
+
throw new Error(
|
|
337
|
+
parsed.agentFeedback ||
|
|
338
|
+
parsed.message ||
|
|
339
|
+
parsed.error ||
|
|
340
|
+
'browser_recording_add_account did not add the account'
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
return parsed;
|
|
344
|
+
}
|
|
345
|
+
|
|
319
346
|
async function parseEgdeskMcpToolResponse(response: Response): Promise<any> {
|
|
320
347
|
const result = await response.json().catch(() => null);
|
|
321
348
|
|
|
@@ -349,13 +376,17 @@ async function parseEgdeskMcpToolResponse(response: Response): Promise<any> {
|
|
|
349
376
|
}
|
|
350
377
|
|
|
351
378
|
const content = result.result?.content?.[0]?.text;
|
|
352
|
-
if (!content)
|
|
379
|
+
if (!content) {
|
|
380
|
+
if (result.result?.isError) throw new Error('EGDesk tool failed');
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
let parsed: any;
|
|
353
384
|
try {
|
|
354
|
-
|
|
385
|
+
parsed = JSON.parse(content);
|
|
355
386
|
} catch {
|
|
356
|
-
|
|
357
|
-
return content;
|
|
387
|
+
parsed = content;
|
|
358
388
|
}
|
|
389
|
+
return finalizeEgdeskMcpPayload(parsed);
|
|
359
390
|
}
|
|
360
391
|
|
|
361
392
|
async function parseEgdeskHttpResponse(response: Response): Promise<any> {
|
|
@@ -1953,6 +1984,24 @@ export async function listBrowserRecordingSites(site?: string) {
|
|
|
1953
1984
|
return callBrowserRecordingTool('browser_recording_list_sites', site ? { site } : {});
|
|
1954
1985
|
}
|
|
1955
1986
|
|
|
1987
|
+
/**
|
|
1988
|
+
* Add a site+login to the Browser Recorder catalog.
|
|
1989
|
+
* Throws unless accountAdded is true (confirmation / needs_more_fields are returned, not thrown).
|
|
1990
|
+
* First call without confirmed; after the user approves, call again with confirmed: true.
|
|
1991
|
+
* Discover misses iframe logins (no_login_form). Do not mask sheet passwords on throw.
|
|
1992
|
+
*/
|
|
1993
|
+
export async function addBrowserRecordingAccount(options: {
|
|
1994
|
+
url: string;
|
|
1995
|
+
password: string;
|
|
1996
|
+
user?: string;
|
|
1997
|
+
id?: string;
|
|
1998
|
+
company?: string;
|
|
1999
|
+
email?: string;
|
|
2000
|
+
confirmed?: boolean;
|
|
2001
|
+
}) {
|
|
2002
|
+
return callBrowserRecordingTool('browser_recording_add_account', options);
|
|
2003
|
+
}
|
|
2004
|
+
|
|
1956
2005
|
/** One recorded login: identity + login vs post-login actions (no passwords) */
|
|
1957
2006
|
export async function getBrowserRecordingAccount(siteKey: string, accountKey: string) {
|
|
1958
2007
|
return callBrowserRecordingTool('browser_recording_get_account', { siteKey, accountKey });
|
|
@@ -1965,12 +2014,14 @@ export async function getBrowserRecordingAccount(siteKey: string, accountKey: st
|
|
|
1965
2014
|
export async function openBrowserRecordingAccount(
|
|
1966
2015
|
siteKey: string,
|
|
1967
2016
|
accountKey: string,
|
|
1968
|
-
scriptPath?: string
|
|
2017
|
+
scriptPath?: string,
|
|
2018
|
+
confirmed?: boolean,
|
|
1969
2019
|
) {
|
|
1970
2020
|
return callBrowserRecordingTool('browser_recording_open_account', {
|
|
1971
2021
|
siteKey,
|
|
1972
2022
|
accountKey,
|
|
1973
|
-
...(scriptPath ? { scriptPath } : {})
|
|
2023
|
+
...(scriptPath ? { scriptPath } : {}),
|
|
2024
|
+
...(confirmed ? { confirmed: true } : {}),
|
|
1974
2025
|
});
|
|
1975
2026
|
}
|
|
1976
2027
|
|
|
@@ -3381,18 +3432,23 @@ export async function uploadDriveFile(options: {
|
|
|
3381
3432
|
}
|
|
3382
3433
|
|
|
3383
3434
|
/** List Drive files by folder and/or query */
|
|
3384
|
-
export async function listDriveFiles(
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3435
|
+
export async function listDriveFiles(
|
|
3436
|
+
options: {
|
|
3437
|
+
folderId?: string;
|
|
3438
|
+
query?: string;
|
|
3439
|
+
pageSize?: number;
|
|
3440
|
+
pageToken?: string;
|
|
3441
|
+
} = {},
|
|
3442
|
+
callOptions: WorkspaceVisitorCallOptions = {},
|
|
3443
|
+
) {
|
|
3444
|
+
const preferOAuth = callOptions.preferOAuth ?? true;
|
|
3445
|
+
return callDriveTool('drive_list_files', { ...options, preferOAuth }, { ...callOptions, preferOAuth });
|
|
3391
3446
|
}
|
|
3392
3447
|
|
|
3393
3448
|
/** Get Drive file or folder metadata */
|
|
3394
|
-
export async function getDriveFile(fileId: string) {
|
|
3395
|
-
|
|
3449
|
+
export async function getDriveFile(fileId: string, options: WorkspaceVisitorCallOptions = {}) {
|
|
3450
|
+
const preferOAuth = options.preferOAuth ?? true;
|
|
3451
|
+
return callDriveTool('drive_get_file', { fileId, preferOAuth }, { ...options, preferOAuth });
|
|
3396
3452
|
}
|
|
3397
3453
|
|
|
3398
3454
|
/** Create a Drive folder */
|
|
@@ -3484,6 +3540,7 @@ export async function syncDrive(options: {
|
|
|
3484
3540
|
* Call EGDesk Sheets MCP tool.
|
|
3485
3541
|
*
|
|
3486
3542
|
* Auth: personal OAuth, service account, or domain-wide delegation (call getSheetsAuthStatus() first).
|
|
3543
|
+
* Read helpers default preferOAuth: true when both credentials exist.
|
|
3487
3544
|
* Pass { asVisitor: true } to act as the website visitor from startVisitorGoogleLogin().
|
|
3488
3545
|
* On the server also pass visitorSessionId and visitorOrigin (or NEXT_PUBLIC_EGDESK_VISITOR_ORIGIN).
|
|
3489
3546
|
* - Server: \`POST {apiUrl}/sheets/tools/call\`
|
|
@@ -3503,37 +3560,73 @@ export async function getSheetsAuthStatus() {
|
|
|
3503
3560
|
}
|
|
3504
3561
|
|
|
3505
3562
|
/** Spreadsheet metadata (tabs, dimensions) */
|
|
3506
|
-
export async function getSpreadsheet(
|
|
3507
|
-
|
|
3563
|
+
export async function getSpreadsheet(
|
|
3564
|
+
spreadsheetId: string,
|
|
3565
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
3566
|
+
) {
|
|
3567
|
+
const preferOAuth = options.preferOAuth ?? true;
|
|
3568
|
+
return callSheetsTool('sheets_get_spreadsheet', { spreadsheetId, preferOAuth }, options);
|
|
3508
3569
|
}
|
|
3509
3570
|
|
|
3510
3571
|
/** Read a range (A1 notation) */
|
|
3511
|
-
export async function getSheetRange(
|
|
3512
|
-
|
|
3572
|
+
export async function getSheetRange(
|
|
3573
|
+
spreadsheetId: string,
|
|
3574
|
+
range: string,
|
|
3575
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
3576
|
+
) {
|
|
3577
|
+
const preferOAuth = options.preferOAuth ?? true;
|
|
3578
|
+
return callSheetsTool('sheets_get_range', { spreadsheetId, range, preferOAuth }, options);
|
|
3513
3579
|
}
|
|
3514
3580
|
|
|
3515
3581
|
/** Read a range including formula vs literal per cell */
|
|
3516
|
-
export async function getSheetRangeWithFormulas(
|
|
3517
|
-
|
|
3582
|
+
export async function getSheetRangeWithFormulas(
|
|
3583
|
+
spreadsheetId: string,
|
|
3584
|
+
range: string,
|
|
3585
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
3586
|
+
) {
|
|
3587
|
+
const preferOAuth = options.preferOAuth ?? true;
|
|
3588
|
+
return callSheetsTool(
|
|
3589
|
+
'sheets_get_range_with_formulas',
|
|
3590
|
+
{ spreadsheetId, range, preferOAuth },
|
|
3591
|
+
options,
|
|
3592
|
+
);
|
|
3518
3593
|
}
|
|
3519
3594
|
|
|
3520
3595
|
/** Header row of a tab */
|
|
3521
|
-
export async function getSheetHeaders(
|
|
3522
|
-
|
|
3596
|
+
export async function getSheetHeaders(
|
|
3597
|
+
spreadsheetId: string,
|
|
3598
|
+
sheetName?: string,
|
|
3599
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
3600
|
+
) {
|
|
3601
|
+
const preferOAuth = options.preferOAuth ?? true;
|
|
3602
|
+
return callSheetsTool('sheets_get_headers', { spreadsheetId, sheetName, preferOAuth }, options);
|
|
3523
3603
|
}
|
|
3524
3604
|
|
|
3525
3605
|
/** First N rows of a tab */
|
|
3526
|
-
export async function getSheetSampleData(
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3606
|
+
export async function getSheetSampleData(
|
|
3607
|
+
options: {
|
|
3608
|
+
spreadsheetId: string;
|
|
3609
|
+
sheetName?: string;
|
|
3610
|
+
rows?: number;
|
|
3611
|
+
},
|
|
3612
|
+
callOptions: WorkspaceVisitorCallOptions = {},
|
|
3613
|
+
) {
|
|
3614
|
+
const preferOAuth = callOptions.preferOAuth ?? true;
|
|
3615
|
+
return callSheetsTool('sheets_get_sample_data', { ...options, preferOAuth }, callOptions);
|
|
3532
3616
|
}
|
|
3533
3617
|
|
|
3534
3618
|
/** Metadata + headers + sample rows for every tab */
|
|
3535
|
-
export async function getSpreadsheetFullContext(
|
|
3536
|
-
|
|
3619
|
+
export async function getSpreadsheetFullContext(
|
|
3620
|
+
spreadsheetId: string,
|
|
3621
|
+
sampleRows?: number,
|
|
3622
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
3623
|
+
) {
|
|
3624
|
+
const preferOAuth = options.preferOAuth ?? true;
|
|
3625
|
+
return callSheetsTool(
|
|
3626
|
+
'sheets_get_full_context',
|
|
3627
|
+
{ spreadsheetId, sampleRows, preferOAuth },
|
|
3628
|
+
options,
|
|
3629
|
+
);
|
|
3537
3630
|
}
|
|
3538
3631
|
|
|
3539
3632
|
/** Create a spreadsheet, optionally seeding Sheet1 */
|
|
@@ -3768,6 +3861,10 @@ export async function sendGmailMessage(options: {
|
|
|
3768
3861
|
/**
|
|
3769
3862
|
* Call EGDesk Apps Script MCP tool.
|
|
3770
3863
|
*
|
|
3864
|
+
* Owner MCP: personal Google login is used by default (service accounts cannot
|
|
3865
|
+
* call Apps Script as themselves).
|
|
3866
|
+
* Pass { asVisitor: true } to act as the website visitor from startVisitorGoogleLogin().
|
|
3867
|
+
*
|
|
3771
3868
|
* - Server: \`POST {apiUrl}/apps-script/tools/call\`
|
|
3772
3869
|
* - Client: \`POST /__apps_script_proxy\`
|
|
3773
3870
|
*/
|
|
@@ -3798,29 +3895,46 @@ export async function pullAppsScriptFromGoogle(projectId: string) {
|
|
|
3798
3895
|
}
|
|
3799
3896
|
|
|
3800
3897
|
/** Create a container-bound Apps Script on a Sheet, Doc, Slide, or Form and register it */
|
|
3801
|
-
export async function createAppsScriptBound(
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3898
|
+
export async function createAppsScriptBound(
|
|
3899
|
+
options: {
|
|
3900
|
+
fileId: string;
|
|
3901
|
+
title?: string;
|
|
3902
|
+
scriptCode?: string;
|
|
3903
|
+
force?: boolean;
|
|
3904
|
+
},
|
|
3905
|
+
callOptions: WorkspaceVisitorCallOptions = {},
|
|
3906
|
+
) {
|
|
3907
|
+
const preferOAuth = callOptions.preferOAuth ?? true;
|
|
3908
|
+
return callAppsScriptTool(
|
|
3909
|
+
'apps_script_create_bound',
|
|
3910
|
+
{ ...options, preferOAuth },
|
|
3911
|
+
{ ...callOptions, preferOAuth },
|
|
3912
|
+
);
|
|
3808
3913
|
}
|
|
3809
3914
|
|
|
3810
3915
|
/** Alias of createAppsScriptBound */
|
|
3811
|
-
export async function createAppsScriptForSpreadsheet(
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3916
|
+
export async function createAppsScriptForSpreadsheet(
|
|
3917
|
+
options: {
|
|
3918
|
+
spreadsheetId?: string;
|
|
3919
|
+
fileId?: string;
|
|
3920
|
+
title?: string;
|
|
3921
|
+
scriptCode?: string;
|
|
3922
|
+
force?: boolean;
|
|
3923
|
+
},
|
|
3924
|
+
callOptions: WorkspaceVisitorCallOptions = {},
|
|
3925
|
+
) {
|
|
3926
|
+
const preferOAuth = callOptions.preferOAuth ?? true;
|
|
3927
|
+
return callAppsScriptTool(
|
|
3928
|
+
'apps_script_create_bound',
|
|
3929
|
+
{
|
|
3930
|
+
fileId: options.fileId || options.spreadsheetId,
|
|
3931
|
+
title: options.title,
|
|
3932
|
+
scriptCode: options.scriptCode,
|
|
3933
|
+
force: options.force,
|
|
3934
|
+
preferOAuth,
|
|
3935
|
+
},
|
|
3936
|
+
{ ...callOptions, preferOAuth },
|
|
3937
|
+
);
|
|
3824
3938
|
}
|
|
3825
3939
|
|
|
3826
3940
|
/**
|
|
@@ -5105,6 +5219,7 @@ export async function listYouTubeHistory(options: {
|
|
|
5105
5219
|
return callYouTubeTool('youtube_list_history', options);
|
|
5106
5220
|
}
|
|
5107
5221
|
`;
|
|
5108
|
-
|
|
5222
|
+
const sanitized = helperContent.replace(/^(\/\*\*[^\n]*\*\/)\}$/gm, '$1');
|
|
5223
|
+
fs.writeFileSync(helperPath, sanitized.replace(/\r?\n/g, os.EOL), 'utf-8');
|
|
5109
5224
|
console.log(`✅ Generated ${helperPath}`);
|
|
5110
5225
|
}
|
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.71";
|
|
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.71';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|