@inkeep/agents-core 0.42.0 → 0.44.0
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/auth/auth.d.ts +28 -26
- package/dist/auth/auth.js +21 -16
- package/dist/auth/authz/client.d.ts +8 -3
- package/dist/auth/authz/client.js +23 -17
- package/dist/auth/authz/config.d.ts +50 -29
- package/dist/auth/authz/config.js +42 -33
- package/dist/auth/authz/index.d.ts +3 -3
- package/dist/auth/authz/index.js +3 -3
- package/dist/auth/authz/permissions.d.ts +0 -4
- package/dist/auth/authz/permissions.js +9 -13
- package/dist/auth/authz/sync.d.ts +23 -2
- package/dist/auth/authz/sync.js +127 -53
- package/dist/auth/init.d.ts +1 -0
- package/dist/auth/init.js +115 -0
- package/dist/auth/permissions.d.ts +9 -9
- package/dist/client-exports.d.ts +3 -6
- package/dist/client-exports.js +4 -7
- package/dist/constants/execution-limits-shared/defaults.d.ts +1 -1
- package/dist/constants/execution-limits-shared/defaults.js +1 -1
- package/dist/constants/execution-limits-shared/index.d.ts +1 -1
- package/dist/constants/otel-attributes.d.ts +5 -0
- package/dist/constants/otel-attributes.js +8 -3
- package/dist/constants/signoz-queries.d.ts +1 -0
- package/dist/constants/signoz-queries.js +2 -1
- package/dist/context/TemplateEngine.d.ts +0 -6
- package/dist/context/TemplateEngine.js +4 -18
- package/dist/credential-stores/keychain-store.d.ts +20 -8
- package/dist/credential-stores/keychain-store.js +107 -43
- package/dist/data-access/index.d.ts +5 -4
- package/dist/data-access/index.js +5 -4
- package/dist/data-access/manage/agentFull.js +70 -25
- package/dist/data-access/manage/agents.d.ts +41 -41
- package/dist/data-access/manage/agents.js +29 -21
- package/dist/data-access/manage/artifactComponents.d.ts +12 -12
- package/dist/data-access/manage/artifactComponents.js +1 -1
- package/dist/data-access/manage/contextConfigs.d.ts +12 -12
- package/dist/data-access/manage/dataComponents.d.ts +6 -6
- package/dist/data-access/manage/dataComponents.js +1 -1
- package/dist/data-access/manage/functionTools.d.ts +44 -21
- package/dist/data-access/manage/functionTools.js +34 -22
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +24 -24
- package/dist/data-access/manage/subAgentRelations.d.ts +26 -26
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +18 -18
- package/dist/data-access/manage/subAgents.d.ts +15 -15
- package/dist/data-access/manage/tools.d.ts +39 -28
- package/dist/data-access/manage/tools.js +73 -31
- package/dist/data-access/manage/triggers.d.ts +27 -1
- package/dist/data-access/runtime/apiKeys.d.ts +20 -20
- package/dist/data-access/runtime/cascade-delete.d.ts +48 -1
- package/dist/data-access/runtime/cascade-delete.js +52 -2
- package/dist/data-access/runtime/conversations.d.ts +24 -24
- package/dist/data-access/runtime/github-work-app-installations.d.ts +261 -0
- package/dist/data-access/runtime/github-work-app-installations.js +457 -0
- package/dist/data-access/runtime/messages.d.ts +18 -18
- package/dist/data-access/runtime/organizations.d.ts +2 -2
- package/dist/data-access/runtime/organizations.js +4 -4
- package/dist/data-access/runtime/tasks.d.ts +6 -6
- package/dist/db/manage/manage-schema.d.ts +533 -402
- package/dist/db/manage/manage-schema.js +38 -27
- package/dist/db/runtime/runtime-schema.d.ts +1021 -177
- package/dist/db/runtime/runtime-schema.js +173 -5
- package/dist/db/utils.d.ts +6 -0
- package/dist/db/utils.js +42 -0
- package/dist/dolt/branch.js +1 -1
- package/dist/dolt/branches-api.js +1 -1
- package/dist/dolt/index.d.ts +2 -2
- package/dist/dolt/index.js +4 -4
- package/dist/dolt/migrate-all-branches.js +6 -1
- package/dist/dolt/migrate-dolt.js +4 -1
- package/dist/dolt/ref-helpers.js +1 -1
- package/dist/dolt/ref-middleware.js +1 -1
- package/dist/dolt/ref-scope.js +1 -1
- package/dist/dolt/schema-sync.d.ts +2 -1
- package/dist/dolt/schema-sync.js +10 -1
- package/dist/env.d.ts +6 -4
- package/dist/env.js +11 -10
- package/dist/index.d.ts +15 -16
- package/dist/index.js +23 -24
- package/dist/types/@napi-rs__keyring/index.d.ts +14 -0
- package/dist/types/entities.d.ts +9 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/utility.d.ts +17 -3
- package/dist/types/utility.js +2 -1
- package/dist/utils/JsonTransformer.d.ts +1 -3
- package/dist/utils/JsonTransformer.js +14 -23
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +3 -3
- package/dist/utils/jmespath-utils.d.ts +152 -0
- package/dist/utils/jmespath-utils.js +213 -0
- package/dist/utils/mcp-client.d.ts +1 -1
- package/dist/utils/mcp-client.js +1 -1
- package/dist/utils/signature-validation.d.ts +2 -0
- package/dist/utils/signature-validation.js +3 -0
- package/dist/utils/third-party-mcp-servers/composio-client.d.ts +13 -1
- package/dist/utils/third-party-mcp-servers/composio-client.js +24 -6
- package/dist/utils/third-party-mcp-servers/index.d.ts +2 -2
- package/dist/utils/third-party-mcp-servers/index.js +2 -2
- package/dist/utils/trigger-auth.d.ts +31 -8
- package/dist/utils/trigger-auth.js +121 -13
- package/dist/validation/agentFull.js +1 -1
- package/dist/validation/drizzle-schema-helpers.d.ts +4 -23
- package/dist/validation/drizzle-schema-helpers.js +3 -30
- package/dist/validation/index.d.ts +3 -5
- package/dist/validation/index.js +5 -7
- package/dist/validation/render-validation.js +19 -0
- package/dist/validation/schemas.d.ts +3675 -1665
- package/dist/validation/schemas.js +409 -94
- package/dist/validation/stream-event-schemas.d.ts +96 -1
- package/dist/validation/stream-event-schemas.js +67 -2
- package/drizzle/manage/0003_tiny_captain_universe.sql +8 -0
- package/drizzle/manage/0004_curious_phil_sheldon.sql +2 -0
- package/drizzle/manage/0005_silent_shatterstar.sql +53 -0
- package/drizzle/manage/0006_fixed_umar.sql +1 -0
- package/drizzle/manage/meta/0003_snapshot.json +3134 -0
- package/drizzle/manage/meta/0004_snapshot.json +3141 -0
- package/drizzle/manage/meta/0005_snapshot.json +3141 -0
- package/drizzle/manage/meta/0006_snapshot.json +3148 -0
- package/drizzle/manage/meta/_journal.json +28 -0
- package/drizzle/runtime/0010_previous_black_knight.sql +84 -0
- package/drizzle/runtime/meta/0010_snapshot.json +3066 -0
- package/drizzle/runtime/meta/_journal.json +7 -0
- package/package.json +12 -5
- package/spicedb/schema.zed +114 -0
- package/dist/validation/id-validation.d.ts +0 -24
- package/dist/validation/id-validation.js +0 -52
|
@@ -1,32 +1,23 @@
|
|
|
1
|
+
import { DANGEROUS_PATTERNS, MAX_EXPRESSION_LENGTH, compileJMESPath, validateJMESPathSecure } from "./jmespath-utils.js";
|
|
1
2
|
import { getLogger } from "./logger.js";
|
|
2
|
-
import * as jmespath
|
|
3
|
+
import * as jmespath from "jmespath";
|
|
3
4
|
|
|
4
5
|
//#region src/utils/JsonTransformer.ts
|
|
5
|
-
const jmespathExt = jmespath$1;
|
|
6
6
|
const logger = getLogger("JsonTransformer");
|
|
7
7
|
var JsonTransformer = class JsonTransformer {
|
|
8
8
|
static DEFAULT_TIMEOUT = 5e3;
|
|
9
|
-
static MAX_EXPRESSION_LENGTH = 1e3;
|
|
10
|
-
static DANGEROUS_PATTERNS = [
|
|
11
|
-
/\$\{.*\}/,
|
|
12
|
-
/eval\s*\(/,
|
|
13
|
-
/function\s*\(/,
|
|
14
|
-
/constructor/,
|
|
15
|
-
/prototype/,
|
|
16
|
-
/__proto__/
|
|
17
|
-
];
|
|
18
9
|
/**
|
|
19
10
|
* Validate JMESPath expression for security and correctness
|
|
20
11
|
*/
|
|
21
|
-
static
|
|
12
|
+
static validateExpression(expression, _allowedFunctions) {
|
|
22
13
|
if (!expression || typeof expression !== "string") throw new Error("JMESPath expression must be a non-empty string");
|
|
23
|
-
if (expression.length >
|
|
24
|
-
for (const pattern of
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
14
|
+
if (expression.length > MAX_EXPRESSION_LENGTH) throw new Error(`JMESPath expression too long (max ${MAX_EXPRESSION_LENGTH} characters)`);
|
|
15
|
+
for (const pattern of DANGEROUS_PATTERNS) if (pattern.test(expression)) throw new Error(`JMESPath expression contains dangerous pattern: ${pattern.source}`);
|
|
16
|
+
const result = validateJMESPathSecure(expression, {
|
|
17
|
+
maxLength: MAX_EXPRESSION_LENGTH + 1,
|
|
18
|
+
dangerousPatterns: []
|
|
19
|
+
});
|
|
20
|
+
if (!result.valid) throw new Error(`Invalid JMESPath syntax: ${result.error}`);
|
|
30
21
|
logger.debug("JMESPath expression validated", `${expression.substring(0, 100)}...`);
|
|
31
22
|
}
|
|
32
23
|
/**
|
|
@@ -38,7 +29,7 @@ var JsonTransformer = class JsonTransformer {
|
|
|
38
29
|
reject(/* @__PURE__ */ new Error(`JMESPath transformation timed out after ${timeoutMs}ms`));
|
|
39
30
|
}, timeoutMs);
|
|
40
31
|
try {
|
|
41
|
-
const result = jmespath
|
|
32
|
+
const result = jmespath.search(input, expression);
|
|
42
33
|
clearTimeout(timeout);
|
|
43
34
|
resolve(result);
|
|
44
35
|
} catch (error) {
|
|
@@ -52,7 +43,7 @@ var JsonTransformer = class JsonTransformer {
|
|
|
52
43
|
*/
|
|
53
44
|
static async transform(input, jmesPathExpression, options = {}) {
|
|
54
45
|
const { timeout = JsonTransformer.DEFAULT_TIMEOUT, allowedFunctions } = options;
|
|
55
|
-
JsonTransformer.
|
|
46
|
+
JsonTransformer.validateExpression(jmesPathExpression, allowedFunctions);
|
|
56
47
|
try {
|
|
57
48
|
logger.debug("Executing JMESPath transformation", `inputType: ${typeof input}, expression: ${jmesPathExpression.substring(0, 100)}..., timeout: ${timeout}`);
|
|
58
49
|
const result = await JsonTransformer.executeWithTimeout(input, jmesPathExpression, timeout);
|
|
@@ -74,7 +65,7 @@ var JsonTransformer = class JsonTransformer {
|
|
|
74
65
|
if (!key || typeof key !== "string") throw new Error("Object transformation keys must be non-empty strings");
|
|
75
66
|
if (!path || typeof path !== "string") throw new Error("Object transformation values must be non-empty strings");
|
|
76
67
|
try {
|
|
77
|
-
|
|
68
|
+
compileJMESPath(path);
|
|
78
69
|
} catch (error) {
|
|
79
70
|
throw new Error(`Invalid JMESPath in object transformation value "${path}": ${error instanceof Error ? error.message : String(error)}`);
|
|
80
71
|
}
|
|
@@ -101,7 +92,7 @@ var JsonTransformer = class JsonTransformer {
|
|
|
101
92
|
static transformSync(input, jmesPathExpression) {
|
|
102
93
|
logger.warn("Using deprecated synchronous transform method - security validation bypassed", "");
|
|
103
94
|
try {
|
|
104
|
-
return jmespath
|
|
95
|
+
return jmespath.search(input, jmesPathExpression);
|
|
105
96
|
} catch (error) {
|
|
106
97
|
throw new Error(`JMESPath transformation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
107
98
|
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -16,9 +16,9 @@ import { convertZodToJsonSchema, convertZodToJsonSchemaWithPreview, extractPrevi
|
|
|
16
16
|
import { GenerateServiceTokenParams, ServiceTokenPayload, VerifyServiceTokenResult, generateServiceToken, validateTargetAgent, validateTenantId, verifyAuthorizationHeader, verifyServiceToken } from "./service-token-auth.js";
|
|
17
17
|
import { SignedTempToken, TempTokenPayload, signTempToken, verifyTempToken } from "./temp-jwt.js";
|
|
18
18
|
import { interpolateTemplate } from "./template-interpolation.js";
|
|
19
|
-
import { CredentialScope, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated } from "./third-party-mcp-servers/composio-client.js";
|
|
19
|
+
import { CredentialScope, buildComposioMCPUrl, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated } from "./third-party-mcp-servers/composio-client.js";
|
|
20
20
|
import { isThirdPartyMCPServerAuthenticated } from "./third-party-mcp-servers/third-party-check.js";
|
|
21
21
|
import "./third-party-mcp-servers/index.js";
|
|
22
22
|
import { getTracer, setSpanWithError } from "./tracer-factory.js";
|
|
23
|
-
import { HashedHeaderValue, TriggerAuthResult, hashAuthenticationHeaders, hashTriggerHeaderValue, validateTriggerHeaderValue,
|
|
24
|
-
export { ApiKeyGenerationResult, CommonCreateErrorResponses, CommonDeleteErrorResponses, CommonGetErrorResponses, CommonUpdateErrorResponses, CredentialScope, ERROR_DOCS_BASE_URL, ErrorCode, ErrorCodes, ErrorResponse, GenerateInternalServiceTokenParams, GenerateServiceTokenParams, HashedHeaderValue, InternalServiceId, InternalServiceTokenPayload, InternalServices, JsonTransformer, JwtVerifyResult, LLMMessage, LoggerFactoryConfig, McpClient, McpClientOptions, McpOAuthFlowResult, McpSSEConfig, McpServerConfig, McpStreamableHttpConfig, McpTokenExchangeResult, ModelFactory, OAuthConfig, PinoLogger, PinoLoggerConfig, ProblemDetails, ServiceTokenPayload, SignJwtOptions, SignedTempToken, TempTokenPayload, TriggerAuthResult, VerifyInternalServiceTokenResult, VerifyJwtOptions, VerifyServiceTokenResult, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, convertZodToJsonSchema, convertZodToJsonSchemaWithPreview, createApiError, decodeJwtPayload, detectAuthenticationRequired, errorResponseSchema, errorSchemaFactory, exchangeMcpAuthorizationCode, extractBearerToken, extractComposioServerId, extractPreviewFields, extractPublicId, fetchComposioServers, fetchSingleComposioServer, formatMessagesForLLM, formatMessagesForLLMContext, generateApiKey, generateId, generateInternalServiceToken, generateServiceToken, getComposioOAuthRedirectUrl, getComposioUserId, getConversationId, getCredentialStoreLookupKeyFromRetrievalParams, getJwtSecret, getLogger, getMetadataFromApiKey, getTracer, handleApiError, hasIssuer, hashApiKey, hashAuthenticationHeaders, hashTriggerHeaderValue, initiateMcpOAuthFlow, interpolateTemplate, isApiKeyExpired, isComposioMCPServerAuthenticated, isInternalServiceToken, isThirdPartyMCPServerAuthenticated, isZodSchema, jsonSchemaToZod, loggerFactory, maskApiKey, normalizeDateString, parseEmbeddedJson, preview, problemDetailsSchema, setSpanWithError, signJwt, signTempToken, toISODateString, validateApiKey, validateInternalServiceProjectAccess, validateInternalServiceTenantAccess, validateTargetAgent, validateTenantId, validateTriggerHeaderValue, verifyAuthorizationHeader, verifyInternalServiceAuthHeader, verifyInternalServiceToken, verifyJwt, verifyServiceToken,
|
|
23
|
+
import { HashedHeaderValue, SignatureVerificationErrorCode, SignatureVerificationResult, TriggerAuthResult, hashAuthenticationHeaders, hashTriggerHeaderValue, validateTriggerHeaderValue, verifySignatureWithConfig, verifyTriggerAuth } from "./trigger-auth.js";
|
|
24
|
+
export { ApiKeyGenerationResult, CommonCreateErrorResponses, CommonDeleteErrorResponses, CommonGetErrorResponses, CommonUpdateErrorResponses, CredentialScope, ERROR_DOCS_BASE_URL, ErrorCode, ErrorCodes, ErrorResponse, GenerateInternalServiceTokenParams, GenerateServiceTokenParams, HashedHeaderValue, InternalServiceId, InternalServiceTokenPayload, InternalServices, JsonTransformer, JwtVerifyResult, LLMMessage, LoggerFactoryConfig, McpClient, McpClientOptions, McpOAuthFlowResult, McpSSEConfig, McpServerConfig, McpStreamableHttpConfig, McpTokenExchangeResult, ModelFactory, OAuthConfig, PinoLogger, PinoLoggerConfig, ProblemDetails, ServiceTokenPayload, SignJwtOptions, SignatureVerificationErrorCode, SignatureVerificationResult, SignedTempToken, TempTokenPayload, TriggerAuthResult, VerifyInternalServiceTokenResult, VerifyJwtOptions, VerifyServiceTokenResult, buildComposioMCPUrl, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, convertZodToJsonSchema, convertZodToJsonSchemaWithPreview, createApiError, decodeJwtPayload, detectAuthenticationRequired, errorResponseSchema, errorSchemaFactory, exchangeMcpAuthorizationCode, extractBearerToken, extractComposioServerId, extractPreviewFields, extractPublicId, fetchComposioServers, fetchSingleComposioServer, formatMessagesForLLM, formatMessagesForLLMContext, generateApiKey, generateId, generateInternalServiceToken, generateServiceToken, getComposioOAuthRedirectUrl, getComposioUserId, getConversationId, getCredentialStoreLookupKeyFromRetrievalParams, getJwtSecret, getLogger, getMetadataFromApiKey, getTracer, handleApiError, hasIssuer, hashApiKey, hashAuthenticationHeaders, hashTriggerHeaderValue, initiateMcpOAuthFlow, interpolateTemplate, isApiKeyExpired, isComposioMCPServerAuthenticated, isInternalServiceToken, isThirdPartyMCPServerAuthenticated, isZodSchema, jsonSchemaToZod, loggerFactory, maskApiKey, normalizeDateString, parseEmbeddedJson, preview, problemDetailsSchema, setSpanWithError, signJwt, signTempToken, toISODateString, validateApiKey, validateInternalServiceProjectAccess, validateInternalServiceTenantAccess, validateTargetAgent, validateTenantId, validateTriggerHeaderValue, verifyAuthorizationHeader, verifyInternalServiceAuthHeader, verifyInternalServiceToken, verifyJwt, verifyServiceToken, verifySignatureWithConfig, verifyTempToken, verifyTriggerAuth };
|
package/dist/utils/index.js
CHANGED
|
@@ -16,10 +16,10 @@ import { ModelFactory } from "./model-factory.js";
|
|
|
16
16
|
import { generateServiceToken, validateTargetAgent, validateTenantId, verifyAuthorizationHeader, verifyServiceToken } from "./service-token-auth.js";
|
|
17
17
|
import { signTempToken, verifyTempToken } from "./temp-jwt.js";
|
|
18
18
|
import { interpolateTemplate } from "./template-interpolation.js";
|
|
19
|
-
import { extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated } from "./third-party-mcp-servers/composio-client.js";
|
|
19
|
+
import { buildComposioMCPUrl, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated } from "./third-party-mcp-servers/composio-client.js";
|
|
20
20
|
import { isThirdPartyMCPServerAuthenticated } from "./third-party-mcp-servers/third-party-check.js";
|
|
21
21
|
import "./third-party-mcp-servers/index.js";
|
|
22
22
|
import { getTracer, setSpanWithError } from "./tracer-factory.js";
|
|
23
|
-
import { hashAuthenticationHeaders, hashTriggerHeaderValue, validateTriggerHeaderValue,
|
|
23
|
+
import { hashAuthenticationHeaders, hashTriggerHeaderValue, validateTriggerHeaderValue, verifySignatureWithConfig, verifyTriggerAuth } from "./trigger-auth.js";
|
|
24
24
|
|
|
25
|
-
export { ERROR_DOCS_BASE_URL, ErrorCode, InternalServices, JsonTransformer, McpClient, ModelFactory, PinoLogger, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, convertZodToJsonSchema, convertZodToJsonSchemaWithPreview, createApiError, decodeJwtPayload, detectAuthenticationRequired, errorResponseSchema, errorSchemaFactory, exchangeMcpAuthorizationCode, extractBearerToken, extractComposioServerId, extractPreviewFields, extractPublicId, fetchComposioServers, fetchSingleComposioServer, formatMessagesForLLM, formatMessagesForLLMContext, generateApiKey, generateId, generateInternalServiceToken, generateServiceToken, getComposioOAuthRedirectUrl, getComposioUserId, getConversationId, getCredentialStoreLookupKeyFromRetrievalParams, getJwtSecret, getLogger, getMetadataFromApiKey, getTracer, handleApiError, hasIssuer, hashApiKey, hashAuthenticationHeaders, hashTriggerHeaderValue, initiateMcpOAuthFlow, interpolateTemplate, isApiKeyExpired, isComposioMCPServerAuthenticated, isInternalServiceToken, isThirdPartyMCPServerAuthenticated, isZodSchema, jsonSchemaToZod, loggerFactory, maskApiKey, normalizeDateString, parseEmbeddedJson, preview, problemDetailsSchema, setSpanWithError, signJwt, signTempToken, toISODateString, validateApiKey, validateInternalServiceProjectAccess, validateInternalServiceTenantAccess, validateTargetAgent, validateTenantId, validateTriggerHeaderValue, verifyAuthorizationHeader, verifyInternalServiceAuthHeader, verifyInternalServiceToken, verifyJwt, verifyServiceToken,
|
|
25
|
+
export { ERROR_DOCS_BASE_URL, ErrorCode, InternalServices, JsonTransformer, McpClient, ModelFactory, PinoLogger, buildComposioMCPUrl, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, convertZodToJsonSchema, convertZodToJsonSchemaWithPreview, createApiError, decodeJwtPayload, detectAuthenticationRequired, errorResponseSchema, errorSchemaFactory, exchangeMcpAuthorizationCode, extractBearerToken, extractComposioServerId, extractPreviewFields, extractPublicId, fetchComposioServers, fetchSingleComposioServer, formatMessagesForLLM, formatMessagesForLLMContext, generateApiKey, generateId, generateInternalServiceToken, generateServiceToken, getComposioOAuthRedirectUrl, getComposioUserId, getConversationId, getCredentialStoreLookupKeyFromRetrievalParams, getJwtSecret, getLogger, getMetadataFromApiKey, getTracer, handleApiError, hasIssuer, hashApiKey, hashAuthenticationHeaders, hashTriggerHeaderValue, initiateMcpOAuthFlow, interpolateTemplate, isApiKeyExpired, isComposioMCPServerAuthenticated, isInternalServiceToken, isThirdPartyMCPServerAuthenticated, isZodSchema, jsonSchemaToZod, loggerFactory, maskApiKey, normalizeDateString, parseEmbeddedJson, preview, problemDetailsSchema, setSpanWithError, signJwt, signTempToken, toISODateString, validateApiKey, validateInternalServiceProjectAccess, validateInternalServiceTenantAccess, validateTargetAgent, validateTenantId, validateTriggerHeaderValue, verifyAuthorizationHeader, verifyInternalServiceAuthHeader, verifyInternalServiceToken, verifyJwt, verifyServiceToken, verifySignatureWithConfig, verifyTempToken, verifyTriggerAuth };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { z } from "@hono/zod-openapi";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/jmespath-utils.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Result of validating a JMESPath expression or regex pattern.
|
|
7
|
+
*/
|
|
8
|
+
interface ValidationResult {
|
|
9
|
+
valid: boolean;
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Maximum allowed length for JMESPath expressions.
|
|
14
|
+
*/
|
|
15
|
+
declare const MAX_EXPRESSION_LENGTH = 1000;
|
|
16
|
+
/**
|
|
17
|
+
* Validates a JMESPath expression by attempting to compile it.
|
|
18
|
+
* Uses the jmespath package which is already available in the codebase.
|
|
19
|
+
*
|
|
20
|
+
* @param expression - The JMESPath expression to validate
|
|
21
|
+
* @returns ValidationResult with valid flag and optional error message
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const result = validateJMESPath('body.user.id');
|
|
26
|
+
* if (!result.valid) {
|
|
27
|
+
* console.error(result.error);
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare function validateJMESPath(expression: string): ValidationResult;
|
|
32
|
+
/**
|
|
33
|
+
* Validates a regex pattern by attempting to construct a RegExp object.
|
|
34
|
+
* Returns clear error messages for common regex issues.
|
|
35
|
+
*
|
|
36
|
+
* @param pattern - The regex pattern to validate (without delimiters)
|
|
37
|
+
* @returns ValidationResult with valid flag and optional error message
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const result = validateRegex('v\\d+,(.+)');
|
|
42
|
+
* if (!result.valid) {
|
|
43
|
+
* console.error(result.error);
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare function validateRegex(pattern: string): ValidationResult;
|
|
48
|
+
/**
|
|
49
|
+
* Compiles a JMESPath expression.
|
|
50
|
+
* Wrapper around jmespath.compile() with proper typing.
|
|
51
|
+
*
|
|
52
|
+
* @param expression - The JMESPath expression to compile
|
|
53
|
+
* @returns The compiled expression object
|
|
54
|
+
* @throws Error if the expression is invalid
|
|
55
|
+
*/
|
|
56
|
+
declare function compileJMESPath(expression: string): unknown;
|
|
57
|
+
/**
|
|
58
|
+
* Safely searches data using a JMESPath expression.
|
|
59
|
+
* Wrapper around jmespath.search() with proper typing.
|
|
60
|
+
*
|
|
61
|
+
* @param data - The object to search (e.g., template context, webhook body, tool result)
|
|
62
|
+
* @param expression - The JMESPath expression
|
|
63
|
+
* @returns The search result
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const data = { users: [{ name: 'Alice' }] };
|
|
68
|
+
* const name = searchJMESPath<string>(data, 'users[0].name');
|
|
69
|
+
* // name is 'Alice'
|
|
70
|
+
*
|
|
71
|
+
* // Common use cases:
|
|
72
|
+
* // - Template contexts: { headers: {...}, body: {...} }
|
|
73
|
+
* // - Webhook payloads: { event: "...", data: {...} }
|
|
74
|
+
* // - Tool results: { status: "success", result: {...} }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function searchJMESPath<T = unknown>(data: Record<string, unknown>, expression: string): T;
|
|
78
|
+
/**
|
|
79
|
+
* Normalize a JMESPath expression by wrapping property names with dashes in quotes.
|
|
80
|
+
* JMESPath requires identifiers with special characters (like dashes) to be quoted.
|
|
81
|
+
*
|
|
82
|
+
* @param path - The JMESPath expression to normalize
|
|
83
|
+
* @returns The normalized JMESPath expression
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* normalizeJMESPath('headers.x-tenant-id');
|
|
88
|
+
* // Returns: 'headers."x-tenant-id"'
|
|
89
|
+
*
|
|
90
|
+
* normalizeJMESPath('api-responses[0].response-code');
|
|
91
|
+
* // Returns: '"api-responses"[0]."response-code"'
|
|
92
|
+
*
|
|
93
|
+
* normalizeJMESPath('simple.path');
|
|
94
|
+
* // Returns: 'simple.path' (unchanged)
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function normalizeJMESPath(path: string): string;
|
|
98
|
+
/**
|
|
99
|
+
* Dangerous patterns that should not appear in JMESPath expressions.
|
|
100
|
+
* These patterns are checked during secure validation to prevent injection attacks.
|
|
101
|
+
*/
|
|
102
|
+
declare const DANGEROUS_PATTERNS: RegExp[];
|
|
103
|
+
/**
|
|
104
|
+
* Options for secure JMESPath validation.
|
|
105
|
+
*/
|
|
106
|
+
interface SecurityOptions {
|
|
107
|
+
maxLength?: number;
|
|
108
|
+
dangerousPatterns?: RegExp[];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Validates a JMESPath expression with security checks.
|
|
112
|
+
* Performs checks in order of cost: length (O(1)), patterns (O(n)), compile (expensive).
|
|
113
|
+
*
|
|
114
|
+
* @param expression - The JMESPath expression to validate
|
|
115
|
+
* @param options - Optional security options
|
|
116
|
+
* @returns ValidationResult with valid flag and optional error message
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const result = validateJMESPathSecure('body.user.id');
|
|
121
|
+
* if (!result.valid) {
|
|
122
|
+
* console.error(result.error);
|
|
123
|
+
* }
|
|
124
|
+
*
|
|
125
|
+
* // With custom options
|
|
126
|
+
* const result2 = validateJMESPathSecure('expression', { maxLength: 500 });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function validateJMESPathSecure(expression: string, options?: SecurityOptions): ValidationResult;
|
|
130
|
+
/**
|
|
131
|
+
* Options for jmespathString Zod schema factory.
|
|
132
|
+
*/
|
|
133
|
+
interface JMESPathStringOptions {
|
|
134
|
+
maxLength?: number;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Creates a Zod string schema for JMESPath expressions with OpenAPI-visible constraints.
|
|
138
|
+
* Includes maxLength constraint and a description with valid/invalid examples.
|
|
139
|
+
*
|
|
140
|
+
* @param options - Optional configuration for the schema
|
|
141
|
+
* @returns A Zod string schema with maxLength and description
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const schema = z.object({
|
|
146
|
+
* transform: jmespathString().optional(),
|
|
147
|
+
* });
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare function jmespathString(options?: JMESPathStringOptions): z.ZodString;
|
|
151
|
+
//#endregion
|
|
152
|
+
export { DANGEROUS_PATTERNS, JMESPathStringOptions, MAX_EXPRESSION_LENGTH, SecurityOptions, ValidationResult, compileJMESPath, jmespathString, normalizeJMESPath, searchJMESPath, validateJMESPath, validateJMESPathSecure, validateRegex };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { z } from "@hono/zod-openapi";
|
|
2
|
+
import * as jmespath from "jmespath";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/jmespath-utils.ts
|
|
5
|
+
const jmespathExt = jmespath;
|
|
6
|
+
/**
|
|
7
|
+
* Maximum allowed length for JMESPath expressions.
|
|
8
|
+
*/
|
|
9
|
+
const MAX_EXPRESSION_LENGTH = 1e3;
|
|
10
|
+
/**
|
|
11
|
+
* Validates a JMESPath expression by attempting to compile it.
|
|
12
|
+
* Uses the jmespath package which is already available in the codebase.
|
|
13
|
+
*
|
|
14
|
+
* @param expression - The JMESPath expression to validate
|
|
15
|
+
* @returns ValidationResult with valid flag and optional error message
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const result = validateJMESPath('body.user.id');
|
|
20
|
+
* if (!result.valid) {
|
|
21
|
+
* console.error(result.error);
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function validateJMESPath(expression) {
|
|
26
|
+
if (!expression || typeof expression !== "string") return {
|
|
27
|
+
valid: false,
|
|
28
|
+
error: "JMESPath expression must be a non-empty string"
|
|
29
|
+
};
|
|
30
|
+
try {
|
|
31
|
+
jmespathExt.compile(expression);
|
|
32
|
+
return { valid: true };
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return {
|
|
35
|
+
valid: false,
|
|
36
|
+
error: `Invalid JMESPath expression: ${error instanceof Error ? error.message : String(error)}`
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validates a regex pattern by attempting to construct a RegExp object.
|
|
42
|
+
* Returns clear error messages for common regex issues.
|
|
43
|
+
*
|
|
44
|
+
* @param pattern - The regex pattern to validate (without delimiters)
|
|
45
|
+
* @returns ValidationResult with valid flag and optional error message
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const result = validateRegex('v\\d+,(.+)');
|
|
50
|
+
* if (!result.valid) {
|
|
51
|
+
* console.error(result.error);
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
function validateRegex(pattern) {
|
|
56
|
+
if (pattern === null || pattern === void 0) return {
|
|
57
|
+
valid: false,
|
|
58
|
+
error: "Regex pattern must be provided"
|
|
59
|
+
};
|
|
60
|
+
if (typeof pattern !== "string") return {
|
|
61
|
+
valid: false,
|
|
62
|
+
error: "Regex pattern must be a string"
|
|
63
|
+
};
|
|
64
|
+
if (pattern === "") return { valid: true };
|
|
65
|
+
try {
|
|
66
|
+
new RegExp(pattern);
|
|
67
|
+
return { valid: true };
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return {
|
|
70
|
+
valid: false,
|
|
71
|
+
error: `Invalid regex pattern: ${error instanceof Error ? error.message : String(error)}`
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Compiles a JMESPath expression.
|
|
77
|
+
* Wrapper around jmespath.compile() with proper typing.
|
|
78
|
+
*
|
|
79
|
+
* @param expression - The JMESPath expression to compile
|
|
80
|
+
* @returns The compiled expression object
|
|
81
|
+
* @throws Error if the expression is invalid
|
|
82
|
+
*/
|
|
83
|
+
function compileJMESPath(expression) {
|
|
84
|
+
return jmespathExt.compile(expression);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Safely searches data using a JMESPath expression.
|
|
88
|
+
* Wrapper around jmespath.search() with proper typing.
|
|
89
|
+
*
|
|
90
|
+
* @param data - The object to search (e.g., template context, webhook body, tool result)
|
|
91
|
+
* @param expression - The JMESPath expression
|
|
92
|
+
* @returns The search result
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const data = { users: [{ name: 'Alice' }] };
|
|
97
|
+
* const name = searchJMESPath<string>(data, 'users[0].name');
|
|
98
|
+
* // name is 'Alice'
|
|
99
|
+
*
|
|
100
|
+
* // Common use cases:
|
|
101
|
+
* // - Template contexts: { headers: {...}, body: {...} }
|
|
102
|
+
* // - Webhook payloads: { event: "...", data: {...} }
|
|
103
|
+
* // - Tool results: { status: "success", result: {...} }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
function searchJMESPath(data, expression) {
|
|
107
|
+
return jmespath.search(data, expression);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Normalize a JMESPath expression by wrapping property names with dashes in quotes.
|
|
111
|
+
* JMESPath requires identifiers with special characters (like dashes) to be quoted.
|
|
112
|
+
*
|
|
113
|
+
* @param path - The JMESPath expression to normalize
|
|
114
|
+
* @returns The normalized JMESPath expression
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* normalizeJMESPath('headers.x-tenant-id');
|
|
119
|
+
* // Returns: 'headers."x-tenant-id"'
|
|
120
|
+
*
|
|
121
|
+
* normalizeJMESPath('api-responses[0].response-code');
|
|
122
|
+
* // Returns: '"api-responses"[0]."response-code"'
|
|
123
|
+
*
|
|
124
|
+
* normalizeJMESPath('simple.path');
|
|
125
|
+
* // Returns: 'simple.path' (unchanged)
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
function normalizeJMESPath(path) {
|
|
129
|
+
return path.split(".").map((segment) => {
|
|
130
|
+
if (!segment.includes("-")) return segment;
|
|
131
|
+
if (segment.startsWith("\"") && segment.includes("\"")) return segment;
|
|
132
|
+
const bracketIndex = segment.indexOf("[");
|
|
133
|
+
if (bracketIndex !== -1) return `"${segment.substring(0, bracketIndex)}"${segment.substring(bracketIndex)}`;
|
|
134
|
+
return `"${segment}"`;
|
|
135
|
+
}).join(".");
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Dangerous patterns that should not appear in JMESPath expressions.
|
|
139
|
+
* These patterns are checked during secure validation to prevent injection attacks.
|
|
140
|
+
*/
|
|
141
|
+
const DANGEROUS_PATTERNS = [
|
|
142
|
+
/\$\{.*\}/,
|
|
143
|
+
/eval\s*\(/,
|
|
144
|
+
/function\s*\(/,
|
|
145
|
+
/constructor/,
|
|
146
|
+
/prototype/,
|
|
147
|
+
/__proto__/
|
|
148
|
+
];
|
|
149
|
+
/**
|
|
150
|
+
* Validates a JMESPath expression with security checks.
|
|
151
|
+
* Performs checks in order of cost: length (O(1)), patterns (O(n)), compile (expensive).
|
|
152
|
+
*
|
|
153
|
+
* @param expression - The JMESPath expression to validate
|
|
154
|
+
* @param options - Optional security options
|
|
155
|
+
* @returns ValidationResult with valid flag and optional error message
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const result = validateJMESPathSecure('body.user.id');
|
|
160
|
+
* if (!result.valid) {
|
|
161
|
+
* console.error(result.error);
|
|
162
|
+
* }
|
|
163
|
+
*
|
|
164
|
+
* // With custom options
|
|
165
|
+
* const result2 = validateJMESPathSecure('expression', { maxLength: 500 });
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
function validateJMESPathSecure(expression, options) {
|
|
169
|
+
if (!expression || typeof expression !== "string") return {
|
|
170
|
+
valid: false,
|
|
171
|
+
error: "JMESPath expression must be a non-empty string"
|
|
172
|
+
};
|
|
173
|
+
const maxLength = options?.maxLength ?? MAX_EXPRESSION_LENGTH;
|
|
174
|
+
const patterns = options?.dangerousPatterns ?? DANGEROUS_PATTERNS;
|
|
175
|
+
if (expression.length > maxLength) return {
|
|
176
|
+
valid: false,
|
|
177
|
+
error: `JMESPath expression exceeds maximum length of ${maxLength} characters`
|
|
178
|
+
};
|
|
179
|
+
for (const pattern of patterns) if (pattern.test(expression)) return {
|
|
180
|
+
valid: false,
|
|
181
|
+
error: `JMESPath expression contains dangerous pattern: ${pattern.source}`
|
|
182
|
+
};
|
|
183
|
+
try {
|
|
184
|
+
jmespathExt.compile(expression);
|
|
185
|
+
return { valid: true };
|
|
186
|
+
} catch (error) {
|
|
187
|
+
return {
|
|
188
|
+
valid: false,
|
|
189
|
+
error: `Invalid JMESPath expression: ${error instanceof Error ? error.message : String(error)}`
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Creates a Zod string schema for JMESPath expressions with OpenAPI-visible constraints.
|
|
195
|
+
* Includes maxLength constraint and a description with valid/invalid examples.
|
|
196
|
+
*
|
|
197
|
+
* @param options - Optional configuration for the schema
|
|
198
|
+
* @returns A Zod string schema with maxLength and description
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const schema = z.object({
|
|
203
|
+
* transform: jmespathString().optional(),
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
function jmespathString(options) {
|
|
208
|
+
const maxLen = options?.maxLength ?? MAX_EXPRESSION_LENGTH;
|
|
209
|
+
return z.string().max(maxLen).describe(`JMESPath expression (max ${maxLen} chars). Valid: "data.items[0].name", "results[?status=='active']", "keys(@)". Invalid: "\${...}" (template injection), "eval" calls, "constructor", "__proto__".`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
//#endregion
|
|
213
|
+
export { DANGEROUS_PATTERNS, MAX_EXPRESSION_LENGTH, compileJMESPath, jmespathString, normalizeJMESPath, searchJMESPath, validateJMESPath, validateJMESPathSecure, validateRegex };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MCPTransportType } from "../types/utility.js";
|
|
2
|
+
import { ClientCapabilities } from "@modelcontextprotocol/sdk/types.js";
|
|
2
3
|
import { SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
3
4
|
import { StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
|
-
import { ClientCapabilities } from "@modelcontextprotocol/sdk/types.js";
|
|
5
5
|
|
|
6
6
|
//#region src/utils/mcp-client.d.ts
|
|
7
7
|
interface SharedServerConfig {
|
package/dist/utils/mcp-client.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MCPTransportType } from "../types/utility.js";
|
|
2
2
|
import { MCP_TOOL_CONNECTION_TIMEOUT_MS, MCP_TOOL_INITIAL_RECONNECTION_DELAY_MS, MCP_TOOL_MAX_RECONNECTION_DELAY_MS, MCP_TOOL_MAX_RETRIES, MCP_TOOL_RECONNECTION_DELAY_GROWTH_FACTOR } from "../constants/execution-limits-shared/index.js";
|
|
3
3
|
import { z } from "@hono/zod-openapi";
|
|
4
|
+
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
4
5
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
5
6
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
6
7
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
7
8
|
import { DEFAULT_REQUEST_TIMEOUT_MSEC } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
8
|
-
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
9
9
|
import { tool } from "ai";
|
|
10
10
|
import { asyncExitHook, gracefulExit } from "exit-hook";
|
|
11
11
|
import { match } from "ts-pattern";
|
|
@@ -14,6 +14,18 @@ type CredentialScope = 'project' | 'user';
|
|
|
14
14
|
* - For user-scoped: uses the actual user ID (per-user credentials)
|
|
15
15
|
*/
|
|
16
16
|
declare function getComposioUserId(tenantId: string, projectId: string, credentialScope: CredentialScope, userId?: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Build a Composio MCP URL with the appropriate user_id parameter
|
|
19
|
+
* Consolidates user_id injection logic used across the codebase
|
|
20
|
+
*
|
|
21
|
+
* @param baseUrl - The base MCP server URL
|
|
22
|
+
* @param tenantId - The tenant ID
|
|
23
|
+
* @param projectId - The project ID
|
|
24
|
+
* @param credentialScope - Whether credentials are 'project' or 'user' scoped
|
|
25
|
+
* @param userId - Optional user ID (required for user-scoped credentials)
|
|
26
|
+
* @returns The URL with user_id parameter set, or original URL if not a Composio URL
|
|
27
|
+
*/
|
|
28
|
+
declare function buildComposioMCPUrl(baseUrl: string, tenantId: string, projectId: string, credentialScope: CredentialScope, userId?: string): string;
|
|
17
29
|
/**
|
|
18
30
|
* Extract server ID from a Composio MCP URL
|
|
19
31
|
* Example: https://backend.composio.dev/v3/mcp/1234-1234-1234?user_id=... -> 1234-1234-1234
|
|
@@ -44,4 +56,4 @@ declare function fetchComposioServers(): Promise<PrebuiltMCPServer[]>;
|
|
|
44
56
|
*/
|
|
45
57
|
declare function fetchSingleComposioServer(tenantId: string, projectId: string, mcpServerUrl: string, credentialScope?: CredentialScope, userId?: string): Promise<PrebuiltMCPServer | null>;
|
|
46
58
|
//#endregion
|
|
47
|
-
export { CredentialScope, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated };
|
|
59
|
+
export { CredentialScope, buildComposioMCPUrl, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated };
|
|
@@ -67,6 +67,25 @@ function getComposioUserId(tenantId, projectId, credentialScope, userId) {
|
|
|
67
67
|
return deriveComposioUserId(tenantId, projectId);
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
+
* Build a Composio MCP URL with the appropriate user_id parameter
|
|
71
|
+
* Consolidates user_id injection logic used across the codebase
|
|
72
|
+
*
|
|
73
|
+
* @param baseUrl - The base MCP server URL
|
|
74
|
+
* @param tenantId - The tenant ID
|
|
75
|
+
* @param projectId - The project ID
|
|
76
|
+
* @param credentialScope - Whether credentials are 'project' or 'user' scoped
|
|
77
|
+
* @param userId - Optional user ID (required for user-scoped credentials)
|
|
78
|
+
* @returns The URL with user_id parameter set, or original URL if not a Composio URL
|
|
79
|
+
*/
|
|
80
|
+
function buildComposioMCPUrl(baseUrl, tenantId, projectId, credentialScope, userId) {
|
|
81
|
+
if (!baseUrl.includes("composio.dev")) return baseUrl;
|
|
82
|
+
const urlObj = new URL(baseUrl);
|
|
83
|
+
if (urlObj.searchParams.has("user_id")) return baseUrl;
|
|
84
|
+
const composioUserId = getComposioUserId(tenantId, projectId, credentialScope, userId);
|
|
85
|
+
urlObj.searchParams.set("user_id", composioUserId);
|
|
86
|
+
return urlObj.toString();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
70
89
|
* Extract server ID from a Composio MCP URL
|
|
71
90
|
* Example: https://backend.composio.dev/v3/mcp/1234-1234-1234?user_id=... -> 1234-1234-1234
|
|
72
91
|
*/
|
|
@@ -142,12 +161,11 @@ async function isComposioMCPServerAuthenticated(tenantId, projectId, mcpServerUr
|
|
|
142
161
|
return false;
|
|
143
162
|
}
|
|
144
163
|
try {
|
|
145
|
-
const composioMcpServer = await composioInstance.mcp.get(serverId);
|
|
146
|
-
|
|
147
|
-
if (!firstAuthConfigId) return false;
|
|
148
|
-
const connectedAccounts = await fetchComposioConnectedAccounts(composioUserId);
|
|
164
|
+
const [composioMcpServer, connectedAccounts] = await Promise.all([composioInstance.mcp.get(serverId), fetchComposioConnectedAccounts(composioUserId)]);
|
|
165
|
+
if (!(composioMcpServer.authConfigIds.length > 0 ? composioMcpServer.authConfigIds[0] : null)) return false;
|
|
149
166
|
if (!connectedAccounts) return false;
|
|
150
|
-
|
|
167
|
+
const activeAuthConfigIds = new Set(connectedAccounts.items.filter((account) => account.status === "ACTIVE").map((account) => account.authConfig.id));
|
|
168
|
+
return composioMcpServer.authConfigIds.some((authConfigId) => activeAuthConfigIds.has(authConfigId));
|
|
151
169
|
} catch (error) {
|
|
152
170
|
logger$1.error({
|
|
153
171
|
error,
|
|
@@ -316,4 +334,4 @@ async function fetchSingleComposioServer(tenantId, projectId, mcpServerUrl, cred
|
|
|
316
334
|
}
|
|
317
335
|
|
|
318
336
|
//#endregion
|
|
319
|
-
export { extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated };
|
|
337
|
+
export { buildComposioMCPUrl, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CredentialScope, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated } from "./composio-client.js";
|
|
1
|
+
import { CredentialScope, buildComposioMCPUrl, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated } from "./composio-client.js";
|
|
2
2
|
import { isThirdPartyMCPServerAuthenticated } from "./third-party-check.js";
|
|
3
|
-
export { CredentialScope, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated, isThirdPartyMCPServerAuthenticated };
|
|
3
|
+
export { CredentialScope, buildComposioMCPUrl, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated, isThirdPartyMCPServerAuthenticated };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated } from "./composio-client.js";
|
|
1
|
+
import { buildComposioMCPUrl, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated } from "./composio-client.js";
|
|
2
2
|
import { isThirdPartyMCPServerAuthenticated } from "./third-party-check.js";
|
|
3
3
|
|
|
4
|
-
export { extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated, isThirdPartyMCPServerAuthenticated };
|
|
4
|
+
export { buildComposioMCPUrl, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated, isThirdPartyMCPServerAuthenticated };
|