integrate-sdk 0.9.56 → 0.9.58
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 +79 -34
- package/dist/adapters/solid-start.js +79 -34
- package/dist/adapters/svelte-kit.js +79 -34
- 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 +16 -7
- package/dist/ai/openai.d.ts.map +1 -1
- package/dist/ai/openai.js +11 -2
- package/dist/ai/utils.d.ts +21 -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 +10 -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 +77 -31
- package/dist/integrations.js +77 -31
- package/dist/server.js +239 -162
- 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/utils.d.ts +21 -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 +4 -2
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/config/types.d.ts +19 -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/server.d.ts +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/ai/openai.js
CHANGED
|
@@ -4060,6 +4060,15 @@ async function tryGetProviderTokens(manualTokens) {
|
|
|
4060
4060
|
}
|
|
4061
4061
|
|
|
4062
4062
|
// utils.ts
|
|
4063
|
+
function toEnabledToolsAsyncOptions(options) {
|
|
4064
|
+
if (!options)
|
|
4065
|
+
return;
|
|
4066
|
+
const { integrationIds, connectedOnly, context, fetchConcurrency } = options;
|
|
4067
|
+
if (integrationIds === undefined && connectedOnly === undefined && context === undefined && fetchConcurrency === undefined) {
|
|
4068
|
+
return;
|
|
4069
|
+
}
|
|
4070
|
+
return { integrationIds, connectedOnly, context, fetchConcurrency };
|
|
4071
|
+
}
|
|
4063
4072
|
function getProviderForTool(client, toolName) {
|
|
4064
4073
|
return client.getProviderForTool?.(toolName);
|
|
4065
4074
|
}
|
|
@@ -5141,7 +5150,7 @@ async function getOpenAITools(client, options) {
|
|
|
5141
5150
|
}
|
|
5142
5151
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
5143
5152
|
await ensureClientConnected(client);
|
|
5144
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
5153
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
5145
5154
|
let effectiveMode;
|
|
5146
5155
|
if (options?.mode !== undefined) {
|
|
5147
5156
|
effectiveMode = options.mode;
|
|
@@ -5203,7 +5212,7 @@ async function handleOpenAIToolCalls(client, toolCalls, options) {
|
|
|
5203
5212
|
const getCodeModeTool = async () => {
|
|
5204
5213
|
if (cachedCodeModeTool)
|
|
5205
5214
|
return cachedCodeModeTool;
|
|
5206
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
5215
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
5207
5216
|
cachedCodeModeTool = buildCodeModeTool(client, {
|
|
5208
5217
|
tools: mcpTools,
|
|
5209
5218
|
providerTokens: options?.providerTokens,
|
package/dist/ai/utils.d.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import type { MCPClient } from "../client.js";
|
|
8
|
+
import type { MCPContext } from "../config/types.js";
|
|
9
|
+
import type { EnabledToolsAsyncOptions } from "../config/types.js";
|
|
8
10
|
/**
|
|
9
11
|
* Options for AI provider tool conversions
|
|
10
12
|
*/
|
|
@@ -38,7 +40,26 @@ export interface AIToolsOptions {
|
|
|
38
40
|
* ```
|
|
39
41
|
*/
|
|
40
42
|
providerTokens?: Record<string, string>;
|
|
43
|
+
/**
|
|
44
|
+
* Limit tool discovery to specific integration IDs (e.g. `['github', 'gmail']`).
|
|
45
|
+
* Only `list_tools_by_integration` calls for these integrations are made.
|
|
46
|
+
*/
|
|
47
|
+
integrationIds?: string[];
|
|
48
|
+
/**
|
|
49
|
+
* When true with `context.userId`, only fetch tools for integrations the user
|
|
50
|
+
* has OAuth tokens for (via `getProviderToken` / database adapter).
|
|
51
|
+
*/
|
|
52
|
+
connectedOnly?: boolean;
|
|
53
|
+
/** User context for connected-only filtering and multi-tenant token lookup */
|
|
54
|
+
context?: MCPContext;
|
|
55
|
+
/**
|
|
56
|
+
* Max parallel `list_tools_by_integration` requests during cold discovery.
|
|
57
|
+
* @default 8
|
|
58
|
+
*/
|
|
59
|
+
fetchConcurrency?: number;
|
|
41
60
|
}
|
|
61
|
+
/** Map AI helper options to client tool-discovery options */
|
|
62
|
+
export declare function toEnabledToolsAsyncOptions(options?: Pick<AIToolsOptions, "integrationIds" | "connectedOnly" | "context" | "fetchConcurrency">): EnabledToolsAsyncOptions | undefined;
|
|
42
63
|
/**
|
|
43
64
|
* Get the provider for a tool by checking which integration includes it
|
|
44
65
|
* @internal
|
package/dist/ai/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/ai/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/ai/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,6DAA6D;AAC7D,wBAAgB,0BAA0B,CACxC,OAAO,CAAC,EAAE,IAAI,CACZ,cAAc,EACd,gBAAgB,GAAG,eAAe,GAAG,SAAS,GAAG,kBAAkB,CACpE,GACA,wBAAwB,GAAG,SAAS,CAYtC;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG/F;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAqFvE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAoD7D;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,GAAG,CAAC,CAuCd;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAIjF;AAED;;;GAGG;AACH,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/ai/utils.js
CHANGED
|
@@ -4060,6 +4060,15 @@ async function tryGetProviderTokens(manualTokens) {
|
|
|
4060
4060
|
}
|
|
4061
4061
|
|
|
4062
4062
|
// utils.ts
|
|
4063
|
+
function toEnabledToolsAsyncOptions(options) {
|
|
4064
|
+
if (!options)
|
|
4065
|
+
return;
|
|
4066
|
+
const { integrationIds, connectedOnly, context, fetchConcurrency } = options;
|
|
4067
|
+
if (integrationIds === undefined && connectedOnly === undefined && context === undefined && fetchConcurrency === undefined) {
|
|
4068
|
+
return;
|
|
4069
|
+
}
|
|
4070
|
+
return { integrationIds, connectedOnly, context, fetchConcurrency };
|
|
4071
|
+
}
|
|
4063
4072
|
function getProviderForTool(client, toolName) {
|
|
4064
4073
|
return client.getProviderForTool?.(toolName);
|
|
4065
4074
|
}
|
|
@@ -4208,6 +4217,7 @@ async function ensureClientConnected(client) {
|
|
|
4208
4217
|
}
|
|
4209
4218
|
export {
|
|
4210
4219
|
tryGetProviderTokens,
|
|
4220
|
+
toEnabledToolsAsyncOptions,
|
|
4211
4221
|
jsonSchemaToZod,
|
|
4212
4222
|
jsonSchemaPropertyToZod,
|
|
4213
4223
|
getProviderTokens,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercel-ai.d.ts","sourceRoot":"","sources":["../../../src/ai/vercel-ai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"vercel-ai.d.ts","sourceRoot":"","sources":["../../../src/ai/vercel-ai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,YAAY,CAAC;AAUpB;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,kDAAkD;IAClD,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AA+BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,oBAAoB,gCAyE/B"}
|
package/dist/ai/vercel-ai.js
CHANGED
|
@@ -4060,6 +4060,15 @@ async function tryGetProviderTokens(manualTokens) {
|
|
|
4060
4060
|
}
|
|
4061
4061
|
|
|
4062
4062
|
// utils.ts
|
|
4063
|
+
function toEnabledToolsAsyncOptions(options) {
|
|
4064
|
+
if (!options)
|
|
4065
|
+
return;
|
|
4066
|
+
const { integrationIds, connectedOnly, context, fetchConcurrency } = options;
|
|
4067
|
+
if (integrationIds === undefined && connectedOnly === undefined && context === undefined && fetchConcurrency === undefined) {
|
|
4068
|
+
return;
|
|
4069
|
+
}
|
|
4070
|
+
return { integrationIds, connectedOnly, context, fetchConcurrency };
|
|
4071
|
+
}
|
|
4063
4072
|
function getProviderForTool(client, toolName) {
|
|
4064
4073
|
return client.getProviderForTool?.(toolName);
|
|
4065
4074
|
}
|
|
@@ -5142,7 +5151,7 @@ async function getVercelAITools(client, options) {
|
|
|
5142
5151
|
}
|
|
5143
5152
|
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
5144
5153
|
await ensureClientConnected(client);
|
|
5145
|
-
const mcpTools = await client.getEnabledToolsAsync();
|
|
5154
|
+
const mcpTools = await client.getEnabledToolsAsync(toEnabledToolsAsyncOptions(options));
|
|
5146
5155
|
const vercelTools = {};
|
|
5147
5156
|
let effectiveMode;
|
|
5148
5157
|
if (options?.mode !== undefined) {
|
package/dist/database/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { AccountIdentity, CreateTriggerInput, DatabaseDriver, DeleteDuplicateProviderTokensInput, DeleteProviderTokensInput, FlattenedTrigger, IntegrateAdapterHooks, IntegrateDatabaseAdapter, IntegrateDatabaseCallbacks, ListTriggersQuery, ProviderTokenRecord, TokenChangeEvent, TokenDatabaseDriver, TriggerDatabaseDriver, TriggerRecord, UpsertProviderTokenInput, } from "./types.js";
|
|
2
2
|
export { createDatabaseAdapterCallbacks, createDatabaseAdapterFactory, } from "./factory.js";
|
|
3
|
-
export { defaultResolveAccountIdentity, hasMeaningfulExpiresAt, hasUsableAccessToken, isLikelyUsableToken, normalizeAccountEmail, normalizeAccountEmailHint, normalizeAccountIdHint, normalizeAccountIdentifier, normalizeProviderTokenType, parseScopes, providerTokenRecordToData, selectProviderTokenRow, } from "./token-store.js";
|
|
3
|
+
export { defaultResolveAccountIdentity, hasMeaningfulExpiresAt, hasUsableAccessToken, isLikelyUsableToken, normalizeAccountEmail, normalizeAccountEmailHint, normalizeAccountIdHint, normalizeAccountIdentifier, normalizeProviderTokenType, parseScopes, providerTokenRecordToData, selectProviderTokenRow, listConnectedProviders, listConnectedProvidersFromRows, } from "./token-store.js";
|
|
4
4
|
export { flattenedTriggerToCreateInput, toDbSchedule, toDbTriggerUpdates, toSdkSchedule, toSdkTrigger, } from "./trigger-store.js";
|
|
5
5
|
export { drizzleAdapter, drizzleAdapterCallbacks, createDrizzleDatabaseDriver, type DrizzleAdapterConfig, type DrizzleIntegrateSchema, type DrizzleProvider, } from "./adapters/drizzle.js";
|
|
6
6
|
export { prismaAdapter, prismaAdapterCallbacks, createPrismaDatabaseDriver, type PrismaAdapterConfig, type PrismaIntegrateModelNames, type PrismaProvider, } from "./adapters/prisma.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/database/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,kCAAkC,EAClC,yBAAyB,EACzB,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,0BAA0B,EAC1B,WAAW,EACX,yBAAyB,EACzB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/database/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,kCAAkC,EAClC,yBAAyB,EACzB,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,0BAA0B,EAC1B,WAAW,EACX,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,GAC/B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,6BAA6B,EAC7B,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,2BAA2B,EAC3B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,GACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,0BAA0B,EAC1B,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,cAAc,GACpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,yBAAyB,EACzB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,GAC1B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC"}
|
package/dist/database/index.js
CHANGED
|
@@ -113,6 +113,43 @@ function providerTokenRecordToData(row) {
|
|
|
113
113
|
accountId: row.accountId ?? undefined
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
+
function listConnectedProvidersFromRows(rows, configuredIntegrationIds) {
|
|
117
|
+
const allowed = configuredIntegrationIds ? new Set(configuredIntegrationIds) : undefined;
|
|
118
|
+
const rowsByProvider = new Map;
|
|
119
|
+
for (const row of rows) {
|
|
120
|
+
if (allowed && !allowed.has(row.provider))
|
|
121
|
+
continue;
|
|
122
|
+
const existing = rowsByProvider.get(row.provider);
|
|
123
|
+
if (existing) {
|
|
124
|
+
existing.push(row);
|
|
125
|
+
} else {
|
|
126
|
+
rowsByProvider.set(row.provider, [row]);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const connected = [];
|
|
130
|
+
for (const [provider, providerRows] of rowsByProvider.entries()) {
|
|
131
|
+
const selected = selectProviderTokenRow(providerRows);
|
|
132
|
+
if (selected && isLikelyUsableToken(selected)) {
|
|
133
|
+
connected.push(provider);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return connected.sort();
|
|
137
|
+
}
|
|
138
|
+
async function listConnectedProviders(configuredIntegrationIds, getProviderToken, context) {
|
|
139
|
+
if (!context.userId || configuredIntegrationIds.length === 0) {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
const connected = [];
|
|
143
|
+
await Promise.all(configuredIntegrationIds.map(async (provider) => {
|
|
144
|
+
try {
|
|
145
|
+
const token = await getProviderToken(provider, undefined, context);
|
|
146
|
+
if (token?.accessToken || typeof token?.refreshToken === "string" && token.refreshToken.length > 0) {
|
|
147
|
+
connected.push(provider);
|
|
148
|
+
}
|
|
149
|
+
} catch {}
|
|
150
|
+
}));
|
|
151
|
+
return connected.sort();
|
|
152
|
+
}
|
|
116
153
|
function defaultResolveAccountIdentity(provider, tokenData, emailHint) {
|
|
117
154
|
const accountEmail = normalizeAccountEmail(emailHint ?? tokenData.email ?? null);
|
|
118
155
|
let accountId = normalizeAccountIdHint(tokenData.accountId ?? null);
|
|
@@ -1111,6 +1148,8 @@ export {
|
|
|
1111
1148
|
normalizeAccountEmail,
|
|
1112
1149
|
mongodbAdapterCallbacks,
|
|
1113
1150
|
mongodbAdapter,
|
|
1151
|
+
listConnectedProvidersFromRows,
|
|
1152
|
+
listConnectedProviders,
|
|
1114
1153
|
isLikelyUsableToken,
|
|
1115
1154
|
integrateTrigger,
|
|
1116
1155
|
integrateProviderToken,
|
package/dist/index.js
CHANGED
|
@@ -1675,6 +1675,25 @@ function toConfiguredIntegrationWithToolMetadata(integration, toolMetadata) {
|
|
|
1675
1675
|
};
|
|
1676
1676
|
}
|
|
1677
1677
|
|
|
1678
|
+
// src/database/token-store.ts
|
|
1679
|
+
var USABLE_ACCESS_TOKEN_BUFFER_MS = 30 * 1000;
|
|
1680
|
+
var MIN_MEANINGFUL_EXPIRY_MS = Date.UTC(2000, 0, 1);
|
|
1681
|
+
async function listConnectedProviders(configuredIntegrationIds, getProviderToken, context) {
|
|
1682
|
+
if (!context.userId || configuredIntegrationIds.length === 0) {
|
|
1683
|
+
return [];
|
|
1684
|
+
}
|
|
1685
|
+
const connected = [];
|
|
1686
|
+
await Promise.all(configuredIntegrationIds.map(async (provider) => {
|
|
1687
|
+
try {
|
|
1688
|
+
const token = await getProviderToken(provider, undefined, context);
|
|
1689
|
+
if (token?.accessToken || typeof token?.refreshToken === "string" && token.refreshToken.length > 0) {
|
|
1690
|
+
connected.push(provider);
|
|
1691
|
+
}
|
|
1692
|
+
} catch {}
|
|
1693
|
+
}));
|
|
1694
|
+
return connected.sort();
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1678
1697
|
// src/client.ts
|
|
1679
1698
|
init_errors();
|
|
1680
1699
|
|
|
@@ -3824,20 +3843,32 @@ class MCPClientBase {
|
|
|
3824
3843
|
getEnabledTools() {
|
|
3825
3844
|
return Array.from(this.availableTools.values()).filter((tool) => this.enabledToolNames.has(tool.name));
|
|
3826
3845
|
}
|
|
3827
|
-
async getEnabledToolsAsync() {
|
|
3828
|
-
|
|
3829
|
-
|
|
3846
|
+
async getEnabledToolsAsync(options) {
|
|
3847
|
+
const targetIntegrationIds = await this.resolveTargetIntegrationIds(options);
|
|
3848
|
+
if (targetIntegrationIds.size === 0) {
|
|
3849
|
+
return [];
|
|
3830
3850
|
}
|
|
3831
|
-
|
|
3832
|
-
|
|
3851
|
+
const filterToTargets = (tools2) => this.filterToolsToIntegrations(tools2, targetIntegrationIds);
|
|
3852
|
+
const hasCompleteCache = () => {
|
|
3853
|
+
for (const integration of this.integrations) {
|
|
3854
|
+
if (!targetIntegrationIds.has(integration.id))
|
|
3855
|
+
continue;
|
|
3856
|
+
for (const toolName of integration.tools) {
|
|
3857
|
+
if (!this.enabledToolNames.has(toolName))
|
|
3858
|
+
continue;
|
|
3859
|
+
if (!this.availableTools.has(toolName))
|
|
3860
|
+
return false;
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3863
|
+
return this.availableTools.size > 0;
|
|
3864
|
+
};
|
|
3865
|
+
if (this.availableTools.size > 0 && hasCompleteCache()) {
|
|
3866
|
+
return filterToTargets(this.getEnabledTools());
|
|
3833
3867
|
}
|
|
3834
3868
|
const tools = [];
|
|
3835
|
-
const integrationIds = new Set;
|
|
3836
|
-
for (const integration of this.integrations) {
|
|
3837
|
-
integrationIds.add(integration.id);
|
|
3838
|
-
}
|
|
3839
3869
|
const { parallelWithLimit: parallelWithLimit2 } = await Promise.resolve().then(() => exports_concurrency);
|
|
3840
|
-
const
|
|
3870
|
+
const concurrency = options?.fetchConcurrency ?? 8;
|
|
3871
|
+
const integrationToolsResults = await parallelWithLimit2(Array.from(targetIntegrationIds), async (integrationId) => {
|
|
3841
3872
|
try {
|
|
3842
3873
|
const response = await this.callServerToolInternal("list_tools_by_integration", {
|
|
3843
3874
|
integration: integrationId
|
|
@@ -3848,25 +3879,14 @@ class MCPClientBase {
|
|
|
3848
3879
|
if (item.type === "text" && item.text) {
|
|
3849
3880
|
try {
|
|
3850
3881
|
const parsed = JSON.parse(item.text);
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
}
|
|
3860
|
-
}
|
|
3861
|
-
} else if (parsed.tools && Array.isArray(parsed.tools)) {
|
|
3862
|
-
for (const tool of parsed.tools) {
|
|
3863
|
-
if (tool.name && tool.inputSchema) {
|
|
3864
|
-
integrationTools.push({
|
|
3865
|
-
name: tool.name,
|
|
3866
|
-
description: tool.description,
|
|
3867
|
-
inputSchema: tool.inputSchema
|
|
3868
|
-
});
|
|
3869
|
-
}
|
|
3882
|
+
const parsedTools = Array.isArray(parsed) ? parsed : parsed.tools && Array.isArray(parsed.tools) ? parsed.tools : [];
|
|
3883
|
+
for (const tool of parsedTools) {
|
|
3884
|
+
if (tool.name && tool.inputSchema) {
|
|
3885
|
+
integrationTools.push({
|
|
3886
|
+
name: tool.name,
|
|
3887
|
+
description: tool.description,
|
|
3888
|
+
inputSchema: tool.inputSchema
|
|
3889
|
+
});
|
|
3870
3890
|
}
|
|
3871
3891
|
}
|
|
3872
3892
|
} catch {}
|
|
@@ -3878,14 +3898,40 @@ class MCPClientBase {
|
|
|
3878
3898
|
logger5.error(`Failed to fetch tools for integration ${integrationId}:`, error);
|
|
3879
3899
|
return [];
|
|
3880
3900
|
}
|
|
3881
|
-
},
|
|
3901
|
+
}, concurrency);
|
|
3882
3902
|
for (const integrationTools of integrationToolsResults) {
|
|
3883
3903
|
tools.push(...integrationTools);
|
|
3884
3904
|
}
|
|
3885
3905
|
for (const tool of tools) {
|
|
3886
3906
|
this.availableTools.set(tool.name, tool);
|
|
3887
3907
|
}
|
|
3888
|
-
return tools.filter((tool) => this.enabledToolNames.has(tool.name));
|
|
3908
|
+
return filterToTargets(tools.filter((tool) => this.enabledToolNames.has(tool.name)));
|
|
3909
|
+
}
|
|
3910
|
+
async resolveTargetIntegrationIds(options) {
|
|
3911
|
+
const configuredIds = this.integrations.map((integration) => integration.id);
|
|
3912
|
+
const configuredSet = new Set(configuredIds);
|
|
3913
|
+
if (options?.integrationIds && options.integrationIds.length > 0) {
|
|
3914
|
+
return new Set(options.integrationIds.filter((id) => configuredSet.has(id)));
|
|
3915
|
+
}
|
|
3916
|
+
if (options?.connectedOnly && options.context?.userId) {
|
|
3917
|
+
const connected = await listConnectedProviders(configuredIds, (provider, email, context) => this.oauthManager.getProviderToken(provider, email, context), options.context);
|
|
3918
|
+
return new Set(connected);
|
|
3919
|
+
}
|
|
3920
|
+
return configuredSet;
|
|
3921
|
+
}
|
|
3922
|
+
filterToolsToIntegrations(tools, integrationIds) {
|
|
3923
|
+
if (integrationIds.size === 0) {
|
|
3924
|
+
return [];
|
|
3925
|
+
}
|
|
3926
|
+
const allowedNames = new Set;
|
|
3927
|
+
for (const integration of this.integrations) {
|
|
3928
|
+
if (!integrationIds.has(integration.id))
|
|
3929
|
+
continue;
|
|
3930
|
+
for (const toolName of integration.tools) {
|
|
3931
|
+
allowedNames.add(toolName);
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
3934
|
+
return tools.filter((tool) => this.enabledToolNames.has(tool.name) && allowedNames.has(tool.name));
|
|
3889
3935
|
}
|
|
3890
3936
|
getOAuthConfig(integrationId) {
|
|
3891
3937
|
const integration = this.integrations.find((p) => p.id === integrationId);
|
package/dist/integrations.js
CHANGED
|
@@ -1675,6 +1675,25 @@ function toConfiguredIntegrationWithToolMetadata(integration, toolMetadata) {
|
|
|
1675
1675
|
};
|
|
1676
1676
|
}
|
|
1677
1677
|
|
|
1678
|
+
// src/database/token-store.ts
|
|
1679
|
+
var USABLE_ACCESS_TOKEN_BUFFER_MS = 30 * 1000;
|
|
1680
|
+
var MIN_MEANINGFUL_EXPIRY_MS = Date.UTC(2000, 0, 1);
|
|
1681
|
+
async function listConnectedProviders(configuredIntegrationIds, getProviderToken, context) {
|
|
1682
|
+
if (!context.userId || configuredIntegrationIds.length === 0) {
|
|
1683
|
+
return [];
|
|
1684
|
+
}
|
|
1685
|
+
const connected = [];
|
|
1686
|
+
await Promise.all(configuredIntegrationIds.map(async (provider) => {
|
|
1687
|
+
try {
|
|
1688
|
+
const token = await getProviderToken(provider, undefined, context);
|
|
1689
|
+
if (token?.accessToken || typeof token?.refreshToken === "string" && token.refreshToken.length > 0) {
|
|
1690
|
+
connected.push(provider);
|
|
1691
|
+
}
|
|
1692
|
+
} catch {}
|
|
1693
|
+
}));
|
|
1694
|
+
return connected.sort();
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1678
1697
|
// src/client.ts
|
|
1679
1698
|
init_errors();
|
|
1680
1699
|
|
|
@@ -3824,20 +3843,32 @@ class MCPClientBase {
|
|
|
3824
3843
|
getEnabledTools() {
|
|
3825
3844
|
return Array.from(this.availableTools.values()).filter((tool) => this.enabledToolNames.has(tool.name));
|
|
3826
3845
|
}
|
|
3827
|
-
async getEnabledToolsAsync() {
|
|
3828
|
-
|
|
3829
|
-
|
|
3846
|
+
async getEnabledToolsAsync(options) {
|
|
3847
|
+
const targetIntegrationIds = await this.resolveTargetIntegrationIds(options);
|
|
3848
|
+
if (targetIntegrationIds.size === 0) {
|
|
3849
|
+
return [];
|
|
3830
3850
|
}
|
|
3831
|
-
|
|
3832
|
-
|
|
3851
|
+
const filterToTargets = (tools2) => this.filterToolsToIntegrations(tools2, targetIntegrationIds);
|
|
3852
|
+
const hasCompleteCache = () => {
|
|
3853
|
+
for (const integration of this.integrations) {
|
|
3854
|
+
if (!targetIntegrationIds.has(integration.id))
|
|
3855
|
+
continue;
|
|
3856
|
+
for (const toolName of integration.tools) {
|
|
3857
|
+
if (!this.enabledToolNames.has(toolName))
|
|
3858
|
+
continue;
|
|
3859
|
+
if (!this.availableTools.has(toolName))
|
|
3860
|
+
return false;
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3863
|
+
return this.availableTools.size > 0;
|
|
3864
|
+
};
|
|
3865
|
+
if (this.availableTools.size > 0 && hasCompleteCache()) {
|
|
3866
|
+
return filterToTargets(this.getEnabledTools());
|
|
3833
3867
|
}
|
|
3834
3868
|
const tools = [];
|
|
3835
|
-
const integrationIds = new Set;
|
|
3836
|
-
for (const integration of this.integrations) {
|
|
3837
|
-
integrationIds.add(integration.id);
|
|
3838
|
-
}
|
|
3839
3869
|
const { parallelWithLimit: parallelWithLimit2 } = await Promise.resolve().then(() => exports_concurrency);
|
|
3840
|
-
const
|
|
3870
|
+
const concurrency = options?.fetchConcurrency ?? 8;
|
|
3871
|
+
const integrationToolsResults = await parallelWithLimit2(Array.from(targetIntegrationIds), async (integrationId) => {
|
|
3841
3872
|
try {
|
|
3842
3873
|
const response = await this.callServerToolInternal("list_tools_by_integration", {
|
|
3843
3874
|
integration: integrationId
|
|
@@ -3848,25 +3879,14 @@ class MCPClientBase {
|
|
|
3848
3879
|
if (item.type === "text" && item.text) {
|
|
3849
3880
|
try {
|
|
3850
3881
|
const parsed = JSON.parse(item.text);
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
}
|
|
3860
|
-
}
|
|
3861
|
-
} else if (parsed.tools && Array.isArray(parsed.tools)) {
|
|
3862
|
-
for (const tool of parsed.tools) {
|
|
3863
|
-
if (tool.name && tool.inputSchema) {
|
|
3864
|
-
integrationTools.push({
|
|
3865
|
-
name: tool.name,
|
|
3866
|
-
description: tool.description,
|
|
3867
|
-
inputSchema: tool.inputSchema
|
|
3868
|
-
});
|
|
3869
|
-
}
|
|
3882
|
+
const parsedTools = Array.isArray(parsed) ? parsed : parsed.tools && Array.isArray(parsed.tools) ? parsed.tools : [];
|
|
3883
|
+
for (const tool of parsedTools) {
|
|
3884
|
+
if (tool.name && tool.inputSchema) {
|
|
3885
|
+
integrationTools.push({
|
|
3886
|
+
name: tool.name,
|
|
3887
|
+
description: tool.description,
|
|
3888
|
+
inputSchema: tool.inputSchema
|
|
3889
|
+
});
|
|
3870
3890
|
}
|
|
3871
3891
|
}
|
|
3872
3892
|
} catch {}
|
|
@@ -3878,14 +3898,40 @@ class MCPClientBase {
|
|
|
3878
3898
|
logger5.error(`Failed to fetch tools for integration ${integrationId}:`, error);
|
|
3879
3899
|
return [];
|
|
3880
3900
|
}
|
|
3881
|
-
},
|
|
3901
|
+
}, concurrency);
|
|
3882
3902
|
for (const integrationTools of integrationToolsResults) {
|
|
3883
3903
|
tools.push(...integrationTools);
|
|
3884
3904
|
}
|
|
3885
3905
|
for (const tool of tools) {
|
|
3886
3906
|
this.availableTools.set(tool.name, tool);
|
|
3887
3907
|
}
|
|
3888
|
-
return tools.filter((tool) => this.enabledToolNames.has(tool.name));
|
|
3908
|
+
return filterToTargets(tools.filter((tool) => this.enabledToolNames.has(tool.name)));
|
|
3909
|
+
}
|
|
3910
|
+
async resolveTargetIntegrationIds(options) {
|
|
3911
|
+
const configuredIds = this.integrations.map((integration) => integration.id);
|
|
3912
|
+
const configuredSet = new Set(configuredIds);
|
|
3913
|
+
if (options?.integrationIds && options.integrationIds.length > 0) {
|
|
3914
|
+
return new Set(options.integrationIds.filter((id) => configuredSet.has(id)));
|
|
3915
|
+
}
|
|
3916
|
+
if (options?.connectedOnly && options.context?.userId) {
|
|
3917
|
+
const connected = await listConnectedProviders(configuredIds, (provider, email, context) => this.oauthManager.getProviderToken(provider, email, context), options.context);
|
|
3918
|
+
return new Set(connected);
|
|
3919
|
+
}
|
|
3920
|
+
return configuredSet;
|
|
3921
|
+
}
|
|
3922
|
+
filterToolsToIntegrations(tools, integrationIds) {
|
|
3923
|
+
if (integrationIds.size === 0) {
|
|
3924
|
+
return [];
|
|
3925
|
+
}
|
|
3926
|
+
const allowedNames = new Set;
|
|
3927
|
+
for (const integration of this.integrations) {
|
|
3928
|
+
if (!integrationIds.has(integration.id))
|
|
3929
|
+
continue;
|
|
3930
|
+
for (const toolName of integration.tools) {
|
|
3931
|
+
allowedNames.add(toolName);
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
3934
|
+
return tools.filter((tool) => this.enabledToolNames.has(tool.name) && allowedNames.has(tool.name));
|
|
3889
3935
|
}
|
|
3890
3936
|
getOAuthConfig(integrationId) {
|
|
3891
3937
|
const integration = this.integrations.find((p) => p.id === integrationId);
|