@composio/core 0.1.9-alpha.0 → 0.1.10-alpha.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/index.cjs CHANGED
@@ -217,7 +217,8 @@ var ToolErrorCodes = {
217
217
  INVALID_MODIFIER: "INVALID_MODIFIER",
218
218
  CUSTOM_TOOLS_NOT_INITIALIZED: "CUSTOM_TOOLS_NOT_INITIALIZED",
219
219
  TOOL_EXECUTION_ERROR: "TOOL_EXECUTION_ERROR",
220
- INVALID_EXECUTE_FUNCTION: "INVALID_EXECUTE_FUNCTION"
220
+ INVALID_EXECUTE_FUNCTION: "INVALID_EXECUTE_FUNCTION",
221
+ GLOBAL_EXECUTE_TOOL_FN_NOT_SET: "GLOBAL_EXECUTE_TOOL_FN_NOT_SET"
221
222
  };
222
223
  var ComposioToolsetNotDefinedError = class extends ComposioError {
223
224
  constructor(message = "Toolset not defined", meta = {}) {
@@ -284,6 +285,16 @@ var ComposioInvalidExecuteFunctionError = class extends ComposioError {
284
285
  this.name = "ComposioInvalidExecuteFunctionError";
285
286
  }
286
287
  };
288
+ var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
289
+ constructor(message = "Global execute tool function not set", meta = {}) {
290
+ super(message, {
291
+ code: ToolErrorCodes.GLOBAL_EXECUTE_TOOL_FN_NOT_SET,
292
+ meta,
293
+ possibleFixes: ["Ensure the global execute tool function is set in the toolset"]
294
+ });
295
+ this.name = "ComposioGlobalExecuteToolFnNotSetError";
296
+ }
297
+ };
287
298
 
288
299
  // src/errors/ConnectedAccountsError.ts
289
300
  var ConnectedAccountErrorCodes = {
@@ -555,12 +566,12 @@ var Tools = class {
555
566
  * @param {ToolList} tools - The tools to check.
556
567
  * @returns {Promise<boolean>} True if the connected account exists for the given tools, false otherwise.
557
568
  */
558
- async checkIfConnectedAccountExistsForTools(userId, tools) {
569
+ async checkIfConnectedAccountExistsForTools(userIds, tools) {
559
570
  if (!tools.length) {
560
571
  return true;
561
572
  }
562
573
  const connectedAccounts = await this.client.connectedAccounts.list({
563
- user_id: userId
574
+ user_ids: userIds
564
575
  });
565
576
  if (connectedAccounts.items.length === 0) {
566
577
  return false;
@@ -609,8 +620,8 @@ var Tools = class {
609
620
  );
610
621
  if (!isNoAuthApp) {
611
622
  const connectedAccounts = await this.client.connectedAccounts.list({
612
- user_id: userId,
613
- toolkit_slug: tool.toolkit.slug
623
+ user_ids: [userId],
624
+ toolkit_slugs: [tool.toolkit.slug]
614
625
  });
615
626
  if (connectedAccounts.items.length === 0) {
616
627
  throw new Error("No connected accounts found");
@@ -633,7 +644,7 @@ var Tools = class {
633
644
  throw new ValidationError(queryParams.error);
634
645
  }
635
646
  const tools = await this.client.tools.list({
636
- tool_slugs: queryParams.data.tools?.join(","),
647
+ tool_slugs: queryParams.data.tools,
637
648
  toolkit_slug: queryParams.data.toolkits?.join(","),
638
649
  cursor: queryParams.data.cursor,
639
650
  important: queryParams.data.important,
@@ -663,6 +674,11 @@ var Tools = class {
663
674
  * Retrieves a tool by its Slug.
664
675
  * @param slug The ID of the tool to be retrieved
665
676
  * @returns {Promise<Tool>} The tool
677
+ *
678
+ * @example
679
+ * ```ts
680
+ * const tool = await composio.tools.getComposioToolBySlug('default', 'github');
681
+ * ```
666
682
  */
667
683
  async getComposioToolBySlug(userId, slug, modifier) {
668
684
  const customTool = await this.customTools.getCustomToolBySlug(slug);
@@ -671,7 +687,9 @@ var Tools = class {
671
687
  }
672
688
  const tool = await this.client.tools.retrieve(slug);
673
689
  if (!tool) {
674
- throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
690
+ throw new ComposioToolNotFoundError(
691
+ `[getComposioToolBySlug] Tool with slug ${slug} not found`
692
+ );
675
693
  }
676
694
  let modifiedToool = this.transformToolCases(tool);
677
695
  if (modifier) {
@@ -683,6 +701,13 @@ var Tools = class {
683
701
  }
684
702
  return modifiedToool;
685
703
  }
704
+ /**
705
+ * Get a tool by its slug
706
+ * @param userId - The user id
707
+ * @param arg2 - The slug of the tool or the filters for the tools
708
+ * @param options - The options for the tools
709
+ * @returns The tool or the tools
710
+ */
686
711
  async get(userId, arg2, options) {
687
712
  const executeToolFn = this.createExecuteToolFn(userId, options);
688
713
  if (typeof arg2 === "string") {
@@ -694,6 +719,7 @@ var Tools = class {
694
719
  }
695
720
  }
696
721
  /**
722
+ * @internal
697
723
  * Creates a function that executes a tool.
698
724
  * This function is used by agentic the toolsets to execute the tool
699
725
  * @param {string} userId - The user id
@@ -713,6 +739,14 @@ var Tools = class {
713
739
  };
714
740
  return executeToolFn;
715
741
  }
742
+ /**
743
+ * @internal
744
+ * Handles the execution of a custom tool
745
+ * @param tool - The tool to execute
746
+ * @param body - The body of the tool execution
747
+ * @param modifiers - The modifiers to be applied to the tool execution
748
+ * @returns The response from the tool execution
749
+ */
716
750
  async handleCustomToolExecution(tool, body, modifiers) {
717
751
  if (modifiers?.beforeToolExecute) {
718
752
  if (typeof modifiers.beforeToolExecute === "function") {
@@ -738,6 +772,14 @@ var Tools = class {
738
772
  }
739
773
  return result;
740
774
  }
775
+ /**
776
+ * @internal
777
+ * Handles the execution of a composio tool
778
+ * @param tool - The tool to execute
779
+ * @param body - The body of the tool execution
780
+ * @param modifiers - The modifiers to be applied to the tool execution
781
+ * @returns The response from the tool execution
782
+ */
741
783
  async handleComposioToolExecution(tool, body, modifiers) {
742
784
  if (modifiers?.beforeToolExecute) {
743
785
  if (typeof modifiers.beforeToolExecute === "function") {
@@ -848,7 +890,7 @@ var Tools = class {
848
890
 
849
891
  // src/types/toolkit.types.ts
850
892
  var import_zod3 = require("zod");
851
- var ToolkitMangedByEnumSchema = import_zod3.z.enum(["all", "composio_managed", "project_managed"]);
893
+ var ToolkitMangedByEnumSchema = import_zod3.z.enum(["all", "composio", "project"]);
852
894
  var ToolkitSortByEnumSchema = import_zod3.z.enum(["usage", "alphabetically"]);
853
895
  var ToolkitsListParamsSchema = import_zod3.z.object({
854
896
  category: import_zod3.z.string().optional(),
@@ -905,8 +947,8 @@ var ToolkitAuthConfigDetailsSchema = import_zod3.z.object({
905
947
  })
906
948
  }),
907
949
  proxy: import_zod3.z.object({
908
- baseUrl: import_zod3.z.string()
909
- })
950
+ baseUrl: import_zod3.z.string().optional()
951
+ }).optional()
910
952
  });
911
953
  var ToolkitRetrieveResponseSchema = import_zod3.z.object({
912
954
  name: import_zod3.z.string(),
@@ -1015,9 +1057,20 @@ var AuthConfigListResponseSchema = import_zod4.z.object({
1015
1057
  nextCursor: import_zod4.z.string().optional(),
1016
1058
  totalPages: import_zod4.z.number()
1017
1059
  });
1018
- var AuthConfigUpdateParamsSchema = import_zod4.z.object({
1019
- credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()]))
1060
+ var AuthCustomConfigUpdateParamsSchema = import_zod4.z.object({
1061
+ credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.unknown()])),
1062
+ type: import_zod4.z.literal("custom"),
1063
+ restrictToFollowingTools: import_zod4.z.array(import_zod4.z.string()).optional()
1064
+ });
1065
+ var AuthDefaultConfigUpdateParamsSchema = import_zod4.z.object({
1066
+ scopes: import_zod4.z.string(),
1067
+ type: import_zod4.z.literal("default"),
1068
+ restrictToFollowingTools: import_zod4.z.array(import_zod4.z.string()).optional()
1020
1069
  });
1070
+ var AuthConfigUpdateParamsSchema = import_zod4.z.discriminatedUnion("type", [
1071
+ AuthCustomConfigUpdateParamsSchema,
1072
+ AuthDefaultConfigUpdateParamsSchema
1073
+ ]);
1021
1074
 
1022
1075
  // src/models/AuthConfigs.ts
1023
1076
  var AuthConfigs = class {
@@ -1025,6 +1078,14 @@ var AuthConfigs = class {
1025
1078
  constructor(client) {
1026
1079
  this.client = client;
1027
1080
  }
1081
+ /**
1082
+ * Protected getter for the client instance.
1083
+ * This is primarily used for testing purposes.
1084
+ * @protected
1085
+ */
1086
+ getClient() {
1087
+ return this.client;
1088
+ }
1028
1089
  parseAuthConfigRetrieveResponse(authConfig) {
1029
1090
  const result = AuthConfigRetrieveResponseSchema.safeParse({
1030
1091
  id: authConfig.id,
@@ -1131,11 +1192,22 @@ var AuthConfigs = class {
1131
1192
  * @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
1132
1193
  */
1133
1194
  async update(nanoid, data) {
1134
- return this.client.authConfigs.update(nanoid, {
1135
- auth_config: {
1136
- credentials: data.credentials
1195
+ const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
1196
+ if (parsedData.error) {
1197
+ throw new ValidationError(parsedData.error);
1198
+ }
1199
+ return this.client.authConfigs.update(
1200
+ nanoid,
1201
+ parsedData.data.type === "custom" ? {
1202
+ type: "custom",
1203
+ credentials: parsedData.data.credentials,
1204
+ restrict_to_following_tools: parsedData.data.restrictToFollowingTools
1205
+ } : {
1206
+ type: "default",
1207
+ scopes: parsedData.data.scopes,
1208
+ restrict_to_following_tools: parsedData.data.restrictToFollowingTools
1137
1209
  }
1138
- });
1210
+ );
1139
1211
  }
1140
1212
  /**
1141
1213
  * Delete an auth config
@@ -1200,7 +1272,7 @@ var import_zod5 = require("zod");
1200
1272
  var ConnectedAccountStatuses = {
1201
1273
  ACTIVE: "ACTIVE",
1202
1274
  INACTIVE: "INACTIVE",
1203
- PENDING: "DELETED",
1275
+ DELETED: "DELETED",
1204
1276
  INITIATED: "INITIATED",
1205
1277
  EXPIRED: "EXPIRED",
1206
1278
  FAILED: "FAILED"
@@ -1208,7 +1280,7 @@ var ConnectedAccountStatuses = {
1208
1280
  var ConnectedAccountStatusSchema = import_zod5.z.enum([
1209
1281
  ConnectedAccountStatuses.ACTIVE,
1210
1282
  ConnectedAccountStatuses.INACTIVE,
1211
- ConnectedAccountStatuses.PENDING,
1283
+ ConnectedAccountStatuses.DELETED,
1212
1284
  ConnectedAccountStatuses.INITIATED,
1213
1285
  ConnectedAccountStatuses.EXPIRED,
1214
1286
  ConnectedAccountStatuses.FAILED
@@ -1300,7 +1372,8 @@ var import_zod6 = require("zod");
1300
1372
 
1301
1373
  // src/errors/ConnectionRequestError.ts
1302
1374
  var ConnectionRequestErrorCodes = {
1303
- CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT"
1375
+ CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
1376
+ CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
1304
1377
  };
1305
1378
  var ConnectionRequestTimeoutError = class extends ComposioError {
1306
1379
  constructor(message = "Connection request timed out", meta = {}) {
@@ -1308,6 +1381,16 @@ var ConnectionRequestTimeoutError = class extends ComposioError {
1308
1381
  code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
1309
1382
  meta
1310
1383
  });
1384
+ this.name = "ConnectionRequestTimeoutError";
1385
+ }
1386
+ };
1387
+ var ConnectionRequestFailedError = class extends ComposioError {
1388
+ constructor(message = "Connection request failed", meta = {}) {
1389
+ super(message, {
1390
+ code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED,
1391
+ meta
1392
+ });
1393
+ this.name = "ConnectionRequestFailedError";
1311
1394
  }
1312
1395
  };
1313
1396
 
@@ -1364,30 +1447,40 @@ var ConnectionRequest = class {
1364
1447
  async waitForConnection(timeout = 6e4) {
1365
1448
  if (this.connectedAccountStatus === ConnectedAccountStatuses.ACTIVE) {
1366
1449
  const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
1367
- return Promise.resolve(this.transformResponse(response));
1368
- }
1369
- return new Promise((resolve, reject) => {
1370
- const interval = setInterval(async () => {
1371
- try {
1372
- const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
1373
- if (response.status === ConnectedAccountStatuses.ACTIVE) {
1374
- clearInterval(interval);
1375
- resolve(this.transformResponse(response));
1376
- }
1377
- } catch (error) {
1378
- clearInterval(interval);
1379
- reject(error);
1450
+ return this.transformResponse(response);
1451
+ }
1452
+ const terminalErrorStates = [
1453
+ ConnectedAccountStatuses.FAILED,
1454
+ ConnectedAccountStatuses.EXPIRED,
1455
+ ConnectedAccountStatuses.DELETED
1456
+ ];
1457
+ const start = Date.now();
1458
+ const pollInterval = 1e3;
1459
+ while (Date.now() - start < timeout) {
1460
+ try {
1461
+ const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
1462
+ if (response.status === ConnectedAccountStatuses.ACTIVE) {
1463
+ return this.transformResponse(response);
1380
1464
  }
1381
- }, 1e3);
1382
- setTimeout(() => {
1383
- clearInterval(interval);
1384
- reject(
1385
- new ConnectionRequestTimeoutError(
1386
- `Connection request timed out for ${this.connectedAccountId}`
1387
- )
1388
- );
1389
- }, timeout);
1390
- });
1465
+ if (terminalErrorStates.includes(response.status)) {
1466
+ throw new ConnectionRequestFailedError(
1467
+ `Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ""}`,
1468
+ {
1469
+ userId: response.user_id,
1470
+ connectedAccountId: this.connectedAccountId,
1471
+ status: response.status,
1472
+ statusReason: response.status_reason
1473
+ }
1474
+ );
1475
+ }
1476
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
1477
+ } catch (error) {
1478
+ throw error;
1479
+ }
1480
+ }
1481
+ throw new ConnectionRequestTimeoutError(
1482
+ `Connection request timed out for ${this.connectedAccountId}`
1483
+ );
1391
1484
  }
1392
1485
  };
1393
1486
 
@@ -1617,20 +1710,21 @@ var Toolkits = class {
1617
1710
  * @param {string} authConfigId - The id of the auth config to use
1618
1711
  * @returns {Promise<ConnectionRequest>} The connection request object
1619
1712
  */
1620
- async authorize(userId, toolkitSlug, authConfigId) {
1713
+ async authorize(userId, toolkitSlug) {
1621
1714
  const toolkit = await this.getToolkitBySlug(toolkitSlug);
1622
1715
  const composioAuthConfig = new AuthConfigs(this.client);
1623
1716
  let authConfigIdToUse;
1624
- if (authConfigId) {
1625
- const authConfig = await composioAuthConfig.get(authConfigId);
1626
- authConfigIdToUse = authConfig.id;
1627
- } else {
1717
+ const authConfig = await composioAuthConfig.list({
1718
+ toolkitSlug
1719
+ });
1720
+ authConfigIdToUse = authConfig.items[0]?.id;
1721
+ if (!authConfigIdToUse) {
1628
1722
  if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
1629
- const authConfig = await composioAuthConfig.create(toolkitSlug, {
1723
+ const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
1630
1724
  type: "use_composio_managed_auth",
1631
1725
  name: `${toolkit.name} Auth Config`
1632
1726
  });
1633
- authConfigIdToUse = authConfig.id;
1727
+ authConfigIdToUse = authConfig2.id;
1634
1728
  } else {
1635
1729
  throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
1636
1730
  toolkitSlug
@@ -1860,6 +1954,7 @@ var Triggers = class {
1860
1954
  const sessionInfo = await session.getInfo();
1861
1955
  const clientId = sessionInfo.project?.id;
1862
1956
  if (!clientId) throw new Error("Client ID not found");
1957
+ if (!this.client.apiKey) throw new Error("API key not found");
1863
1958
  await PusherUtils.getPusherClient(this.client.baseURL, this.client.apiKey);
1864
1959
  const shouldSendTrigger = (data) => {
1865
1960
  if (Object.keys(filters).length === 0) return true;
@@ -2176,7 +2271,7 @@ var BaseToolset = class {
2176
2271
  /**
2177
2272
  * @internal
2178
2273
  * Set the function to execute a tool.
2179
- * This is set automatically injected by the core SDK.
2274
+ * This is set automatically and injected by the core SDK.
2180
2275
  */
2181
2276
  _setExecuteToolFn(executeToolFn) {
2182
2277
  this._globalExecuteToolFn = executeToolFn;
@@ -2191,6 +2286,9 @@ var BaseToolset = class {
2191
2286
  * @returns {Promise<string>} The result of the tool execution.
2192
2287
  */
2193
2288
  executeTool(toolSlug, body, modifers) {
2289
+ if (!this._globalExecuteToolFn) {
2290
+ throw new ComposioGlobalExecuteToolFnNotSetError("executeToolFn is not set");
2291
+ }
2194
2292
  return this._globalExecuteToolFn(toolSlug, body, modifers);
2195
2293
  }
2196
2294
  };
@@ -2367,7 +2465,7 @@ var OpenAIToolset = class extends BaseNonAgenticToolset {
2367
2465
  };
2368
2466
 
2369
2467
  // package.json
2370
- var version = "0.1.9-alpha.0";
2468
+ var version = "0.1.10-alpha.0";
2371
2469
 
2372
2470
  // src/utils/uuid.ts
2373
2471
  var import_uuid = require("uuid");
package/dist/index.d.cts CHANGED
@@ -297,7 +297,7 @@ declare abstract class BaseToolset {
297
297
  /**
298
298
  * @internal
299
299
  * Set the function to execute a tool.
300
- * This is set automatically injected by the core SDK.
300
+ * This is set automatically and injected by the core SDK.
301
301
  */
302
302
  _setExecuteToolFn(executeToolFn: GlobalExecuteToolFn): void;
303
303
  /**
@@ -447,11 +447,43 @@ declare class Tools<TToolCollection, TTool, TToolset extends BaseComposioToolset
447
447
  * Retrieves a tool by its Slug.
448
448
  * @param slug The ID of the tool to be retrieved
449
449
  * @returns {Promise<Tool>} The tool
450
+ *
451
+ * @example
452
+ * ```ts
453
+ * const tool = await composio.tools.getComposioToolBySlug('default', 'github');
454
+ * ```
450
455
  */
451
456
  getComposioToolBySlug(userId: string, slug: string, modifier?: TransformToolSchemaModifier): Promise<Tool>;
457
+ /**
458
+ * Get a tool by its slug
459
+ * @param userId - The user id
460
+ * @param slug - The slug of the tool
461
+ * @param options - The options for the tool
462
+ * @returns The tool
463
+ *
464
+ * @example
465
+ * ```ts
466
+ * const tool = await composio.tools.get('default', 'github');
467
+ * ```
468
+ */
452
469
  get<T extends TToolset>(userId: string, slug: string, options?: ToolsetOptions<TToolset>): Promise<ReturnType<T['wrapTool']>>;
470
+ /**
471
+ * Get a list of tools by their slugs
472
+ * @param userId - The user id
473
+ * @param filters - The filters for the tools
474
+ * @param options - The options for the tools
475
+ * @returns The tools
476
+ *
477
+ * @example
478
+ * ```ts
479
+ * const tools = await composio.tools.get('default', {
480
+ * tools: ['github'],
481
+ * });
482
+ * ```
483
+ */
453
484
  get<T extends TToolset>(userId: string, filters: ToolListParams, options?: ToolsetOptions<TToolset>): Promise<ReturnType<T['wrapTools']>>;
454
485
  /**
486
+ * @internal
455
487
  * Creates a function that executes a tool.
456
488
  * This function is used by agentic the toolsets to execute the tool
457
489
  * @param {string} userId - The user id
@@ -459,7 +491,23 @@ declare class Tools<TToolCollection, TTool, TToolset extends BaseComposioToolset
459
491
  * @returns {ExecuteToolFn} The execute tool function
460
492
  */
461
493
  private createExecuteToolFn;
494
+ /**
495
+ * @internal
496
+ * Handles the execution of a custom tool
497
+ * @param tool - The tool to execute
498
+ * @param body - The body of the tool execution
499
+ * @param modifiers - The modifiers to be applied to the tool execution
500
+ * @returns The response from the tool execution
501
+ */
462
502
  private handleCustomToolExecution;
503
+ /**
504
+ * @internal
505
+ * Handles the execution of a composio tool
506
+ * @param tool - The tool to execute
507
+ * @param body - The body of the tool execution
508
+ * @param modifiers - The modifiers to be applied to the tool execution
509
+ * @returns The response from the tool execution
510
+ */
463
511
  private handleComposioToolExecution;
464
512
  /**
465
513
  * Exectes a given tool with the provided parameters.
@@ -506,17 +554,17 @@ declare class Tools<TToolCollection, TTool, TToolset extends BaseComposioToolset
506
554
  declare const ToolkitsListParamsSchema: z.ZodObject<{
507
555
  category: z.ZodOptional<z.ZodString>;
508
556
  isLocal: z.ZodOptional<z.ZodBoolean>;
509
- managedBy: z.ZodOptional<z.ZodEnum<["all", "composio_managed", "project_managed"]>>;
557
+ managedBy: z.ZodOptional<z.ZodEnum<["all", "composio", "project"]>>;
510
558
  sortBy: z.ZodOptional<z.ZodEnum<["usage", "alphabetically"]>>;
511
559
  }, "strip", z.ZodTypeAny, {
512
560
  category?: string | undefined;
513
561
  isLocal?: boolean | undefined;
514
- managedBy?: "all" | "composio_managed" | "project_managed" | undefined;
562
+ managedBy?: "all" | "composio" | "project" | undefined;
515
563
  sortBy?: "usage" | "alphabetically" | undefined;
516
564
  }, {
517
565
  category?: string | undefined;
518
566
  isLocal?: boolean | undefined;
519
- managedBy?: "all" | "composio_managed" | "project_managed" | undefined;
567
+ managedBy?: "all" | "composio" | "project" | undefined;
520
568
  sortBy?: "usage" | "alphabetically" | undefined;
521
569
  }>;
522
570
  type ToolkitListParams = z.infer<typeof ToolkitsListParamsSchema>;
@@ -895,13 +943,13 @@ declare const ToolkitRetrieveResponseSchema: z.ZodObject<{
895
943
  }[];
896
944
  };
897
945
  }>;
898
- proxy: z.ZodObject<{
899
- baseUrl: z.ZodString;
946
+ proxy: z.ZodOptional<z.ZodObject<{
947
+ baseUrl: z.ZodOptional<z.ZodString>;
900
948
  }, "strip", z.ZodTypeAny, {
901
- baseUrl: string;
949
+ baseUrl?: string | undefined;
902
950
  }, {
903
- baseUrl: string;
904
- }>;
951
+ baseUrl?: string | undefined;
952
+ }>>;
905
953
  }, "strip", z.ZodTypeAny, {
906
954
  name: string;
907
955
  mode: string;
@@ -935,9 +983,9 @@ declare const ToolkitRetrieveResponseSchema: z.ZodObject<{
935
983
  }[];
936
984
  };
937
985
  };
938
- proxy: {
939
- baseUrl: string;
940
- };
986
+ proxy?: {
987
+ baseUrl?: string | undefined;
988
+ } | undefined;
941
989
  }, {
942
990
  name: string;
943
991
  mode: string;
@@ -971,9 +1019,9 @@ declare const ToolkitRetrieveResponseSchema: z.ZodObject<{
971
1019
  }[];
972
1020
  };
973
1021
  };
974
- proxy: {
975
- baseUrl: string;
976
- };
1022
+ proxy?: {
1023
+ baseUrl?: string | undefined;
1024
+ } | undefined;
977
1025
  }>, "many">>;
978
1026
  }, "strip", z.ZodTypeAny, {
979
1027
  slug: string;
@@ -1026,9 +1074,9 @@ declare const ToolkitRetrieveResponseSchema: z.ZodObject<{
1026
1074
  }[];
1027
1075
  };
1028
1076
  };
1029
- proxy: {
1030
- baseUrl: string;
1031
- };
1077
+ proxy?: {
1078
+ baseUrl?: string | undefined;
1079
+ } | undefined;
1032
1080
  }[] | undefined;
1033
1081
  }, {
1034
1082
  slug: string;
@@ -1081,9 +1129,9 @@ declare const ToolkitRetrieveResponseSchema: z.ZodObject<{
1081
1129
  }[];
1082
1130
  };
1083
1131
  };
1084
- proxy: {
1085
- baseUrl: string;
1086
- };
1132
+ proxy?: {
1133
+ baseUrl?: string | undefined;
1134
+ } | undefined;
1087
1135
  }[] | undefined;
1088
1136
  }>;
1089
1137
  type ToolkitRetrieveResponse = z.infer<typeof ToolkitRetrieveResponseSchema>;
@@ -1123,7 +1171,7 @@ type ToolkitRetrieveCategoriesResponse = z.infer<typeof ToolkitRetrieveCategorie
1123
1171
  declare const ConnectedAccountStatuses: {
1124
1172
  readonly ACTIVE: "ACTIVE";
1125
1173
  readonly INACTIVE: "INACTIVE";
1126
- readonly PENDING: "DELETED";
1174
+ readonly DELETED: "DELETED";
1127
1175
  readonly INITIATED: "INITIATED";
1128
1176
  readonly EXPIRED: "EXPIRED";
1129
1177
  readonly FAILED: "FAILED";
@@ -1298,7 +1346,7 @@ declare class Toolkits {
1298
1346
  * @param {string} authConfigId - The id of the auth config to use
1299
1347
  * @returns {Promise<ConnectionRequest>} The connection request object
1300
1348
  */
1301
- authorize(userId: string, toolkitSlug: string, authConfigId?: string): Promise<ConnectionRequest>;
1349
+ authorize(userId: string, toolkitSlug: string): Promise<ConnectionRequest>;
1302
1350
  }
1303
1351
 
1304
1352
  type TriggerStatusEnum = "enable" | "disable";
@@ -1692,13 +1740,31 @@ declare const AuthConfigListResponseSchema: z.ZodObject<{
1692
1740
  nextCursor?: string | undefined;
1693
1741
  }>;
1694
1742
  type AuthConfigListResponse = z.infer<typeof AuthConfigListResponseSchema>;
1695
- declare const AuthConfigUpdateParamsSchema: z.ZodObject<{
1696
- credentials: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
1743
+ declare const AuthConfigUpdateParamsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
1744
+ credentials: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodUnknown]>>;
1745
+ type: z.ZodLiteral<"custom">;
1746
+ restrictToFollowingTools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1697
1747
  }, "strip", z.ZodTypeAny, {
1698
- credentials: Record<string, string | number | boolean>;
1748
+ type: "custom";
1749
+ credentials: Record<string, unknown>;
1750
+ restrictToFollowingTools?: string[] | undefined;
1699
1751
  }, {
1700
- credentials: Record<string, string | number | boolean>;
1701
- }>;
1752
+ type: "custom";
1753
+ credentials: Record<string, unknown>;
1754
+ restrictToFollowingTools?: string[] | undefined;
1755
+ }>, z.ZodObject<{
1756
+ scopes: z.ZodString;
1757
+ type: z.ZodLiteral<"default">;
1758
+ restrictToFollowingTools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1759
+ }, "strip", z.ZodTypeAny, {
1760
+ type: "default";
1761
+ scopes: string;
1762
+ restrictToFollowingTools?: string[] | undefined;
1763
+ }, {
1764
+ type: "default";
1765
+ scopes: string;
1766
+ restrictToFollowingTools?: string[] | undefined;
1767
+ }>]>;
1702
1768
  type AuthConfigUpdateParams = z.infer<typeof AuthConfigUpdateParamsSchema>;
1703
1769
 
1704
1770
  /**
@@ -1718,6 +1784,12 @@ type AuthConfigUpdateParams = z.infer<typeof AuthConfigUpdateParamsSchema>;
1718
1784
  declare class AuthConfigs {
1719
1785
  private client;
1720
1786
  constructor(client: ComposioClient);
1787
+ /**
1788
+ * Protected getter for the client instance.
1789
+ * This is primarily used for testing purposes.
1790
+ * @protected
1791
+ */
1792
+ protected getClient(): ComposioClient;
1721
1793
  private parseAuthConfigRetrieveResponse;
1722
1794
  /**
1723
1795
  * List all auth configs
package/dist/index.d.ts CHANGED
@@ -297,7 +297,7 @@ declare abstract class BaseToolset {
297
297
  /**
298
298
  * @internal
299
299
  * Set the function to execute a tool.
300
- * This is set automatically injected by the core SDK.
300
+ * This is set automatically and injected by the core SDK.
301
301
  */
302
302
  _setExecuteToolFn(executeToolFn: GlobalExecuteToolFn): void;
303
303
  /**
@@ -447,11 +447,43 @@ declare class Tools<TToolCollection, TTool, TToolset extends BaseComposioToolset
447
447
  * Retrieves a tool by its Slug.
448
448
  * @param slug The ID of the tool to be retrieved
449
449
  * @returns {Promise<Tool>} The tool
450
+ *
451
+ * @example
452
+ * ```ts
453
+ * const tool = await composio.tools.getComposioToolBySlug('default', 'github');
454
+ * ```
450
455
  */
451
456
  getComposioToolBySlug(userId: string, slug: string, modifier?: TransformToolSchemaModifier): Promise<Tool>;
457
+ /**
458
+ * Get a tool by its slug
459
+ * @param userId - The user id
460
+ * @param slug - The slug of the tool
461
+ * @param options - The options for the tool
462
+ * @returns The tool
463
+ *
464
+ * @example
465
+ * ```ts
466
+ * const tool = await composio.tools.get('default', 'github');
467
+ * ```
468
+ */
452
469
  get<T extends TToolset>(userId: string, slug: string, options?: ToolsetOptions<TToolset>): Promise<ReturnType<T['wrapTool']>>;
470
+ /**
471
+ * Get a list of tools by their slugs
472
+ * @param userId - The user id
473
+ * @param filters - The filters for the tools
474
+ * @param options - The options for the tools
475
+ * @returns The tools
476
+ *
477
+ * @example
478
+ * ```ts
479
+ * const tools = await composio.tools.get('default', {
480
+ * tools: ['github'],
481
+ * });
482
+ * ```
483
+ */
453
484
  get<T extends TToolset>(userId: string, filters: ToolListParams, options?: ToolsetOptions<TToolset>): Promise<ReturnType<T['wrapTools']>>;
454
485
  /**
486
+ * @internal
455
487
  * Creates a function that executes a tool.
456
488
  * This function is used by agentic the toolsets to execute the tool
457
489
  * @param {string} userId - The user id
@@ -459,7 +491,23 @@ declare class Tools<TToolCollection, TTool, TToolset extends BaseComposioToolset
459
491
  * @returns {ExecuteToolFn} The execute tool function
460
492
  */
461
493
  private createExecuteToolFn;
494
+ /**
495
+ * @internal
496
+ * Handles the execution of a custom tool
497
+ * @param tool - The tool to execute
498
+ * @param body - The body of the tool execution
499
+ * @param modifiers - The modifiers to be applied to the tool execution
500
+ * @returns The response from the tool execution
501
+ */
462
502
  private handleCustomToolExecution;
503
+ /**
504
+ * @internal
505
+ * Handles the execution of a composio tool
506
+ * @param tool - The tool to execute
507
+ * @param body - The body of the tool execution
508
+ * @param modifiers - The modifiers to be applied to the tool execution
509
+ * @returns The response from the tool execution
510
+ */
463
511
  private handleComposioToolExecution;
464
512
  /**
465
513
  * Exectes a given tool with the provided parameters.
@@ -506,17 +554,17 @@ declare class Tools<TToolCollection, TTool, TToolset extends BaseComposioToolset
506
554
  declare const ToolkitsListParamsSchema: z.ZodObject<{
507
555
  category: z.ZodOptional<z.ZodString>;
508
556
  isLocal: z.ZodOptional<z.ZodBoolean>;
509
- managedBy: z.ZodOptional<z.ZodEnum<["all", "composio_managed", "project_managed"]>>;
557
+ managedBy: z.ZodOptional<z.ZodEnum<["all", "composio", "project"]>>;
510
558
  sortBy: z.ZodOptional<z.ZodEnum<["usage", "alphabetically"]>>;
511
559
  }, "strip", z.ZodTypeAny, {
512
560
  category?: string | undefined;
513
561
  isLocal?: boolean | undefined;
514
- managedBy?: "all" | "composio_managed" | "project_managed" | undefined;
562
+ managedBy?: "all" | "composio" | "project" | undefined;
515
563
  sortBy?: "usage" | "alphabetically" | undefined;
516
564
  }, {
517
565
  category?: string | undefined;
518
566
  isLocal?: boolean | undefined;
519
- managedBy?: "all" | "composio_managed" | "project_managed" | undefined;
567
+ managedBy?: "all" | "composio" | "project" | undefined;
520
568
  sortBy?: "usage" | "alphabetically" | undefined;
521
569
  }>;
522
570
  type ToolkitListParams = z.infer<typeof ToolkitsListParamsSchema>;
@@ -895,13 +943,13 @@ declare const ToolkitRetrieveResponseSchema: z.ZodObject<{
895
943
  }[];
896
944
  };
897
945
  }>;
898
- proxy: z.ZodObject<{
899
- baseUrl: z.ZodString;
946
+ proxy: z.ZodOptional<z.ZodObject<{
947
+ baseUrl: z.ZodOptional<z.ZodString>;
900
948
  }, "strip", z.ZodTypeAny, {
901
- baseUrl: string;
949
+ baseUrl?: string | undefined;
902
950
  }, {
903
- baseUrl: string;
904
- }>;
951
+ baseUrl?: string | undefined;
952
+ }>>;
905
953
  }, "strip", z.ZodTypeAny, {
906
954
  name: string;
907
955
  mode: string;
@@ -935,9 +983,9 @@ declare const ToolkitRetrieveResponseSchema: z.ZodObject<{
935
983
  }[];
936
984
  };
937
985
  };
938
- proxy: {
939
- baseUrl: string;
940
- };
986
+ proxy?: {
987
+ baseUrl?: string | undefined;
988
+ } | undefined;
941
989
  }, {
942
990
  name: string;
943
991
  mode: string;
@@ -971,9 +1019,9 @@ declare const ToolkitRetrieveResponseSchema: z.ZodObject<{
971
1019
  }[];
972
1020
  };
973
1021
  };
974
- proxy: {
975
- baseUrl: string;
976
- };
1022
+ proxy?: {
1023
+ baseUrl?: string | undefined;
1024
+ } | undefined;
977
1025
  }>, "many">>;
978
1026
  }, "strip", z.ZodTypeAny, {
979
1027
  slug: string;
@@ -1026,9 +1074,9 @@ declare const ToolkitRetrieveResponseSchema: z.ZodObject<{
1026
1074
  }[];
1027
1075
  };
1028
1076
  };
1029
- proxy: {
1030
- baseUrl: string;
1031
- };
1077
+ proxy?: {
1078
+ baseUrl?: string | undefined;
1079
+ } | undefined;
1032
1080
  }[] | undefined;
1033
1081
  }, {
1034
1082
  slug: string;
@@ -1081,9 +1129,9 @@ declare const ToolkitRetrieveResponseSchema: z.ZodObject<{
1081
1129
  }[];
1082
1130
  };
1083
1131
  };
1084
- proxy: {
1085
- baseUrl: string;
1086
- };
1132
+ proxy?: {
1133
+ baseUrl?: string | undefined;
1134
+ } | undefined;
1087
1135
  }[] | undefined;
1088
1136
  }>;
1089
1137
  type ToolkitRetrieveResponse = z.infer<typeof ToolkitRetrieveResponseSchema>;
@@ -1123,7 +1171,7 @@ type ToolkitRetrieveCategoriesResponse = z.infer<typeof ToolkitRetrieveCategorie
1123
1171
  declare const ConnectedAccountStatuses: {
1124
1172
  readonly ACTIVE: "ACTIVE";
1125
1173
  readonly INACTIVE: "INACTIVE";
1126
- readonly PENDING: "DELETED";
1174
+ readonly DELETED: "DELETED";
1127
1175
  readonly INITIATED: "INITIATED";
1128
1176
  readonly EXPIRED: "EXPIRED";
1129
1177
  readonly FAILED: "FAILED";
@@ -1298,7 +1346,7 @@ declare class Toolkits {
1298
1346
  * @param {string} authConfigId - The id of the auth config to use
1299
1347
  * @returns {Promise<ConnectionRequest>} The connection request object
1300
1348
  */
1301
- authorize(userId: string, toolkitSlug: string, authConfigId?: string): Promise<ConnectionRequest>;
1349
+ authorize(userId: string, toolkitSlug: string): Promise<ConnectionRequest>;
1302
1350
  }
1303
1351
 
1304
1352
  type TriggerStatusEnum = "enable" | "disable";
@@ -1692,13 +1740,31 @@ declare const AuthConfigListResponseSchema: z.ZodObject<{
1692
1740
  nextCursor?: string | undefined;
1693
1741
  }>;
1694
1742
  type AuthConfigListResponse = z.infer<typeof AuthConfigListResponseSchema>;
1695
- declare const AuthConfigUpdateParamsSchema: z.ZodObject<{
1696
- credentials: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
1743
+ declare const AuthConfigUpdateParamsSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
1744
+ credentials: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodUnknown]>>;
1745
+ type: z.ZodLiteral<"custom">;
1746
+ restrictToFollowingTools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1697
1747
  }, "strip", z.ZodTypeAny, {
1698
- credentials: Record<string, string | number | boolean>;
1748
+ type: "custom";
1749
+ credentials: Record<string, unknown>;
1750
+ restrictToFollowingTools?: string[] | undefined;
1699
1751
  }, {
1700
- credentials: Record<string, string | number | boolean>;
1701
- }>;
1752
+ type: "custom";
1753
+ credentials: Record<string, unknown>;
1754
+ restrictToFollowingTools?: string[] | undefined;
1755
+ }>, z.ZodObject<{
1756
+ scopes: z.ZodString;
1757
+ type: z.ZodLiteral<"default">;
1758
+ restrictToFollowingTools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1759
+ }, "strip", z.ZodTypeAny, {
1760
+ type: "default";
1761
+ scopes: string;
1762
+ restrictToFollowingTools?: string[] | undefined;
1763
+ }, {
1764
+ type: "default";
1765
+ scopes: string;
1766
+ restrictToFollowingTools?: string[] | undefined;
1767
+ }>]>;
1702
1768
  type AuthConfigUpdateParams = z.infer<typeof AuthConfigUpdateParamsSchema>;
1703
1769
 
1704
1770
  /**
@@ -1718,6 +1784,12 @@ type AuthConfigUpdateParams = z.infer<typeof AuthConfigUpdateParamsSchema>;
1718
1784
  declare class AuthConfigs {
1719
1785
  private client;
1720
1786
  constructor(client: ComposioClient);
1787
+ /**
1788
+ * Protected getter for the client instance.
1789
+ * This is primarily used for testing purposes.
1790
+ * @protected
1791
+ */
1792
+ protected getClient(): ComposioClient;
1721
1793
  private parseAuthConfigRetrieveResponse;
1722
1794
  /**
1723
1795
  * List all auth configs
package/dist/index.js CHANGED
@@ -179,7 +179,8 @@ var ToolErrorCodes = {
179
179
  INVALID_MODIFIER: "INVALID_MODIFIER",
180
180
  CUSTOM_TOOLS_NOT_INITIALIZED: "CUSTOM_TOOLS_NOT_INITIALIZED",
181
181
  TOOL_EXECUTION_ERROR: "TOOL_EXECUTION_ERROR",
182
- INVALID_EXECUTE_FUNCTION: "INVALID_EXECUTE_FUNCTION"
182
+ INVALID_EXECUTE_FUNCTION: "INVALID_EXECUTE_FUNCTION",
183
+ GLOBAL_EXECUTE_TOOL_FN_NOT_SET: "GLOBAL_EXECUTE_TOOL_FN_NOT_SET"
183
184
  };
184
185
  var ComposioToolsetNotDefinedError = class extends ComposioError {
185
186
  constructor(message = "Toolset not defined", meta = {}) {
@@ -246,6 +247,16 @@ var ComposioInvalidExecuteFunctionError = class extends ComposioError {
246
247
  this.name = "ComposioInvalidExecuteFunctionError";
247
248
  }
248
249
  };
250
+ var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
251
+ constructor(message = "Global execute tool function not set", meta = {}) {
252
+ super(message, {
253
+ code: ToolErrorCodes.GLOBAL_EXECUTE_TOOL_FN_NOT_SET,
254
+ meta,
255
+ possibleFixes: ["Ensure the global execute tool function is set in the toolset"]
256
+ });
257
+ this.name = "ComposioGlobalExecuteToolFnNotSetError";
258
+ }
259
+ };
249
260
 
250
261
  // src/errors/ConnectedAccountsError.ts
251
262
  var ConnectedAccountErrorCodes = {
@@ -517,12 +528,12 @@ var Tools = class {
517
528
  * @param {ToolList} tools - The tools to check.
518
529
  * @returns {Promise<boolean>} True if the connected account exists for the given tools, false otherwise.
519
530
  */
520
- async checkIfConnectedAccountExistsForTools(userId, tools) {
531
+ async checkIfConnectedAccountExistsForTools(userIds, tools) {
521
532
  if (!tools.length) {
522
533
  return true;
523
534
  }
524
535
  const connectedAccounts = await this.client.connectedAccounts.list({
525
- user_id: userId
536
+ user_ids: userIds
526
537
  });
527
538
  if (connectedAccounts.items.length === 0) {
528
539
  return false;
@@ -571,8 +582,8 @@ var Tools = class {
571
582
  );
572
583
  if (!isNoAuthApp) {
573
584
  const connectedAccounts = await this.client.connectedAccounts.list({
574
- user_id: userId,
575
- toolkit_slug: tool.toolkit.slug
585
+ user_ids: [userId],
586
+ toolkit_slugs: [tool.toolkit.slug]
576
587
  });
577
588
  if (connectedAccounts.items.length === 0) {
578
589
  throw new Error("No connected accounts found");
@@ -595,7 +606,7 @@ var Tools = class {
595
606
  throw new ValidationError(queryParams.error);
596
607
  }
597
608
  const tools = await this.client.tools.list({
598
- tool_slugs: queryParams.data.tools?.join(","),
609
+ tool_slugs: queryParams.data.tools,
599
610
  toolkit_slug: queryParams.data.toolkits?.join(","),
600
611
  cursor: queryParams.data.cursor,
601
612
  important: queryParams.data.important,
@@ -625,6 +636,11 @@ var Tools = class {
625
636
  * Retrieves a tool by its Slug.
626
637
  * @param slug The ID of the tool to be retrieved
627
638
  * @returns {Promise<Tool>} The tool
639
+ *
640
+ * @example
641
+ * ```ts
642
+ * const tool = await composio.tools.getComposioToolBySlug('default', 'github');
643
+ * ```
628
644
  */
629
645
  async getComposioToolBySlug(userId, slug, modifier) {
630
646
  const customTool = await this.customTools.getCustomToolBySlug(slug);
@@ -633,7 +649,9 @@ var Tools = class {
633
649
  }
634
650
  const tool = await this.client.tools.retrieve(slug);
635
651
  if (!tool) {
636
- throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
652
+ throw new ComposioToolNotFoundError(
653
+ `[getComposioToolBySlug] Tool with slug ${slug} not found`
654
+ );
637
655
  }
638
656
  let modifiedToool = this.transformToolCases(tool);
639
657
  if (modifier) {
@@ -645,6 +663,13 @@ var Tools = class {
645
663
  }
646
664
  return modifiedToool;
647
665
  }
666
+ /**
667
+ * Get a tool by its slug
668
+ * @param userId - The user id
669
+ * @param arg2 - The slug of the tool or the filters for the tools
670
+ * @param options - The options for the tools
671
+ * @returns The tool or the tools
672
+ */
648
673
  async get(userId, arg2, options) {
649
674
  const executeToolFn = this.createExecuteToolFn(userId, options);
650
675
  if (typeof arg2 === "string") {
@@ -656,6 +681,7 @@ var Tools = class {
656
681
  }
657
682
  }
658
683
  /**
684
+ * @internal
659
685
  * Creates a function that executes a tool.
660
686
  * This function is used by agentic the toolsets to execute the tool
661
687
  * @param {string} userId - The user id
@@ -675,6 +701,14 @@ var Tools = class {
675
701
  };
676
702
  return executeToolFn;
677
703
  }
704
+ /**
705
+ * @internal
706
+ * Handles the execution of a custom tool
707
+ * @param tool - The tool to execute
708
+ * @param body - The body of the tool execution
709
+ * @param modifiers - The modifiers to be applied to the tool execution
710
+ * @returns The response from the tool execution
711
+ */
678
712
  async handleCustomToolExecution(tool, body, modifiers) {
679
713
  if (modifiers?.beforeToolExecute) {
680
714
  if (typeof modifiers.beforeToolExecute === "function") {
@@ -700,6 +734,14 @@ var Tools = class {
700
734
  }
701
735
  return result;
702
736
  }
737
+ /**
738
+ * @internal
739
+ * Handles the execution of a composio tool
740
+ * @param tool - The tool to execute
741
+ * @param body - The body of the tool execution
742
+ * @param modifiers - The modifiers to be applied to the tool execution
743
+ * @returns The response from the tool execution
744
+ */
703
745
  async handleComposioToolExecution(tool, body, modifiers) {
704
746
  if (modifiers?.beforeToolExecute) {
705
747
  if (typeof modifiers.beforeToolExecute === "function") {
@@ -810,7 +852,7 @@ var Tools = class {
810
852
 
811
853
  // src/types/toolkit.types.ts
812
854
  import { z as z2 } from "zod";
813
- var ToolkitMangedByEnumSchema = z2.enum(["all", "composio_managed", "project_managed"]);
855
+ var ToolkitMangedByEnumSchema = z2.enum(["all", "composio", "project"]);
814
856
  var ToolkitSortByEnumSchema = z2.enum(["usage", "alphabetically"]);
815
857
  var ToolkitsListParamsSchema = z2.object({
816
858
  category: z2.string().optional(),
@@ -867,8 +909,8 @@ var ToolkitAuthConfigDetailsSchema = z2.object({
867
909
  })
868
910
  }),
869
911
  proxy: z2.object({
870
- baseUrl: z2.string()
871
- })
912
+ baseUrl: z2.string().optional()
913
+ }).optional()
872
914
  });
873
915
  var ToolkitRetrieveResponseSchema = z2.object({
874
916
  name: z2.string(),
@@ -977,9 +1019,20 @@ var AuthConfigListResponseSchema = z3.object({
977
1019
  nextCursor: z3.string().optional(),
978
1020
  totalPages: z3.number()
979
1021
  });
980
- var AuthConfigUpdateParamsSchema = z3.object({
981
- credentials: z3.record(z3.string(), z3.union([z3.string(), z3.number(), z3.boolean()]))
1022
+ var AuthCustomConfigUpdateParamsSchema = z3.object({
1023
+ credentials: z3.record(z3.string(), z3.union([z3.string(), z3.unknown()])),
1024
+ type: z3.literal("custom"),
1025
+ restrictToFollowingTools: z3.array(z3.string()).optional()
1026
+ });
1027
+ var AuthDefaultConfigUpdateParamsSchema = z3.object({
1028
+ scopes: z3.string(),
1029
+ type: z3.literal("default"),
1030
+ restrictToFollowingTools: z3.array(z3.string()).optional()
982
1031
  });
1032
+ var AuthConfigUpdateParamsSchema = z3.discriminatedUnion("type", [
1033
+ AuthCustomConfigUpdateParamsSchema,
1034
+ AuthDefaultConfigUpdateParamsSchema
1035
+ ]);
983
1036
 
984
1037
  // src/models/AuthConfigs.ts
985
1038
  var AuthConfigs = class {
@@ -987,6 +1040,14 @@ var AuthConfigs = class {
987
1040
  constructor(client) {
988
1041
  this.client = client;
989
1042
  }
1043
+ /**
1044
+ * Protected getter for the client instance.
1045
+ * This is primarily used for testing purposes.
1046
+ * @protected
1047
+ */
1048
+ getClient() {
1049
+ return this.client;
1050
+ }
990
1051
  parseAuthConfigRetrieveResponse(authConfig) {
991
1052
  const result = AuthConfigRetrieveResponseSchema.safeParse({
992
1053
  id: authConfig.id,
@@ -1093,11 +1154,22 @@ var AuthConfigs = class {
1093
1154
  * @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
1094
1155
  */
1095
1156
  async update(nanoid, data) {
1096
- return this.client.authConfigs.update(nanoid, {
1097
- auth_config: {
1098
- credentials: data.credentials
1157
+ const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
1158
+ if (parsedData.error) {
1159
+ throw new ValidationError(parsedData.error);
1160
+ }
1161
+ return this.client.authConfigs.update(
1162
+ nanoid,
1163
+ parsedData.data.type === "custom" ? {
1164
+ type: "custom",
1165
+ credentials: parsedData.data.credentials,
1166
+ restrict_to_following_tools: parsedData.data.restrictToFollowingTools
1167
+ } : {
1168
+ type: "default",
1169
+ scopes: parsedData.data.scopes,
1170
+ restrict_to_following_tools: parsedData.data.restrictToFollowingTools
1099
1171
  }
1100
- });
1172
+ );
1101
1173
  }
1102
1174
  /**
1103
1175
  * Delete an auth config
@@ -1162,7 +1234,7 @@ import { z as z4 } from "zod";
1162
1234
  var ConnectedAccountStatuses = {
1163
1235
  ACTIVE: "ACTIVE",
1164
1236
  INACTIVE: "INACTIVE",
1165
- PENDING: "DELETED",
1237
+ DELETED: "DELETED",
1166
1238
  INITIATED: "INITIATED",
1167
1239
  EXPIRED: "EXPIRED",
1168
1240
  FAILED: "FAILED"
@@ -1170,7 +1242,7 @@ var ConnectedAccountStatuses = {
1170
1242
  var ConnectedAccountStatusSchema = z4.enum([
1171
1243
  ConnectedAccountStatuses.ACTIVE,
1172
1244
  ConnectedAccountStatuses.INACTIVE,
1173
- ConnectedAccountStatuses.PENDING,
1245
+ ConnectedAccountStatuses.DELETED,
1174
1246
  ConnectedAccountStatuses.INITIATED,
1175
1247
  ConnectedAccountStatuses.EXPIRED,
1176
1248
  ConnectedAccountStatuses.FAILED
@@ -1262,7 +1334,8 @@ import { ZodError as ZodError2 } from "zod";
1262
1334
 
1263
1335
  // src/errors/ConnectionRequestError.ts
1264
1336
  var ConnectionRequestErrorCodes = {
1265
- CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT"
1337
+ CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
1338
+ CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
1266
1339
  };
1267
1340
  var ConnectionRequestTimeoutError = class extends ComposioError {
1268
1341
  constructor(message = "Connection request timed out", meta = {}) {
@@ -1270,6 +1343,16 @@ var ConnectionRequestTimeoutError = class extends ComposioError {
1270
1343
  code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
1271
1344
  meta
1272
1345
  });
1346
+ this.name = "ConnectionRequestTimeoutError";
1347
+ }
1348
+ };
1349
+ var ConnectionRequestFailedError = class extends ComposioError {
1350
+ constructor(message = "Connection request failed", meta = {}) {
1351
+ super(message, {
1352
+ code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED,
1353
+ meta
1354
+ });
1355
+ this.name = "ConnectionRequestFailedError";
1273
1356
  }
1274
1357
  };
1275
1358
 
@@ -1326,30 +1409,40 @@ var ConnectionRequest = class {
1326
1409
  async waitForConnection(timeout = 6e4) {
1327
1410
  if (this.connectedAccountStatus === ConnectedAccountStatuses.ACTIVE) {
1328
1411
  const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
1329
- return Promise.resolve(this.transformResponse(response));
1330
- }
1331
- return new Promise((resolve, reject) => {
1332
- const interval = setInterval(async () => {
1333
- try {
1334
- const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
1335
- if (response.status === ConnectedAccountStatuses.ACTIVE) {
1336
- clearInterval(interval);
1337
- resolve(this.transformResponse(response));
1338
- }
1339
- } catch (error) {
1340
- clearInterval(interval);
1341
- reject(error);
1412
+ return this.transformResponse(response);
1413
+ }
1414
+ const terminalErrorStates = [
1415
+ ConnectedAccountStatuses.FAILED,
1416
+ ConnectedAccountStatuses.EXPIRED,
1417
+ ConnectedAccountStatuses.DELETED
1418
+ ];
1419
+ const start = Date.now();
1420
+ const pollInterval = 1e3;
1421
+ while (Date.now() - start < timeout) {
1422
+ try {
1423
+ const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
1424
+ if (response.status === ConnectedAccountStatuses.ACTIVE) {
1425
+ return this.transformResponse(response);
1342
1426
  }
1343
- }, 1e3);
1344
- setTimeout(() => {
1345
- clearInterval(interval);
1346
- reject(
1347
- new ConnectionRequestTimeoutError(
1348
- `Connection request timed out for ${this.connectedAccountId}`
1349
- )
1350
- );
1351
- }, timeout);
1352
- });
1427
+ if (terminalErrorStates.includes(response.status)) {
1428
+ throw new ConnectionRequestFailedError(
1429
+ `Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ""}`,
1430
+ {
1431
+ userId: response.user_id,
1432
+ connectedAccountId: this.connectedAccountId,
1433
+ status: response.status,
1434
+ statusReason: response.status_reason
1435
+ }
1436
+ );
1437
+ }
1438
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
1439
+ } catch (error) {
1440
+ throw error;
1441
+ }
1442
+ }
1443
+ throw new ConnectionRequestTimeoutError(
1444
+ `Connection request timed out for ${this.connectedAccountId}`
1445
+ );
1353
1446
  }
1354
1447
  };
1355
1448
 
@@ -1579,20 +1672,21 @@ var Toolkits = class {
1579
1672
  * @param {string} authConfigId - The id of the auth config to use
1580
1673
  * @returns {Promise<ConnectionRequest>} The connection request object
1581
1674
  */
1582
- async authorize(userId, toolkitSlug, authConfigId) {
1675
+ async authorize(userId, toolkitSlug) {
1583
1676
  const toolkit = await this.getToolkitBySlug(toolkitSlug);
1584
1677
  const composioAuthConfig = new AuthConfigs(this.client);
1585
1678
  let authConfigIdToUse;
1586
- if (authConfigId) {
1587
- const authConfig = await composioAuthConfig.get(authConfigId);
1588
- authConfigIdToUse = authConfig.id;
1589
- } else {
1679
+ const authConfig = await composioAuthConfig.list({
1680
+ toolkitSlug
1681
+ });
1682
+ authConfigIdToUse = authConfig.items[0]?.id;
1683
+ if (!authConfigIdToUse) {
1590
1684
  if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
1591
- const authConfig = await composioAuthConfig.create(toolkitSlug, {
1685
+ const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
1592
1686
  type: "use_composio_managed_auth",
1593
1687
  name: `${toolkit.name} Auth Config`
1594
1688
  });
1595
- authConfigIdToUse = authConfig.id;
1689
+ authConfigIdToUse = authConfig2.id;
1596
1690
  } else {
1597
1691
  throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
1598
1692
  toolkitSlug
@@ -1822,6 +1916,7 @@ var Triggers = class {
1822
1916
  const sessionInfo = await session.getInfo();
1823
1917
  const clientId = sessionInfo.project?.id;
1824
1918
  if (!clientId) throw new Error("Client ID not found");
1919
+ if (!this.client.apiKey) throw new Error("API key not found");
1825
1920
  await PusherUtils.getPusherClient(this.client.baseURL, this.client.apiKey);
1826
1921
  const shouldSendTrigger = (data) => {
1827
1922
  if (Object.keys(filters).length === 0) return true;
@@ -2138,7 +2233,7 @@ var BaseToolset = class {
2138
2233
  /**
2139
2234
  * @internal
2140
2235
  * Set the function to execute a tool.
2141
- * This is set automatically injected by the core SDK.
2236
+ * This is set automatically and injected by the core SDK.
2142
2237
  */
2143
2238
  _setExecuteToolFn(executeToolFn) {
2144
2239
  this._globalExecuteToolFn = executeToolFn;
@@ -2153,6 +2248,9 @@ var BaseToolset = class {
2153
2248
  * @returns {Promise<string>} The result of the tool execution.
2154
2249
  */
2155
2250
  executeTool(toolSlug, body, modifers) {
2251
+ if (!this._globalExecuteToolFn) {
2252
+ throw new ComposioGlobalExecuteToolFnNotSetError("executeToolFn is not set");
2253
+ }
2156
2254
  return this._globalExecuteToolFn(toolSlug, body, modifers);
2157
2255
  }
2158
2256
  };
@@ -2329,7 +2427,7 @@ var OpenAIToolset = class extends BaseNonAgenticToolset {
2329
2427
  };
2330
2428
 
2331
2429
  // package.json
2332
- var version = "0.1.9-alpha.0";
2430
+ var version = "0.1.10-alpha.0";
2333
2431
 
2334
2432
  // src/utils/uuid.ts
2335
2433
  import { v4 as uuidv4 } from "uuid";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composio/core",
3
- "version": "0.1.9-alpha.0",
3
+ "version": "0.1.10-alpha.0",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "build": "tsup",
25
- "test": "echo \"Error: no test specified\" && exit 1"
25
+ "test": "vitest"
26
26
  },
27
27
  "keywords": [],
28
28
  "author": "",
@@ -31,15 +31,16 @@
31
31
  "devDependencies": {
32
32
  "tsup": "^8.4.0",
33
33
  "tsx": "^4.19.3",
34
- "typescript": "^5.8.3"
34
+ "typescript": "^5.8.3",
35
+ "vitest": "^3.1.3"
35
36
  },
36
37
  "dependencies": {
37
- "@composio/client": "0.1.0-alpha.9",
38
+ "@composio/client": "^0.1.0-alpha.10",
38
39
  "openai": "^4.94.0",
39
40
  "pusher-js": "^8.4.0",
40
41
  "uuid": "^11.1.0",
41
42
  "zod": "^3.24.2",
42
43
  "zod-to-json-schema": "^3.24.5"
43
44
  },
44
- "gitHead": "f1d3e98644b917030fe9b4cc43db84d21934894a"
45
+ "gitHead": "8f757632d77f40800f7ebc0dddec87ee14d52720"
45
46
  }