integrate-sdk 0.9.56 → 0.9.61
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/adapters/index.js +80 -35
- package/dist/adapters/solid-start.js +80 -35
- package/dist/adapters/svelte-kit.js +80 -35
- package/dist/ai/anthropic.d.ts.map +1 -1
- package/dist/ai/anthropic.js +11 -2
- package/dist/ai/google.d.ts.map +1 -1
- package/dist/ai/google.js +11 -2
- package/dist/ai/index.js +93 -7
- package/dist/ai/openai.d.ts.map +1 -1
- package/dist/ai/openai.js +11 -2
- package/dist/ai/tool-cache.d.ts +50 -0
- package/dist/ai/tool-cache.d.ts.map +1 -0
- package/dist/ai/utils.d.ts +26 -0
- package/dist/ai/utils.d.ts.map +1 -1
- package/dist/ai/utils.js +10 -0
- package/dist/ai/vercel-ai.d.ts.map +1 -1
- package/dist/ai/vercel-ai.js +87 -1
- package/dist/database/index.d.ts +1 -1
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +39 -0
- package/dist/index.js +142 -32
- package/dist/integrations.js +142 -32
- package/dist/react.d.ts +2 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +86 -0
- package/dist/server.js +578 -189
- package/dist/src/ai/anthropic.d.ts.map +1 -1
- package/dist/src/ai/google.d.ts.map +1 -1
- package/dist/src/ai/openai.d.ts.map +1 -1
- package/dist/src/ai/tool-cache.d.ts +50 -0
- package/dist/src/ai/tool-cache.d.ts.map +1 -0
- package/dist/src/ai/utils.d.ts +26 -0
- package/dist/src/ai/utils.d.ts.map +1 -1
- package/dist/src/ai/vercel-ai.d.ts.map +1 -1
- package/dist/src/client.d.ts +5 -5
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/config/types.d.ts +30 -0
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/database/index.d.ts +1 -1
- package/dist/src/database/index.d.ts.map +1 -1
- package/dist/src/database/token-store.d.ts +10 -0
- package/dist/src/database/token-store.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/integrations/bundle.d.ts +18 -0
- package/dist/src/integrations/bundle.d.ts.map +1 -0
- package/dist/src/react/hooks.d.ts +16 -0
- package/dist/src/react/hooks.d.ts.map +1 -1
- package/dist/src/server.d.ts +13 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/utils/normalize-tool-name.d.ts +14 -0
- package/dist/src/utils/normalize-tool-name.d.ts.map +1 -0
- package/dist/src/utils/parse-tool-result.d.ts +23 -0
- package/dist/src/utils/parse-tool-result.d.ts.map +1 -0
- package/package.json +1 -1
- package/react.ts +10 -2
package/dist/server.js
CHANGED
|
@@ -3449,6 +3449,169 @@ class HttpSessionTransport {
|
|
|
3449
3449
|
// src/client.ts
|
|
3450
3450
|
init_integration_summary();
|
|
3451
3451
|
init_library_metadata();
|
|
3452
|
+
|
|
3453
|
+
// src/database/token-store.ts
|
|
3454
|
+
var USABLE_ACCESS_TOKEN_BUFFER_MS = 30 * 1000;
|
|
3455
|
+
var MIN_MEANINGFUL_EXPIRY_MS = Date.UTC(2000, 0, 1);
|
|
3456
|
+
function getRowUpdatedAtMs(row) {
|
|
3457
|
+
return row.updatedAt instanceof Date ? row.updatedAt.getTime() : 0;
|
|
3458
|
+
}
|
|
3459
|
+
function normalizeAccountEmail(value) {
|
|
3460
|
+
if (!value)
|
|
3461
|
+
return null;
|
|
3462
|
+
const normalized = value.trim().toLowerCase();
|
|
3463
|
+
return normalized.length > 0 ? normalized : null;
|
|
3464
|
+
}
|
|
3465
|
+
function normalizeAccountEmailHint(value) {
|
|
3466
|
+
const normalized = normalizeAccountEmail(value);
|
|
3467
|
+
if (!normalized)
|
|
3468
|
+
return null;
|
|
3469
|
+
return normalized.includes("@") ? normalized : null;
|
|
3470
|
+
}
|
|
3471
|
+
function normalizeAccountIdentifier(value) {
|
|
3472
|
+
return normalizeAccountEmail(value);
|
|
3473
|
+
}
|
|
3474
|
+
function normalizeAccountIdHint(value) {
|
|
3475
|
+
if (!value)
|
|
3476
|
+
return null;
|
|
3477
|
+
const normalized = value.trim().toLowerCase();
|
|
3478
|
+
return normalized.length > 0 ? normalized : null;
|
|
3479
|
+
}
|
|
3480
|
+
function normalizeProviderTokenType(value) {
|
|
3481
|
+
const normalized = value?.trim();
|
|
3482
|
+
return normalized && normalized.length > 0 ? normalized : "Bearer";
|
|
3483
|
+
}
|
|
3484
|
+
function hasMeaningfulExpiresAt(value) {
|
|
3485
|
+
if (!value)
|
|
3486
|
+
return false;
|
|
3487
|
+
const ms = value.getTime();
|
|
3488
|
+
return Number.isFinite(ms) && ms >= MIN_MEANINGFUL_EXPIRY_MS;
|
|
3489
|
+
}
|
|
3490
|
+
function hasUsableAccessToken(row, now = Date.now(), bufferMs = USABLE_ACCESS_TOKEN_BUFFER_MS) {
|
|
3491
|
+
if (!row.accessToken)
|
|
3492
|
+
return false;
|
|
3493
|
+
const expiresAt = row.expiresAt;
|
|
3494
|
+
if (!hasMeaningfulExpiresAt(expiresAt))
|
|
3495
|
+
return true;
|
|
3496
|
+
return expiresAt.getTime() > now + bufferMs;
|
|
3497
|
+
}
|
|
3498
|
+
function isLikelyUsableToken(row, now = Date.now()) {
|
|
3499
|
+
return hasUsableAccessToken(row, now) || Boolean(row.refreshToken);
|
|
3500
|
+
}
|
|
3501
|
+
function parseScopes(scope) {
|
|
3502
|
+
if (!scope)
|
|
3503
|
+
return;
|
|
3504
|
+
const scopes = scope.split(" ").map((item) => item.trim()).filter((item) => item.length > 0);
|
|
3505
|
+
return scopes.length > 0 ? scopes : undefined;
|
|
3506
|
+
}
|
|
3507
|
+
function choosePreferredTokenRow(rows) {
|
|
3508
|
+
if (rows.length === 0)
|
|
3509
|
+
return;
|
|
3510
|
+
const sorted = [...rows].sort((left, right) => getRowUpdatedAtMs(right) - getRowUpdatedAtMs(left));
|
|
3511
|
+
return sorted.find((row) => hasUsableAccessToken(row)) ?? sorted.find((row) => Boolean(row.refreshToken)) ?? sorted[0];
|
|
3512
|
+
}
|
|
3513
|
+
function selectProviderTokenRow(rows, email, accountId) {
|
|
3514
|
+
if (rows.length === 0) {
|
|
3515
|
+
return;
|
|
3516
|
+
}
|
|
3517
|
+
const normalizedEmail = normalizeAccountEmailHint(email);
|
|
3518
|
+
const normalizedAccountId = normalizeAccountIdHint(accountId);
|
|
3519
|
+
if (normalizedAccountId && normalizedEmail) {
|
|
3520
|
+
const exactBoth = rows.filter((row) => normalizeAccountIdHint(row.accountId) === normalizedAccountId && normalizeAccountEmail(row.accountEmail) === normalizedEmail);
|
|
3521
|
+
if (exactBoth.length > 0) {
|
|
3522
|
+
return choosePreferredTokenRow(exactBoth);
|
|
3523
|
+
}
|
|
3524
|
+
}
|
|
3525
|
+
if (normalizedAccountId) {
|
|
3526
|
+
const exactAccountId = rows.filter((row) => normalizeAccountIdHint(row.accountId) === normalizedAccountId);
|
|
3527
|
+
if (exactAccountId.length > 0) {
|
|
3528
|
+
return choosePreferredTokenRow(exactAccountId);
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
if (normalizedEmail) {
|
|
3532
|
+
const exactEmail = rows.filter((row) => normalizeAccountEmail(row.accountEmail) === normalizedEmail);
|
|
3533
|
+
if (exactEmail.length > 0) {
|
|
3534
|
+
return choosePreferredTokenRow(exactEmail);
|
|
3535
|
+
}
|
|
3536
|
+
} else if (email) {
|
|
3537
|
+
const normalizedIdentifier = normalizeAccountIdentifier(email);
|
|
3538
|
+
if (normalizedIdentifier) {
|
|
3539
|
+
const identifierMatches = rows.filter((row) => normalizeAccountIdHint(row.accountId) === normalizedIdentifier);
|
|
3540
|
+
if (identifierMatches.length > 0) {
|
|
3541
|
+
return choosePreferredTokenRow(identifierMatches);
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
if (normalizedAccountId || normalizedEmail) {
|
|
3546
|
+
const legacyRows = rows.filter((row) => !normalizeAccountIdHint(row.accountId) && !normalizeAccountEmail(row.accountEmail));
|
|
3547
|
+
if (legacyRows.length === 1) {
|
|
3548
|
+
return choosePreferredTokenRow(legacyRows);
|
|
3549
|
+
}
|
|
3550
|
+
return;
|
|
3551
|
+
}
|
|
3552
|
+
return choosePreferredTokenRow(rows);
|
|
3553
|
+
}
|
|
3554
|
+
function providerTokenRecordToData(row) {
|
|
3555
|
+
const expiresAt = hasMeaningfulExpiresAt(row.expiresAt) ? row.expiresAt : null;
|
|
3556
|
+
const expiresIn = expiresAt ? Math.max(0, Math.floor((expiresAt.getTime() - Date.now()) / 1000)) : 3600;
|
|
3557
|
+
return {
|
|
3558
|
+
accessToken: row.accessToken,
|
|
3559
|
+
refreshToken: row.refreshToken ?? undefined,
|
|
3560
|
+
tokenType: normalizeProviderTokenType(row.tokenType),
|
|
3561
|
+
expiresIn,
|
|
3562
|
+
expiresAt: expiresAt?.toISOString(),
|
|
3563
|
+
scopes: parseScopes(row.scope),
|
|
3564
|
+
email: row.accountEmail ?? undefined,
|
|
3565
|
+
accountId: row.accountId ?? undefined
|
|
3566
|
+
};
|
|
3567
|
+
}
|
|
3568
|
+
function listConnectedProvidersFromRows(rows, configuredIntegrationIds) {
|
|
3569
|
+
const allowed = configuredIntegrationIds ? new Set(configuredIntegrationIds) : undefined;
|
|
3570
|
+
const rowsByProvider = new Map;
|
|
3571
|
+
for (const row of rows) {
|
|
3572
|
+
if (allowed && !allowed.has(row.provider))
|
|
3573
|
+
continue;
|
|
3574
|
+
const existing = rowsByProvider.get(row.provider);
|
|
3575
|
+
if (existing) {
|
|
3576
|
+
existing.push(row);
|
|
3577
|
+
} else {
|
|
3578
|
+
rowsByProvider.set(row.provider, [row]);
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
const connected = [];
|
|
3582
|
+
for (const [provider, providerRows] of rowsByProvider.entries()) {
|
|
3583
|
+
const selected = selectProviderTokenRow(providerRows);
|
|
3584
|
+
if (selected && isLikelyUsableToken(selected)) {
|
|
3585
|
+
connected.push(provider);
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
return connected.sort();
|
|
3589
|
+
}
|
|
3590
|
+
async function listConnectedProviders(configuredIntegrationIds, getProviderToken, context) {
|
|
3591
|
+
if (!context.userId || configuredIntegrationIds.length === 0) {
|
|
3592
|
+
return [];
|
|
3593
|
+
}
|
|
3594
|
+
const connected = [];
|
|
3595
|
+
await Promise.all(configuredIntegrationIds.map(async (provider) => {
|
|
3596
|
+
try {
|
|
3597
|
+
const token = await getProviderToken(provider, undefined, context);
|
|
3598
|
+
if (token?.accessToken || typeof token?.refreshToken === "string" && token.refreshToken.length > 0) {
|
|
3599
|
+
connected.push(provider);
|
|
3600
|
+
}
|
|
3601
|
+
} catch {}
|
|
3602
|
+
}));
|
|
3603
|
+
return connected.sort();
|
|
3604
|
+
}
|
|
3605
|
+
function defaultResolveAccountIdentity(provider, tokenData, emailHint) {
|
|
3606
|
+
const accountEmail = normalizeAccountEmail(emailHint ?? tokenData.email ?? null);
|
|
3607
|
+
let accountId = normalizeAccountIdHint(tokenData.accountId ?? null);
|
|
3608
|
+
if (!accountId && accountEmail) {
|
|
3609
|
+
accountId = `${provider}:${accountEmail}`;
|
|
3610
|
+
}
|
|
3611
|
+
return { accountEmail, accountId };
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
// src/client.ts
|
|
3452
3615
|
init_errors();
|
|
3453
3616
|
init_logger();
|
|
3454
3617
|
|
|
@@ -5135,7 +5298,7 @@ class MCPClientBase {
|
|
|
5135
5298
|
logger5.debug(`Discovered ${totalDiscovered} tools, ${enabledCount} enabled by integrations`);
|
|
5136
5299
|
}
|
|
5137
5300
|
async _callToolByName(name, args, options) {
|
|
5138
|
-
return await this.
|
|
5301
|
+
return await this.callTool(name, args, options);
|
|
5139
5302
|
}
|
|
5140
5303
|
async callTool(name, args, options) {
|
|
5141
5304
|
return await this.callToolWithRetry(name, args, 0, options);
|
|
@@ -5314,20 +5477,32 @@ class MCPClientBase {
|
|
|
5314
5477
|
getEnabledTools() {
|
|
5315
5478
|
return Array.from(this.availableTools.values()).filter((tool) => this.enabledToolNames.has(tool.name));
|
|
5316
5479
|
}
|
|
5317
|
-
async getEnabledToolsAsync() {
|
|
5318
|
-
|
|
5319
|
-
|
|
5480
|
+
async getEnabledToolsAsync(options) {
|
|
5481
|
+
const targetIntegrationIds = await this.resolveTargetIntegrationIds(options);
|
|
5482
|
+
if (targetIntegrationIds.size === 0) {
|
|
5483
|
+
return [];
|
|
5320
5484
|
}
|
|
5321
|
-
|
|
5322
|
-
|
|
5485
|
+
const filterToTargets = (tools2) => this.filterToolsToIntegrations(tools2, targetIntegrationIds);
|
|
5486
|
+
const hasCompleteCache = () => {
|
|
5487
|
+
for (const integration of this.integrations) {
|
|
5488
|
+
if (!targetIntegrationIds.has(integration.id))
|
|
5489
|
+
continue;
|
|
5490
|
+
for (const toolName of integration.tools) {
|
|
5491
|
+
if (!this.enabledToolNames.has(toolName))
|
|
5492
|
+
continue;
|
|
5493
|
+
if (!this.availableTools.has(toolName))
|
|
5494
|
+
return false;
|
|
5495
|
+
}
|
|
5496
|
+
}
|
|
5497
|
+
return this.availableTools.size > 0;
|
|
5498
|
+
};
|
|
5499
|
+
if (this.availableTools.size > 0 && hasCompleteCache()) {
|
|
5500
|
+
return filterToTargets(this.getEnabledTools());
|
|
5323
5501
|
}
|
|
5324
5502
|
const tools = [];
|
|
5325
|
-
const integrationIds = new Set;
|
|
5326
|
-
for (const integration of this.integrations) {
|
|
5327
|
-
integrationIds.add(integration.id);
|
|
5328
|
-
}
|
|
5329
5503
|
const { parallelWithLimit: parallelWithLimit2 } = await Promise.resolve().then(() => exports_concurrency);
|
|
5330
|
-
const
|
|
5504
|
+
const concurrency = options?.fetchConcurrency ?? 8;
|
|
5505
|
+
const integrationToolsResults = await parallelWithLimit2(Array.from(targetIntegrationIds), async (integrationId) => {
|
|
5331
5506
|
try {
|
|
5332
5507
|
const response = await this.callServerToolInternal("list_tools_by_integration", {
|
|
5333
5508
|
integration: integrationId
|
|
@@ -5338,25 +5513,14 @@ class MCPClientBase {
|
|
|
5338
5513
|
if (item.type === "text" && item.text) {
|
|
5339
5514
|
try {
|
|
5340
5515
|
const parsed = JSON.parse(item.text);
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
}
|
|
5350
|
-
}
|
|
5351
|
-
} else if (parsed.tools && Array.isArray(parsed.tools)) {
|
|
5352
|
-
for (const tool of parsed.tools) {
|
|
5353
|
-
if (tool.name && tool.inputSchema) {
|
|
5354
|
-
integrationTools.push({
|
|
5355
|
-
name: tool.name,
|
|
5356
|
-
description: tool.description,
|
|
5357
|
-
inputSchema: tool.inputSchema
|
|
5358
|
-
});
|
|
5359
|
-
}
|
|
5516
|
+
const parsedTools = Array.isArray(parsed) ? parsed : parsed.tools && Array.isArray(parsed.tools) ? parsed.tools : [];
|
|
5517
|
+
for (const tool of parsedTools) {
|
|
5518
|
+
if (tool.name && tool.inputSchema) {
|
|
5519
|
+
integrationTools.push({
|
|
5520
|
+
name: tool.name,
|
|
5521
|
+
description: tool.description,
|
|
5522
|
+
inputSchema: tool.inputSchema
|
|
5523
|
+
});
|
|
5360
5524
|
}
|
|
5361
5525
|
}
|
|
5362
5526
|
} catch {}
|
|
@@ -5368,14 +5532,40 @@ class MCPClientBase {
|
|
|
5368
5532
|
logger5.error(`Failed to fetch tools for integration ${integrationId}:`, error);
|
|
5369
5533
|
return [];
|
|
5370
5534
|
}
|
|
5371
|
-
},
|
|
5535
|
+
}, concurrency);
|
|
5372
5536
|
for (const integrationTools of integrationToolsResults) {
|
|
5373
5537
|
tools.push(...integrationTools);
|
|
5374
5538
|
}
|
|
5375
5539
|
for (const tool of tools) {
|
|
5376
5540
|
this.availableTools.set(tool.name, tool);
|
|
5377
5541
|
}
|
|
5378
|
-
return tools.filter((tool) => this.enabledToolNames.has(tool.name));
|
|
5542
|
+
return filterToTargets(tools.filter((tool) => this.enabledToolNames.has(tool.name)));
|
|
5543
|
+
}
|
|
5544
|
+
async resolveTargetIntegrationIds(options) {
|
|
5545
|
+
const configuredIds = this.integrations.map((integration) => integration.id);
|
|
5546
|
+
const configuredSet = new Set(configuredIds);
|
|
5547
|
+
if (options?.integrationIds && options.integrationIds.length > 0) {
|
|
5548
|
+
return new Set(options.integrationIds.filter((id) => configuredSet.has(id)));
|
|
5549
|
+
}
|
|
5550
|
+
if (options?.connectedOnly && options.context?.userId) {
|
|
5551
|
+
const connected = await listConnectedProviders(configuredIds, (provider, email, context) => this.oauthManager.getProviderToken(provider, email, context), options.context);
|
|
5552
|
+
return new Set(connected);
|
|
5553
|
+
}
|
|
5554
|
+
return configuredSet;
|
|
5555
|
+
}
|
|
5556
|
+
filterToolsToIntegrations(tools, integrationIds) {
|
|
5557
|
+
if (integrationIds.size === 0) {
|
|
5558
|
+
return [];
|
|
5559
|
+
}
|
|
5560
|
+
const allowedNames = new Set;
|
|
5561
|
+
for (const integration of this.integrations) {
|
|
5562
|
+
if (!integrationIds.has(integration.id))
|
|
5563
|
+
continue;
|
|
5564
|
+
for (const toolName of integration.tools) {
|
|
5565
|
+
allowedNames.add(toolName);
|
|
5566
|
+
}
|
|
5567
|
+
}
|
|
5568
|
+
return tools.filter((tool) => this.enabledToolNames.has(tool.name) && allowedNames.has(tool.name));
|
|
5379
5569
|
}
|
|
5380
5570
|
getOAuthConfig(integrationId) {
|
|
5381
5571
|
const integration = this.integrations.find((p) => p.id === integrationId);
|
|
@@ -5958,6 +6148,51 @@ async function sendWebResponse(webRes, nodeRes) {
|
|
|
5958
6148
|
// src/server.ts
|
|
5959
6149
|
init_logger();
|
|
5960
6150
|
|
|
6151
|
+
// src/utils/normalize-tool-name.ts
|
|
6152
|
+
var TOOL_ALIASES = {
|
|
6153
|
+
github_list_repo_contents: "github_get_file_contents",
|
|
6154
|
+
gdrive_list: "gdrive_list_files",
|
|
6155
|
+
gdrive_get: "gdrive_get_file",
|
|
6156
|
+
gdrive_delete: "gdrive_delete_file",
|
|
6157
|
+
gdrive_trash: "gdrive_trash_file",
|
|
6158
|
+
gdrive_upload: "gdrive_upload_text_file",
|
|
6159
|
+
gdrive_download: "gdrive_download_file",
|
|
6160
|
+
slack_send: "slack_send_message",
|
|
6161
|
+
gmail_send: "gmail_send_email",
|
|
6162
|
+
notion_create_page: "notion_create_page"
|
|
6163
|
+
};
|
|
6164
|
+
function normalizeToolName(toolName, integrationCandidates = []) {
|
|
6165
|
+
if (TOOL_ALIASES[toolName]) {
|
|
6166
|
+
return TOOL_ALIASES[toolName];
|
|
6167
|
+
}
|
|
6168
|
+
const tripleIdx = toolName.indexOf("___");
|
|
6169
|
+
if (tripleIdx > 0) {
|
|
6170
|
+
const prefix = toolName.slice(0, tripleIdx);
|
|
6171
|
+
const suffix = toolName.slice(tripleIdx + 3);
|
|
6172
|
+
if (integrationCandidates.some((c) => c === prefix)) {
|
|
6173
|
+
if (suffix.startsWith("_")) {
|
|
6174
|
+
return `___${suffix.slice(1)}`;
|
|
6175
|
+
}
|
|
6176
|
+
return `${prefix}_${suffix}`;
|
|
6177
|
+
}
|
|
6178
|
+
}
|
|
6179
|
+
for (const candidate of integrationCandidates) {
|
|
6180
|
+
const doublePrefix = `${candidate}_${candidate}_`;
|
|
6181
|
+
if (toolName.startsWith(doublePrefix)) {
|
|
6182
|
+
return `${candidate}_${toolName.slice(doublePrefix.length)}`;
|
|
6183
|
+
}
|
|
6184
|
+
}
|
|
6185
|
+
const firstUnderscore = toolName.indexOf("_");
|
|
6186
|
+
if (firstUnderscore > 0) {
|
|
6187
|
+
const prefix = toolName.slice(0, firstUnderscore);
|
|
6188
|
+
const rest = toolName.slice(firstUnderscore + 1);
|
|
6189
|
+
if (integrationCandidates.includes(prefix) && rest.startsWith(`${prefix}_`)) {
|
|
6190
|
+
return `${prefix}_${rest.slice(prefix.length + 1)}`;
|
|
6191
|
+
}
|
|
6192
|
+
}
|
|
6193
|
+
return toolName;
|
|
6194
|
+
}
|
|
6195
|
+
|
|
5961
6196
|
// src/integrations/github.ts
|
|
5962
6197
|
init_logger();
|
|
5963
6198
|
var logger8 = createLogger("GitHub");
|
|
@@ -18330,6 +18565,15 @@ var coerce = {
|
|
|
18330
18565
|
};
|
|
18331
18566
|
var NEVER = INVALID;
|
|
18332
18567
|
// src/ai/utils.ts
|
|
18568
|
+
function toEnabledToolsAsyncOptions(options) {
|
|
18569
|
+
if (!options)
|
|
18570
|
+
return;
|
|
18571
|
+
const { integrationIds, connectedOnly, context, fetchConcurrency } = options;
|
|
18572
|
+
if (integrationIds === undefined && connectedOnly === undefined && context === undefined && fetchConcurrency === undefined) {
|
|
18573
|
+
return;
|
|
18574
|
+
}
|
|
18575
|
+
return { integrationIds, connectedOnly, context, fetchConcurrency };
|
|
18576
|
+
}
|
|
18333
18577
|
function getProviderForTool(client, toolName) {
|
|
18334
18578
|
return client.getProviderForTool?.(toolName);
|
|
18335
18579
|
}
|
|
@@ -18635,6 +18879,82 @@ function createTriggerTools(config, context) {
|
|
|
18635
18879
|
|
|
18636
18880
|
// src/ai/vercel-ai.ts
|
|
18637
18881
|
init_tool_builder();
|
|
18882
|
+
|
|
18883
|
+
// src/ai/tool-cache.ts
|
|
18884
|
+
function buildToolDiscoveryCacheKey(userId, connectedIntegrationIds) {
|
|
18885
|
+
const sorted = [...connectedIntegrationIds].sort().join(",");
|
|
18886
|
+
return `${userId}:${sorted}`;
|
|
18887
|
+
}
|
|
18888
|
+
function createMemoryToolDiscoveryCache() {
|
|
18889
|
+
const store = new Map;
|
|
18890
|
+
return {
|
|
18891
|
+
async get(key) {
|
|
18892
|
+
const entry = store.get(key);
|
|
18893
|
+
if (!entry)
|
|
18894
|
+
return null;
|
|
18895
|
+
if (entry.expiresAt <= Date.now()) {
|
|
18896
|
+
store.delete(key);
|
|
18897
|
+
return null;
|
|
18898
|
+
}
|
|
18899
|
+
return entry.stubs;
|
|
18900
|
+
},
|
|
18901
|
+
async set(key, stubs, ttlMs = 5 * 60 * 1000) {
|
|
18902
|
+
store.set(key, { stubs, expiresAt: Date.now() + ttlMs });
|
|
18903
|
+
},
|
|
18904
|
+
async invalidate(userIdOrKey) {
|
|
18905
|
+
for (const key of [...store.keys()]) {
|
|
18906
|
+
if (key === userIdOrKey || key.startsWith(`${userIdOrKey}:`)) {
|
|
18907
|
+
store.delete(key);
|
|
18908
|
+
}
|
|
18909
|
+
}
|
|
18910
|
+
}
|
|
18911
|
+
};
|
|
18912
|
+
}
|
|
18913
|
+
function createToolDiscoveryCacheInvalidator(cache) {
|
|
18914
|
+
return ({ userId }) => {
|
|
18915
|
+
cache.invalidate(userId);
|
|
18916
|
+
};
|
|
18917
|
+
}
|
|
18918
|
+
async function resolveToolDiscoveryCacheKey(client, context, options) {
|
|
18919
|
+
const userId = context.userId;
|
|
18920
|
+
if (!userId)
|
|
18921
|
+
return;
|
|
18922
|
+
const configuredIds = (client.integrations ?? []).map((i) => i.id);
|
|
18923
|
+
let targetIds;
|
|
18924
|
+
if (options?.integrationIds?.length) {
|
|
18925
|
+
targetIds = options.integrationIds;
|
|
18926
|
+
} else if (options?.connectedOnly) {
|
|
18927
|
+
targetIds = await listConnectedProviders(configuredIds, (provider, email, ctx) => client.getProviderToken(provider, email, ctx), context);
|
|
18928
|
+
} else {
|
|
18929
|
+
targetIds = configuredIds;
|
|
18930
|
+
}
|
|
18931
|
+
return buildToolDiscoveryCacheKey(userId, targetIds);
|
|
18932
|
+
}
|
|
18933
|
+
function stubsFromTools(tools) {
|
|
18934
|
+
return tools.map((t) => ({
|
|
18935
|
+
name: t.name,
|
|
18936
|
+
description: t.description,
|
|
18937
|
+
inputSchema: t.inputSchema
|
|
18938
|
+
}));
|
|
18939
|
+
}
|
|
18940
|
+
function applyToolDiscoveryCache(client, stubs) {
|
|
18941
|
+
client.hydrateToolCache(stubs);
|
|
18942
|
+
}
|
|
18943
|
+
async function persistToolDiscoveryCache(client, cache, cacheKey, ttlMs) {
|
|
18944
|
+
const tools = client.getAvailableTools();
|
|
18945
|
+
if (tools.length === 0)
|
|
18946
|
+
return;
|
|
18947
|
+
await cache.set(cacheKey, stubsFromTools(tools), ttlMs);
|
|
18948
|
+
}
|
|
18949
|
+
async function warmToolDiscoveryFromCache(client, cache, cacheKey) {
|
|
18950
|
+
const stubs = await cache.get(cacheKey);
|
|
18951
|
+
if (!stubs || stubs.length === 0)
|
|
18952
|
+
return false;
|
|
18953
|
+
applyToolDiscoveryCache(client, stubs);
|
|
18954
|
+
return true;
|
|
18955
|
+
}
|
|
18956
|
+
|
|
18957
|
+
// src/ai/vercel-ai.ts
|
|
18638
18958
|
function convertMCPToolToVercelAI(mcpTool, client, options) {
|
|
18639
18959
|
return {
|
|
18640
18960
|
description: mcpTool.description || `Execute ${mcpTool.name}`,
|
|
@@ -18656,7 +18976,21 @@ async function getVercelAITools(client, options) {
|
|
|
18656
18976
|
}
|
|
18657
18977
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
18658
18978
|
await ensureClientConnected(client);
|
|
18659
|
-
const
|
|
18979
|
+
const cacheConfig = options?.cache;
|
|
18980
|
+
let cacheKey;
|
|
18981
|
+
if (cacheConfig?.cache && options?.context) {
|
|
18982
|
+
cacheKey = await resolveToolDiscoveryCacheKey(client, options.context, {
|
|
18983
|
+
integrationIds: options.integrationIds,
|
|
18984
|
+
connectedOnly: options.connectedOnly
|
|
18985
|
+
});
|
|
18986
|
+
if (cacheKey) {
|
|
18987
|
+
await warmToolDiscoveryFromCache(client, cacheConfig.cache, cacheKey);
|
|
18988
|
+
}
|
|
18989
|
+
}
|
|
18990
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
18991
|
+
if (cacheConfig?.cache && cacheKey) {
|
|
18992
|
+
await persistToolDiscoveryCache(client, cacheConfig.cache, cacheKey, cacheConfig.ttlMs);
|
|
18993
|
+
}
|
|
18660
18994
|
const vercelTools = {};
|
|
18661
18995
|
let effectiveMode;
|
|
18662
18996
|
if (options?.mode !== undefined) {
|
|
@@ -19962,7 +20296,7 @@ async function getOpenAITools(client, options) {
|
|
|
19962
20296
|
}
|
|
19963
20297
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
19964
20298
|
await ensureClientConnected(client);
|
|
19965
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20299
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
19966
20300
|
let effectiveMode;
|
|
19967
20301
|
if (options?.mode !== undefined) {
|
|
19968
20302
|
effectiveMode = options.mode;
|
|
@@ -20024,7 +20358,7 @@ async function handleOpenAIToolCalls(client, toolCalls, options) {
|
|
|
20024
20358
|
const getCodeModeTool = async () => {
|
|
20025
20359
|
if (cachedCodeModeTool)
|
|
20026
20360
|
return cachedCodeModeTool;
|
|
20027
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20361
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
20028
20362
|
cachedCodeModeTool = buildCodeModeTool(client, {
|
|
20029
20363
|
tools: mcpTools,
|
|
20030
20364
|
providerTokens: options?.providerTokens,
|
|
@@ -20108,7 +20442,7 @@ async function handleAnthropicToolCalls(client, messageContent, options) {
|
|
|
20108
20442
|
const getCodeModeTool = async () => {
|
|
20109
20443
|
if (cachedCodeModeTool)
|
|
20110
20444
|
return cachedCodeModeTool;
|
|
20111
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20445
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
20112
20446
|
cachedCodeModeTool = buildCodeModeTool(client, {
|
|
20113
20447
|
tools: mcpTools,
|
|
20114
20448
|
providerTokens: options?.providerTokens,
|
|
@@ -20159,7 +20493,7 @@ async function getAnthropicTools(client, options) {
|
|
|
20159
20493
|
}
|
|
20160
20494
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
20161
20495
|
await ensureClientConnected(client);
|
|
20162
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20496
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
20163
20497
|
let effectiveMode;
|
|
20164
20498
|
if (options?.mode !== undefined) {
|
|
20165
20499
|
effectiveMode = options.mode;
|
|
@@ -20325,7 +20659,7 @@ async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
|
20325
20659
|
const getCodeModeTool = async () => {
|
|
20326
20660
|
if (cachedCodeModeTool)
|
|
20327
20661
|
return cachedCodeModeTool;
|
|
20328
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20662
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
20329
20663
|
cachedCodeModeTool = buildCodeModeTool(client, {
|
|
20330
20664
|
tools: mcpTools,
|
|
20331
20665
|
providerTokens: finalOptions?.providerTokens,
|
|
@@ -20364,7 +20698,7 @@ async function getGoogleTools(client, options) {
|
|
|
20364
20698
|
}
|
|
20365
20699
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
20366
20700
|
await ensureClientConnected(client);
|
|
20367
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
20701
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
20368
20702
|
let effectiveMode;
|
|
20369
20703
|
if (options?.mode !== undefined) {
|
|
20370
20704
|
effectiveMode = options.mode;
|
|
@@ -21233,130 +21567,126 @@ function zohoSprintsIntegration(config = {}) {
|
|
|
21233
21567
|
}
|
|
21234
21568
|
};
|
|
21235
21569
|
}
|
|
21236
|
-
// src/
|
|
21237
|
-
|
|
21238
|
-
|
|
21239
|
-
|
|
21240
|
-
|
|
21241
|
-
|
|
21242
|
-
|
|
21243
|
-
|
|
21244
|
-
|
|
21245
|
-
|
|
21246
|
-
|
|
21247
|
-
|
|
21248
|
-
|
|
21249
|
-
|
|
21250
|
-
|
|
21251
|
-
|
|
21252
|
-
|
|
21253
|
-
|
|
21254
|
-
|
|
21255
|
-
|
|
21256
|
-
|
|
21257
|
-
|
|
21258
|
-
|
|
21259
|
-
|
|
21260
|
-
|
|
21261
|
-
|
|
21262
|
-
|
|
21263
|
-
|
|
21264
|
-
|
|
21265
|
-
|
|
21266
|
-
|
|
21267
|
-
|
|
21268
|
-
|
|
21269
|
-
|
|
21270
|
-
|
|
21271
|
-
|
|
21272
|
-
|
|
21273
|
-
|
|
21274
|
-
|
|
21275
|
-
|
|
21276
|
-
|
|
21277
|
-
|
|
21278
|
-
|
|
21279
|
-
|
|
21280
|
-
|
|
21281
|
-
|
|
21282
|
-
|
|
21283
|
-
|
|
21284
|
-
|
|
21285
|
-
|
|
21286
|
-
|
|
21287
|
-
|
|
21288
|
-
|
|
21289
|
-
|
|
21290
|
-
|
|
21291
|
-
|
|
21292
|
-
|
|
21293
|
-
|
|
21294
|
-
|
|
21295
|
-
|
|
21296
|
-
|
|
21297
|
-
|
|
21298
|
-
|
|
21299
|
-
|
|
21300
|
-
|
|
21301
|
-
|
|
21302
|
-
|
|
21303
|
-
|
|
21304
|
-
|
|
21305
|
-
|
|
21306
|
-
|
|
21307
|
-
|
|
21308
|
-
|
|
21309
|
-
|
|
21310
|
-
|
|
21311
|
-
|
|
21312
|
-
|
|
21313
|
-
|
|
21314
|
-
|
|
21315
|
-
|
|
21316
|
-
|
|
21317
|
-
|
|
21318
|
-
|
|
21319
|
-
|
|
21320
|
-
|
|
21321
|
-
|
|
21322
|
-
|
|
21323
|
-
|
|
21324
|
-
|
|
21325
|
-
|
|
21326
|
-
|
|
21327
|
-
|
|
21328
|
-
|
|
21329
|
-
|
|
21330
|
-
|
|
21331
|
-
|
|
21332
|
-
|
|
21333
|
-
|
|
21334
|
-
|
|
21335
|
-
|
|
21336
|
-
|
|
21337
|
-
|
|
21338
|
-
|
|
21339
|
-
|
|
21340
|
-
|
|
21341
|
-
|
|
21342
|
-
|
|
21343
|
-
|
|
21344
|
-
|
|
21345
|
-
|
|
21346
|
-
|
|
21347
|
-
|
|
21348
|
-
accountId: row.accountId ?? undefined
|
|
21349
|
-
};
|
|
21570
|
+
// src/integrations/bundle.ts
|
|
21571
|
+
function allIntegrations() {
|
|
21572
|
+
return [
|
|
21573
|
+
githubIntegration(),
|
|
21574
|
+
gmailIntegration(),
|
|
21575
|
+
notionIntegration(),
|
|
21576
|
+
slackIntegration(),
|
|
21577
|
+
discordIntegration(),
|
|
21578
|
+
boxIntegration(),
|
|
21579
|
+
paypalIntegration(),
|
|
21580
|
+
squareIntegration(),
|
|
21581
|
+
spotifyIntegration(),
|
|
21582
|
+
stravaIntegration(),
|
|
21583
|
+
asanaIntegration(),
|
|
21584
|
+
confluenceIntegration(),
|
|
21585
|
+
oktaIntegration(),
|
|
21586
|
+
quickbooksIntegration(),
|
|
21587
|
+
bitbucketIntegration(),
|
|
21588
|
+
smartthingsIntegration(),
|
|
21589
|
+
googleAdsIntegration(),
|
|
21590
|
+
pinterestIntegration(),
|
|
21591
|
+
twitchIntegration(),
|
|
21592
|
+
xIntegration(),
|
|
21593
|
+
ebayIntegration(),
|
|
21594
|
+
miroIntegration(),
|
|
21595
|
+
smartsheetIntegration(),
|
|
21596
|
+
docusignIntegration(),
|
|
21597
|
+
pipedriveIntegration(),
|
|
21598
|
+
freshserviceIntegration(),
|
|
21599
|
+
zohoCrmIntegration(),
|
|
21600
|
+
zohoMailIntegration(),
|
|
21601
|
+
zohoDeskIntegration(),
|
|
21602
|
+
zohoBooksIntegration(),
|
|
21603
|
+
zohoProjectsIntegration(),
|
|
21604
|
+
zohoCampaignsIntegration(),
|
|
21605
|
+
zohoAnalyticsIntegration(),
|
|
21606
|
+
zohoInvoiceIntegration(),
|
|
21607
|
+
linearIntegration(),
|
|
21608
|
+
vercelIntegration(),
|
|
21609
|
+
zendeskIntegration(),
|
|
21610
|
+
stripeIntegration(),
|
|
21611
|
+
gcalIntegration(),
|
|
21612
|
+
gmeetIntegration(),
|
|
21613
|
+
gtasksIntegration(),
|
|
21614
|
+
gkeepIntegration(),
|
|
21615
|
+
gcontactsIntegration(),
|
|
21616
|
+
outlookIntegration(),
|
|
21617
|
+
teamsIntegration(),
|
|
21618
|
+
airtableIntegration(),
|
|
21619
|
+
attioIntegration(),
|
|
21620
|
+
todoistIntegration(),
|
|
21621
|
+
whatsappIntegration(),
|
|
21622
|
+
calcomIntegration(),
|
|
21623
|
+
canvaIntegration(),
|
|
21624
|
+
cloudflareIntegration(),
|
|
21625
|
+
rampIntegration(),
|
|
21626
|
+
onedriveIntegration(),
|
|
21627
|
+
plannerIntegration(),
|
|
21628
|
+
sharepointIntegration(),
|
|
21629
|
+
wordIntegration(),
|
|
21630
|
+
excelIntegration(),
|
|
21631
|
+
powerpointIntegration(),
|
|
21632
|
+
gdocsIntegration(),
|
|
21633
|
+
gdriveIntegration(),
|
|
21634
|
+
gsheetsIntegration(),
|
|
21635
|
+
gslidesIntegration(),
|
|
21636
|
+
polarIntegration(),
|
|
21637
|
+
facebookIntegration(),
|
|
21638
|
+
figmaIntegration(),
|
|
21639
|
+
intercomIntegration(),
|
|
21640
|
+
hubspotIntegration(),
|
|
21641
|
+
instagramIntegration(),
|
|
21642
|
+
linkedinIntegration(),
|
|
21643
|
+
threadsIntegration(),
|
|
21644
|
+
tiktokIntegration(),
|
|
21645
|
+
typeformIntegration(),
|
|
21646
|
+
xeroIntegration(),
|
|
21647
|
+
gchatIntegration(),
|
|
21648
|
+
shopifyIntegration(),
|
|
21649
|
+
youtubeIntegration(),
|
|
21650
|
+
zoomIntegration(),
|
|
21651
|
+
redditIntegration(),
|
|
21652
|
+
cursorIntegration(),
|
|
21653
|
+
posthogIntegration(),
|
|
21654
|
+
sentryIntegration(),
|
|
21655
|
+
datadogIntegration(),
|
|
21656
|
+
netlifyIntegration(),
|
|
21657
|
+
mondayIntegration(),
|
|
21658
|
+
webflowIntegration(),
|
|
21659
|
+
jiraIntegration(),
|
|
21660
|
+
salesforceIntegration(),
|
|
21661
|
+
workdayIntegration(),
|
|
21662
|
+
calendlyIntegration(),
|
|
21663
|
+
klaviyoIntegration(),
|
|
21664
|
+
googleFormsIntegration(),
|
|
21665
|
+
firebaseIntegration(),
|
|
21666
|
+
microsoftToDoIntegration(),
|
|
21667
|
+
onenoteIntegration(),
|
|
21668
|
+
microsoftBookingsIntegration(),
|
|
21669
|
+
azureDevopsIntegration(),
|
|
21670
|
+
googlePlayConsoleIntegration(),
|
|
21671
|
+
squarespaceIntegration(),
|
|
21672
|
+
zohoPeopleIntegration(),
|
|
21673
|
+
zohoRecruitIntegration(),
|
|
21674
|
+
zohoSignIntegration(),
|
|
21675
|
+
zohoWorkdriveIntegration(),
|
|
21676
|
+
zohoCreatorIntegration(),
|
|
21677
|
+
zohoInventoryIntegration(),
|
|
21678
|
+
zohoBillingIntegration(),
|
|
21679
|
+
zohoWriterIntegration(),
|
|
21680
|
+
zohoSprintsIntegration()
|
|
21681
|
+
];
|
|
21350
21682
|
}
|
|
21351
|
-
function
|
|
21352
|
-
const
|
|
21353
|
-
|
|
21354
|
-
|
|
21355
|
-
|
|
21356
|
-
|
|
21357
|
-
return { accountEmail, accountId };
|
|
21683
|
+
function createIntegrationBundle(options) {
|
|
21684
|
+
const all = allIntegrations();
|
|
21685
|
+
if (!options?.include?.length)
|
|
21686
|
+
return all;
|
|
21687
|
+
const allowed = new Set(options.include);
|
|
21688
|
+
return all.filter((i) => allowed.has(i.id));
|
|
21358
21689
|
}
|
|
21359
|
-
|
|
21360
21690
|
// src/database/trigger-store.ts
|
|
21361
21691
|
function toIsoString(value) {
|
|
21362
21692
|
if (!value)
|
|
@@ -24693,6 +25023,69 @@ var integrateTrigger = pgTable("trigger", {
|
|
|
24693
25023
|
index("trigger_status_idx").on(table.status),
|
|
24694
25024
|
index("trigger_next_run_at_idx").on(table.nextRunAt)
|
|
24695
25025
|
]);
|
|
25026
|
+
// src/utils/parse-tool-result.ts
|
|
25027
|
+
function isRecord(value) {
|
|
25028
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25029
|
+
}
|
|
25030
|
+
function getBooleanProperty(value, key) {
|
|
25031
|
+
const property = value[key];
|
|
25032
|
+
return typeof property === "boolean" ? property : undefined;
|
|
25033
|
+
}
|
|
25034
|
+
function getStringProperty(value, key) {
|
|
25035
|
+
const property = value[key];
|
|
25036
|
+
if (typeof property !== "string") {
|
|
25037
|
+
return;
|
|
25038
|
+
}
|
|
25039
|
+
const trimmed = property.trim();
|
|
25040
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
25041
|
+
}
|
|
25042
|
+
function getStructuredContent(result) {
|
|
25043
|
+
const structuredContent = result.structuredContent;
|
|
25044
|
+
return isRecord(structuredContent) ? structuredContent : undefined;
|
|
25045
|
+
}
|
|
25046
|
+
function getContentText(result) {
|
|
25047
|
+
const content = result.content;
|
|
25048
|
+
if (!Array.isArray(content)) {
|
|
25049
|
+
return;
|
|
25050
|
+
}
|
|
25051
|
+
for (const item of content) {
|
|
25052
|
+
if (!isRecord(item)) {
|
|
25053
|
+
continue;
|
|
25054
|
+
}
|
|
25055
|
+
const text2 = getStringProperty(item, "text");
|
|
25056
|
+
if (text2) {
|
|
25057
|
+
return text2;
|
|
25058
|
+
}
|
|
25059
|
+
}
|
|
25060
|
+
return;
|
|
25061
|
+
}
|
|
25062
|
+
function isMCPToolError(result) {
|
|
25063
|
+
return parseMCPToolResult(result).ok === false;
|
|
25064
|
+
}
|
|
25065
|
+
function parseMCPToolResult(result) {
|
|
25066
|
+
if (!isRecord(result)) {
|
|
25067
|
+
return {
|
|
25068
|
+
ok: true,
|
|
25069
|
+
data: result,
|
|
25070
|
+
raw: result
|
|
25071
|
+
};
|
|
25072
|
+
}
|
|
25073
|
+
const structuredContent = getStructuredContent(result);
|
|
25074
|
+
const failed = getBooleanProperty(result, "isError") === true || getBooleanProperty(result, "success") === false || getBooleanProperty(structuredContent ?? {}, "isError") === true || getBooleanProperty(structuredContent ?? {}, "success") === false;
|
|
25075
|
+
if (!failed) {
|
|
25076
|
+
return {
|
|
25077
|
+
ok: true,
|
|
25078
|
+
data: structuredContent ?? result,
|
|
25079
|
+
raw: result
|
|
25080
|
+
};
|
|
25081
|
+
}
|
|
25082
|
+
return {
|
|
25083
|
+
ok: false,
|
|
25084
|
+
error: getStringProperty(result, "error") ?? getStringProperty(structuredContent ?? {}, "error") ?? getContentText(result) ?? "Tool returned an error result",
|
|
25085
|
+
raw: result
|
|
25086
|
+
};
|
|
25087
|
+
}
|
|
25088
|
+
|
|
24696
25089
|
// src/server.ts
|
|
24697
25090
|
var SERVER_LOG_CONTEXT3 = "server";
|
|
24698
25091
|
var logger203 = createLogger("MCPServer", SERVER_LOG_CONTEXT3);
|
|
@@ -24766,33 +25159,6 @@ function resolveProviderFromToolName(toolName, candidates) {
|
|
|
24766
25159
|
}
|
|
24767
25160
|
return best;
|
|
24768
25161
|
}
|
|
24769
|
-
var TOOL_ALIASES = {
|
|
24770
|
-
github_list_repo_contents: "github_get_file_contents",
|
|
24771
|
-
gdrive_list: "gdrive_list_files",
|
|
24772
|
-
gdrive_get: "gdrive_get_file",
|
|
24773
|
-
gdrive_delete: "gdrive_delete_file",
|
|
24774
|
-
gdrive_trash: "gdrive_trash_file",
|
|
24775
|
-
gdrive_upload: "gdrive_upload_text_file",
|
|
24776
|
-
gdrive_download: "gdrive_download_file"
|
|
24777
|
-
};
|
|
24778
|
-
function normalizeToolName(toolName, candidates) {
|
|
24779
|
-
if (TOOL_ALIASES[toolName])
|
|
24780
|
-
return TOOL_ALIASES[toolName];
|
|
24781
|
-
const tripleIdx = toolName.indexOf("___");
|
|
24782
|
-
if (tripleIdx > 0) {
|
|
24783
|
-
const prefix = toolName.slice(0, tripleIdx);
|
|
24784
|
-
if (candidates.some((c) => c === prefix)) {
|
|
24785
|
-
return toolName.slice(tripleIdx);
|
|
24786
|
-
}
|
|
24787
|
-
}
|
|
24788
|
-
for (const candidate of candidates) {
|
|
24789
|
-
const doublePrefix = `${candidate}_${candidate}_`;
|
|
24790
|
-
if (toolName.startsWith(doublePrefix)) {
|
|
24791
|
-
return `${candidate}_${toolName.slice(doublePrefix.length)}`;
|
|
24792
|
-
}
|
|
24793
|
-
}
|
|
24794
|
-
return toolName;
|
|
24795
|
-
}
|
|
24796
25162
|
var unauthenticatedCodeModeWarnings = new Set;
|
|
24797
25163
|
function warnUnauthenticatedCodeModeCallback(details) {
|
|
24798
25164
|
if (unauthenticatedCodeModeWarnings.has(details.toolName))
|
|
@@ -24847,7 +25213,14 @@ function getDefaultRedirectUri() {
|
|
|
24847
25213
|
return "http://localhost:3000/api/integrate/oauth/callback";
|
|
24848
25214
|
}
|
|
24849
25215
|
function createMCPServer(inputConfig) {
|
|
24850
|
-
|
|
25216
|
+
let config = mergeDatabaseConfig(inputConfig);
|
|
25217
|
+
if (config.enabledProviders?.length) {
|
|
25218
|
+
const allowed = new Set(config.enabledProviders);
|
|
25219
|
+
config = {
|
|
25220
|
+
...config,
|
|
25221
|
+
integrations: config.integrations.filter((i) => allowed.has(i.id))
|
|
25222
|
+
};
|
|
25223
|
+
}
|
|
24851
25224
|
setLogLevel(config.debug ? "debug" : "error", SERVER_LOG_CONTEXT3);
|
|
24852
25225
|
if (typeof window !== "undefined") {
|
|
24853
25226
|
throw new Error("createMCPServer() should only be called on the server-side. " + "Use createMCPClient() for client-side code.");
|
|
@@ -25784,6 +26157,7 @@ export {
|
|
|
25784
26157
|
whoopIntegration,
|
|
25785
26158
|
whatsappIntegration,
|
|
25786
26159
|
webflowIntegration,
|
|
26160
|
+
warmToolDiscoveryFromCache,
|
|
25787
26161
|
vercelIntegration,
|
|
25788
26162
|
upstashIntegration,
|
|
25789
26163
|
upsIntegration,
|
|
@@ -25816,6 +26190,7 @@ export {
|
|
|
25816
26190
|
tableauIntegration,
|
|
25817
26191
|
svelteKitHandler,
|
|
25818
26192
|
supabaseIntegration,
|
|
26193
|
+
stubsFromTools,
|
|
25819
26194
|
stripeIntegration,
|
|
25820
26195
|
stravaIntegration,
|
|
25821
26196
|
storeCodeVerifier,
|
|
@@ -25835,6 +26210,7 @@ export {
|
|
|
25835
26210
|
salesforceIntegration,
|
|
25836
26211
|
sageIntegration,
|
|
25837
26212
|
ringIntegration,
|
|
26213
|
+
resolveToolDiscoveryCacheKey,
|
|
25838
26214
|
resendIntegration,
|
|
25839
26215
|
redisIntegration,
|
|
25840
26216
|
redditIntegration,
|
|
@@ -25855,8 +26231,10 @@ export {
|
|
|
25855
26231
|
pinterestIntegration,
|
|
25856
26232
|
philipsHueIntegration,
|
|
25857
26233
|
phantomIntegration,
|
|
26234
|
+
persistToolDiscoveryCache,
|
|
25858
26235
|
paypalIntegration,
|
|
25859
26236
|
parseScopes,
|
|
26237
|
+
parseMCPToolResult,
|
|
25860
26238
|
paperIntegration,
|
|
25861
26239
|
pandadocIntegration,
|
|
25862
26240
|
outlookIntegration,
|
|
@@ -25866,6 +26244,7 @@ export {
|
|
|
25866
26244
|
onedriveIntegration,
|
|
25867
26245
|
oktaIntegration,
|
|
25868
26246
|
notionIntegration,
|
|
26247
|
+
normalizeToolName,
|
|
25869
26248
|
normalizeProviderTokenType,
|
|
25870
26249
|
normalizeAccountIdentifier,
|
|
25871
26250
|
normalizeAccountIdHint,
|
|
@@ -25891,12 +26270,15 @@ export {
|
|
|
25891
26270
|
mapmyfitnessIntegration,
|
|
25892
26271
|
mailchimpIntegration,
|
|
25893
26272
|
lookerIntegration,
|
|
26273
|
+
listConnectedProvidersFromRows,
|
|
26274
|
+
listConnectedProviders,
|
|
25894
26275
|
linkedinIntegration,
|
|
25895
26276
|
linearIntegration,
|
|
25896
26277
|
leverIntegration,
|
|
25897
26278
|
klaviyoIntegration,
|
|
25898
26279
|
kickIntegration,
|
|
25899
26280
|
jiraIntegration,
|
|
26281
|
+
isMCPToolError,
|
|
25900
26282
|
isLikelyUsableToken,
|
|
25901
26283
|
intercomIntegration,
|
|
25902
26284
|
integrateTrigger,
|
|
@@ -25971,10 +26353,13 @@ export {
|
|
|
25971
26353
|
databricksIntegration,
|
|
25972
26354
|
cursorIntegration,
|
|
25973
26355
|
createTriggerTools,
|
|
26356
|
+
createToolDiscoveryCacheInvalidator,
|
|
25974
26357
|
createTanStackOAuthHandler,
|
|
25975
26358
|
createSimpleIntegration,
|
|
25976
26359
|
createNextOAuthHandler,
|
|
26360
|
+
createMemoryToolDiscoveryCache,
|
|
25977
26361
|
createMCPServer,
|
|
26362
|
+
createIntegrationBundle,
|
|
25978
26363
|
createDatabaseAdapterFactory,
|
|
25979
26364
|
createDatabaseAdapterCallbacks,
|
|
25980
26365
|
convexIntegration,
|
|
@@ -25987,6 +26372,7 @@ export {
|
|
|
25987
26372
|
canvaIntegration,
|
|
25988
26373
|
calendlyIntegration,
|
|
25989
26374
|
calcomIntegration,
|
|
26375
|
+
buildToolDiscoveryCacheKey,
|
|
25990
26376
|
buildPhantomBrowseDeeplink,
|
|
25991
26377
|
buildCodeModeTool,
|
|
25992
26378
|
boxIntegration,
|
|
@@ -26002,13 +26388,16 @@ export {
|
|
|
26002
26388
|
attioIntegration,
|
|
26003
26389
|
astronomerIntegration,
|
|
26004
26390
|
asanaIntegration,
|
|
26391
|
+
applyToolDiscoveryCache,
|
|
26005
26392
|
amazonIntegration,
|
|
26006
26393
|
amazonAdsIntegration,
|
|
26007
26394
|
amadeusIntegration,
|
|
26008
26395
|
alpacaIntegration,
|
|
26396
|
+
allIntegrations,
|
|
26009
26397
|
airtableIntegration,
|
|
26010
26398
|
adobeAcrobatSignIntegration,
|
|
26011
26399
|
__resetUnauthenticatedCodeModeWarnings,
|
|
26400
|
+
TOOL_ALIASES,
|
|
26012
26401
|
RUNTIME_STUB_SOURCE,
|
|
26013
26402
|
POST,
|
|
26014
26403
|
OAuthHandler,
|