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/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
|
|
|
@@ -3645,7 +3664,7 @@ class MCPClientBase {
|
|
|
3645
3664
|
logger5.debug(`Discovered ${totalDiscovered} tools, ${enabledCount} enabled by integrations`);
|
|
3646
3665
|
}
|
|
3647
3666
|
async _callToolByName(name, args, options) {
|
|
3648
|
-
return await this.
|
|
3667
|
+
return await this.callTool(name, args, options);
|
|
3649
3668
|
}
|
|
3650
3669
|
async callTool(name, args, options) {
|
|
3651
3670
|
return await this.callToolWithRetry(name, args, 0, options);
|
|
@@ -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);
|
|
@@ -14114,6 +14160,68 @@ function createSimpleIntegration(config) {
|
|
|
14114
14160
|
onDisconnect: config.onDisconnect
|
|
14115
14161
|
};
|
|
14116
14162
|
}
|
|
14163
|
+
// src/utils/parse-tool-result.ts
|
|
14164
|
+
function isRecord(value) {
|
|
14165
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14166
|
+
}
|
|
14167
|
+
function getBooleanProperty(value, key) {
|
|
14168
|
+
const property = value[key];
|
|
14169
|
+
return typeof property === "boolean" ? property : undefined;
|
|
14170
|
+
}
|
|
14171
|
+
function getStringProperty(value, key) {
|
|
14172
|
+
const property = value[key];
|
|
14173
|
+
if (typeof property !== "string") {
|
|
14174
|
+
return;
|
|
14175
|
+
}
|
|
14176
|
+
const trimmed = property.trim();
|
|
14177
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
14178
|
+
}
|
|
14179
|
+
function getStructuredContent(result) {
|
|
14180
|
+
const structuredContent = result.structuredContent;
|
|
14181
|
+
return isRecord(structuredContent) ? structuredContent : undefined;
|
|
14182
|
+
}
|
|
14183
|
+
function getContentText(result) {
|
|
14184
|
+
const content = result.content;
|
|
14185
|
+
if (!Array.isArray(content)) {
|
|
14186
|
+
return;
|
|
14187
|
+
}
|
|
14188
|
+
for (const item of content) {
|
|
14189
|
+
if (!isRecord(item)) {
|
|
14190
|
+
continue;
|
|
14191
|
+
}
|
|
14192
|
+
const text = getStringProperty(item, "text");
|
|
14193
|
+
if (text) {
|
|
14194
|
+
return text;
|
|
14195
|
+
}
|
|
14196
|
+
}
|
|
14197
|
+
return;
|
|
14198
|
+
}
|
|
14199
|
+
function isMCPToolError(result) {
|
|
14200
|
+
return parseMCPToolResult(result).ok === false;
|
|
14201
|
+
}
|
|
14202
|
+
function parseMCPToolResult(result) {
|
|
14203
|
+
if (!isRecord(result)) {
|
|
14204
|
+
return {
|
|
14205
|
+
ok: true,
|
|
14206
|
+
data: result,
|
|
14207
|
+
raw: result
|
|
14208
|
+
};
|
|
14209
|
+
}
|
|
14210
|
+
const structuredContent = getStructuredContent(result);
|
|
14211
|
+
const failed = getBooleanProperty(result, "isError") === true || getBooleanProperty(result, "success") === false || getBooleanProperty(structuredContent ?? {}, "isError") === true || getBooleanProperty(structuredContent ?? {}, "success") === false;
|
|
14212
|
+
if (!failed) {
|
|
14213
|
+
return {
|
|
14214
|
+
ok: true,
|
|
14215
|
+
data: structuredContent ?? result,
|
|
14216
|
+
raw: result
|
|
14217
|
+
};
|
|
14218
|
+
}
|
|
14219
|
+
return {
|
|
14220
|
+
ok: false,
|
|
14221
|
+
error: getStringProperty(result, "error") ?? getStringProperty(structuredContent ?? {}, "error") ?? getContentText(result) ?? "Tool returned an error result",
|
|
14222
|
+
raw: result
|
|
14223
|
+
};
|
|
14224
|
+
}
|
|
14117
14225
|
// index.ts
|
|
14118
14226
|
var client = createMCPClient({
|
|
14119
14227
|
integrations: [
|
|
@@ -14326,6 +14434,7 @@ export {
|
|
|
14326
14434
|
paypalIntegration,
|
|
14327
14435
|
parseState,
|
|
14328
14436
|
parseServerError,
|
|
14437
|
+
parseMCPToolResult,
|
|
14329
14438
|
paperIntegration,
|
|
14330
14439
|
pandadocIntegration,
|
|
14331
14440
|
outlookIntegration,
|
|
@@ -14360,6 +14469,7 @@ export {
|
|
|
14360
14469
|
kickIntegration,
|
|
14361
14470
|
jiraIntegration,
|
|
14362
14471
|
isTokenExpiredError,
|
|
14472
|
+
isMCPToolError,
|
|
14363
14473
|
isAuthorizationError,
|
|
14364
14474
|
isAuthError,
|
|
14365
14475
|
intercomIntegration,
|
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
|
|
|
@@ -3645,7 +3664,7 @@ class MCPClientBase {
|
|
|
3645
3664
|
logger5.debug(`Discovered ${totalDiscovered} tools, ${enabledCount} enabled by integrations`);
|
|
3646
3665
|
}
|
|
3647
3666
|
async _callToolByName(name, args, options) {
|
|
3648
|
-
return await this.
|
|
3667
|
+
return await this.callTool(name, args, options);
|
|
3649
3668
|
}
|
|
3650
3669
|
async callTool(name, args, options) {
|
|
3651
3670
|
return await this.callToolWithRetry(name, args, 0, options);
|
|
@@ -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);
|
|
@@ -14114,6 +14160,68 @@ function createSimpleIntegration(config) {
|
|
|
14114
14160
|
onDisconnect: config.onDisconnect
|
|
14115
14161
|
};
|
|
14116
14162
|
}
|
|
14163
|
+
// src/utils/parse-tool-result.ts
|
|
14164
|
+
function isRecord(value) {
|
|
14165
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14166
|
+
}
|
|
14167
|
+
function getBooleanProperty(value, key) {
|
|
14168
|
+
const property = value[key];
|
|
14169
|
+
return typeof property === "boolean" ? property : undefined;
|
|
14170
|
+
}
|
|
14171
|
+
function getStringProperty(value, key) {
|
|
14172
|
+
const property = value[key];
|
|
14173
|
+
if (typeof property !== "string") {
|
|
14174
|
+
return;
|
|
14175
|
+
}
|
|
14176
|
+
const trimmed = property.trim();
|
|
14177
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
14178
|
+
}
|
|
14179
|
+
function getStructuredContent(result) {
|
|
14180
|
+
const structuredContent = result.structuredContent;
|
|
14181
|
+
return isRecord(structuredContent) ? structuredContent : undefined;
|
|
14182
|
+
}
|
|
14183
|
+
function getContentText(result) {
|
|
14184
|
+
const content = result.content;
|
|
14185
|
+
if (!Array.isArray(content)) {
|
|
14186
|
+
return;
|
|
14187
|
+
}
|
|
14188
|
+
for (const item of content) {
|
|
14189
|
+
if (!isRecord(item)) {
|
|
14190
|
+
continue;
|
|
14191
|
+
}
|
|
14192
|
+
const text = getStringProperty(item, "text");
|
|
14193
|
+
if (text) {
|
|
14194
|
+
return text;
|
|
14195
|
+
}
|
|
14196
|
+
}
|
|
14197
|
+
return;
|
|
14198
|
+
}
|
|
14199
|
+
function isMCPToolError(result) {
|
|
14200
|
+
return parseMCPToolResult(result).ok === false;
|
|
14201
|
+
}
|
|
14202
|
+
function parseMCPToolResult(result) {
|
|
14203
|
+
if (!isRecord(result)) {
|
|
14204
|
+
return {
|
|
14205
|
+
ok: true,
|
|
14206
|
+
data: result,
|
|
14207
|
+
raw: result
|
|
14208
|
+
};
|
|
14209
|
+
}
|
|
14210
|
+
const structuredContent = getStructuredContent(result);
|
|
14211
|
+
const failed = getBooleanProperty(result, "isError") === true || getBooleanProperty(result, "success") === false || getBooleanProperty(structuredContent ?? {}, "isError") === true || getBooleanProperty(structuredContent ?? {}, "success") === false;
|
|
14212
|
+
if (!failed) {
|
|
14213
|
+
return {
|
|
14214
|
+
ok: true,
|
|
14215
|
+
data: structuredContent ?? result,
|
|
14216
|
+
raw: result
|
|
14217
|
+
};
|
|
14218
|
+
}
|
|
14219
|
+
return {
|
|
14220
|
+
ok: false,
|
|
14221
|
+
error: getStringProperty(result, "error") ?? getStringProperty(structuredContent ?? {}, "error") ?? getContentText(result) ?? "Tool returned an error result",
|
|
14222
|
+
raw: result
|
|
14223
|
+
};
|
|
14224
|
+
}
|
|
14117
14225
|
export {
|
|
14118
14226
|
zoomIntegration,
|
|
14119
14227
|
zohoWriterIntegration,
|
|
@@ -14212,6 +14320,7 @@ export {
|
|
|
14212
14320
|
paypalIntegration,
|
|
14213
14321
|
parseState,
|
|
14214
14322
|
parseServerError,
|
|
14323
|
+
parseMCPToolResult,
|
|
14215
14324
|
paperIntegration,
|
|
14216
14325
|
pandadocIntegration,
|
|
14217
14326
|
outlookIntegration,
|
|
@@ -14246,6 +14355,7 @@ export {
|
|
|
14246
14355
|
kickIntegration,
|
|
14247
14356
|
jiraIntegration,
|
|
14248
14357
|
isTokenExpiredError,
|
|
14358
|
+
isMCPToolError,
|
|
14249
14359
|
isAuthorizationError,
|
|
14250
14360
|
isAuthError,
|
|
14251
14361
|
intercomIntegration,
|
package/dist/react.d.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @packageDocumentation
|
|
5
5
|
*/
|
|
6
|
-
export { useIntegrateTokens, useIntegrateAI } from "./src/react/hooks.js";
|
|
7
|
-
export type { UseIntegrateTokensResult, UseIntegrateAIOptions } from "./src/react/hooks.js";
|
|
6
|
+
export { useIntegrateTokens, useIntegrateAI, useIntegrateAuth, } from "./src/react/hooks.js";
|
|
7
|
+
export type { UseIntegrateTokensResult, UseIntegrateAIOptions, UseIntegrateAuthResult, } from "./src/react/hooks.js";
|
|
8
8
|
//# sourceMappingURL=react.d.ts.map
|
package/dist/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../react.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../react.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC"}
|
package/dist/react.js
CHANGED
|
@@ -202,7 +202,93 @@ function useIntegrateAI(client, options = {}) {
|
|
|
202
202
|
};
|
|
203
203
|
}, [client, apiPattern, debug]);
|
|
204
204
|
}
|
|
205
|
+
function useIntegrateAuth(client, provider, options) {
|
|
206
|
+
const [isAuthorized, setIsAuthorized] = useState(false);
|
|
207
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
208
|
+
const [error, setError] = useState(null);
|
|
209
|
+
const refresh = async () => {
|
|
210
|
+
if (!client) {
|
|
211
|
+
setIsAuthorized(false);
|
|
212
|
+
setIsLoading(false);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
const authorized = await client.isAuthorized(provider, options?.email);
|
|
217
|
+
setIsAuthorized(authorized);
|
|
218
|
+
setError(null);
|
|
219
|
+
} catch (err) {
|
|
220
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
221
|
+
} finally {
|
|
222
|
+
setIsLoading(false);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
if (!client || !isReactHooksAvailable()) {
|
|
227
|
+
setIsLoading(false);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
refresh();
|
|
231
|
+
const onChange = () => {
|
|
232
|
+
refresh();
|
|
233
|
+
};
|
|
234
|
+
const onError = (event) => {
|
|
235
|
+
const payload = event;
|
|
236
|
+
if (payload.provider === provider) {
|
|
237
|
+
setError(payload.error ?? "Authorization failed");
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
client.on("auth:complete", onChange);
|
|
241
|
+
client.on("auth:disconnect", onChange);
|
|
242
|
+
client.on("auth:logout", onChange);
|
|
243
|
+
client.on("auth:error", onError);
|
|
244
|
+
return () => {
|
|
245
|
+
client.off("auth:complete", onChange);
|
|
246
|
+
client.off("auth:disconnect", onChange);
|
|
247
|
+
client.off("auth:logout", onChange);
|
|
248
|
+
client.off("auth:error", onError);
|
|
249
|
+
};
|
|
250
|
+
}, [client, provider, options?.email]);
|
|
251
|
+
const authorize = async () => {
|
|
252
|
+
if (!client)
|
|
253
|
+
return;
|
|
254
|
+
setError(null);
|
|
255
|
+
setIsLoading(true);
|
|
256
|
+
try {
|
|
257
|
+
await client.authorize(provider, options?.returnUrl ? { returnUrl: options.returnUrl } : undefined);
|
|
258
|
+
await refresh();
|
|
259
|
+
} catch (err) {
|
|
260
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
261
|
+
setIsLoading(false);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
const disconnect = async (email) => {
|
|
265
|
+
if (!client)
|
|
266
|
+
return;
|
|
267
|
+
setError(null);
|
|
268
|
+
setIsLoading(true);
|
|
269
|
+
try {
|
|
270
|
+
if (email) {
|
|
271
|
+
await client.disconnectAccount(provider, email);
|
|
272
|
+
} else {
|
|
273
|
+
await client.disconnectProvider(provider);
|
|
274
|
+
}
|
|
275
|
+
await refresh();
|
|
276
|
+
} catch (err) {
|
|
277
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
278
|
+
setIsLoading(false);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
return {
|
|
282
|
+
isAuthorized,
|
|
283
|
+
isLoading,
|
|
284
|
+
error,
|
|
285
|
+
authorize,
|
|
286
|
+
disconnect,
|
|
287
|
+
refresh
|
|
288
|
+
};
|
|
289
|
+
}
|
|
205
290
|
export {
|
|
206
291
|
useIntegrateTokens,
|
|
292
|
+
useIntegrateAuth,
|
|
207
293
|
useIntegrateAI
|
|
208
294
|
};
|