Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Fix: Relax connected account types parsing (#1733)

Musthaq Ahamadb1c35900a1d7
diff --git a/ts/packages/core/src/models/AuthScheme.ts b/ts/packages/core/src/models/AuthScheme.ts
index dd224cfa1..f93136126 100644
--- a/ts/packages/core/src/models/AuthScheme.ts
+++ b/ts/packages/core/src/models/AuthScheme.ts
@@ -86,7 +86,9 @@ export class AuthScheme {
* @param params The API key parameters
* @returns ConnectionData object
*/
- static APIKey(params: BaseConnectionFields & { api_key: string }): ConnectionData {
+ static APIKey(
+ params: BaseConnectionFields & { api_key?: string; generic_api_key?: string }
+ ): ConnectionData {
return {
authScheme: AuthSchemeTypes.API_KEY,
val: {
diff --git a/ts/packages/core/src/models/ConnectedAccounts.ts b/ts/packages/core/src/models/ConnectedAccounts.ts
index bb927656d..f0fc908eb 100644
--- a/ts/packages/core/src/models/ConnectedAccounts.ts
+++ b/ts/packages/core/src/models/ConnectedAccounts.ts
@@ -182,16 +182,18 @@ export class ConnectedAccounts {
);
}
- let state: ConnectionData | undefined = undefined;
- if (options?.config) {
- const connectionDataParsed = ConnectionDataSchema.safeParse(options.config);
- if (!connectionDataParsed.success) {
- throw new ValidationError('Failed to parse connection data', {
- cause: connectionDataParsed.error,
- });
- }
- state = connectionDataParsed.data;
- }
+ const state: ConnectionData | undefined = options?.config ?? undefined;
+ // @TODO: Commenting this out. This is a temporary fix to allow api_key to be optional, in future ideally we should fix this from API side
+
+ // if (options?.config) {
+ // const connectionDataParsed = ConnectionDataSchema.safeParse(options.config);
+ // if (!connectionDataParsed.success) {
+ // throw new ValidationError('Failed to parse connection data', {
+ // cause: connectionDataParsed.error,
+ // });
+ // }
+ // state = connectionDataParsed.data;
+ // }
const response = await this.client.connectedAccounts.create({
auth_config: {
@@ -202,7 +204,8 @@ export class ConnectedAccounts {
user_id: userId,
state,
},
- });
+ // @TODO: This is a temporary fix to allow api_key to be optional, in future ideally we should fix this from API side
+ } as ConnectedAccountCreateParamsRaw);
const redirectUrl =
typeof response.connectionData?.val?.redirectUrl === 'string'
diff --git a/ts/packages/core/src/types/connectedAccountAuthStates.types.ts b/ts/packages/core/src/types/connectedAccountAuthStates.types.ts
index 72d1e01dc..a81e1f957 100644
--- a/ts/packages/core/src/types/connectedAccountAuthStates.types.ts
+++ b/ts/packages/core/src/types/connectedAccountAuthStates.types.ts
@@ -61,6 +61,10 @@ const BaseSchemeRaw = z
server_location: z.string().optional(),
// base_url only
base_url: z.string().optional(),
+ // for api key
+ api_key: z.string().optional(),
+ // for generic api key
+ generic_api_key: z.string().optional(),
})
.catchall(z.unknown());
@@ -235,7 +239,8 @@ const BasicConnectionDataSchema = BasicInitiatingSchema;
// API_KEY
const ApiKeyInitiatingSchema = BaseSchemeRaw.extend({
status: z.literal(ConnectionStatuses.ACTIVE),
- api_key: z.string(),
+ api_key: z.string().optional(),
+ generic_api_key: z.string().optional(),
}).catchall(z.unknown());
const ApiKeyConnectionDataSchema = ApiKeyInitiatingSchema;