@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.cjs CHANGED
@@ -54,6 +54,7 @@ __export(index_exports, {
54
54
  ComposioInvalidExecuteFunctionError: () => ComposioInvalidExecuteFunctionError,
55
55
  ComposioInvalidModifierError: () => ComposioInvalidModifierError,
56
56
  ComposioLinkConnectionDataSchema: () => ComposioLinkConnectionDataSchema,
57
+ ComposioMultipleConnectedAccountsError: () => ComposioMultipleConnectedAccountsError,
57
58
  ComposioNoAPIKeyError: () => ComposioNoAPIKeyError,
58
59
  ComposioProvider: () => ComposioProvider,
59
60
  ComposioProviderNotDefinedError: () => ComposioProviderNotDefinedError,
@@ -127,7 +128,8 @@ __export(index_exports, {
127
128
  ValidationError: () => ValidationError,
128
129
  ValidationErrorCodes: () => ValidationErrorCodes,
129
130
  jsonSchemaToZodSchema: () => jsonSchemaToZodSchema,
130
- logger: () => logger_default
131
+ logger: () => logger_default,
132
+ removeNonRequiredProperties: () => removeNonRequiredProperties
131
133
  });
132
134
  module.exports = __toCommonJS(index_exports);
133
135
 
@@ -234,19 +236,13 @@ var ToolListFilterByToolkitsSchema = import_zod.z.object({
234
236
  important: import_zod.z.boolean().optional(),
235
237
  cursor: import_zod.z.string().optional(),
236
238
  limit: import_zod.z.number().optional(),
237
- search: import_zod.z.string().optional(),
238
- strict: import_zod.z.boolean().optional().describe(
239
- "If true, all the non-required fields will be removed from the input/output params of the tool"
240
- )
239
+ search: import_zod.z.string().optional()
241
240
  });
242
241
  var ToolListFilterBySearchSchema = import_zod.z.object({
243
242
  search: import_zod.z.string(),
244
243
  toolkits: import_zod.z.array(import_zod.z.string()).optional(),
245
244
  cursor: import_zod.z.string().optional(),
246
- limit: import_zod.z.number().optional(),
247
- strict: import_zod.z.boolean().optional().describe(
248
- "If true, all the non-required fields will be removed from the input/output params of the tool"
249
- )
245
+ limit: import_zod.z.number().optional()
250
246
  });
251
247
  var ToolListParamsSchema = import_zod.z.union([
252
248
  ToolListFilterByToolsSchema,
@@ -722,7 +718,8 @@ var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
722
718
 
723
719
  // src/errors/ConnectedAccountsErrors.ts
724
720
  var ConnectedAccountErrorCodes = {
725
- CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
721
+ CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND",
722
+ MULTIPLE_CONNECTED_ACCOUNTS: "MULTIPLE_CONNECTED_ACCOUNTS"
726
723
  };
727
724
  var ComposioConnectedAccountNotFoundError = class extends ComposioError {
728
725
  constructor(message = "Connected account not found", options = {}) {
@@ -737,6 +734,17 @@ var ComposioConnectedAccountNotFoundError = class extends ComposioError {
737
734
  this.name = "ComposioConnectedAccountNotFoundError";
738
735
  }
739
736
  };
737
+ var ComposioMultipleConnectedAccountsError = class extends ComposioError {
738
+ constructor(message = "Multiple connected accounts found") {
739
+ super(message, {
740
+ code: ConnectedAccountErrorCodes.MULTIPLE_CONNECTED_ACCOUNTS,
741
+ possibleFixes: [
742
+ "Use the allowMultiple flag to allow multiple connected accounts per user for an auth config"
743
+ ]
744
+ });
745
+ this.name = "ComposioMultipleConnectedAccountsError";
746
+ }
747
+ };
740
748
 
741
749
  // src/telemetry/Telemetry.ts
742
750
  var import_client2 = require("@composio/client");
@@ -1229,6 +1237,7 @@ var AuthConfigRetrieveResponseSchema = import_zod4.z.object({
1229
1237
  authScheme: AuthSchemeEnum.optional(),
1230
1238
  credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()).optional(),
1231
1239
  expectedInputFields: import_zod4.z.array(import_zod4.z.unknown()).optional(),
1240
+ restrictToFollowingTools: import_zod4.z.array(import_zod4.z.string()).optional(),
1232
1241
  isComposioManaged: import_zod4.z.boolean().optional(),
1233
1242
  createdBy: import_zod4.z.string().optional(),
1234
1243
  createdAt: import_zod4.z.string().optional(),
@@ -1691,6 +1700,7 @@ var DefaultCreateConnectedAccountParamsSchema = import_zod6.z.object({
1691
1700
  })
1692
1701
  });
1693
1702
  var CreateConnectedAccountOptionsSchema = import_zod6.z.object({
1703
+ allowMultiple: import_zod6.z.boolean().optional(),
1694
1704
  callbackUrl: import_zod6.z.string().optional(),
1695
1705
  config: ConnectionDataSchema.optional()
1696
1706
  });
@@ -2047,37 +2057,6 @@ var CustomTools = class {
2047
2057
  }
2048
2058
  };
2049
2059
 
2050
- // src/utils/jsonSchema.ts
2051
- var import_json_schema_to_zod = require("@composio/json-schema-to-zod");
2052
- var removeNonRequiredProperties = (schema) => {
2053
- if (schema && schema.type === "object" && schema.required?.length) {
2054
- schema.properties = Object.fromEntries(
2055
- Object.entries(schema.properties || {}).filter(
2056
- ([key]) => schema.required.includes(key)
2057
- )
2058
- );
2059
- }
2060
- return schema;
2061
- };
2062
- function jsonSchemaToZodSchema(jsonSchema, { strict } = {
2063
- strict: false
2064
- }) {
2065
- try {
2066
- let schema = jsonSchema;
2067
- if (strict && schema) {
2068
- schema = removeNonRequiredProperties(
2069
- schema
2070
- );
2071
- }
2072
- const zodSchema = (0, import_json_schema_to_zod.jsonSchemaToZod)(schema);
2073
- return zodSchema;
2074
- } catch (error) {
2075
- throw new JsonSchemaToZodError("Failed to convert JSON Schema to Zod Schema", {
2076
- cause: error
2077
- });
2078
- }
2079
- }
2080
-
2081
2060
  // src/models/Tools.ts
2082
2061
  var Tools = class {
2083
2062
  client;
@@ -2338,14 +2317,7 @@ var Tools = class {
2338
2317
  const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifySchema);
2339
2318
  return this.provider.wrapTools([tool], executeToolFn);
2340
2319
  } else {
2341
- let tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
2342
- if (arg2?.strict) {
2343
- tools = tools.map((tool) => ({
2344
- ...tool,
2345
- inputParameters: tool.inputParameters ? removeNonRequiredProperties(tool.inputParameters) : void 0,
2346
- outputParameters: tool.outputParameters ? removeNonRequiredProperties(tool.outputParameters) : void 0
2347
- }));
2348
- }
2320
+ const tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
2349
2321
  return this.provider.wrapTools(tools, executeToolFn);
2350
2322
  }
2351
2323
  }
@@ -2772,7 +2744,8 @@ var AuthConfigs = class {
2772
2744
  isComposioManaged: authConfig.is_composio_managed,
2773
2745
  createdBy: authConfig.created_by,
2774
2746
  createdAt: authConfig.created_at,
2775
- lastUpdatedAt: authConfig.last_updated_at
2747
+ lastUpdatedAt: authConfig.last_updated_at,
2748
+ restrictToFollowingTools: authConfig.restrict_to_following_tools
2776
2749
  });
2777
2750
  if (result.error) {
2778
2751
  throw new ValidationError("Failed to parse auth config response", {
@@ -3269,6 +3242,19 @@ var ConnectedAccounts = class {
3269
3242
  * @link https://docs.composio.dev/reference/connected-accounts/create-connected-account
3270
3243
  */
3271
3244
  async initiate(userId, authConfigId, options) {
3245
+ const connectedAccount = await this.list({
3246
+ userIds: [userId],
3247
+ authConfigIds: [authConfigId]
3248
+ });
3249
+ if (connectedAccount.items.length > 0 && !options?.allowMultiple) {
3250
+ throw new ComposioMultipleConnectedAccountsError(
3251
+ `Multiple connected accounts found for user ${userId} in auth config ${authConfigId}`
3252
+ );
3253
+ } else if (connectedAccount.items.length > 0) {
3254
+ logger_default.warn(
3255
+ `[Warn:AllowMultiple] Multiple connected accounts found for user ${userId} in auth config ${authConfigId}`
3256
+ );
3257
+ }
3272
3258
  const response = await this.client.connectedAccounts.create({
3273
3259
  auth_config: {
3274
3260
  id: authConfigId
@@ -3737,7 +3723,10 @@ var Toolkits = class {
3737
3723
  }
3738
3724
  }
3739
3725
  const composioConnectedAccount = new ConnectedAccounts(this.client);
3740
- return await composioConnectedAccount.initiate(userId, authConfigIdToUse);
3726
+ return await composioConnectedAccount.initiate(userId, authConfigIdToUse, {
3727
+ // in this magic function we allow multiple connected accounts per user for an auth config
3728
+ allowMultiple: true
3729
+ });
3741
3730
  }
3742
3731
  };
3743
3732
 
@@ -3800,6 +3789,7 @@ var TriggerInstanceManageDeleteResponseSchema = import_zod8.z.object({
3800
3789
  });
3801
3790
  var IncomingTriggerPayloadSchema = import_zod8.z.object({
3802
3791
  id: import_zod8.z.string().describe("The ID of the trigger"),
3792
+ uuid: import_zod8.z.string().describe("The UUID of the trigger"),
3803
3793
  triggerSlug: import_zod8.z.string().describe("The slug of the trigger that triggered the event"),
3804
3794
  toolkitSlug: import_zod8.z.string().describe("The slug of the toolkit that triggered the event"),
3805
3795
  userId: import_zod8.z.string().describe("The ID of the user that triggered the event"),
@@ -3807,6 +3797,7 @@ var IncomingTriggerPayloadSchema = import_zod8.z.object({
3807
3797
  originalPayload: import_zod8.z.record(import_zod8.z.unknown()).describe("The original payload of the trigger").optional(),
3808
3798
  metadata: import_zod8.z.object({
3809
3799
  id: import_zod8.z.string(),
3800
+ uuid: import_zod8.z.string(),
3810
3801
  toolkitSlug: import_zod8.z.string(),
3811
3802
  triggerSlug: import_zod8.z.string(),
3812
3803
  triggerData: import_zod8.z.string().optional(),
@@ -4273,6 +4264,54 @@ var Triggers = class {
4273
4264
  async listEnum() {
4274
4265
  return this.client.triggersTypes.retrieveEnum();
4275
4266
  }
4267
+ /**
4268
+ * Applies compound filters to the trigger data
4269
+ * @param data data to apply filters to
4270
+ * @returns True if the trigger data matches the filters, false otherwise
4271
+ */
4272
+ shouldSendTriggerAfterFilters(filters, data) {
4273
+ if (filters.toolkits?.length && !filters.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
4274
+ logger_default.debug(
4275
+ "Trigger does not match toolkits filter",
4276
+ JSON.stringify(filters.toolkits, null, 2)
4277
+ );
4278
+ return false;
4279
+ }
4280
+ if (filters.triggerId && filters.triggerId !== data.id) {
4281
+ logger_default.debug(
4282
+ "Trigger does not match triggerId filter",
4283
+ JSON.stringify(filters.triggerId, null, 2)
4284
+ );
4285
+ return false;
4286
+ }
4287
+ if (filters.connectedAccountId && filters.connectedAccountId !== data.metadata.connectedAccount.id) {
4288
+ logger_default.debug(
4289
+ "Trigger does not match connectedAccountId filter",
4290
+ JSON.stringify(filters.connectedAccountId, null, 2)
4291
+ );
4292
+ return false;
4293
+ }
4294
+ if (filters.triggerSlug?.length && !filters.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
4295
+ logger_default.debug(
4296
+ "Trigger does not match triggerSlug filter",
4297
+ JSON.stringify(filters.triggerSlug, null, 2)
4298
+ );
4299
+ return false;
4300
+ }
4301
+ if (filters.triggerData && filters.triggerData !== data.metadata.triggerData) {
4302
+ logger_default.debug(
4303
+ "Trigger does not match triggerData filter",
4304
+ JSON.stringify(filters.triggerData, null, 2)
4305
+ );
4306
+ return false;
4307
+ }
4308
+ if (filters.userId && filters.userId !== data.metadata.connectedAccount.userId) {
4309
+ logger_default.debug("Trigger does not match userId filter", JSON.stringify(filters.userId, null, 2));
4310
+ return false;
4311
+ }
4312
+ logger_default.debug("Trigger matches all filters", JSON.stringify(filters, null, 2));
4313
+ return true;
4314
+ }
4276
4315
  /**
4277
4316
  * Subscribe to all the triggers
4278
4317
  *
@@ -4295,65 +4334,21 @@ var Triggers = class {
4295
4334
  cause: parsedFilters.error
4296
4335
  });
4297
4336
  }
4298
- const shouldSendTriggerAfterFilters = (data) => {
4299
- if (parsedFilters.data.toolkits?.length && !parsedFilters.data.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
4300
- logger_default.debug(
4301
- "Trigger does not match toolkits filter",
4302
- JSON.stringify(parsedFilters.data.toolkits, null, 2)
4303
- );
4304
- return false;
4305
- }
4306
- if (parsedFilters.data.triggerId && parsedFilters.data.triggerId !== data.id) {
4307
- logger_default.debug(
4308
- "Trigger does not match triggerId filter",
4309
- JSON.stringify(parsedFilters.data.triggerId, null, 2)
4310
- );
4311
- return false;
4312
- }
4313
- if (parsedFilters.data.connectedAccountId && parsedFilters.data.connectedAccountId !== data.metadata.connectedAccount.id) {
4314
- logger_default.debug(
4315
- "Trigger does not match connectedAccountId filter",
4316
- JSON.stringify(parsedFilters.data.connectedAccountId, null, 2)
4317
- );
4318
- return false;
4319
- }
4320
- if (parsedFilters.data.triggerSlug?.length && !parsedFilters.data.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
4321
- logger_default.debug(
4322
- "Trigger does not match triggerSlug filter",
4323
- JSON.stringify(parsedFilters.data.triggerSlug, null, 2)
4324
- );
4325
- return false;
4326
- }
4327
- if (parsedFilters.data.triggerData && parsedFilters.data.triggerData !== data.metadata.triggerData) {
4328
- logger_default.debug(
4329
- "Trigger does not match triggerData filter",
4330
- JSON.stringify(parsedFilters.data.triggerData, null, 2)
4331
- );
4332
- return false;
4333
- }
4334
- if (parsedFilters.data.userId && parsedFilters.data.userId !== data.metadata.connectedAccount.userId) {
4335
- logger_default.debug(
4336
- "Trigger does not match userId filter",
4337
- JSON.stringify(parsedFilters.data.userId, null, 2)
4338
- );
4339
- return false;
4340
- }
4341
- logger_default.debug("Trigger matches all filters", JSON.stringify(parsedFilters.data, null, 2));
4342
- return true;
4343
- };
4344
4337
  logger_default.debug("\u{1F504} Subscribing to triggers with filters: ", JSON.stringify(filters, null, 2));
4345
4338
  await this.pusherService.subscribe((_data) => {
4346
4339
  logger_default.debug("Received raw trigger data", JSON.stringify(_data, null, 2));
4347
4340
  const data = _data;
4348
4341
  const parsedData = IncomingTriggerPayloadSchema.safeParse({
4349
- id: data.metadata.id,
4342
+ id: data.metadata.nanoId,
4343
+ uuid: data.metadata.id,
4350
4344
  triggerSlug: data.metadata.triggerName,
4351
4345
  toolkitSlug: data.appName,
4352
4346
  userId: data.metadata.connection?.clientUniqueUserId,
4353
4347
  payload: data.payload,
4354
4348
  originalPayload: data.originalPayload,
4355
4349
  metadata: {
4356
- id: data.metadata.id,
4350
+ id: data.metadata.nanoId,
4351
+ uuid: data.metadata.id,
4357
4352
  triggerConfig: data.metadata.triggerConfig,
4358
4353
  triggerSlug: data.metadata.triggerName,
4359
4354
  toolkitSlug: data.appName,
@@ -4374,7 +4369,7 @@ var Triggers = class {
4374
4369
  cause: parsedData.error
4375
4370
  });
4376
4371
  }
4377
- if (shouldSendTriggerAfterFilters(parsedData.data)) {
4372
+ if (this.shouldSendTriggerAfterFilters(parsedFilters.data, parsedData.data)) {
4378
4373
  try {
4379
4374
  fn(parsedData.data);
4380
4375
  } catch (error) {
@@ -4926,7 +4921,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
4926
4921
  };
4927
4922
 
4928
4923
  // package.json
4929
- var version = "0.1.21";
4924
+ var version = "0.1.22";
4930
4925
 
4931
4926
  // src/composio.ts
4932
4927
  var Composio = class _Composio {
@@ -5089,6 +5084,38 @@ var ComposioProvider = class extends BaseNonAgenticProvider {
5089
5084
  }
5090
5085
  };
5091
5086
 
5087
+ // src/utils/jsonSchema.ts
5088
+ var import_json_schema_to_zod = require("@composio/json-schema-to-zod");
5089
+ var removeNonRequiredProperties = (schema) => {
5090
+ if (schema && schema.type === "object" && schema.required?.length) {
5091
+ schema.properties = Object.fromEntries(
5092
+ Object.entries(schema.properties || {}).filter(
5093
+ ([key]) => schema.required.includes(key)
5094
+ )
5095
+ );
5096
+ }
5097
+ schema.additionalProperties = false;
5098
+ return schema;
5099
+ };
5100
+ function jsonSchemaToZodSchema(jsonSchema, { strict } = {
5101
+ strict: false
5102
+ }) {
5103
+ try {
5104
+ let schema = jsonSchema;
5105
+ if (strict && schema) {
5106
+ schema = removeNonRequiredProperties(
5107
+ schema
5108
+ );
5109
+ }
5110
+ const zodSchema = (0, import_json_schema_to_zod.jsonSchemaToZod)(schema);
5111
+ return zodSchema;
5112
+ } catch (error) {
5113
+ throw new JsonSchemaToZodError("Failed to convert JSON Schema to Zod Schema", {
5114
+ cause: error
5115
+ });
5116
+ }
5117
+ }
5118
+
5092
5119
  // src/models/AuthScheme.ts
5093
5120
  var AuthScheme = class {
5094
5121
  /**
@@ -5281,6 +5308,7 @@ var AuthScheme = class {
5281
5308
  ComposioInvalidExecuteFunctionError,
5282
5309
  ComposioInvalidModifierError,
5283
5310
  ComposioLinkConnectionDataSchema,
5311
+ ComposioMultipleConnectedAccountsError,
5284
5312
  ComposioNoAPIKeyError,
5285
5313
  ComposioProvider,
5286
5314
  ComposioProviderNotDefinedError,
@@ -5354,5 +5382,6 @@ var AuthScheme = class {
5354
5382
  ValidationError,
5355
5383
  ValidationErrorCodes,
5356
5384
  jsonSchemaToZodSchema,
5357
- logger
5385
+ logger,
5386
+ removeNonRequiredProperties
5358
5387
  });