@composio/core 0.1.12-alpha.7 → 0.1.12-alpha.9

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
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/composio.ts
9
- import ComposioClient from "@composio/client";
9
+ import ComposioClient2 from "@composio/client";
10
10
 
11
11
  // src/types/tool.types.ts
12
12
  import { z } from "zod";
@@ -379,8 +379,8 @@ var CustomTools = class {
379
379
  });
380
380
  }
381
381
  const connectedAccounts = await this.client.connectedAccounts.list({
382
- toolkit_slug: toolkitSlug,
383
- user_id: metadata.userId
382
+ toolkit_slugs: [toolkitSlug],
383
+ user_ids: [metadata.userId]
384
384
  });
385
385
  if (!connectedAccounts.items.length) {
386
386
  throw new ComposioConnectedAccountNotFoundError(
@@ -447,7 +447,7 @@ var ValidationErrorCodes = {
447
447
  };
448
448
  var ValidationError = class extends ComposioError {
449
449
  zodError;
450
- constructor(zodError, message = "Input validation failed") {
450
+ constructor(zodError, message = "Input validation failed", meta) {
451
451
  let zodErrorInstance;
452
452
  if (!(zodError instanceof ZodError)) {
453
453
  zodErrorInstance = new ZodError([
@@ -460,20 +460,16 @@ var ValidationError = class extends ComposioError {
460
460
  } else {
461
461
  zodErrorInstance = zodError;
462
462
  }
463
+ const issues = zodErrorInstance.issues.map(
464
+ (issue) => `[${issue.code}] ${issue.path.join(".")} - ${issue.message}`
465
+ );
463
466
  super(message, {
464
467
  code: ValidationErrorCodes.VALIDATION_ERROR,
465
- meta: {
466
- issues: JSON.stringify(
467
- zodErrorInstance.issues.map((issue) => ({
468
- path: issue.path.join("."),
469
- message: issue.message,
470
- code: issue.code
471
- }))
472
- )
473
- },
474
- cause: zodErrorInstance
468
+ meta,
469
+ cause: issues.join("\n")
475
470
  });
476
471
  this.zodError = zodErrorInstance;
472
+ this.name = "ValidationError";
477
473
  }
478
474
  };
479
475
 
@@ -498,9 +494,15 @@ var Tools = class {
498
494
  this.getRawComposioTools = this.getRawComposioTools.bind(this);
499
495
  }
500
496
  /**
501
- * Transform the tool cases
502
- * @param {ToolRetrieveResponse | ComposioToolListResponse['items'][0]} tool - The tool to transform
503
- * @returns {Tool} The transformed tool
497
+ * Transforms tool data from snake_case API format to camelCase for internal SDK use.
498
+ *
499
+ * This method standardizes the property naming convention for tools retrieved from the Composio API,
500
+ * making them more consistent with JavaScript/TypeScript conventions.
501
+ *
502
+ * @param {ToolRetrieveResponse | ComposioToolListResponse['items'][0]} tool - The tool object to transform
503
+ * @returns {Tool} The transformed tool with camelCase properties
504
+ *
505
+ * @private
504
506
  */
505
507
  transformToolCases(tool) {
506
508
  return ToolSchema.parse({
@@ -510,9 +512,15 @@ var Tools = class {
510
512
  });
511
513
  }
512
514
  /**
513
- * Transform the tool execute response to camelcase
514
- * @param {ComposioToolExecuteResponse} response - The response to transform
515
- * @returns {ToolExecuteResponse} The transformed response
515
+ * Transforms tool execution response from snake_case API format to camelCase.
516
+ *
517
+ * This method converts the response received from the Composio API to a standardized format
518
+ * with consistent property naming that follows JavaScript/TypeScript conventions.
519
+ *
520
+ * @param {ComposioToolExecuteResponse} response - The raw API response to transform
521
+ * @returns {ToolExecuteResponse} The transformed response with camelCase properties
522
+ *
523
+ * @private
516
524
  */
517
525
  transformToolExecuteResponse(response) {
518
526
  return ToolExecuteResponseSchema.parse({
@@ -597,9 +605,35 @@ var Tools = class {
597
605
  return null;
598
606
  }
599
607
  /**
600
- * Lists all tools available in the Composio SDK as well as custom tools.
601
- * This method fetches the tools from the Composio API in the raw format.
602
- * @returns {ToolList} List of tools
608
+ * Lists all tools available in the Composio SDK including custom tools.
609
+ *
610
+ * This method fetches tools from the Composio API in raw format and combines them with
611
+ * any registered custom tools. The response can be filtered and modified as needed.
612
+ *
613
+ * @param {string} userId - The user ID for whom to fetch the tools
614
+ * @param {ToolListParams} [query={}] - Optional query parameters to filter the tools
615
+ * @param {TransformToolSchemaModifier} [modifier] - Optional function to transform tool schemas
616
+ * @returns {Promise<ToolList>} List of tools matching the query criteria
617
+ *
618
+ * @example
619
+ * ```typescript
620
+ * // Get all tools
621
+ * const tools = await composio.tools.getRawComposioTools('default');
622
+ *
623
+ * // Get tools with filters
624
+ * const githubTools = await composio.tools.getRawComposioTools('default', {
625
+ * toolkits: ['github'],
626
+ * important: true
627
+ * });
628
+ *
629
+ * // Get tools with schema transformation
630
+ * const tools = await composio.tools.getRawComposioTools('default', {},
631
+ * (toolSlug, toolkitSlug, tool) => {
632
+ * // Add custom properties to tool schema
633
+ * return {...tool, customProperty: 'value'};
634
+ * }
635
+ * );
636
+ * ```
603
637
  */
604
638
  async getRawComposioTools(userId, query = {}, modifier) {
605
639
  const queryParams = ToolListParamsSchema.safeParse(query);
@@ -666,11 +700,13 @@ var Tools = class {
666
700
  return modifiedToool;
667
701
  }
668
702
  /**
669
- * Get a tool by its slug
670
- * @param userId - The user id
671
- * @param arg2 - The slug of the tool or the filters for the tools
672
- * @param options - The options for the tools
673
- * @returns The tool or the tools
703
+ * Get a tool or list of tools based on the provided arguments.
704
+ * This is an implementation method that handles both overloads.
705
+ *
706
+ * @param {string} userId - The user id to get the tool(s) for
707
+ * @param {ToolListParams | string} arg2 - Either a slug string or filters object
708
+ * @param {ProviderOptions<TProvider>} [options] - Optional provider options
709
+ * @returns {Promise<TToolCollection>} The tool collection
674
710
  */
675
711
  async get(userId, arg2, options) {
676
712
  const executeToolFn = this.createExecuteToolFn(userId, options);
@@ -780,13 +816,43 @@ var Tools = class {
780
816
  return result;
781
817
  }
782
818
  /**
783
- * Exectes a given tool with the provided parameters.
819
+ * Executes a given tool with the provided parameters.
784
820
  *
785
- * This method calls the Composio API to execute the tool and returns the response.
821
+ * This method calls the Composio API or a custom tool handler to execute the tool and returns the response.
822
+ * It automatically determines whether to use a custom tool or a Composio API tool based on the slug.
786
823
  *
787
- * @param {string} slug - The ID of the tool to be executed
824
+ * @param {string} slug - The slug/ID of the tool to be executed
788
825
  * @param {ToolExecuteParams} body - The parameters to be passed to the tool
826
+ * @param {ExecuteToolModifiers} [modifiers] - Optional modifiers to transform the request or response
789
827
  * @returns {Promise<ToolExecuteResponse>} - The response from the tool execution
828
+ *
829
+ * @throws {ComposioCustomToolsNotInitializedError} If the CustomTools instance is not initialized
830
+ * @throws {ComposioToolNotFoundError} If the tool with the given slug is not found
831
+ * @throws {ComposioToolExecutionError} If there is an error during tool execution
832
+ *
833
+ * @example
834
+ * ```typescript
835
+ * // Execute a Composio API tool
836
+ * const result = await composio.tools.execute('HACKERNEWS_GET_USER', {
837
+ * userId: 'default',
838
+ * arguments: { userId: 'pg' }
839
+ * });
840
+ *
841
+ * // Execute with modifiers
842
+ * const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
843
+ * userId: 'default',
844
+ * arguments: { owner: 'composio', repo: 'sdk' }
845
+ * }, {
846
+ * beforeToolExecute: (toolSlug, toolkitSlug, params) => {
847
+ * // Modify params before execution
848
+ * return params;
849
+ * },
850
+ * afterToolExecute: (toolSlug, toolkitSlug, result) => {
851
+ * // Transform result after execution
852
+ * return result;
853
+ * }
854
+ * });
855
+ * ```
790
856
  */
791
857
  async execute(slug, body, modifiers) {
792
858
  if (!this.customTools) {
@@ -843,9 +909,39 @@ var Tools = class {
843
909
  return this.client.tools.proxy(body);
844
910
  }
845
911
  /**
846
- * Execute a custom tool
847
- * @param body
848
- * @returns
912
+ * Creates a custom tool that can be used within the Composio SDK.
913
+ *
914
+ * Custom tools allow you to extend the functionality of Composio with your own implementations
915
+ * while keeping a consistent interface for both built-in and custom tools.
916
+ *
917
+ * @param {CustomToolOptions} body - The configuration for the custom tool
918
+ * @returns {Promise<Tool>} The created custom tool
919
+ *
920
+ * @example
921
+ * ```typescript
922
+ * const customTool = await composio.tools.createCustomTool({
923
+ * name: 'My Custom Tool',
924
+ * description: 'A custom tool that does something specific',
925
+ * slug: 'MY_CUSTOM_TOOL',
926
+ * inputParameters: {
927
+ * param1: {
928
+ * type: 'string',
929
+ * description: 'First parameter',
930
+ * required: true
931
+ * }
932
+ * },
933
+ * outputParameters: {
934
+ * result: {
935
+ * type: 'string',
936
+ * description: 'The result of the operation'
937
+ * }
938
+ * },
939
+ * handler: async (params, context) => {
940
+ * // Custom logic here
941
+ * return { data: { result: 'Success!' } };
942
+ * }
943
+ * });
944
+ * ```
849
945
  */
850
946
  async createCustomTool(body) {
851
947
  return this.customTools.createTool(body);
@@ -1003,7 +1099,7 @@ var AuthConfigRetrieveResponseSchema = z3.object({
1003
1099
  status: z3.enum(["ENABLED", "DISABLED"]),
1004
1100
  uuid: z3.string(),
1005
1101
  authScheme: AuthSchemeEnum.optional(),
1006
- credentials: z3.record(z3.string(), z3.union([z3.string(), z3.number(), z3.boolean()])),
1102
+ credentials: z3.record(z3.string(), z3.unknown()).optional(),
1007
1103
  expectedInputFields: z3.array(z3.unknown()).optional(),
1008
1104
  isComposioManaged: z3.boolean().optional(),
1009
1105
  createdBy: z3.string().optional(),
@@ -1050,6 +1146,18 @@ var AuthConfigs = class {
1050
1146
  getClient() {
1051
1147
  return this.client;
1052
1148
  }
1149
+ /**
1150
+ * Transforms an auth config response from API format to SDK format.
1151
+ *
1152
+ * This method converts property names from snake_case to camelCase and reorganizes
1153
+ * the data structure to match the SDK's standardized format for auth configurations.
1154
+ *
1155
+ * @param {ComposioAuthConfigRetrieveResponse} authConfig - The raw API response to transform
1156
+ * @returns {AuthConfigRetrieveResponse} The transformed auth config data
1157
+ * @throws {ValidationError} If the response fails validation against the expected schema
1158
+ *
1159
+ * @private
1160
+ */
1053
1161
  parseAuthConfigRetrieveResponse(authConfig) {
1054
1162
  const result = AuthConfigRetrieveResponseSchema.safeParse({
1055
1163
  id: authConfig.id,
@@ -1075,10 +1183,30 @@ var AuthConfigs = class {
1075
1183
  return result.data;
1076
1184
  }
1077
1185
  /**
1078
- * List all auth configs
1079
- * @param {AuthConfigListParams} query - Query parameters for filtering auth configs
1080
- * @param {RequestOptions} options - Request options
1081
- * @returns {Promise<AuthConfigListResponse>} List of auth configs
1186
+ * Lists authentication configurations based on provided filter criteria.
1187
+ *
1188
+ * This method retrieves auth configs from the Composio API, transforms them to the SDK format,
1189
+ * and supports filtering by various parameters.
1190
+ *
1191
+ * @param {AuthConfigListParams} [query] - Optional query parameters for filtering auth configs
1192
+ * @returns {Promise<AuthConfigListResponse>} A paginated list of auth configurations
1193
+ * @throws {ValidationError} If the query parameters or response fail validation
1194
+ *
1195
+ * @example
1196
+ * ```typescript
1197
+ * // List all auth configs
1198
+ * const allConfigs = await composio.authConfigs.list();
1199
+ *
1200
+ * // List auth configs for a specific toolkit
1201
+ * const githubConfigs = await composio.authConfigs.list({
1202
+ * toolkitSlug: 'github'
1203
+ * });
1204
+ *
1205
+ * // List Composio-managed auth configs
1206
+ * const managedConfigs = await composio.authConfigs.list({
1207
+ * isComposioManaged: true
1208
+ * });
1209
+ * ```
1082
1210
  */
1083
1211
  async list(query) {
1084
1212
  const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : void 0;
@@ -1139,21 +1267,57 @@ var AuthConfigs = class {
1139
1267
  return parsedResult.data;
1140
1268
  }
1141
1269
  /**
1142
- * Get an auth config by nanoid
1143
- * @param {string} nanoid - Unique identifier of the auth config
1144
- * @param {RequestOptions} options - Request options
1145
- * @returns {Promise<AuthConfigRetrieveResponse>} Auth config details
1270
+ * Retrieves a specific authentication configuration by its ID.
1271
+ *
1272
+ * This method fetches detailed information about a single auth config
1273
+ * and transforms the response to the SDK's standardized format.
1274
+ *
1275
+ * @param {string} nanoid - The unique identifier of the auth config to retrieve
1276
+ * @returns {Promise<AuthConfigRetrieveResponse>} The auth config details
1277
+ * @throws {Error} If the auth config cannot be found or an API error occurs
1278
+ * @throws {ValidationError} If the response fails validation
1279
+ *
1280
+ * @example
1281
+ * ```typescript
1282
+ * // Get an auth config by ID
1283
+ * const authConfig = await composio.authConfigs.get('auth_abc123');
1284
+ * console.log(authConfig.name); // e.g., 'GitHub Auth'
1285
+ * console.log(authConfig.toolkit.slug); // e.g., 'github'
1286
+ * ```
1146
1287
  */
1147
1288
  async get(nanoid) {
1148
1289
  const result = await this.client.authConfigs.retrieve(nanoid);
1149
1290
  return this.parseAuthConfigRetrieveResponse(result);
1150
1291
  }
1151
1292
  /**
1152
- * Update an auth config
1153
- * @param {string} nanoid - Unique identifier of the auth config to update
1154
- * @param {AuthConfigUpdateParams} data - Data to update
1155
- * @param {RequestOptions} options - Request options
1156
- * @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
1293
+ * Updates an existing authentication configuration.
1294
+ *
1295
+ * This method allows you to modify properties of an auth config such as credentials,
1296
+ * scopes, or tool restrictions. The update type (custom or default) determines which
1297
+ * fields can be updated.
1298
+ *
1299
+ * @param {string} nanoid - The unique identifier of the auth config to update
1300
+ * @param {AuthConfigUpdateParams} data - The data to update, which can be either custom or default type
1301
+ * @returns {Promise<AuthConfigUpdateResponse>} The updated auth config
1302
+ * @throws {ValidationError} If the update parameters are invalid
1303
+ * @throws {Error} If the auth config cannot be found or updated
1304
+ *
1305
+ * @example
1306
+ * ```typescript
1307
+ * // Update a custom auth config with new credentials
1308
+ * const updatedConfig = await composio.authConfigs.update('auth_abc123', {
1309
+ * type: 'custom',
1310
+ * credentials: {
1311
+ * apiKey: 'new-api-key-value'
1312
+ * }
1313
+ * });
1314
+ *
1315
+ * // Update a default auth config with new scopes
1316
+ * const updatedConfig = await composio.authConfigs.update('auth_abc123', {
1317
+ * type: 'default',
1318
+ * scopes: ['read:user', 'repo']
1319
+ * });
1320
+ * ```
1157
1321
  */
1158
1322
  async update(nanoid, data) {
1159
1323
  const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
@@ -1174,38 +1338,85 @@ var AuthConfigs = class {
1174
1338
  );
1175
1339
  }
1176
1340
  /**
1177
- * Delete an auth config
1178
- * @param {string} nanoid - Unique identifier of the auth config to delete
1179
- * @param {RequestOptions} options - Request options
1180
- * @returns {Promise<AuthConfigDeleteResponse>} Response from deletion
1341
+ * Deletes an authentication configuration.
1342
+ *
1343
+ * This method permanently removes an auth config from the Composio platform.
1344
+ * This action cannot be undone and will prevent any connected accounts that use
1345
+ * this auth config from functioning.
1346
+ *
1347
+ * @param {string} nanoid - The unique identifier of the auth config to delete
1348
+ * @returns {Promise<AuthConfigDeleteResponse>} The deletion response
1349
+ * @throws {Error} If the auth config doesn't exist or cannot be deleted
1350
+ *
1351
+ * @example
1352
+ * ```typescript
1353
+ * // Delete an auth config
1354
+ * await composio.authConfigs.delete('auth_abc123');
1355
+ * ```
1181
1356
  */
1182
1357
  async delete(nanoid) {
1183
1358
  return this.client.authConfigs.delete(nanoid);
1184
1359
  }
1185
1360
  /**
1186
- * Update the status of an auth config
1187
- * @param {string} status - The status to update the auth config to
1188
- * @param {string} nanoid - Unique identifier of the auth config
1189
- * @param {RequestOptions} options - Request options
1190
- * @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
1361
+ * Updates the status of an authentication configuration.
1362
+ *
1363
+ * This method allows you to enable or disable an auth config. When disabled,
1364
+ * the auth config cannot be used to create new connected accounts or authenticate
1365
+ * with third-party services.
1366
+ *
1367
+ * @param {string} status - The status to set ('ENABLED' or 'DISABLED')
1368
+ * @param {string} nanoid - The unique identifier of the auth config
1369
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
1370
+ * @throws {Error} If the auth config cannot be found or the status cannot be updated
1371
+ *
1372
+ * @example
1373
+ * ```typescript
1374
+ * // Disable an auth config
1375
+ * await composio.authConfigs.updateStatus('DISABLED', 'auth_abc123');
1376
+ *
1377
+ * // Enable an auth config
1378
+ * await composio.authConfigs.updateStatus('ENABLED', 'auth_abc123');
1379
+ * ```
1191
1380
  */
1192
1381
  async updateStatus(status, nanoid) {
1193
1382
  return this.client.authConfigs.updateStatus(status, { nanoid });
1194
1383
  }
1195
1384
  /**
1196
- * Enable an auth config
1197
- * @param {string} nanoid - Unique identifier of the auth config
1198
- * @param {RequestOptions} options - Request options
1199
- * @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
1385
+ * Enables an authentication configuration.
1386
+ *
1387
+ * This is a convenience method that calls updateStatus with 'ENABLED'.
1388
+ * When enabled, the auth config can be used to create new connected accounts
1389
+ * and authenticate with third-party services.
1390
+ *
1391
+ * @param {string} nanoid - The unique identifier of the auth config to enable
1392
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
1393
+ * @throws {Error} If the auth config cannot be found or enabled
1394
+ *
1395
+ * @example
1396
+ * ```typescript
1397
+ * // Enable an auth config
1398
+ * await composio.authConfigs.enable('auth_abc123');
1399
+ * ```
1200
1400
  */
1201
1401
  async enable(nanoid) {
1202
1402
  return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
1203
1403
  }
1204
1404
  /**
1205
- * Disable an auth config
1206
- * @param {string} nanoid - Unique identifier of the auth config
1207
- * @param {RequestOptions} options - Request options
1208
- * @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
1405
+ * Disables an authentication configuration.
1406
+ *
1407
+ * This is a convenience method that calls updateStatus with 'DISABLED'.
1408
+ * When disabled, the auth config cannot be used to create new connected accounts
1409
+ * or authenticate with third-party services, but existing connections may continue to work.
1410
+ *
1411
+ * @param {string} nanoid - The unique identifier of the auth config to disable
1412
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
1413
+ * @throws {Error} If the auth config cannot be found or disabled
1414
+ *
1415
+ * @example
1416
+ * ```typescript
1417
+ * // Disable an auth config
1418
+ * await composio.authConfigs.disable('auth_abc123');
1419
+ * ```
1209
1420
  */
1210
1421
  async disable(nanoid) {
1211
1422
  return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
@@ -1255,7 +1466,7 @@ var CreateConnectedAccountParamsSchema = z4.object({
1255
1466
  }),
1256
1467
  connection: z4.object({
1257
1468
  data: z4.record(z4.string(), z4.unknown()).optional(),
1258
- redirectUrl: z4.string().optional(),
1469
+ callbackUrl: z4.string().optional(),
1259
1470
  userId: z4.string().optional()
1260
1471
  })
1261
1472
  });
@@ -1265,12 +1476,12 @@ var DefaultCreateConnectedAccountParamsSchema = z4.object({
1265
1476
  }),
1266
1477
  connection: z4.object({
1267
1478
  data: z4.record(z4.string(), z4.unknown()).optional(),
1268
- redirect_uri: z4.string().optional(),
1479
+ callback_url: z4.string().optional(),
1269
1480
  user_id: z4.string().optional()
1270
1481
  })
1271
1482
  });
1272
1483
  var CreateConnectedAccountOptionsSchema = z4.object({
1273
- redirectUrl: z4.string().optional(),
1484
+ callbackUrl: z4.string().optional(),
1274
1485
  data: z4.record(z4.string(), z4.unknown()).optional()
1275
1486
  });
1276
1487
  var CreateConnectedAccountResponseSchema = z4.object({
@@ -1319,7 +1530,7 @@ var ConnectedAccountRetrieveResponseSchema = z4.object({
1319
1530
  authConfig: ConnectedAccountAuthConfigSchema,
1320
1531
  userId: z4.string(),
1321
1532
  data: z4.record(z4.string(), z4.unknown()),
1322
- params: z4.record(z4.string(), z4.unknown()),
1533
+ params: z4.record(z4.string(), z4.unknown()).optional(),
1323
1534
  status: ConnectedAccountStatusSchema,
1324
1535
  statusReason: z4.string().nullable(),
1325
1536
  toolkit: z4.object({
@@ -1330,8 +1541,24 @@ var ConnectedAccountRetrieveResponseSchema = z4.object({
1330
1541
  createdAt: z4.string(),
1331
1542
  updatedAt: z4.string()
1332
1543
  });
1544
+ var ConnectedAccountListParamsSchema = z4.object({
1545
+ authConfigIds: z4.array(z4.string()).nullable().optional().describe("The auth config ids of the connected accounts"),
1546
+ cursor: z4.number().nullable().optional().describe("The cursor to paginate through the connected accounts"),
1547
+ labels: z4.array(z4.string()).nullable().optional().describe("The labels of the connected accounts"),
1548
+ limit: z4.number().nullable().optional().describe("The limit of the connected accounts to return"),
1549
+ orderBy: z4.enum(["created_at", "updated_at"]).optional().describe("The order by of the connected accounts"),
1550
+ statuses: z4.array(ConnectedAccountStatusSchema).nullable().optional().describe("The statuses of the connected accounts"),
1551
+ toolkitSlugs: z4.array(z4.string()).nullable().optional().describe("The toolkit slugs of the connected accounts"),
1552
+ userIds: z4.array(z4.string()).nullable().optional().describe("The user ids of the connected accounts")
1553
+ });
1554
+ var ConnectedAccountListResponseSchema = z4.object({
1555
+ items: z4.array(ConnectedAccountRetrieveResponseSchema).describe("The list of connected accounts"),
1556
+ nextCursor: z4.string().nullable().describe("The next cursor to paginate through the connected accounts"),
1557
+ totalPages: z4.number().describe("The total number of pages of connected accounts")
1558
+ });
1333
1559
 
1334
1560
  // src/models/ConnectionRequest.ts
1561
+ import ComposioClient from "@composio/client";
1335
1562
  import { ZodError as ZodError2 } from "zod";
1336
1563
 
1337
1564
  // src/errors/ConnectionRequestError.ts
@@ -1364,16 +1591,23 @@ var ConnectionRequest = class {
1364
1591
  id;
1365
1592
  status;
1366
1593
  redirectUrl;
1367
- constructor(client, connectedAccountId, connectedAccountStatus, redirectUrl) {
1594
+ constructor(client, connectedAccountId, status, redirectUrl) {
1368
1595
  this.client = client;
1369
1596
  this.id = connectedAccountId;
1370
- this.status = connectedAccountStatus;
1597
+ this.status = status || ConnectedAccountStatuses.INITIATED;
1371
1598
  this.redirectUrl = redirectUrl;
1372
1599
  }
1373
1600
  /**
1374
- * Transform the response from the Composio API to the SDK format
1375
- * @param response
1376
- * @returns
1601
+ * Transforms the raw connected account response from the Composio API to the SDK format.
1602
+ *
1603
+ * This method converts property names from snake_case to camelCase and reorganizes
1604
+ * the data structure to match the SDK's standardized format.
1605
+ *
1606
+ * @param {OriginalConnectedAccountResponse} response - The raw API response to transform
1607
+ * @returns {Promise<ConnectedAccountRetrieveResponse>} The transformed response
1608
+ * @throws {ZodError} If the response fails validation against the expected schema
1609
+ *
1610
+ * @private
1377
1611
  */
1378
1612
  async transformResponse(response) {
1379
1613
  try {
@@ -1403,15 +1637,49 @@ var ConnectionRequest = class {
1403
1637
  }
1404
1638
  }
1405
1639
  /**
1406
- * Wait for the connection to be established.
1407
- * The function will poll the Composio API every second until the connection is established or the timeout is reached.
1408
- * @param {number} timeout - The time in milliseconds to wait for the connection to be established. Default is 30 seconds.
1409
- * @returns
1640
+ * Waits for the connection request to complete and become active.
1641
+ *
1642
+ * This method continuously polls the Composio API to check the status of the connection request
1643
+ * until it either becomes active, enters a terminal error state, or times out.
1644
+ *
1645
+ * @param {number} [timeout=60000] - Maximum time to wait in milliseconds before timing out (default: 60 seconds)
1646
+ * @returns {Promise<ConnectedAccountRetrieveResponse>} The final connected account response when successful
1647
+ * @throws {ComposioConnectedAccountNotFoundError} If the connected account cannot be found
1648
+ * @throws {ConnectionRequestFailedError} If the connection enters a failed, expired, or deleted state
1649
+ * @throws {ConnectionRequestTimeoutError} If the connection request does not complete within the timeout period
1650
+ *
1651
+ * @example
1652
+ * ```typescript
1653
+ * // Wait for connection with default timeout (60 seconds)
1654
+ * try {
1655
+ * const connection = await connectionRequest.waitForConnection();
1656
+ * console.log('Connection established:', connection.id);
1657
+ * } catch (error) {
1658
+ * console.error('Connection failed:', error.message);
1659
+ * }
1660
+ *
1661
+ * // Wait for connection with custom timeout (2 minutes)
1662
+ * const connection = await connectionRequest.waitForConnection(120000);
1663
+ * ```
1410
1664
  */
1411
1665
  async waitForConnection(timeout = 6e4) {
1412
- if (this.status === ConnectedAccountStatuses.ACTIVE) {
1666
+ try {
1413
1667
  const response = await this.client.connectedAccounts.retrieve(this.id);
1414
- return this.transformResponse(response);
1668
+ if (response.status === ConnectedAccountStatuses.ACTIVE) {
1669
+ this.status = ConnectedAccountStatuses.ACTIVE;
1670
+ return this.transformResponse(response);
1671
+ }
1672
+ } catch (error) {
1673
+ if (error instanceof ComposioClient.NotFoundError) {
1674
+ throw new ComposioConnectedAccountNotFoundError(
1675
+ `Connected account with id ${this.id} not found`,
1676
+ {
1677
+ connectedAccountId: this.id
1678
+ }
1679
+ );
1680
+ } else {
1681
+ throw error;
1682
+ }
1415
1683
  }
1416
1684
  const terminalErrorStates = [
1417
1685
  ConnectedAccountStatuses.FAILED,
@@ -1423,6 +1691,7 @@ var ConnectionRequest = class {
1423
1691
  while (Date.now() - start < timeout) {
1424
1692
  try {
1425
1693
  const response = await this.client.connectedAccounts.retrieve(this.id);
1694
+ this.status = response.status;
1426
1695
  if (response.status === ConnectedAccountStatuses.ACTIVE) {
1427
1696
  return this.transformResponse(response);
1428
1697
  }
@@ -1445,17 +1714,6 @@ var ConnectionRequest = class {
1445
1714
  throw new ConnectionRequestTimeoutError(`Connection request timed out for ${this.id}`);
1446
1715
  }
1447
1716
  };
1448
- var connectionRequest = (client) => {
1449
- return {
1450
- waitForConnection: async (connectedAccountId, timeout = 6e4) => {
1451
- return new ConnectionRequest(
1452
- client,
1453
- connectedAccountId,
1454
- ConnectedAccountStatuses.INITIATED
1455
- ).waitForConnection(timeout);
1456
- }
1457
- };
1458
- };
1459
1717
 
1460
1718
  // src/models/ConnectedAccounts.ts
1461
1719
  var ConnectedAccounts = class {
@@ -1463,14 +1721,95 @@ var ConnectedAccounts = class {
1463
1721
  constructor(client) {
1464
1722
  this.client = client;
1465
1723
  }
1724
+ transformConnectedAccountRetrieveResponse(response) {
1725
+ const result = ConnectedAccountRetrieveResponseSchema.safeParse({
1726
+ ...response,
1727
+ userId: response.user_id,
1728
+ // Add the missing userId property
1729
+ authConfig: {
1730
+ ...response.auth_config,
1731
+ authScheme: response.auth_config.auth_scheme,
1732
+ isComposioManaged: response.auth_config.is_composio_managed,
1733
+ isDisabled: response.auth_config.is_disabled
1734
+ },
1735
+ statusReason: response.status_reason,
1736
+ isDisabled: response.is_disabled,
1737
+ createdAt: response.created_at,
1738
+ updatedAt: response.updated_at,
1739
+ testRequestEndpoint: response.test_request_endpoint
1740
+ });
1741
+ if (!result.success) {
1742
+ throw new ValidationError(result.error);
1743
+ }
1744
+ return result.data;
1745
+ }
1466
1746
  /**
1467
- * List all connected accounts
1468
- * @param {ConnectedAccountListParams} query - Query parameters for filtering connected accounts
1469
- * @param {RequestOptions} options - Request options
1470
- * @returns {Promise<ConnectedAccountListResponse>} List of connected accounts
1747
+ * Lists all connected accounts based on provided filter criteria.
1748
+ *
1749
+ * This method retrieves connected accounts from the Composio API with optional filtering.
1750
+ *
1751
+ * @param {ConnectedAccountListParams} [query] - Optional query parameters for filtering connected accounts
1752
+ * @returns {Promise<ConnectedAccountListResponse>} A paginated list of connected accounts
1753
+ * @throws {ValidationError} If the query fails validation against the expected schema
1754
+ * @example
1755
+ * ```typescript
1756
+ * // List all connected accounts
1757
+ * const allAccounts = await composio.connectedAccounts.list();
1758
+ *
1759
+ * // List accounts for a specific user
1760
+ * const userAccounts = await composio.connectedAccounts.list({
1761
+ * userIds: ['user123']
1762
+ * });
1763
+ *
1764
+ * // List accounts for a specific toolkit
1765
+ * const githubAccounts = await composio.connectedAccounts.list({
1766
+ * toolkitSlugs: ['github']
1767
+ * });
1768
+ * ```
1471
1769
  */
1472
1770
  async list(query) {
1473
- return this.client.connectedAccounts.list(query);
1771
+ let rawQuery = void 0;
1772
+ if (query) {
1773
+ const parsedQuery = ConnectedAccountListParamsSchema.safeParse(query);
1774
+ if (!parsedQuery.success) {
1775
+ throw new ValidationError(parsedQuery.error);
1776
+ }
1777
+ rawQuery = {
1778
+ auth_config_ids: parsedQuery.data.authConfigIds,
1779
+ cursor: parsedQuery.data.cursor,
1780
+ labels: parsedQuery.data.labels,
1781
+ limit: parsedQuery.data.limit,
1782
+ order_by: parsedQuery.data.orderBy,
1783
+ statuses: parsedQuery.data.statuses,
1784
+ toolkit_slugs: parsedQuery.data.toolkitSlugs,
1785
+ user_ids: parsedQuery.data.userIds
1786
+ };
1787
+ }
1788
+ const result = await this.client.connectedAccounts.list(rawQuery);
1789
+ const parsedResponse = ConnectedAccountListResponseSchema.safeParse({
1790
+ items: result.items.map(this.transformConnectedAccountRetrieveResponse),
1791
+ nextCursor: result.next_cursor,
1792
+ totalPages: result.total_pages
1793
+ });
1794
+ if (!parsedResponse.success) {
1795
+ throw new ValidationError(parsedResponse.error);
1796
+ }
1797
+ return parsedResponse.data;
1798
+ }
1799
+ /**
1800
+ * Transforms connected account data from API format to SDK format.
1801
+ *
1802
+ * This method converts property names from snake_case to camelCase and reorganizes
1803
+ * the data structure to match the SDK's standardized format for connected accounts.
1804
+ *
1805
+ * @param {ConnectedAccountRetrieveResponseRaw} response - The raw API response to transform
1806
+ * @returns {ConnectedAccountRetrieveResponse} The transformed connected account data
1807
+ * @throws {ValidationError} If the response fails validation against the expected schema
1808
+ *
1809
+ * @private
1810
+ */
1811
+ transformConnectedAccountResponse(response) {
1812
+ return this.transformConnectedAccountRetrieveResponse(response);
1474
1813
  }
1475
1814
  /**
1476
1815
  * Compound function to create a new connected account.
@@ -1497,75 +1836,94 @@ var ConnectedAccounts = class {
1497
1836
  },
1498
1837
  connection: {
1499
1838
  data: options?.data,
1500
- redirect_uri: options?.redirectUrl,
1839
+ callback_url: options?.callbackUrl,
1501
1840
  user_id: userId
1502
1841
  }
1503
1842
  });
1504
- return new ConnectionRequest(this.client, response.id, response.status, response.redirect_uri);
1843
+ return new ConnectionRequest(this.client, response.id, response.status, response.redirect_url);
1505
1844
  }
1845
+ /**
1846
+ * Waits for a connection request to complete and become active.
1847
+ *
1848
+ * This method continuously polls the Composio API to check the status of a connection
1849
+ * until it either becomes active, enters a terminal error state, or times out.
1850
+ *
1851
+ * @param {string} connectedAccountId - The ID of the connected account to wait for
1852
+ * @param {number} [timeout=60000] - Maximum time to wait in milliseconds (default: 60 seconds)
1853
+ * @returns {Promise<ConnectedAccountRetrieveResponse>} The finalized connected account data
1854
+ * @throws {ComposioConnectedAccountNotFoundError} If the connected account cannot be found
1855
+ * @throws {ConnectionRequestFailedError} If the connection enters a failed, expired, or deleted state
1856
+ * @throws {ConnectionRequestTimeoutError} If the connection does not complete within the timeout period
1857
+ *
1858
+ * @example
1859
+ * ```typescript
1860
+ * // Wait for a connection to complete with default timeout
1861
+ * const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc');
1862
+ *
1863
+ * // Wait with a custom timeout of 2 minutes
1864
+ * const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc', 120000);
1865
+ * ```
1866
+ */
1506
1867
  async waitForConnection(connectedAccountId, timeout = 6e4) {
1507
- let connectedAccount;
1508
- try {
1509
- connectedAccount = await this.get(connectedAccountId);
1510
- } catch (error) {
1511
- logger_default.error(error);
1512
- throw new ComposioConnectedAccountNotFoundError(
1513
- `Unable to retrieve connected account with Id: ${connectedAccountId}`,
1514
- {
1515
- connectedAccountId
1516
- }
1517
- );
1518
- }
1519
- const connectionRequest2 = new ConnectionRequest(
1520
- this.client,
1521
- connectedAccountId,
1522
- connectedAccount.status
1523
- );
1524
- return connectionRequest2.waitForConnection(timeout);
1868
+ const connectionRequest = new ConnectionRequest(this.client, connectedAccountId);
1869
+ return connectionRequest.waitForConnection(timeout);
1525
1870
  }
1526
1871
  /**
1527
- * Get a connected account by nanoid
1528
- * @param {string} nanoid - Unique identifier of the connected account
1529
- * @param {RequestOptions} options - Request options
1530
- * @returns {Promise<ConnectedAccountRetrieveResponse>} Connected account details
1872
+ * Retrieves a specific connected account by its ID.
1873
+ *
1874
+ * This method fetches detailed information about a single connected account
1875
+ * and transforms the response to the SDK's standardized format.
1876
+ *
1877
+ * @param {string} nanoid - The unique identifier of the connected account
1878
+ * @returns {Promise<ConnectedAccountRetrieveResponse>} The connected account details
1879
+ * @throws {Error} If the connected account cannot be found or an API error occurs
1880
+ *
1881
+ * @example
1882
+ * ```typescript
1883
+ * // Get a connected account by ID
1884
+ * const account = await composio.connectedAccounts.get('conn_abc123');
1885
+ * console.log(account.status); // e.g., 'ACTIVE'
1886
+ * console.log(account.toolkit.slug); // e.g., 'github'
1887
+ * ```
1531
1888
  */
1532
1889
  async get(nanoid) {
1533
1890
  const response = await this.client.connectedAccounts.retrieve(nanoid);
1534
- const parsedResult = ConnectedAccountRetrieveResponseSchema.safeParse({
1535
- ...response,
1536
- userId: response.user_id,
1537
- // Add the missing userId property
1538
- authConfig: {
1539
- ...response.auth_config,
1540
- authScheme: response.auth_config.auth_scheme,
1541
- isComposioManaged: response.auth_config.is_composio_managed,
1542
- isDisabled: response.auth_config.is_disabled
1543
- },
1544
- statusReason: response.status_reason,
1545
- isDisabled: response.is_disabled,
1546
- createdAt: response.created_at,
1547
- updatedAt: response.updated_at,
1548
- testRequestEndpoint: response.test_request_endpoint
1549
- });
1550
- if (parsedResult.error) {
1551
- throw new ValidationError(parsedResult.error);
1552
- }
1553
- return parsedResult.data;
1891
+ return this.transformConnectedAccountResponse(response);
1554
1892
  }
1555
1893
  /**
1556
- * Delete a connected account
1557
- * @param {string} nanoid - Unique identifier of the connected account to delete
1558
- * @param {RequestOptions} options - Request options
1559
- * @returns {Promise<ConnectedAccountDeleteResponse>} Response from deletion
1894
+ * Deletes a connected account.
1895
+ *
1896
+ * This method permanently removes a connected account from the Composio platform.
1897
+ * This action cannot be undone and will revoke any access tokens associated with the account.
1898
+ *
1899
+ * @param {string} nanoid - The unique identifier of the connected account to delete
1900
+ * @returns {Promise<ConnectedAccountDeleteResponse>} The deletion response
1901
+ * @throws {Error} If the account doesn't exist or cannot be deleted
1902
+ *
1903
+ * @example
1904
+ * ```typescript
1905
+ * // Delete a connected account
1906
+ * await composio.connectedAccounts.delete('conn_abc123');
1907
+ * ```
1560
1908
  */
1561
1909
  async delete(nanoid) {
1562
1910
  return this.client.connectedAccounts.delete(nanoid);
1563
1911
  }
1564
1912
  /**
1565
- * Refresh a connected account's credentials
1566
- * @param {string} nanoid - Unique identifier of the connected account to refresh
1567
- * @param {RequestOptions} options - Request options
1568
- * @returns {Promise<ConnectedAccountRefreshResponse>} Refreshed connected account details
1913
+ * Refreshes a connected account's authentication credentials.
1914
+ *
1915
+ * This method attempts to refresh OAuth tokens or other credentials associated with
1916
+ * the connected account. This is useful when a token has expired or is about to expire.
1917
+ *
1918
+ * @param {string} nanoid - The unique identifier of the connected account to refresh
1919
+ * @returns {Promise<ConnectedAccountRefreshResponse>} The response containing the refreshed account details
1920
+ * @throws {Error} If the account doesn't exist or credentials cannot be refreshed
1921
+ *
1922
+ * @example
1923
+ * ```typescript
1924
+ * // Refresh a connected account's credentials
1925
+ * const refreshedAccount = await composio.connectedAccounts.refresh('conn_abc123');
1926
+ * ```
1569
1927
  */
1570
1928
  async refresh(nanoid) {
1571
1929
  return this.client.connectedAccounts.refresh(nanoid);
@@ -1608,9 +1966,15 @@ var Toolkits = class {
1608
1966
  this.authorize = this.authorize.bind(this);
1609
1967
  }
1610
1968
  /**
1611
- * List all toolkits available in the Composio SDK.
1612
- * This method fetches the toolkits from the Composio API.
1613
- * @returns {Promise<Toolkit[]>} List of toolkits
1969
+ * Retrieves a list of toolkits based on the provided query parameters.
1970
+ *
1971
+ * This method fetches toolkits from the Composio API and transforms the response
1972
+ * from snake_case to camelCase format for consistency with JavaScript/TypeScript conventions.
1973
+ *
1974
+ * @param {ToolkitListParams} query - The query parameters to filter toolkits
1975
+ * @returns {Promise<ToolKitListResponse>} The transformed list of toolkits
1976
+ *
1977
+ * @private
1614
1978
  */
1615
1979
  async getToolkits(query) {
1616
1980
  const parsedQuery = ToolkitsListParamsSchema.parse(query);
@@ -1639,11 +2003,29 @@ var Toolkits = class {
1639
2003
  return parsedResult;
1640
2004
  }
1641
2005
  /**
1642
- * Fetches a toolkit by its Slug.
1643
- * This method retrieves the toolkit from the Composio API.
1644
- * @param slug - The ID of the toolkit to be retrieved
1645
- * @param options - Request options
1646
- * @returns {Promise<ToolkitRetrieveResponse>} The toolkit object
2006
+ * Implementation method that handles both overloads for retrieving toolkits.
2007
+ *
2008
+ * @param {string | ToolkitListParams} arg - Either a toolkit slug or query parameters
2009
+ * @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit or list of toolkits
2010
+ */
2011
+ async get(arg) {
2012
+ if (typeof arg === "string") {
2013
+ return this.getToolkitBySlug(arg);
2014
+ }
2015
+ return this.getToolkits(arg);
2016
+ }
2017
+ /**
2018
+ * Retrieves a specific toolkit by its slug identifier.
2019
+ *
2020
+ * This method fetches a single toolkit from the Composio API and transforms
2021
+ * the response to use camelCase property naming consistent with JavaScript/TypeScript conventions.
2022
+ *
2023
+ * @param {string} slug - The unique slug identifier of the toolkit to retrieve
2024
+ * @returns {Promise<ToolkitRetrieveResponse>} The transformed toolkit object
2025
+ * @throws {ValidationError} If the response cannot be properly parsed
2026
+ * @throws {ComposioToolNotFoundError} If no toolkit with the given slug exists
2027
+ *
2028
+ * @private
1647
2029
  */
1648
2030
  async getToolkitBySlug(slug) {
1649
2031
  try {
@@ -1684,21 +2066,19 @@ var Toolkits = class {
1684
2066
  }
1685
2067
  }
1686
2068
  /**
1687
- * Fetches a toolkit by its Slug or a list of toolkits.
1688
- * This method retrieves the toolkit from the Composio API.
1689
- * @param arg - The ID of the toolkit to be retrieved or a list of parameters
1690
- * @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit object or a list of toolkits
1691
- */
1692
- async get(arg) {
1693
- if (typeof arg === "string") {
1694
- return this.getToolkitBySlug(arg);
1695
- }
1696
- return this.getToolkits(arg);
1697
- }
1698
- /**
1699
- * Fetches all categories available in the Composio SDK
2069
+ * Retrieves all toolkit categories available in the Composio SDK.
2070
+ *
2071
+ * This method fetches the complete list of categories from the Composio API
2072
+ * and transforms the response to use camelCase property naming.
1700
2073
  *
1701
- * @returns {Promise<ToolkitRetrieveCategoriesResponse>} List of categories
2074
+ * @returns {Promise<ToolkitRetrieveCategoriesResponse>} The list of toolkit categories
2075
+ *
2076
+ * @example
2077
+ * ```typescript
2078
+ * // Get all toolkit categories
2079
+ * const categories = await composio.toolkits.listCategories();
2080
+ * console.log(categories.items); // Array of category objects
2081
+ * ```
1702
2082
  */
1703
2083
  async listCategories() {
1704
2084
  const result = await this.client.toolkits.retrieveCategories();
@@ -1720,8 +2100,12 @@ var Toolkits = class {
1720
2100
  * This method will create an auth config if one doesn't exist and initiate a connection request.
1721
2101
  * @param {string} userId - The user id of the user to authorize
1722
2102
  * @param {string} toolkitSlug - The slug of the toolkit to authorize
1723
- * @param {string} authConfigId - The id of the auth config to use
1724
2103
  * @returns {Promise<ConnectionRequest>} The connection request object
2104
+ *
2105
+ * @example
2106
+ * ```typescript
2107
+ * const connectionRequest = await composio.toolkits.authorize(userId, 'github');
2108
+ * ```
1725
2109
  */
1726
2110
  async authorize(userId, toolkitSlug) {
1727
2111
  const toolkit = await this.getToolkitBySlug(toolkitSlug);
@@ -2478,7 +2862,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
2478
2862
  };
2479
2863
 
2480
2864
  // package.json
2481
- var version = "0.1.12-alpha.6";
2865
+ var version = "0.1.12-alpha.9";
2482
2866
 
2483
2867
  // src/utils/uuid.ts
2484
2868
  import { v4 as uuidv4 } from "uuid";
@@ -2510,7 +2894,6 @@ var Composio = class {
2510
2894
  authConfigs;
2511
2895
  // connected accounts
2512
2896
  connectedAccounts;
2513
- experimental;
2514
2897
  /**
2515
2898
  * @param {Object} config Configuration for the Composio SDK.
2516
2899
  * @param {string} config.apiKey The API key for the Composio SDK.
@@ -2528,7 +2911,7 @@ var Composio = class {
2528
2911
  if (IS_DEVELOPMENT_OR_CI) {
2529
2912
  logger_default.info(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
2530
2913
  }
2531
- this.client = new ComposioClient({
2914
+ this.client = new ComposioClient2({
2532
2915
  apiKey: apiKeyParsed,
2533
2916
  baseURL: baseURLParsed
2534
2917
  });
@@ -2542,9 +2925,6 @@ var Composio = class {
2542
2925
  this.triggers = new Triggers(this.client);
2543
2926
  this.authConfigs = new AuthConfigs(this.client);
2544
2927
  this.connectedAccounts = new ConnectedAccounts(this.client);
2545
- this.experimental = {
2546
- connectionRequest: connectionRequest(this.client)
2547
- };
2548
2928
  if (this.config.allowTracking ?? true) {
2549
2929
  this.initializeTelemetry(
2550
2930
  {