@composio/core 0.1.22 → 0.1.23

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
@@ -134,7 +134,7 @@ __export(index_exports, {
134
134
  module.exports = __toCommonJS(index_exports);
135
135
 
136
136
  // src/composio.ts
137
- var import_client6 = __toESM(require("@composio/client"), 1);
137
+ var import_client7 = __toESM(require("@composio/client"), 1);
138
138
 
139
139
  // src/types/tool.types.ts
140
140
  var import_zod = require("zod");
@@ -1669,7 +1669,8 @@ var ConnectedAccountStatuses = {
1669
1669
  INITIATED: "INITIATED",
1670
1670
  ACTIVE: "ACTIVE",
1671
1671
  FAILED: "FAILED",
1672
- EXPIRED: "EXPIRED"
1672
+ EXPIRED: "EXPIRED",
1673
+ INACTIVE: "INACTIVE"
1673
1674
  };
1674
1675
  var ConnectedAccountStatusSchema = import_zod6.z.enum([
1675
1676
  ConnectedAccountStatuses.INITIALIZING,
@@ -2237,12 +2238,16 @@ var Tools = class {
2237
2238
  "Invalid tool list parameters, atleast one of the following parameters is required: tools, toolkits, search"
2238
2239
  );
2239
2240
  }
2241
+ let limit = "limit" in queryParams.data ? queryParams.data.limit?.toString() : void 0;
2242
+ if ("tools" in queryParams.data) {
2243
+ limit = "9999";
2244
+ }
2240
2245
  const tools = await this.client.tools.list({
2241
2246
  tool_slugs: "tools" in queryParams.data ? queryParams.data.tools?.join(",") : void 0,
2242
2247
  toolkit_slug: "toolkits" in queryParams.data ? queryParams.data.toolkits?.join(",") : void 0,
2243
2248
  cursor: "cursor" in queryParams.data ? queryParams.data.cursor : void 0,
2244
2249
  important: "important" in queryParams.data ? queryParams.data.important ? "true" : "false" : void 0,
2245
- limit: "limit" in queryParams.data ? queryParams.data.limit?.toString() : void 0,
2250
+ limit,
2246
2251
  search: "search" in queryParams.data ? queryParams.data.search : void 0
2247
2252
  });
2248
2253
  if (!tools) {
@@ -3730,6 +3735,9 @@ var Toolkits = class {
3730
3735
  }
3731
3736
  };
3732
3737
 
3738
+ // src/models/Triggers.ts
3739
+ var import_client6 = require("@composio/client");
3740
+
3733
3741
  // src/types/triggers.types.ts
3734
3742
  var import_zod8 = require("zod");
3735
3743
  var TriggerStatuses = {
@@ -3860,7 +3868,8 @@ var TriggerErrorCodes = {
3860
3868
  TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS: "TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS",
3861
3869
  TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT: "TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT",
3862
3870
  TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL",
3863
- TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL"
3871
+ TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL",
3872
+ TRIGGER_TYPE_NOT_FOUND: "TRIGGER_TYPE_NOT_FOUND"
3864
3873
  };
3865
3874
  var ComposioFailedToGetSDKRealtimeCredentialsError = class extends import_client5.ComposioError {
3866
3875
  name = "ComposioFailedToGetSDKRealtimeCredentialsError";
@@ -3889,6 +3898,15 @@ var ComposioFailedToSubscribeToPusherChannelError = class extends import_client5
3889
3898
  super(message, options);
3890
3899
  }
3891
3900
  };
3901
+ var ComposioTriggerTypeNotFoundError = class extends import_client5.ComposioError {
3902
+ name = "ComposioTriggerTypeNotFoundError";
3903
+ code = TriggerErrorCodes.TRIGGER_TYPE_NOT_FOUND;
3904
+ statusCode = 404;
3905
+ possibleFixes = ["Please contact support."];
3906
+ constructor(message = "Trigger type not found", options) {
3907
+ super(message, options);
3908
+ }
3909
+ };
3892
3910
 
3893
3911
  // src/services/pusher/Pusher.ts
3894
3912
  var PusherService = class {
@@ -4154,21 +4172,89 @@ var Triggers = class {
4154
4172
  return parsedResult.data;
4155
4173
  }
4156
4174
  /**
4157
- * Create a new trigger instance
4175
+ * Create a new trigger instance for a user
4176
+ * If the connected account id is not provided, the first connected account for the user and toolkit will be used
4158
4177
  *
4178
+ * @param {string} userId - The user id of the trigger instance
4159
4179
  * @param {string} slug - The slug of the trigger instance
4160
4180
  * @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
4161
4181
  * @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
4162
4182
  */
4163
- async create(slug, body) {
4164
- const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body);
4183
+ async create(userId, slug, body) {
4184
+ const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body ?? {});
4165
4185
  if (!parsedBody.success) {
4166
4186
  throw new ValidationError(`Invalid parameters passed to create trigger`, {
4167
4187
  cause: parsedBody.error
4168
4188
  });
4169
4189
  }
4190
+ let triggerType;
4191
+ let toolkitSlug;
4192
+ try {
4193
+ triggerType = await this.getType(slug);
4194
+ toolkitSlug = triggerType.toolkit.slug;
4195
+ } catch (error) {
4196
+ if (error instanceof import_client6.APIError && (error.status === 400 || error.status === 404)) {
4197
+ throw new ComposioTriggerTypeNotFoundError(`Trigger type ${slug} not found`, {
4198
+ cause: error,
4199
+ possibleFixes: [
4200
+ `Please check the trigger slug`,
4201
+ `Visit the toolkit page to see the available triggers`
4202
+ ]
4203
+ });
4204
+ } else {
4205
+ throw error;
4206
+ }
4207
+ }
4208
+ let connectedAccountId = body?.connectedAccountId;
4209
+ try {
4210
+ const { items: connectedAccounts } = await this.client.connectedAccounts.list({
4211
+ user_ids: [userId],
4212
+ toolkit_slugs: [toolkitSlug]
4213
+ });
4214
+ if (connectedAccounts.length === 0) {
4215
+ throw new ComposioConnectedAccountNotFoundError(
4216
+ `No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
4217
+ {
4218
+ cause: new Error(`No connected account found for user ${userId}`),
4219
+ possibleFixes: [`Create a new connected account for user ${userId}`]
4220
+ }
4221
+ );
4222
+ }
4223
+ const accountExists = connectedAccounts.some((acc) => acc.id === connectedAccountId);
4224
+ if (connectedAccountId && !accountExists) {
4225
+ throw new ComposioConnectedAccountNotFoundError(
4226
+ `Connected account ID ${connectedAccountId} not found for user ${userId}`,
4227
+ {
4228
+ cause: new Error(
4229
+ `Connected account ID ${connectedAccountId} not found for user ${userId}`
4230
+ ),
4231
+ possibleFixes: [
4232
+ `Create a new connected account for user ${userId}`,
4233
+ `Verify the connected account ID`
4234
+ ]
4235
+ }
4236
+ );
4237
+ }
4238
+ if (!connectedAccountId) {
4239
+ connectedAccountId = connectedAccounts[0].id;
4240
+ logger_default.warn(
4241
+ `[Warn] Multiple connected accounts found for user ${userId}, using the first one. Pass connectedAccountId to select a specific account.`
4242
+ );
4243
+ }
4244
+ } catch (error) {
4245
+ if (error instanceof import_client6.APIError && [400, 404].includes(error.status)) {
4246
+ throw new ComposioConnectedAccountNotFoundError(
4247
+ `No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
4248
+ {
4249
+ cause: error,
4250
+ possibleFixes: [`Create a new connected account for user ${userId}`]
4251
+ }
4252
+ );
4253
+ }
4254
+ throw error;
4255
+ }
4170
4256
  const result = await this.client.triggerInstances.upsert(slug, {
4171
- connected_account_id: parsedBody.data.connectedAccountId,
4257
+ connected_account_id: connectedAccountId,
4172
4258
  trigger_config: parsedBody.data.triggerConfig
4173
4259
  });
4174
4260
  const parsedResult = TriggerInstanceUpsertResponseSchema.safeParse({
@@ -4921,7 +5007,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
4921
5007
  };
4922
5008
 
4923
5009
  // package.json
4924
- var version = "0.1.22";
5010
+ var version = "0.1.23";
4925
5011
 
4926
5012
  // src/composio.ts
4927
5013
  var Composio = class _Composio {
@@ -4985,7 +5071,7 @@ var Composio = class _Composio {
4985
5071
  if (IS_DEVELOPMENT_OR_CI) {
4986
5072
  logger_default.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
4987
5073
  }
4988
- this.client = new import_client6.default({
5074
+ this.client = new import_client7.default({
4989
5075
  apiKey: apiKeyParsed,
4990
5076
  baseURL: baseURLParsed,
4991
5077
  defaultHeaders: config?.defaultHeaders,
package/dist/index.d.cts CHANGED
@@ -11487,6 +11487,7 @@ declare const ConnectedAccountStatuses: {
11487
11487
  readonly ACTIVE: "ACTIVE";
11488
11488
  readonly FAILED: "FAILED";
11489
11489
  readonly EXPIRED: "EXPIRED";
11490
+ readonly INACTIVE: "INACTIVE";
11490
11491
  };
11491
11492
  type ConnectedAccountStatus = (typeof ConnectedAccountStatuses)[keyof typeof ConnectedAccountStatuses];
11492
11493
  declare const CreateConnectedAccountOptionsSchema: z.ZodObject<{
@@ -40651,13 +40652,15 @@ declare class Triggers {
40651
40652
  */
40652
40653
  listActive(query?: TriggerInstanceListActiveParams): Promise<TriggerInstanceListActiveResponse>;
40653
40654
  /**
40654
- * Create a new trigger instance
40655
+ * Create a new trigger instance for a user
40656
+ * If the connected account id is not provided, the first connected account for the user and toolkit will be used
40655
40657
  *
40658
+ * @param {string} userId - The user id of the trigger instance
40656
40659
  * @param {string} slug - The slug of the trigger instance
40657
40660
  * @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
40658
40661
  * @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
40659
40662
  */
40660
- create(slug: string, body: TriggerInstanceUpsertParams): Promise<TriggerInstanceUpsertResponse>;
40663
+ create(userId: string, slug: string, body?: TriggerInstanceUpsertParams): Promise<TriggerInstanceUpsertResponse>;
40661
40664
  /**
40662
40665
  * Update an existing trigger instance
40663
40666
  *
package/dist/index.d.ts CHANGED
@@ -11487,6 +11487,7 @@ declare const ConnectedAccountStatuses: {
11487
11487
  readonly ACTIVE: "ACTIVE";
11488
11488
  readonly FAILED: "FAILED";
11489
11489
  readonly EXPIRED: "EXPIRED";
11490
+ readonly INACTIVE: "INACTIVE";
11490
11491
  };
11491
11492
  type ConnectedAccountStatus = (typeof ConnectedAccountStatuses)[keyof typeof ConnectedAccountStatuses];
11492
11493
  declare const CreateConnectedAccountOptionsSchema: z.ZodObject<{
@@ -40651,13 +40652,15 @@ declare class Triggers {
40651
40652
  */
40652
40653
  listActive(query?: TriggerInstanceListActiveParams): Promise<TriggerInstanceListActiveResponse>;
40653
40654
  /**
40654
- * Create a new trigger instance
40655
+ * Create a new trigger instance for a user
40656
+ * If the connected account id is not provided, the first connected account for the user and toolkit will be used
40655
40657
  *
40658
+ * @param {string} userId - The user id of the trigger instance
40656
40659
  * @param {string} slug - The slug of the trigger instance
40657
40660
  * @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
40658
40661
  * @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
40659
40662
  */
40660
- create(slug: string, body: TriggerInstanceUpsertParams): Promise<TriggerInstanceUpsertResponse>;
40663
+ create(userId: string, slug: string, body?: TriggerInstanceUpsertParams): Promise<TriggerInstanceUpsertResponse>;
40661
40664
  /**
40662
40665
  * Update an existing trigger instance
40663
40666
  *
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/composio.ts
9
- import ComposioClient3 from "@composio/client";
9
+ import ComposioClient4 from "@composio/client";
10
10
 
11
11
  // src/types/tool.types.ts
12
12
  import { z } from "zod";
@@ -1541,7 +1541,8 @@ var ConnectedAccountStatuses = {
1541
1541
  INITIATED: "INITIATED",
1542
1542
  ACTIVE: "ACTIVE",
1543
1543
  FAILED: "FAILED",
1544
- EXPIRED: "EXPIRED"
1544
+ EXPIRED: "EXPIRED",
1545
+ INACTIVE: "INACTIVE"
1545
1546
  };
1546
1547
  var ConnectedAccountStatusSchema = z4.enum([
1547
1548
  ConnectedAccountStatuses.INITIALIZING,
@@ -2109,12 +2110,16 @@ var Tools = class {
2109
2110
  "Invalid tool list parameters, atleast one of the following parameters is required: tools, toolkits, search"
2110
2111
  );
2111
2112
  }
2113
+ let limit = "limit" in queryParams.data ? queryParams.data.limit?.toString() : void 0;
2114
+ if ("tools" in queryParams.data) {
2115
+ limit = "9999";
2116
+ }
2112
2117
  const tools = await this.client.tools.list({
2113
2118
  tool_slugs: "tools" in queryParams.data ? queryParams.data.tools?.join(",") : void 0,
2114
2119
  toolkit_slug: "toolkits" in queryParams.data ? queryParams.data.toolkits?.join(",") : void 0,
2115
2120
  cursor: "cursor" in queryParams.data ? queryParams.data.cursor : void 0,
2116
2121
  important: "important" in queryParams.data ? queryParams.data.important ? "true" : "false" : void 0,
2117
- limit: "limit" in queryParams.data ? queryParams.data.limit?.toString() : void 0,
2122
+ limit,
2118
2123
  search: "search" in queryParams.data ? queryParams.data.search : void 0
2119
2124
  });
2120
2125
  if (!tools) {
@@ -3602,6 +3607,9 @@ var Toolkits = class {
3602
3607
  }
3603
3608
  };
3604
3609
 
3610
+ // src/models/Triggers.ts
3611
+ import { APIError } from "@composio/client";
3612
+
3605
3613
  // src/types/triggers.types.ts
3606
3614
  import { z as z6 } from "zod";
3607
3615
  var TriggerStatuses = {
@@ -3732,7 +3740,8 @@ var TriggerErrorCodes = {
3732
3740
  TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS: "TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS",
3733
3741
  TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT: "TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT",
3734
3742
  TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL",
3735
- TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL"
3743
+ TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL",
3744
+ TRIGGER_TYPE_NOT_FOUND: "TRIGGER_TYPE_NOT_FOUND"
3736
3745
  };
3737
3746
  var ComposioFailedToGetSDKRealtimeCredentialsError = class extends ComposioError2 {
3738
3747
  name = "ComposioFailedToGetSDKRealtimeCredentialsError";
@@ -3761,6 +3770,15 @@ var ComposioFailedToSubscribeToPusherChannelError = class extends ComposioError2
3761
3770
  super(message, options);
3762
3771
  }
3763
3772
  };
3773
+ var ComposioTriggerTypeNotFoundError = class extends ComposioError2 {
3774
+ name = "ComposioTriggerTypeNotFoundError";
3775
+ code = TriggerErrorCodes.TRIGGER_TYPE_NOT_FOUND;
3776
+ statusCode = 404;
3777
+ possibleFixes = ["Please contact support."];
3778
+ constructor(message = "Trigger type not found", options) {
3779
+ super(message, options);
3780
+ }
3781
+ };
3764
3782
 
3765
3783
  // src/services/pusher/Pusher.ts
3766
3784
  var PusherService = class {
@@ -4026,21 +4044,89 @@ var Triggers = class {
4026
4044
  return parsedResult.data;
4027
4045
  }
4028
4046
  /**
4029
- * Create a new trigger instance
4047
+ * Create a new trigger instance for a user
4048
+ * If the connected account id is not provided, the first connected account for the user and toolkit will be used
4030
4049
  *
4050
+ * @param {string} userId - The user id of the trigger instance
4031
4051
  * @param {string} slug - The slug of the trigger instance
4032
4052
  * @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
4033
4053
  * @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
4034
4054
  */
4035
- async create(slug, body) {
4036
- const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body);
4055
+ async create(userId, slug, body) {
4056
+ const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body ?? {});
4037
4057
  if (!parsedBody.success) {
4038
4058
  throw new ValidationError(`Invalid parameters passed to create trigger`, {
4039
4059
  cause: parsedBody.error
4040
4060
  });
4041
4061
  }
4062
+ let triggerType;
4063
+ let toolkitSlug;
4064
+ try {
4065
+ triggerType = await this.getType(slug);
4066
+ toolkitSlug = triggerType.toolkit.slug;
4067
+ } catch (error) {
4068
+ if (error instanceof APIError && (error.status === 400 || error.status === 404)) {
4069
+ throw new ComposioTriggerTypeNotFoundError(`Trigger type ${slug} not found`, {
4070
+ cause: error,
4071
+ possibleFixes: [
4072
+ `Please check the trigger slug`,
4073
+ `Visit the toolkit page to see the available triggers`
4074
+ ]
4075
+ });
4076
+ } else {
4077
+ throw error;
4078
+ }
4079
+ }
4080
+ let connectedAccountId = body?.connectedAccountId;
4081
+ try {
4082
+ const { items: connectedAccounts } = await this.client.connectedAccounts.list({
4083
+ user_ids: [userId],
4084
+ toolkit_slugs: [toolkitSlug]
4085
+ });
4086
+ if (connectedAccounts.length === 0) {
4087
+ throw new ComposioConnectedAccountNotFoundError(
4088
+ `No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
4089
+ {
4090
+ cause: new Error(`No connected account found for user ${userId}`),
4091
+ possibleFixes: [`Create a new connected account for user ${userId}`]
4092
+ }
4093
+ );
4094
+ }
4095
+ const accountExists = connectedAccounts.some((acc) => acc.id === connectedAccountId);
4096
+ if (connectedAccountId && !accountExists) {
4097
+ throw new ComposioConnectedAccountNotFoundError(
4098
+ `Connected account ID ${connectedAccountId} not found for user ${userId}`,
4099
+ {
4100
+ cause: new Error(
4101
+ `Connected account ID ${connectedAccountId} not found for user ${userId}`
4102
+ ),
4103
+ possibleFixes: [
4104
+ `Create a new connected account for user ${userId}`,
4105
+ `Verify the connected account ID`
4106
+ ]
4107
+ }
4108
+ );
4109
+ }
4110
+ if (!connectedAccountId) {
4111
+ connectedAccountId = connectedAccounts[0].id;
4112
+ logger_default.warn(
4113
+ `[Warn] Multiple connected accounts found for user ${userId}, using the first one. Pass connectedAccountId to select a specific account.`
4114
+ );
4115
+ }
4116
+ } catch (error) {
4117
+ if (error instanceof APIError && [400, 404].includes(error.status)) {
4118
+ throw new ComposioConnectedAccountNotFoundError(
4119
+ `No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
4120
+ {
4121
+ cause: error,
4122
+ possibleFixes: [`Create a new connected account for user ${userId}`]
4123
+ }
4124
+ );
4125
+ }
4126
+ throw error;
4127
+ }
4042
4128
  const result = await this.client.triggerInstances.upsert(slug, {
4043
- connected_account_id: parsedBody.data.connectedAccountId,
4129
+ connected_account_id: connectedAccountId,
4044
4130
  trigger_config: parsedBody.data.triggerConfig
4045
4131
  });
4046
4132
  const parsedResult = TriggerInstanceUpsertResponseSchema.safeParse({
@@ -4793,7 +4879,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
4793
4879
  };
4794
4880
 
4795
4881
  // package.json
4796
- var version = "0.1.22";
4882
+ var version = "0.1.23";
4797
4883
 
4798
4884
  // src/composio.ts
4799
4885
  var Composio = class _Composio {
@@ -4857,7 +4943,7 @@ var Composio = class _Composio {
4857
4943
  if (IS_DEVELOPMENT_OR_CI) {
4858
4944
  logger_default.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
4859
4945
  }
4860
- this.client = new ComposioClient3({
4946
+ this.client = new ComposioClient4({
4861
4947
  apiKey: apiKeyParsed,
4862
4948
  baseURL: baseURLParsed,
4863
4949
  defaultHeaders: config?.defaultHeaders,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composio/core",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -30,7 +30,7 @@
30
30
  "@composio/json-schema-to-zod": "0.1.9"
31
31
  },
32
32
  "dependencies": {
33
- "@composio/client": "0.1.0-alpha.22",
33
+ "@composio/client": "0.1.0-alpha.23",
34
34
  "@composio/json-schema-to-zod": "0.1.9",
35
35
  "chalk": "^5.4.1",
36
36
  "openai": "^4.94.0",