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

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(
@@ -474,6 +474,7 @@ var ValidationError = class extends ComposioError {
474
474
  cause: zodErrorInstance
475
475
  });
476
476
  this.zodError = zodErrorInstance;
477
+ this.name = "ValidationError";
477
478
  }
478
479
  };
479
480
 
@@ -498,9 +499,15 @@ var Tools = class {
498
499
  this.getRawComposioTools = this.getRawComposioTools.bind(this);
499
500
  }
500
501
  /**
501
- * Transform the tool cases
502
- * @param {ToolRetrieveResponse | ComposioToolListResponse['items'][0]} tool - The tool to transform
503
- * @returns {Tool} The transformed tool
502
+ * Transforms tool data from snake_case API format to camelCase for internal SDK use.
503
+ *
504
+ * This method standardizes the property naming convention for tools retrieved from the Composio API,
505
+ * making them more consistent with JavaScript/TypeScript conventions.
506
+ *
507
+ * @param {ToolRetrieveResponse | ComposioToolListResponse['items'][0]} tool - The tool object to transform
508
+ * @returns {Tool} The transformed tool with camelCase properties
509
+ *
510
+ * @private
504
511
  */
505
512
  transformToolCases(tool) {
506
513
  return ToolSchema.parse({
@@ -510,9 +517,15 @@ var Tools = class {
510
517
  });
511
518
  }
512
519
  /**
513
- * Transform the tool execute response to camelcase
514
- * @param {ComposioToolExecuteResponse} response - The response to transform
515
- * @returns {ToolExecuteResponse} The transformed response
520
+ * Transforms tool execution response from snake_case API format to camelCase.
521
+ *
522
+ * This method converts the response received from the Composio API to a standardized format
523
+ * with consistent property naming that follows JavaScript/TypeScript conventions.
524
+ *
525
+ * @param {ComposioToolExecuteResponse} response - The raw API response to transform
526
+ * @returns {ToolExecuteResponse} The transformed response with camelCase properties
527
+ *
528
+ * @private
516
529
  */
517
530
  transformToolExecuteResponse(response) {
518
531
  return ToolExecuteResponseSchema.parse({
@@ -597,9 +610,35 @@ var Tools = class {
597
610
  return null;
598
611
  }
599
612
  /**
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
613
+ * Lists all tools available in the Composio SDK including custom tools.
614
+ *
615
+ * This method fetches tools from the Composio API in raw format and combines them with
616
+ * any registered custom tools. The response can be filtered and modified as needed.
617
+ *
618
+ * @param {string} userId - The user ID for whom to fetch the tools
619
+ * @param {ToolListParams} [query={}] - Optional query parameters to filter the tools
620
+ * @param {TransformToolSchemaModifier} [modifier] - Optional function to transform tool schemas
621
+ * @returns {Promise<ToolList>} List of tools matching the query criteria
622
+ *
623
+ * @example
624
+ * ```typescript
625
+ * // Get all tools
626
+ * const tools = await composio.tools.getRawComposioTools('default');
627
+ *
628
+ * // Get tools with filters
629
+ * const githubTools = await composio.tools.getRawComposioTools('default', {
630
+ * toolkits: ['github'],
631
+ * important: true
632
+ * });
633
+ *
634
+ * // Get tools with schema transformation
635
+ * const tools = await composio.tools.getRawComposioTools('default', {},
636
+ * (toolSlug, toolkitSlug, tool) => {
637
+ * // Add custom properties to tool schema
638
+ * return {...tool, customProperty: 'value'};
639
+ * }
640
+ * );
641
+ * ```
603
642
  */
604
643
  async getRawComposioTools(userId, query = {}, modifier) {
605
644
  const queryParams = ToolListParamsSchema.safeParse(query);
@@ -666,11 +705,13 @@ var Tools = class {
666
705
  return modifiedToool;
667
706
  }
668
707
  /**
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
708
+ * Get a tool or list of tools based on the provided arguments.
709
+ * This is an implementation method that handles both overloads.
710
+ *
711
+ * @param {string} userId - The user id to get the tool(s) for
712
+ * @param {ToolListParams | string} arg2 - Either a slug string or filters object
713
+ * @param {ProviderOptions<TProvider>} [options] - Optional provider options
714
+ * @returns {Promise<TToolCollection>} The tool collection
674
715
  */
675
716
  async get(userId, arg2, options) {
676
717
  const executeToolFn = this.createExecuteToolFn(userId, options);
@@ -780,13 +821,43 @@ var Tools = class {
780
821
  return result;
781
822
  }
782
823
  /**
783
- * Exectes a given tool with the provided parameters.
824
+ * Executes a given tool with the provided parameters.
784
825
  *
785
- * This method calls the Composio API to execute the tool and returns the response.
826
+ * This method calls the Composio API or a custom tool handler to execute the tool and returns the response.
827
+ * It automatically determines whether to use a custom tool or a Composio API tool based on the slug.
786
828
  *
787
- * @param {string} slug - The ID of the tool to be executed
829
+ * @param {string} slug - The slug/ID of the tool to be executed
788
830
  * @param {ToolExecuteParams} body - The parameters to be passed to the tool
831
+ * @param {ExecuteToolModifiers} [modifiers] - Optional modifiers to transform the request or response
789
832
  * @returns {Promise<ToolExecuteResponse>} - The response from the tool execution
833
+ *
834
+ * @throws {ComposioCustomToolsNotInitializedError} If the CustomTools instance is not initialized
835
+ * @throws {ComposioToolNotFoundError} If the tool with the given slug is not found
836
+ * @throws {ComposioToolExecutionError} If there is an error during tool execution
837
+ *
838
+ * @example
839
+ * ```typescript
840
+ * // Execute a Composio API tool
841
+ * const result = await composio.tools.execute('HACKERNEWS_GET_USER', {
842
+ * userId: 'default',
843
+ * arguments: { userId: 'pg' }
844
+ * });
845
+ *
846
+ * // Execute with modifiers
847
+ * const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
848
+ * userId: 'default',
849
+ * arguments: { owner: 'composio', repo: 'sdk' }
850
+ * }, {
851
+ * beforeToolExecute: (toolSlug, toolkitSlug, params) => {
852
+ * // Modify params before execution
853
+ * return params;
854
+ * },
855
+ * afterToolExecute: (toolSlug, toolkitSlug, result) => {
856
+ * // Transform result after execution
857
+ * return result;
858
+ * }
859
+ * });
860
+ * ```
790
861
  */
791
862
  async execute(slug, body, modifiers) {
792
863
  if (!this.customTools) {
@@ -843,9 +914,39 @@ var Tools = class {
843
914
  return this.client.tools.proxy(body);
844
915
  }
845
916
  /**
846
- * Execute a custom tool
847
- * @param body
848
- * @returns
917
+ * Creates a custom tool that can be used within the Composio SDK.
918
+ *
919
+ * Custom tools allow you to extend the functionality of Composio with your own implementations
920
+ * while keeping a consistent interface for both built-in and custom tools.
921
+ *
922
+ * @param {CustomToolOptions} body - The configuration for the custom tool
923
+ * @returns {Promise<Tool>} The created custom tool
924
+ *
925
+ * @example
926
+ * ```typescript
927
+ * const customTool = await composio.tools.createCustomTool({
928
+ * name: 'My Custom Tool',
929
+ * description: 'A custom tool that does something specific',
930
+ * slug: 'MY_CUSTOM_TOOL',
931
+ * inputParameters: {
932
+ * param1: {
933
+ * type: 'string',
934
+ * description: 'First parameter',
935
+ * required: true
936
+ * }
937
+ * },
938
+ * outputParameters: {
939
+ * result: {
940
+ * type: 'string',
941
+ * description: 'The result of the operation'
942
+ * }
943
+ * },
944
+ * handler: async (params, context) => {
945
+ * // Custom logic here
946
+ * return { data: { result: 'Success!' } };
947
+ * }
948
+ * });
949
+ * ```
849
950
  */
850
951
  async createCustomTool(body) {
851
952
  return this.customTools.createTool(body);
@@ -1050,6 +1151,18 @@ var AuthConfigs = class {
1050
1151
  getClient() {
1051
1152
  return this.client;
1052
1153
  }
1154
+ /**
1155
+ * Transforms an auth config response from API format to SDK format.
1156
+ *
1157
+ * This method converts property names from snake_case to camelCase and reorganizes
1158
+ * the data structure to match the SDK's standardized format for auth configurations.
1159
+ *
1160
+ * @param {ComposioAuthConfigRetrieveResponse} authConfig - The raw API response to transform
1161
+ * @returns {AuthConfigRetrieveResponse} The transformed auth config data
1162
+ * @throws {ValidationError} If the response fails validation against the expected schema
1163
+ *
1164
+ * @private
1165
+ */
1053
1166
  parseAuthConfigRetrieveResponse(authConfig) {
1054
1167
  const result = AuthConfigRetrieveResponseSchema.safeParse({
1055
1168
  id: authConfig.id,
@@ -1075,10 +1188,30 @@ var AuthConfigs = class {
1075
1188
  return result.data;
1076
1189
  }
1077
1190
  /**
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
1191
+ * Lists authentication configurations based on provided filter criteria.
1192
+ *
1193
+ * This method retrieves auth configs from the Composio API, transforms them to the SDK format,
1194
+ * and supports filtering by various parameters.
1195
+ *
1196
+ * @param {AuthConfigListParams} [query] - Optional query parameters for filtering auth configs
1197
+ * @returns {Promise<AuthConfigListResponse>} A paginated list of auth configurations
1198
+ * @throws {ValidationError} If the query parameters or response fail validation
1199
+ *
1200
+ * @example
1201
+ * ```typescript
1202
+ * // List all auth configs
1203
+ * const allConfigs = await composio.authConfigs.list();
1204
+ *
1205
+ * // List auth configs for a specific toolkit
1206
+ * const githubConfigs = await composio.authConfigs.list({
1207
+ * toolkitSlug: 'github'
1208
+ * });
1209
+ *
1210
+ * // List Composio-managed auth configs
1211
+ * const managedConfigs = await composio.authConfigs.list({
1212
+ * isComposioManaged: true
1213
+ * });
1214
+ * ```
1082
1215
  */
1083
1216
  async list(query) {
1084
1217
  const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : void 0;
@@ -1139,21 +1272,57 @@ var AuthConfigs = class {
1139
1272
  return parsedResult.data;
1140
1273
  }
1141
1274
  /**
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
1275
+ * Retrieves a specific authentication configuration by its ID.
1276
+ *
1277
+ * This method fetches detailed information about a single auth config
1278
+ * and transforms the response to the SDK's standardized format.
1279
+ *
1280
+ * @param {string} nanoid - The unique identifier of the auth config to retrieve
1281
+ * @returns {Promise<AuthConfigRetrieveResponse>} The auth config details
1282
+ * @throws {Error} If the auth config cannot be found or an API error occurs
1283
+ * @throws {ValidationError} If the response fails validation
1284
+ *
1285
+ * @example
1286
+ * ```typescript
1287
+ * // Get an auth config by ID
1288
+ * const authConfig = await composio.authConfigs.get('auth_abc123');
1289
+ * console.log(authConfig.name); // e.g., 'GitHub Auth'
1290
+ * console.log(authConfig.toolkit.slug); // e.g., 'github'
1291
+ * ```
1146
1292
  */
1147
1293
  async get(nanoid) {
1148
1294
  const result = await this.client.authConfigs.retrieve(nanoid);
1149
1295
  return this.parseAuthConfigRetrieveResponse(result);
1150
1296
  }
1151
1297
  /**
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
1298
+ * Updates an existing authentication configuration.
1299
+ *
1300
+ * This method allows you to modify properties of an auth config such as credentials,
1301
+ * scopes, or tool restrictions. The update type (custom or default) determines which
1302
+ * fields can be updated.
1303
+ *
1304
+ * @param {string} nanoid - The unique identifier of the auth config to update
1305
+ * @param {AuthConfigUpdateParams} data - The data to update, which can be either custom or default type
1306
+ * @returns {Promise<AuthConfigUpdateResponse>} The updated auth config
1307
+ * @throws {ValidationError} If the update parameters are invalid
1308
+ * @throws {Error} If the auth config cannot be found or updated
1309
+ *
1310
+ * @example
1311
+ * ```typescript
1312
+ * // Update a custom auth config with new credentials
1313
+ * const updatedConfig = await composio.authConfigs.update('auth_abc123', {
1314
+ * type: 'custom',
1315
+ * credentials: {
1316
+ * apiKey: 'new-api-key-value'
1317
+ * }
1318
+ * });
1319
+ *
1320
+ * // Update a default auth config with new scopes
1321
+ * const updatedConfig = await composio.authConfigs.update('auth_abc123', {
1322
+ * type: 'default',
1323
+ * scopes: ['read:user', 'repo']
1324
+ * });
1325
+ * ```
1157
1326
  */
1158
1327
  async update(nanoid, data) {
1159
1328
  const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
@@ -1174,38 +1343,85 @@ var AuthConfigs = class {
1174
1343
  );
1175
1344
  }
1176
1345
  /**
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
1346
+ * Deletes an authentication configuration.
1347
+ *
1348
+ * This method permanently removes an auth config from the Composio platform.
1349
+ * This action cannot be undone and will prevent any connected accounts that use
1350
+ * this auth config from functioning.
1351
+ *
1352
+ * @param {string} nanoid - The unique identifier of the auth config to delete
1353
+ * @returns {Promise<AuthConfigDeleteResponse>} The deletion response
1354
+ * @throws {Error} If the auth config doesn't exist or cannot be deleted
1355
+ *
1356
+ * @example
1357
+ * ```typescript
1358
+ * // Delete an auth config
1359
+ * await composio.authConfigs.delete('auth_abc123');
1360
+ * ```
1181
1361
  */
1182
1362
  async delete(nanoid) {
1183
1363
  return this.client.authConfigs.delete(nanoid);
1184
1364
  }
1185
1365
  /**
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
1366
+ * Updates the status of an authentication configuration.
1367
+ *
1368
+ * This method allows you to enable or disable an auth config. When disabled,
1369
+ * the auth config cannot be used to create new connected accounts or authenticate
1370
+ * with third-party services.
1371
+ *
1372
+ * @param {string} status - The status to set ('ENABLED' or 'DISABLED')
1373
+ * @param {string} nanoid - The unique identifier of the auth config
1374
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
1375
+ * @throws {Error} If the auth config cannot be found or the status cannot be updated
1376
+ *
1377
+ * @example
1378
+ * ```typescript
1379
+ * // Disable an auth config
1380
+ * await composio.authConfigs.updateStatus('DISABLED', 'auth_abc123');
1381
+ *
1382
+ * // Enable an auth config
1383
+ * await composio.authConfigs.updateStatus('ENABLED', 'auth_abc123');
1384
+ * ```
1191
1385
  */
1192
1386
  async updateStatus(status, nanoid) {
1193
1387
  return this.client.authConfigs.updateStatus(status, { nanoid });
1194
1388
  }
1195
1389
  /**
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
1390
+ * Enables an authentication configuration.
1391
+ *
1392
+ * This is a convenience method that calls updateStatus with 'ENABLED'.
1393
+ * When enabled, the auth config can be used to create new connected accounts
1394
+ * and authenticate with third-party services.
1395
+ *
1396
+ * @param {string} nanoid - The unique identifier of the auth config to enable
1397
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
1398
+ * @throws {Error} If the auth config cannot be found or enabled
1399
+ *
1400
+ * @example
1401
+ * ```typescript
1402
+ * // Enable an auth config
1403
+ * await composio.authConfigs.enable('auth_abc123');
1404
+ * ```
1200
1405
  */
1201
1406
  async enable(nanoid) {
1202
1407
  return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
1203
1408
  }
1204
1409
  /**
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
1410
+ * Disables an authentication configuration.
1411
+ *
1412
+ * This is a convenience method that calls updateStatus with 'DISABLED'.
1413
+ * When disabled, the auth config cannot be used to create new connected accounts
1414
+ * or authenticate with third-party services, but existing connections may continue to work.
1415
+ *
1416
+ * @param {string} nanoid - The unique identifier of the auth config to disable
1417
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
1418
+ * @throws {Error} If the auth config cannot be found or disabled
1419
+ *
1420
+ * @example
1421
+ * ```typescript
1422
+ * // Disable an auth config
1423
+ * await composio.authConfigs.disable('auth_abc123');
1424
+ * ```
1209
1425
  */
1210
1426
  async disable(nanoid) {
1211
1427
  return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
@@ -1319,7 +1535,7 @@ var ConnectedAccountRetrieveResponseSchema = z4.object({
1319
1535
  authConfig: ConnectedAccountAuthConfigSchema,
1320
1536
  userId: z4.string(),
1321
1537
  data: z4.record(z4.string(), z4.unknown()),
1322
- params: z4.record(z4.string(), z4.unknown()),
1538
+ params: z4.record(z4.string(), z4.unknown()).optional(),
1323
1539
  status: ConnectedAccountStatusSchema,
1324
1540
  statusReason: z4.string().nullable(),
1325
1541
  toolkit: z4.object({
@@ -1330,8 +1546,24 @@ var ConnectedAccountRetrieveResponseSchema = z4.object({
1330
1546
  createdAt: z4.string(),
1331
1547
  updatedAt: z4.string()
1332
1548
  });
1549
+ var ConnectedAccountListParamsSchema = z4.object({
1550
+ authConfigIds: z4.array(z4.string()).nullable().optional().describe("The auth config ids of the connected accounts"),
1551
+ cursor: z4.number().nullable().optional().describe("The cursor to paginate through the connected accounts"),
1552
+ labels: z4.array(z4.string()).nullable().optional().describe("The labels of the connected accounts"),
1553
+ limit: z4.number().nullable().optional().describe("The limit of the connected accounts to return"),
1554
+ orderBy: z4.enum(["created_at", "updated_at"]).optional().describe("The order by of the connected accounts"),
1555
+ statuses: z4.array(ConnectedAccountStatusSchema).nullable().optional().describe("The statuses of the connected accounts"),
1556
+ toolkitSlugs: z4.array(z4.string()).nullable().optional().describe("The toolkit slugs of the connected accounts"),
1557
+ userIds: z4.array(z4.string()).nullable().optional().describe("The user ids of the connected accounts")
1558
+ });
1559
+ var ConnectedAccountListResponseSchema = z4.object({
1560
+ items: z4.array(ConnectedAccountRetrieveResponseSchema).describe("The list of connected accounts"),
1561
+ nextCursor: z4.string().nullable().describe("The next cursor to paginate through the connected accounts"),
1562
+ totalPages: z4.number().describe("The total number of pages of connected accounts")
1563
+ });
1333
1564
 
1334
1565
  // src/models/ConnectionRequest.ts
1566
+ import ComposioClient from "@composio/client";
1335
1567
  import { ZodError as ZodError2 } from "zod";
1336
1568
 
1337
1569
  // src/errors/ConnectionRequestError.ts
@@ -1371,9 +1603,16 @@ var ConnectionRequest = class {
1371
1603
  this.redirectUrl = redirectUrl;
1372
1604
  }
1373
1605
  /**
1374
- * Transform the response from the Composio API to the SDK format
1375
- * @param response
1376
- * @returns
1606
+ * Transforms the raw connected account response from the Composio API to the SDK format.
1607
+ *
1608
+ * This method converts property names from snake_case to camelCase and reorganizes
1609
+ * the data structure to match the SDK's standardized format.
1610
+ *
1611
+ * @param {OriginalConnectedAccountResponse} response - The raw API response to transform
1612
+ * @returns {Promise<ConnectedAccountRetrieveResponse>} The transformed response
1613
+ * @throws {ZodError} If the response fails validation against the expected schema
1614
+ *
1615
+ * @private
1377
1616
  */
1378
1617
  async transformResponse(response) {
1379
1618
  try {
@@ -1403,15 +1642,48 @@ var ConnectionRequest = class {
1403
1642
  }
1404
1643
  }
1405
1644
  /**
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
1645
+ * Waits for the connection request to complete and become active.
1646
+ *
1647
+ * This method continuously polls the Composio API to check the status of the connection request
1648
+ * until it either becomes active, enters a terminal error state, or times out.
1649
+ *
1650
+ * @param {number} [timeout=60000] - Maximum time to wait in milliseconds before timing out (default: 60 seconds)
1651
+ * @returns {Promise<ConnectedAccountRetrieveResponse>} The final connected account response when successful
1652
+ * @throws {ComposioConnectedAccountNotFoundError} If the connected account cannot be found
1653
+ * @throws {ConnectionRequestFailedError} If the connection enters a failed, expired, or deleted state
1654
+ * @throws {ConnectionRequestTimeoutError} If the connection request does not complete within the timeout period
1655
+ *
1656
+ * @example
1657
+ * ```typescript
1658
+ * // Wait for connection with default timeout (60 seconds)
1659
+ * try {
1660
+ * const connection = await connectionRequest.waitForConnection();
1661
+ * console.log('Connection established:', connection.id);
1662
+ * } catch (error) {
1663
+ * console.error('Connection failed:', error.message);
1664
+ * }
1665
+ *
1666
+ * // Wait for connection with custom timeout (2 minutes)
1667
+ * const connection = await connectionRequest.waitForConnection(120000);
1668
+ * ```
1410
1669
  */
1411
1670
  async waitForConnection(timeout = 6e4) {
1412
- if (this.status === ConnectedAccountStatuses.ACTIVE) {
1671
+ try {
1413
1672
  const response = await this.client.connectedAccounts.retrieve(this.id);
1414
- return this.transformResponse(response);
1673
+ if (response.status === ConnectedAccountStatuses.ACTIVE) {
1674
+ return this.transformResponse(response);
1675
+ }
1676
+ } catch (error) {
1677
+ if (error instanceof ComposioClient.NotFoundError) {
1678
+ throw new ComposioConnectedAccountNotFoundError(
1679
+ `Connected account with id ${this.id} not found`,
1680
+ {
1681
+ connectedAccountId: this.id
1682
+ }
1683
+ );
1684
+ } else {
1685
+ throw error;
1686
+ }
1415
1687
  }
1416
1688
  const terminalErrorStates = [
1417
1689
  ConnectedAccountStatuses.FAILED,
@@ -1463,14 +1735,95 @@ var ConnectedAccounts = class {
1463
1735
  constructor(client) {
1464
1736
  this.client = client;
1465
1737
  }
1738
+ transformConnectedAccountRetrieveResponse(response) {
1739
+ const result = ConnectedAccountRetrieveResponseSchema.safeParse({
1740
+ ...response,
1741
+ userId: response.user_id,
1742
+ // Add the missing userId property
1743
+ authConfig: {
1744
+ ...response.auth_config,
1745
+ authScheme: response.auth_config.auth_scheme,
1746
+ isComposioManaged: response.auth_config.is_composio_managed,
1747
+ isDisabled: response.auth_config.is_disabled
1748
+ },
1749
+ statusReason: response.status_reason,
1750
+ isDisabled: response.is_disabled,
1751
+ createdAt: response.created_at,
1752
+ updatedAt: response.updated_at,
1753
+ testRequestEndpoint: response.test_request_endpoint
1754
+ });
1755
+ if (!result.success) {
1756
+ throw new ValidationError(result.error);
1757
+ }
1758
+ return result.data;
1759
+ }
1466
1760
  /**
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
1761
+ * Lists all connected accounts based on provided filter criteria.
1762
+ *
1763
+ * This method retrieves connected accounts from the Composio API with optional filtering.
1764
+ *
1765
+ * @param {ConnectedAccountListParams} [query] - Optional query parameters for filtering connected accounts
1766
+ * @returns {Promise<ConnectedAccountListResponse>} A paginated list of connected accounts
1767
+ * @throws {ValidationError} If the query fails validation against the expected schema
1768
+ * @example
1769
+ * ```typescript
1770
+ * // List all connected accounts
1771
+ * const allAccounts = await composio.connectedAccounts.list();
1772
+ *
1773
+ * // List accounts for a specific user
1774
+ * const userAccounts = await composio.connectedAccounts.list({
1775
+ * userIds: ['user123']
1776
+ * });
1777
+ *
1778
+ * // List accounts for a specific toolkit
1779
+ * const githubAccounts = await composio.connectedAccounts.list({
1780
+ * toolkitSlugs: ['github']
1781
+ * });
1782
+ * ```
1471
1783
  */
1472
1784
  async list(query) {
1473
- return this.client.connectedAccounts.list(query);
1785
+ let rawQuery = void 0;
1786
+ if (query) {
1787
+ const parsedQuery = ConnectedAccountListParamsSchema.safeParse(query);
1788
+ if (!parsedQuery.success) {
1789
+ throw new ValidationError(parsedQuery.error);
1790
+ }
1791
+ rawQuery = {
1792
+ auth_config_ids: parsedQuery.data.authConfigIds,
1793
+ cursor: parsedQuery.data.cursor,
1794
+ labels: parsedQuery.data.labels,
1795
+ limit: parsedQuery.data.limit,
1796
+ order_by: parsedQuery.data.orderBy,
1797
+ statuses: parsedQuery.data.statuses,
1798
+ toolkit_slugs: parsedQuery.data.toolkitSlugs,
1799
+ user_ids: parsedQuery.data.userIds
1800
+ };
1801
+ }
1802
+ const result = await this.client.connectedAccounts.list(rawQuery);
1803
+ const parsedResponse = ConnectedAccountListResponseSchema.safeParse({
1804
+ items: result.items.map(this.transformConnectedAccountRetrieveResponse),
1805
+ nextCursor: result.next_cursor,
1806
+ totalPages: result.total_pages
1807
+ });
1808
+ if (!parsedResponse.success) {
1809
+ throw new ValidationError(parsedResponse.error);
1810
+ }
1811
+ return parsedResponse.data;
1812
+ }
1813
+ /**
1814
+ * Transforms connected account data from API format to SDK format.
1815
+ *
1816
+ * This method converts property names from snake_case to camelCase and reorganizes
1817
+ * the data structure to match the SDK's standardized format for connected accounts.
1818
+ *
1819
+ * @param {ConnectedAccountRetrieveResponseRaw} response - The raw API response to transform
1820
+ * @returns {ConnectedAccountRetrieveResponse} The transformed connected account data
1821
+ * @throws {ValidationError} If the response fails validation against the expected schema
1822
+ *
1823
+ * @private
1824
+ */
1825
+ transformConnectedAccountResponse(response) {
1826
+ return this.transformConnectedAccountRetrieveResponse(response);
1474
1827
  }
1475
1828
  /**
1476
1829
  * Compound function to create a new connected account.
@@ -1503,69 +1856,88 @@ var ConnectedAccounts = class {
1503
1856
  });
1504
1857
  return new ConnectionRequest(this.client, response.id, response.status, response.redirect_uri);
1505
1858
  }
1859
+ /**
1860
+ * Waits for a connection request to complete and become active.
1861
+ *
1862
+ * This method continuously polls the Composio API to check the status of a connection
1863
+ * until it either becomes active, enters a terminal error state, or times out.
1864
+ *
1865
+ * @param {string} connectedAccountId - The ID of the connected account to wait for
1866
+ * @param {number} [timeout=60000] - Maximum time to wait in milliseconds (default: 60 seconds)
1867
+ * @returns {Promise<ConnectedAccountRetrieveResponse>} The finalized connected account data
1868
+ * @throws {ComposioConnectedAccountNotFoundError} If the connected account cannot be found
1869
+ * @throws {ConnectionRequestFailedError} If the connection enters a failed, expired, or deleted state
1870
+ * @throws {ConnectionRequestTimeoutError} If the connection does not complete within the timeout period
1871
+ *
1872
+ * @example
1873
+ * ```typescript
1874
+ * // Wait for a connection to complete with default timeout
1875
+ * const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc');
1876
+ *
1877
+ * // Wait with a custom timeout of 2 minutes
1878
+ * const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc', 120000);
1879
+ * ```
1880
+ */
1506
1881
  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
- );
1882
+ const connectionRequest2 = new ConnectionRequest(this.client, connectedAccountId);
1524
1883
  return connectionRequest2.waitForConnection(timeout);
1525
1884
  }
1526
1885
  /**
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
1886
+ * Retrieves a specific connected account by its ID.
1887
+ *
1888
+ * This method fetches detailed information about a single connected account
1889
+ * and transforms the response to the SDK's standardized format.
1890
+ *
1891
+ * @param {string} nanoid - The unique identifier of the connected account
1892
+ * @returns {Promise<ConnectedAccountRetrieveResponse>} The connected account details
1893
+ * @throws {Error} If the connected account cannot be found or an API error occurs
1894
+ *
1895
+ * @example
1896
+ * ```typescript
1897
+ * // Get a connected account by ID
1898
+ * const account = await composio.connectedAccounts.get('conn_abc123');
1899
+ * console.log(account.status); // e.g., 'ACTIVE'
1900
+ * console.log(account.toolkit.slug); // e.g., 'github'
1901
+ * ```
1531
1902
  */
1532
1903
  async get(nanoid) {
1533
1904
  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;
1905
+ return this.transformConnectedAccountResponse(response);
1554
1906
  }
1555
1907
  /**
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
1908
+ * Deletes a connected account.
1909
+ *
1910
+ * This method permanently removes a connected account from the Composio platform.
1911
+ * This action cannot be undone and will revoke any access tokens associated with the account.
1912
+ *
1913
+ * @param {string} nanoid - The unique identifier of the connected account to delete
1914
+ * @returns {Promise<ConnectedAccountDeleteResponse>} The deletion response
1915
+ * @throws {Error} If the account doesn't exist or cannot be deleted
1916
+ *
1917
+ * @example
1918
+ * ```typescript
1919
+ * // Delete a connected account
1920
+ * await composio.connectedAccounts.delete('conn_abc123');
1921
+ * ```
1560
1922
  */
1561
1923
  async delete(nanoid) {
1562
1924
  return this.client.connectedAccounts.delete(nanoid);
1563
1925
  }
1564
1926
  /**
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
1927
+ * Refreshes a connected account's authentication credentials.
1928
+ *
1929
+ * This method attempts to refresh OAuth tokens or other credentials associated with
1930
+ * the connected account. This is useful when a token has expired or is about to expire.
1931
+ *
1932
+ * @param {string} nanoid - The unique identifier of the connected account to refresh
1933
+ * @returns {Promise<ConnectedAccountRefreshResponse>} The response containing the refreshed account details
1934
+ * @throws {Error} If the account doesn't exist or credentials cannot be refreshed
1935
+ *
1936
+ * @example
1937
+ * ```typescript
1938
+ * // Refresh a connected account's credentials
1939
+ * const refreshedAccount = await composio.connectedAccounts.refresh('conn_abc123');
1940
+ * ```
1569
1941
  */
1570
1942
  async refresh(nanoid) {
1571
1943
  return this.client.connectedAccounts.refresh(nanoid);
@@ -1608,9 +1980,15 @@ var Toolkits = class {
1608
1980
  this.authorize = this.authorize.bind(this);
1609
1981
  }
1610
1982
  /**
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
1983
+ * Retrieves a list of toolkits based on the provided query parameters.
1984
+ *
1985
+ * This method fetches toolkits from the Composio API and transforms the response
1986
+ * from snake_case to camelCase format for consistency with JavaScript/TypeScript conventions.
1987
+ *
1988
+ * @param {ToolkitListParams} query - The query parameters to filter toolkits
1989
+ * @returns {Promise<ToolKitListResponse>} The transformed list of toolkits
1990
+ *
1991
+ * @private
1614
1992
  */
1615
1993
  async getToolkits(query) {
1616
1994
  const parsedQuery = ToolkitsListParamsSchema.parse(query);
@@ -1639,11 +2017,29 @@ var Toolkits = class {
1639
2017
  return parsedResult;
1640
2018
  }
1641
2019
  /**
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
2020
+ * Implementation method that handles both overloads for retrieving toolkits.
2021
+ *
2022
+ * @param {string | ToolkitListParams} arg - Either a toolkit slug or query parameters
2023
+ * @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit or list of toolkits
2024
+ */
2025
+ async get(arg) {
2026
+ if (typeof arg === "string") {
2027
+ return this.getToolkitBySlug(arg);
2028
+ }
2029
+ return this.getToolkits(arg);
2030
+ }
2031
+ /**
2032
+ * Retrieves a specific toolkit by its slug identifier.
2033
+ *
2034
+ * This method fetches a single toolkit from the Composio API and transforms
2035
+ * the response to use camelCase property naming consistent with JavaScript/TypeScript conventions.
2036
+ *
2037
+ * @param {string} slug - The unique slug identifier of the toolkit to retrieve
2038
+ * @returns {Promise<ToolkitRetrieveResponse>} The transformed toolkit object
2039
+ * @throws {ValidationError} If the response cannot be properly parsed
2040
+ * @throws {ComposioToolNotFoundError} If no toolkit with the given slug exists
2041
+ *
2042
+ * @private
1647
2043
  */
1648
2044
  async getToolkitBySlug(slug) {
1649
2045
  try {
@@ -1684,21 +2080,19 @@ var Toolkits = class {
1684
2080
  }
1685
2081
  }
1686
2082
  /**
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
2083
+ * Retrieves all toolkit categories available in the Composio SDK.
1700
2084
  *
1701
- * @returns {Promise<ToolkitRetrieveCategoriesResponse>} List of categories
2085
+ * This method fetches the complete list of categories from the Composio API
2086
+ * and transforms the response to use camelCase property naming.
2087
+ *
2088
+ * @returns {Promise<ToolkitRetrieveCategoriesResponse>} The list of toolkit categories
2089
+ *
2090
+ * @example
2091
+ * ```typescript
2092
+ * // Get all toolkit categories
2093
+ * const categories = await composio.toolkits.listCategories();
2094
+ * console.log(categories.items); // Array of category objects
2095
+ * ```
1702
2096
  */
1703
2097
  async listCategories() {
1704
2098
  const result = await this.client.toolkits.retrieveCategories();
@@ -1720,8 +2114,12 @@ var Toolkits = class {
1720
2114
  * This method will create an auth config if one doesn't exist and initiate a connection request.
1721
2115
  * @param {string} userId - The user id of the user to authorize
1722
2116
  * @param {string} toolkitSlug - The slug of the toolkit to authorize
1723
- * @param {string} authConfigId - The id of the auth config to use
1724
2117
  * @returns {Promise<ConnectionRequest>} The connection request object
2118
+ *
2119
+ * @example
2120
+ * ```typescript
2121
+ * const connectionRequest = await composio.toolkits.authorize(userId, 'github');
2122
+ * ```
1725
2123
  */
1726
2124
  async authorize(userId, toolkitSlug) {
1727
2125
  const toolkit = await this.getToolkitBySlug(toolkitSlug);
@@ -2478,7 +2876,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
2478
2876
  };
2479
2877
 
2480
2878
  // package.json
2481
- var version = "0.1.12-alpha.6";
2879
+ var version = "0.1.12-alpha.8";
2482
2880
 
2483
2881
  // src/utils/uuid.ts
2484
2882
  import { v4 as uuidv4 } from "uuid";
@@ -2528,7 +2926,7 @@ var Composio = class {
2528
2926
  if (IS_DEVELOPMENT_OR_CI) {
2529
2927
  logger_default.info(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
2530
2928
  }
2531
- this.client = new ComposioClient({
2929
+ this.client = new ComposioClient2({
2532
2930
  apiKey: apiKeyParsed,
2533
2931
  baseURL: baseURLParsed
2534
2932
  });