@composio/core 0.1.21 → 0.1.22

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/index.js CHANGED
@@ -108,19 +108,13 @@ var ToolListFilterByToolkitsSchema = z.object({
108
108
  important: z.boolean().optional(),
109
109
  cursor: z.string().optional(),
110
110
  limit: z.number().optional(),
111
- search: z.string().optional(),
112
- strict: z.boolean().optional().describe(
113
- "If true, all the non-required fields will be removed from the input/output params of the tool"
114
- )
111
+ search: z.string().optional()
115
112
  });
116
113
  var ToolListFilterBySearchSchema = z.object({
117
114
  search: z.string(),
118
115
  toolkits: z.array(z.string()).optional(),
119
116
  cursor: z.string().optional(),
120
- limit: z.number().optional(),
121
- strict: z.boolean().optional().describe(
122
- "If true, all the non-required fields will be removed from the input/output params of the tool"
123
- )
117
+ limit: z.number().optional()
124
118
  });
125
119
  var ToolListParamsSchema = z.union([
126
120
  ToolListFilterByToolsSchema,
@@ -596,7 +590,8 @@ var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
596
590
 
597
591
  // src/errors/ConnectedAccountsErrors.ts
598
592
  var ConnectedAccountErrorCodes = {
599
- CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
593
+ CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND",
594
+ MULTIPLE_CONNECTED_ACCOUNTS: "MULTIPLE_CONNECTED_ACCOUNTS"
600
595
  };
601
596
  var ComposioConnectedAccountNotFoundError = class extends ComposioError {
602
597
  constructor(message = "Connected account not found", options = {}) {
@@ -611,6 +606,17 @@ var ComposioConnectedAccountNotFoundError = class extends ComposioError {
611
606
  this.name = "ComposioConnectedAccountNotFoundError";
612
607
  }
613
608
  };
609
+ var ComposioMultipleConnectedAccountsError = class extends ComposioError {
610
+ constructor(message = "Multiple connected accounts found") {
611
+ super(message, {
612
+ code: ConnectedAccountErrorCodes.MULTIPLE_CONNECTED_ACCOUNTS,
613
+ possibleFixes: [
614
+ "Use the allowMultiple flag to allow multiple connected accounts per user for an auth config"
615
+ ]
616
+ });
617
+ this.name = "ComposioMultipleConnectedAccountsError";
618
+ }
619
+ };
614
620
 
615
621
  // src/telemetry/Telemetry.ts
616
622
  import { ComposioError as ComposioClientError } from "@composio/client";
@@ -1103,6 +1109,7 @@ var AuthConfigRetrieveResponseSchema = z2.object({
1103
1109
  authScheme: AuthSchemeEnum.optional(),
1104
1110
  credentials: z2.record(z2.string(), z2.unknown()).optional(),
1105
1111
  expectedInputFields: z2.array(z2.unknown()).optional(),
1112
+ restrictToFollowingTools: z2.array(z2.string()).optional(),
1106
1113
  isComposioManaged: z2.boolean().optional(),
1107
1114
  createdBy: z2.string().optional(),
1108
1115
  createdAt: z2.string().optional(),
@@ -1565,6 +1572,7 @@ var DefaultCreateConnectedAccountParamsSchema = z4.object({
1565
1572
  })
1566
1573
  });
1567
1574
  var CreateConnectedAccountOptionsSchema = z4.object({
1575
+ allowMultiple: z4.boolean().optional(),
1568
1576
  callbackUrl: z4.string().optional(),
1569
1577
  config: ConnectionDataSchema.optional()
1570
1578
  });
@@ -1921,37 +1929,6 @@ var CustomTools = class {
1921
1929
  }
1922
1930
  };
1923
1931
 
1924
- // src/utils/jsonSchema.ts
1925
- import { jsonSchemaToZod } from "@composio/json-schema-to-zod";
1926
- var removeNonRequiredProperties = (schema) => {
1927
- if (schema && schema.type === "object" && schema.required?.length) {
1928
- schema.properties = Object.fromEntries(
1929
- Object.entries(schema.properties || {}).filter(
1930
- ([key]) => schema.required.includes(key)
1931
- )
1932
- );
1933
- }
1934
- return schema;
1935
- };
1936
- function jsonSchemaToZodSchema(jsonSchema, { strict } = {
1937
- strict: false
1938
- }) {
1939
- try {
1940
- let schema = jsonSchema;
1941
- if (strict && schema) {
1942
- schema = removeNonRequiredProperties(
1943
- schema
1944
- );
1945
- }
1946
- const zodSchema = jsonSchemaToZod(schema);
1947
- return zodSchema;
1948
- } catch (error) {
1949
- throw new JsonSchemaToZodError("Failed to convert JSON Schema to Zod Schema", {
1950
- cause: error
1951
- });
1952
- }
1953
- }
1954
-
1955
1932
  // src/models/Tools.ts
1956
1933
  var Tools = class {
1957
1934
  client;
@@ -2212,14 +2189,7 @@ var Tools = class {
2212
2189
  const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifySchema);
2213
2190
  return this.provider.wrapTools([tool], executeToolFn);
2214
2191
  } else {
2215
- let tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
2216
- if (arg2?.strict) {
2217
- tools = tools.map((tool) => ({
2218
- ...tool,
2219
- inputParameters: tool.inputParameters ? removeNonRequiredProperties(tool.inputParameters) : void 0,
2220
- outputParameters: tool.outputParameters ? removeNonRequiredProperties(tool.outputParameters) : void 0
2221
- }));
2222
- }
2192
+ const tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
2223
2193
  return this.provider.wrapTools(tools, executeToolFn);
2224
2194
  }
2225
2195
  }
@@ -2646,7 +2616,8 @@ var AuthConfigs = class {
2646
2616
  isComposioManaged: authConfig.is_composio_managed,
2647
2617
  createdBy: authConfig.created_by,
2648
2618
  createdAt: authConfig.created_at,
2649
- lastUpdatedAt: authConfig.last_updated_at
2619
+ lastUpdatedAt: authConfig.last_updated_at,
2620
+ restrictToFollowingTools: authConfig.restrict_to_following_tools
2650
2621
  });
2651
2622
  if (result.error) {
2652
2623
  throw new ValidationError("Failed to parse auth config response", {
@@ -3143,6 +3114,19 @@ var ConnectedAccounts = class {
3143
3114
  * @link https://docs.composio.dev/reference/connected-accounts/create-connected-account
3144
3115
  */
3145
3116
  async initiate(userId, authConfigId, options) {
3117
+ const connectedAccount = await this.list({
3118
+ userIds: [userId],
3119
+ authConfigIds: [authConfigId]
3120
+ });
3121
+ if (connectedAccount.items.length > 0 && !options?.allowMultiple) {
3122
+ throw new ComposioMultipleConnectedAccountsError(
3123
+ `Multiple connected accounts found for user ${userId} in auth config ${authConfigId}`
3124
+ );
3125
+ } else if (connectedAccount.items.length > 0) {
3126
+ logger_default.warn(
3127
+ `[Warn:AllowMultiple] Multiple connected accounts found for user ${userId} in auth config ${authConfigId}`
3128
+ );
3129
+ }
3146
3130
  const response = await this.client.connectedAccounts.create({
3147
3131
  auth_config: {
3148
3132
  id: authConfigId
@@ -3611,7 +3595,10 @@ var Toolkits = class {
3611
3595
  }
3612
3596
  }
3613
3597
  const composioConnectedAccount = new ConnectedAccounts(this.client);
3614
- return await composioConnectedAccount.initiate(userId, authConfigIdToUse);
3598
+ return await composioConnectedAccount.initiate(userId, authConfigIdToUse, {
3599
+ // in this magic function we allow multiple connected accounts per user for an auth config
3600
+ allowMultiple: true
3601
+ });
3615
3602
  }
3616
3603
  };
3617
3604
 
@@ -3674,6 +3661,7 @@ var TriggerInstanceManageDeleteResponseSchema = z6.object({
3674
3661
  });
3675
3662
  var IncomingTriggerPayloadSchema = z6.object({
3676
3663
  id: z6.string().describe("The ID of the trigger"),
3664
+ uuid: z6.string().describe("The UUID of the trigger"),
3677
3665
  triggerSlug: z6.string().describe("The slug of the trigger that triggered the event"),
3678
3666
  toolkitSlug: z6.string().describe("The slug of the toolkit that triggered the event"),
3679
3667
  userId: z6.string().describe("The ID of the user that triggered the event"),
@@ -3681,6 +3669,7 @@ var IncomingTriggerPayloadSchema = z6.object({
3681
3669
  originalPayload: z6.record(z6.unknown()).describe("The original payload of the trigger").optional(),
3682
3670
  metadata: z6.object({
3683
3671
  id: z6.string(),
3672
+ uuid: z6.string(),
3684
3673
  toolkitSlug: z6.string(),
3685
3674
  triggerSlug: z6.string(),
3686
3675
  triggerData: z6.string().optional(),
@@ -4147,6 +4136,54 @@ var Triggers = class {
4147
4136
  async listEnum() {
4148
4137
  return this.client.triggersTypes.retrieveEnum();
4149
4138
  }
4139
+ /**
4140
+ * Applies compound filters to the trigger data
4141
+ * @param data data to apply filters to
4142
+ * @returns True if the trigger data matches the filters, false otherwise
4143
+ */
4144
+ shouldSendTriggerAfterFilters(filters, data) {
4145
+ if (filters.toolkits?.length && !filters.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
4146
+ logger_default.debug(
4147
+ "Trigger does not match toolkits filter",
4148
+ JSON.stringify(filters.toolkits, null, 2)
4149
+ );
4150
+ return false;
4151
+ }
4152
+ if (filters.triggerId && filters.triggerId !== data.id) {
4153
+ logger_default.debug(
4154
+ "Trigger does not match triggerId filter",
4155
+ JSON.stringify(filters.triggerId, null, 2)
4156
+ );
4157
+ return false;
4158
+ }
4159
+ if (filters.connectedAccountId && filters.connectedAccountId !== data.metadata.connectedAccount.id) {
4160
+ logger_default.debug(
4161
+ "Trigger does not match connectedAccountId filter",
4162
+ JSON.stringify(filters.connectedAccountId, null, 2)
4163
+ );
4164
+ return false;
4165
+ }
4166
+ if (filters.triggerSlug?.length && !filters.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
4167
+ logger_default.debug(
4168
+ "Trigger does not match triggerSlug filter",
4169
+ JSON.stringify(filters.triggerSlug, null, 2)
4170
+ );
4171
+ return false;
4172
+ }
4173
+ if (filters.triggerData && filters.triggerData !== data.metadata.triggerData) {
4174
+ logger_default.debug(
4175
+ "Trigger does not match triggerData filter",
4176
+ JSON.stringify(filters.triggerData, null, 2)
4177
+ );
4178
+ return false;
4179
+ }
4180
+ if (filters.userId && filters.userId !== data.metadata.connectedAccount.userId) {
4181
+ logger_default.debug("Trigger does not match userId filter", JSON.stringify(filters.userId, null, 2));
4182
+ return false;
4183
+ }
4184
+ logger_default.debug("Trigger matches all filters", JSON.stringify(filters, null, 2));
4185
+ return true;
4186
+ }
4150
4187
  /**
4151
4188
  * Subscribe to all the triggers
4152
4189
  *
@@ -4169,65 +4206,21 @@ var Triggers = class {
4169
4206
  cause: parsedFilters.error
4170
4207
  });
4171
4208
  }
4172
- const shouldSendTriggerAfterFilters = (data) => {
4173
- if (parsedFilters.data.toolkits?.length && !parsedFilters.data.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
4174
- logger_default.debug(
4175
- "Trigger does not match toolkits filter",
4176
- JSON.stringify(parsedFilters.data.toolkits, null, 2)
4177
- );
4178
- return false;
4179
- }
4180
- if (parsedFilters.data.triggerId && parsedFilters.data.triggerId !== data.id) {
4181
- logger_default.debug(
4182
- "Trigger does not match triggerId filter",
4183
- JSON.stringify(parsedFilters.data.triggerId, null, 2)
4184
- );
4185
- return false;
4186
- }
4187
- if (parsedFilters.data.connectedAccountId && parsedFilters.data.connectedAccountId !== data.metadata.connectedAccount.id) {
4188
- logger_default.debug(
4189
- "Trigger does not match connectedAccountId filter",
4190
- JSON.stringify(parsedFilters.data.connectedAccountId, null, 2)
4191
- );
4192
- return false;
4193
- }
4194
- if (parsedFilters.data.triggerSlug?.length && !parsedFilters.data.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
4195
- logger_default.debug(
4196
- "Trigger does not match triggerSlug filter",
4197
- JSON.stringify(parsedFilters.data.triggerSlug, null, 2)
4198
- );
4199
- return false;
4200
- }
4201
- if (parsedFilters.data.triggerData && parsedFilters.data.triggerData !== data.metadata.triggerData) {
4202
- logger_default.debug(
4203
- "Trigger does not match triggerData filter",
4204
- JSON.stringify(parsedFilters.data.triggerData, null, 2)
4205
- );
4206
- return false;
4207
- }
4208
- if (parsedFilters.data.userId && parsedFilters.data.userId !== data.metadata.connectedAccount.userId) {
4209
- logger_default.debug(
4210
- "Trigger does not match userId filter",
4211
- JSON.stringify(parsedFilters.data.userId, null, 2)
4212
- );
4213
- return false;
4214
- }
4215
- logger_default.debug("Trigger matches all filters", JSON.stringify(parsedFilters.data, null, 2));
4216
- return true;
4217
- };
4218
4209
  logger_default.debug("\u{1F504} Subscribing to triggers with filters: ", JSON.stringify(filters, null, 2));
4219
4210
  await this.pusherService.subscribe((_data) => {
4220
4211
  logger_default.debug("Received raw trigger data", JSON.stringify(_data, null, 2));
4221
4212
  const data = _data;
4222
4213
  const parsedData = IncomingTriggerPayloadSchema.safeParse({
4223
- id: data.metadata.id,
4214
+ id: data.metadata.nanoId,
4215
+ uuid: data.metadata.id,
4224
4216
  triggerSlug: data.metadata.triggerName,
4225
4217
  toolkitSlug: data.appName,
4226
4218
  userId: data.metadata.connection?.clientUniqueUserId,
4227
4219
  payload: data.payload,
4228
4220
  originalPayload: data.originalPayload,
4229
4221
  metadata: {
4230
- id: data.metadata.id,
4222
+ id: data.metadata.nanoId,
4223
+ uuid: data.metadata.id,
4231
4224
  triggerConfig: data.metadata.triggerConfig,
4232
4225
  triggerSlug: data.metadata.triggerName,
4233
4226
  toolkitSlug: data.appName,
@@ -4248,7 +4241,7 @@ var Triggers = class {
4248
4241
  cause: parsedData.error
4249
4242
  });
4250
4243
  }
4251
- if (shouldSendTriggerAfterFilters(parsedData.data)) {
4244
+ if (this.shouldSendTriggerAfterFilters(parsedFilters.data, parsedData.data)) {
4252
4245
  try {
4253
4246
  fn(parsedData.data);
4254
4247
  } catch (error) {
@@ -4800,7 +4793,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
4800
4793
  };
4801
4794
 
4802
4795
  // package.json
4803
- var version = "0.1.21";
4796
+ var version = "0.1.22";
4804
4797
 
4805
4798
  // src/composio.ts
4806
4799
  var Composio = class _Composio {
@@ -4963,6 +4956,38 @@ var ComposioProvider = class extends BaseNonAgenticProvider {
4963
4956
  }
4964
4957
  };
4965
4958
 
4959
+ // src/utils/jsonSchema.ts
4960
+ import { jsonSchemaToZod } from "@composio/json-schema-to-zod";
4961
+ var removeNonRequiredProperties = (schema) => {
4962
+ if (schema && schema.type === "object" && schema.required?.length) {
4963
+ schema.properties = Object.fromEntries(
4964
+ Object.entries(schema.properties || {}).filter(
4965
+ ([key]) => schema.required.includes(key)
4966
+ )
4967
+ );
4968
+ }
4969
+ schema.additionalProperties = false;
4970
+ return schema;
4971
+ };
4972
+ function jsonSchemaToZodSchema(jsonSchema, { strict } = {
4973
+ strict: false
4974
+ }) {
4975
+ try {
4976
+ let schema = jsonSchema;
4977
+ if (strict && schema) {
4978
+ schema = removeNonRequiredProperties(
4979
+ schema
4980
+ );
4981
+ }
4982
+ const zodSchema = jsonSchemaToZod(schema);
4983
+ return zodSchema;
4984
+ } catch (error) {
4985
+ throw new JsonSchemaToZodError("Failed to convert JSON Schema to Zod Schema", {
4986
+ cause: error
4987
+ });
4988
+ }
4989
+ }
4990
+
4966
4991
  // src/models/AuthScheme.ts
4967
4992
  var AuthScheme = class {
4968
4993
  /**
@@ -5154,6 +5179,7 @@ export {
5154
5179
  ComposioInvalidExecuteFunctionError,
5155
5180
  ComposioInvalidModifierError,
5156
5181
  ComposioLinkConnectionDataSchema,
5182
+ ComposioMultipleConnectedAccountsError,
5157
5183
  ComposioNoAPIKeyError,
5158
5184
  ComposioProvider,
5159
5185
  ComposioProviderNotDefinedError,
@@ -5227,5 +5253,6 @@ export {
5227
5253
  ValidationError,
5228
5254
  ValidationErrorCodes,
5229
5255
  jsonSchemaToZodSchema,
5230
- logger_default as logger
5256
+ logger_default as logger,
5257
+ removeNonRequiredProperties
5231
5258
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composio/core",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  "tsx": "^4.19.3",
28
28
  "typescript": "^5.8.3",
29
29
  "vitest": "^3.1.4",
30
- "@composio/json-schema-to-zod": "0.1.6"
30
+ "@composio/json-schema-to-zod": "0.1.9"
31
31
  },
32
32
  "dependencies": {
33
33
  "@composio/client": "0.1.0-alpha.22",