@composio/core 0.18.1 → 1.0.0-beta.1

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.
Files changed (69) hide show
  1. package/dist/{CustomTool-Bz0f52QR.mjs → CustomTool-CM-roKk7.mjs} +1 -1
  2. package/dist/{CustomTool-VRfWzMix.d.mts → CustomTool-yMQjEyMz.d.mts} +1 -1
  3. package/dist/{FileModifierErrors-CwB-Inm9.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
  4. package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
  5. package/dist/{SsrfErrors-xhdVE4yw.mjs → SsrfErrors-DiQldIdC.mjs} +32 -17
  6. package/dist/{Telemetry-Dw9W5RSp.mjs → Telemetry-JRJJYS4I.mjs} +2 -2
  7. package/dist/{cancellation-P5YUlcfz.mjs → cancellation-BEpFk2S8.mjs} +7 -5
  8. package/dist/{composio-Cb3d1jFe.d.mts → composio-BVNJTVYa.d.mts} +2449 -118
  9. package/dist/{customTool.types-B6ej_8XZ.d.mts → customTool.types-CY5SXFfF.d.mts} +118 -5
  10. package/dist/{errors-Ue9wMrPK.mjs → errors-CvZjP9CH.mjs} +39 -4
  11. package/dist/experimental/index.d.mts +2 -2
  12. package/dist/experimental/index.mjs +1 -1
  13. package/dist/{fileUtils.node-KE5Fa-af.mjs → fileUtils.node-HQsywtTj.mjs} +8 -6
  14. package/dist/index.d.mts +292 -140
  15. package/dist/index.mjs +1914 -160
  16. package/dist/models/Files.node.d.mts +2 -3
  17. package/dist/models/Files.node.mjs +2 -2
  18. package/dist/models/Files.workerd.d.mts +2 -3
  19. package/dist/platform/node.d.mts +2 -3
  20. package/dist/platform/workerd.d.mts +2 -3
  21. package/dist/{sensitiveFileUploadPaths-QN7w4n8v.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
  22. package/dist/{ssrfGuard.node-BLX6b-Rf.mjs → ssrfGuard.node-BK50mYTq.mjs} +94 -8
  23. package/dist/{types-CGdgK442.d.mts → types-CqGfjlZg.d.mts} +2 -2
  24. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
  25. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
  26. package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
  27. package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
  28. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
  29. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  30. package/dist/utils/ssrfGuard.node.d.mts +7 -7
  31. package/dist/utils/ssrfGuard.node.mjs +1 -1
  32. package/dist/utils/ssrfGuard.workerd.d.mts +3 -4
  33. package/dist/utils/ssrfGuard.workerd.mjs +1 -1
  34. package/package.json +7 -7
  35. package/src/composio.ts +86 -2
  36. package/src/errors/ConnectedAccountsErrors.ts +47 -0
  37. package/src/index.ts +15 -0
  38. package/src/models/ConnectedAccounts.ts +118 -2
  39. package/src/models/CustomToolkits.ts +169 -0
  40. package/src/models/Experimental.ts +27 -0
  41. package/src/models/Keyring.ts +65 -0
  42. package/src/models/Logs.ts +101 -0
  43. package/src/models/ToolRouterSession.ts +51 -0
  44. package/src/models/Toolkits.ts +180 -0
  45. package/src/models/Tools.ts +3 -1
  46. package/src/models/Triggers.ts +2 -87
  47. package/src/models/Usage.ts +119 -0
  48. package/src/models/Webhooks.ts +520 -0
  49. package/src/types/authConfigs.types.ts +2 -0
  50. package/src/types/connectedAccounts.types.ts +54 -0
  51. package/src/types/customToolkits.types.ts +102 -0
  52. package/src/types/keyring.types.ts +32 -0
  53. package/src/types/logs.types.ts +108 -0
  54. package/src/types/toolRouter.types.ts +49 -1
  55. package/src/types/toolkit.types.ts +131 -0
  56. package/src/types/usage.types.ts +81 -0
  57. package/src/types/webhooks.types.ts +143 -0
  58. package/src/utils/constants.ts +1 -5
  59. package/src/utils/jsonSchema.ts +4 -1
  60. package/src/utils/logger.ts +39 -7
  61. package/src/utils/ssrfGuard.node.ts +98 -7
  62. package/src/utils/transformers/connectedAccounts.ts +37 -2
  63. package/src/utils/transformers/customToolkits.ts +98 -0
  64. package/src/utils/transformers/keyring.ts +24 -0
  65. package/src/utils/transformers/logs.ts +85 -0
  66. package/src/utils/transformers/toolkits.ts +100 -1
  67. package/src/utils/transformers/triggers.ts +2 -2
  68. package/src/utils/transformers/usage.ts +77 -0
  69. package/src/utils/transformers/webhooks.ts +139 -0
@@ -8,6 +8,8 @@ export const ConnectedAccountErrorCodes = {
8
8
  SHARED_ACCESS_DENIED: 'SHARED_ACCESS_DENIED',
9
9
  ACL_ONLY_FOR_SHARED: 'ACL_ONLY_FOR_SHARED',
10
10
  SHARED_CONNECTION_NOT_ACCESSIBLE: 'SHARED_CONNECTION_NOT_ACCESSIBLE',
11
+ REVOCATION_NOT_SUPPORTED: 'CONNECTED_ACCOUNT_REVOCATION_NOT_SUPPORTED',
12
+ NOT_REVOKABLE: 'CONNECTED_ACCOUNT_NOT_REVOKABLE',
11
13
  } as const;
12
14
 
13
15
  export class ComposioConnectedAccountNotFoundError extends ComposioError {
@@ -156,3 +158,48 @@ export class ComposioLegacyConnectedAccountsEndpointRetiredError extends Composi
156
158
  this.name = 'ComposioLegacyConnectedAccountsEndpointRetiredError';
157
159
  }
158
160
  }
161
+
162
+ /**
163
+ * Thrown by `composio.connectedAccounts.revoke()` when the toolkit behind the
164
+ * connection does not support programmatic revocation at the provider (API
165
+ * 400).
166
+ */
167
+ export class ComposioConnectedAccountRevocationNotSupportedError extends ComposioError {
168
+ constructor(
169
+ message: string = 'This toolkit does not support programmatic revocation of connected accounts',
170
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
171
+ ) {
172
+ super(message, {
173
+ ...options,
174
+ code: ConnectedAccountErrorCodes.REVOCATION_NOT_SUPPORTED,
175
+ statusCode: 400,
176
+ possibleFixes: options.possibleFixes || [
177
+ "Revoke the grant from the provider's own settings page, then disable or delete the connected account with composio.connectedAccounts.disable() / delete().",
178
+ ],
179
+ });
180
+ this.name = 'ComposioConnectedAccountRevocationNotSupportedError';
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Thrown by `composio.connectedAccounts.revoke()` when the connection is not
186
+ * in a state that can be revoked (API 409), for example it never completed
187
+ * authentication. Revoking an already revoked connection is not an error: it
188
+ * returns an empty `revokedTokens` list.
189
+ */
190
+ export class ComposioConnectedAccountNotRevokableError extends ComposioError {
191
+ constructor(
192
+ message: string = 'The connected account is not in a revokable state',
193
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
194
+ ) {
195
+ super(message, {
196
+ ...options,
197
+ code: ConnectedAccountErrorCodes.NOT_REVOKABLE,
198
+ statusCode: 409,
199
+ possibleFixes: options.possibleFixes || [
200
+ 'Check the connection status with composio.connectedAccounts.get(); only ACTIVE connections can be revoked.',
201
+ ],
202
+ });
203
+ this.name = 'ComposioConnectedAccountNotRevokableError';
204
+ }
205
+ }
package/src/index.ts CHANGED
@@ -33,6 +33,10 @@ export {
33
33
  isBlockedSensitiveFileUploadPath,
34
34
  BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS,
35
35
  } from './utils/sensitiveFileUploadPaths';
36
+ // Bounded response reader for files fetched from user-supplied URLs. Exported
37
+ // for the same reason as the denylist guard above: downstream packages read
38
+ // remote files too, and every such read must enforce the same size cap.
39
+ export { readResponseBodyWithLimit, MAX_URL_UPLOAD_SIZE_BYTES } from './utils/readResponseBody';
36
40
  export {
37
41
  sanitizeSchemaPropertyKeys,
38
42
  restoreOriginalKeys,
@@ -41,6 +45,11 @@ export {
41
45
  export type { KeyMapping, KeySanitizationPolicy } from './utils/schemaPropertyKeys';
42
46
  export { AuthScheme } from './models/AuthScheme';
43
47
  export { MCP } from './models/MCP';
48
+ export { Webhooks, WebhookSubscriptions, WebhookEndpoints } from './models/Webhooks';
49
+ export { Logs } from './models/Logs';
50
+ export { Usage } from './models/Usage';
51
+ export { Keyring } from './models/Keyring';
52
+ export { CustomToolkits } from './models/CustomToolkits';
44
53
  export { RemoteFile } from './models/RemoteFile';
45
54
  export { createConnectionRequest } from './models/ConnectionRequest';
46
55
  export { ToolRouterSession } from './models/ToolRouterSession';
@@ -55,6 +64,11 @@ export * from './types/connectedAccounts.types';
55
64
  export * from './types/toolkit.types';
56
65
  export * from './types/triggers.types';
57
66
  export * from './types/webhookEvents.types';
67
+ export * from './types/webhooks.types';
68
+ export * from './types/logs.types';
69
+ export * from './types/usage.types';
70
+ export * from './types/keyring.types';
71
+ export * from './types/customToolkits.types';
58
72
  export * from './types/mcp.types';
59
73
  export * from './types/files.types';
60
74
  export * from './types/connectionRequest.types';
@@ -64,6 +78,7 @@ export * from './types/requestOptions.types';
64
78
  export * as constants from './utils/constants';
65
79
 
66
80
  export { default as logger } from './utils/logger';
81
+ export type { ComposioLogger, LogLevel } from './utils/logger';
67
82
  export { telemetry } from './telemetry/Telemetry';
68
83
 
69
84
  // Experimental custom tools — exported with experimental_ prefix for top-level import
@@ -5,7 +5,7 @@
5
5
  * @date 2025-05-05
6
6
  * @module ConnectedAccounts
7
7
  */
8
- import ComposioClient, { BadRequestError } from '@composio/client';
8
+ import ComposioClient, { BadRequestError, ConflictError } from '@composio/client';
9
9
  import {
10
10
  ConnectedAccountCreateResponse,
11
11
  ConnectedAccountDeleteResponse,
@@ -29,6 +29,10 @@ import {
29
29
  ConnectedAccountStatuses,
30
30
  ConnectedAccountRefreshOptions,
31
31
  ConnectedAccountRefreshOptionsSchema,
32
+ ConnectedAccountRevokeResponse,
33
+ ConnectedAccountCompleteAuthParams,
34
+ ConnectedAccountCompleteAuthParamsSchema,
35
+ ConnectedAccountCompleteAuthResponse,
32
36
  UpdateConnectedAccountAclParams,
33
37
  UpdateConnectedAccountParams,
34
38
  UpdateConnectedAccountParamsSchema,
@@ -45,9 +49,13 @@ import { telemetry } from '../telemetry/Telemetry';
45
49
  import {
46
50
  transformConnectedAccountListResponse,
47
51
  transformConnectedAccountResponse,
52
+ transformConnectedAccountRevokeResponse,
53
+ transformConnectedAccountCompleteAuthResponse,
48
54
  } from '../utils/transformers/connectedAccounts';
49
55
  import {
50
56
  ComposioAclOnlyForSharedError,
57
+ ComposioConnectedAccountNotRevokableError,
58
+ ComposioConnectedAccountRevocationNotSupportedError,
51
59
  ComposioFailedToCreateConnectedAccountLink,
52
60
  ComposioLegacyConnectedAccountsEndpointRetiredError,
53
61
  ComposioMultipleConnectedAccountsError,
@@ -554,6 +562,11 @@ export class ConnectedAccounts {
554
562
  * // Refresh a connected account's credentials
555
563
  * const refreshedAccount = await composio.connectedAccounts.refresh('conn_abc123');
556
564
  * ```
565
+ *
566
+ * @deprecated The `POST /connected_accounts/{id}/refresh` endpoint is deprecated by the
567
+ * Composio API. Re-initiate authentication instead: `composio.connectedAccounts.link(userId, authConfigId)`
568
+ * for a fresh connection, or `session.authorize(toolkit)` from a session. Behaviour is unchanged
569
+ * while the endpoint remains available; do not generate new code against `refresh`.
557
570
  */
558
571
  async refresh(
559
572
  nanoid: string,
@@ -570,9 +583,14 @@ export class ConnectedAccounts {
570
583
  });
571
584
  }
572
585
 
586
+ if (parsedOptions.data.validateCredentials !== undefined) {
587
+ logger.warn(
588
+ 'connectedAccounts.refresh(): the Composio API no longer accepts `validateCredentials`; the option is ignored.'
589
+ );
590
+ }
591
+
573
592
  params = {
574
593
  query_redirect_url: parsedOptions.data.redirectUrl,
575
- validate_credentials: parsedOptions.data.validateCredentials,
576
594
  };
577
595
  }
578
596
 
@@ -582,6 +600,104 @@ export class ConnectedAccounts {
582
600
  );
583
601
  }
584
602
 
603
+ /**
604
+ * Revoke a connected account at the upstream provider.
605
+ *
606
+ * Best-effort upstream revocation of the stored tokens/credentials; on
607
+ * success the connection status becomes `REVOKED`. Revoking an already
608
+ * revoked connection returns an empty `revokedTokens` list without an
609
+ * upstream call.
610
+ *
611
+ * @param {string} nanoid - The unique identifier of the connected account to revoke
612
+ * @returns {Promise<ConnectedAccountRevokeResponse>} Which tokens were revoked and the resulting status
613
+ * @throws {ComposioConnectedAccountRevocationNotSupportedError} If the toolkit does not support programmatic revocation (400)
614
+ * @throws {ComposioConnectedAccountNotRevokableError} If the connection is not in a revokable state (409)
615
+ *
616
+ * @example
617
+ * ```typescript
618
+ * const result = await composio.connectedAccounts.revoke('conn_abc123');
619
+ * console.log(result.connectedAccount.status); // 'REVOKED'
620
+ * console.log(result.revokedTokens); // e.g. ['access_token', 'refresh_token']
621
+ * ```
622
+ */
623
+ async revoke(
624
+ nanoid: string,
625
+ requestOptions?: ComposioRequestOptions
626
+ ): Promise<ConnectedAccountRevokeResponse> {
627
+ try {
628
+ const result = await withCancellation(
629
+ () => this.client.connectedAccounts.revoke(nanoid, requestOptions),
630
+ requestOptions?.signal
631
+ );
632
+ return transformConnectedAccountRevokeResponse(result);
633
+ } catch (error) {
634
+ if (error instanceof BadRequestError) {
635
+ throw new ComposioConnectedAccountRevocationNotSupportedError(
636
+ `Connected account ${nanoid} cannot be revoked programmatically: ${error.message}`,
637
+ { cause: error, meta: { nanoid } }
638
+ );
639
+ }
640
+ if (error instanceof ConflictError) {
641
+ throw new ComposioConnectedAccountNotRevokableError(
642
+ `Connected account ${nanoid} is not in a revokable state: ${error.message}`,
643
+ { cause: error, meta: { nanoid } }
644
+ );
645
+ }
646
+ throw error;
647
+ }
648
+ }
649
+
650
+ /**
651
+ * Complete a deferred OAuth connection once you have verified the user's
652
+ * identity.
653
+ *
654
+ * When your project has an OAuth callback verifier configured, Composio
655
+ * does not activate a new OAuth connection by itself: it redirects to your
656
+ * verifier with a single-use session URI. After confirming who the user is,
657
+ * redeem that session URI here; Composio checks that your project owns the
658
+ * pending connection and that `userId` is its owner, completes the token
659
+ * exchange, and the connection becomes `ACTIVE`.
660
+ *
661
+ * The session URI is single-use: redeeming it twice, or after it expires,
662
+ * fails with a 404 from the API.
663
+ *
664
+ * @param {ConnectedAccountCompleteAuthParams} params - `userId` the connection was initiated for and the verifier's `sessionUri`
665
+ * @returns {Promise<ConnectedAccountCompleteAuthResponse>} The completed connection's ID and toolkit
666
+ * @throws {ValidationError} If the params fail validation
667
+ *
668
+ * @example
669
+ * ```typescript
670
+ * // In your verifier route, after authenticating the user:
671
+ * const { connectedAccountId, toolkitSlug } = await composio.connectedAccounts.completeAuth({
672
+ * userId: 'user_123',
673
+ * sessionUri, // the session URI from the verifier redirect
674
+ * });
675
+ * ```
676
+ */
677
+ async completeAuth(
678
+ params: ConnectedAccountCompleteAuthParams,
679
+ requestOptions?: ComposioRequestOptions
680
+ ): Promise<ConnectedAccountCompleteAuthResponse> {
681
+ const parsedParams = ConnectedAccountCompleteAuthParamsSchema.safeParse(params);
682
+ if (!parsedParams.success) {
683
+ throw new ValidationError('Failed to parse connected account completeAuth params', {
684
+ cause: parsedParams.error,
685
+ });
686
+ }
687
+ const result = await withCancellation(
688
+ () =>
689
+ this.client.connectedAccounts.completeAuth(
690
+ {
691
+ user_id: parsedParams.data.userId,
692
+ session_uri: parsedParams.data.sessionUri,
693
+ },
694
+ requestOptions
695
+ ),
696
+ requestOptions?.signal
697
+ );
698
+ return transformConnectedAccountCompleteAuthResponse(result);
699
+ }
700
+
585
701
  /**
586
702
  * Update the status of a connected account
587
703
  * @param {string} nanoid - Unique identifier of the connected account
@@ -0,0 +1,169 @@
1
+ /**
2
+ * @fileoverview `composio.experimental.customToolkits`: register and manage
3
+ * project-owned custom toolkits.
4
+ * **Experimental — custom toolkits are in pilot; shape may change.**
5
+ *
6
+ * @module CustomToolkits
7
+ */
8
+ import ComposioClient from '@composio/client';
9
+ import {
10
+ CustomToolkitDeleteResponse,
11
+ CustomToolkitSyncParams,
12
+ CustomToolkitSyncParamsSchema,
13
+ CustomToolkitSyncResponse,
14
+ CustomToolkitUpsertParams,
15
+ CustomToolkitUpsertParamsSchema,
16
+ CustomToolkitUpsertResponse,
17
+ } from '../types/customToolkits.types';
18
+ import { ComposioRequestOptions } from '../types/requestOptions.types';
19
+ import { ValidationError } from '../errors/ValidationErrors';
20
+ import { telemetry } from '../telemetry/Telemetry';
21
+ import { withCancellation } from '../utils/cancellation';
22
+ import {
23
+ transformCustomToolkitDeleteResponse,
24
+ transformCustomToolkitSyncParams,
25
+ transformCustomToolkitSyncResponse,
26
+ transformCustomToolkitUpsertParams,
27
+ transformCustomToolkitUpsertResponse,
28
+ } from '../utils/transformers/customToolkits';
29
+
30
+ /**
31
+ * `composio.experimental.customToolkits` — toolkits your project registers
32
+ * from its own app or MCP server, with their own auth configs and connected
33
+ * accounts. **Experimental — custom toolkits are in pilot; shape may change.**
34
+ *
35
+ * These live on the Composio platform. They are unrelated to the in-process
36
+ * toolkits built with `experimental_createToolkit()`, which run inside your
37
+ * application.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const { slug } = await composio.experimental.customToolkits.upsert({
42
+ * slug: 'MY_TOOLKIT',
43
+ * toolkitConfig: {
44
+ * name: 'My Toolkit',
45
+ * appUrl: 'https://mcp.example.com/mcp',
46
+ * authSchemes: [{ mode: 'DCR_OAUTH', discoveryUrl: 'https://mcp.example.com/.well-known/oauth-authorization-server' }],
47
+ * },
48
+ * });
49
+ * await composio.experimental.customToolkits.sync(slug);
50
+ * ```
51
+ */
52
+ export class CustomToolkits {
53
+ private client: ComposioClient;
54
+
55
+ constructor(client: ComposioClient) {
56
+ this.client = client;
57
+ telemetry.instrument(this, 'CustomToolkits');
58
+ }
59
+
60
+ /**
61
+ * Creates a custom toolkit, or updates its display metadata (name, API key
62
+ * field copy) when the project already owns a toolkit with this slug.
63
+ * **Experimental — custom toolkits are in pilot; shape may change.**
64
+ *
65
+ * `appUrl` and `authSchemes` cannot change on an existing toolkit:
66
+ * re-sending them unchanged is a no-op, and changing them fails with a 409.
67
+ * Delete and re-register the toolkit instead, which revokes its connections.
68
+ *
69
+ * @param {CustomToolkitUpsertParams} params - The slug and toolkit configuration
70
+ * @returns {Promise<CustomToolkitUpsertResponse>} The toolkit's slug
71
+ * @throws {ValidationError} If the params fail validation
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * await composio.experimental.customToolkits.upsert({
76
+ * slug: 'INTERNAL_API',
77
+ * toolkitConfig: {
78
+ * name: 'Internal API',
79
+ * appUrl: 'https://mcp.internal.example.com/mcp',
80
+ * authSchemes: [
81
+ * { mode: 'API_KEY', headers: { Authorization: 'Bearer {{generic_api_key}}' } },
82
+ * ],
83
+ * },
84
+ * });
85
+ * ```
86
+ */
87
+ async upsert(
88
+ params: CustomToolkitUpsertParams,
89
+ requestOptions?: ComposioRequestOptions
90
+ ): Promise<CustomToolkitUpsertResponse> {
91
+ const parsedParams = CustomToolkitUpsertParamsSchema.safeParse(params);
92
+ if (!parsedParams.success) {
93
+ throw new ValidationError('Failed to parse custom toolkit upsert params', {
94
+ cause: parsedParams.error,
95
+ });
96
+ }
97
+ const body = transformCustomToolkitUpsertParams(parsedParams.data);
98
+ const result = await withCancellation(
99
+ () => this.client.custom.upsert(body, requestOptions),
100
+ requestOptions?.signal
101
+ );
102
+ return transformCustomToolkitUpsertResponse(result);
103
+ }
104
+
105
+ /**
106
+ * Re-fetches the tool definitions of a custom toolkit from its remote MCP
107
+ * server. Call it when automatic sync fails or the remote tools change.
108
+ * **Experimental — custom toolkits are in pilot; shape may change.**
109
+ *
110
+ * @param {string} slug - The custom toolkit slug (`CUSTOM_...`)
111
+ * @param {CustomToolkitSyncParams} [params] - Optional connected account to fetch the definitions with
112
+ * @returns {Promise<CustomToolkitSyncResponse>} The toolkit version and number of tools synced
113
+ * @throws {ValidationError} If the params fail validation
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const { version, syncedCount } = await composio.experimental.customToolkits.sync(
118
+ * 'CUSTOM_MY_TOOLKIT',
119
+ * { connectedAccountId: 'ca_abc123' }
120
+ * );
121
+ * ```
122
+ */
123
+ async sync(
124
+ slug: string,
125
+ params?: CustomToolkitSyncParams,
126
+ requestOptions?: ComposioRequestOptions
127
+ ): Promise<CustomToolkitSyncResponse> {
128
+ const parsedParams = CustomToolkitSyncParamsSchema.safeParse(params ?? {});
129
+ if (!parsedParams.success) {
130
+ throw new ValidationError('Failed to parse custom toolkit sync params', {
131
+ cause: parsedParams.error,
132
+ });
133
+ }
134
+ const body = transformCustomToolkitSyncParams(slug, parsedParams.data);
135
+ const result = await withCancellation(
136
+ () => this.client.custom.sync(body, requestOptions),
137
+ requestOptions?.signal
138
+ );
139
+ return transformCustomToolkitSyncResponse(result);
140
+ }
141
+
142
+ /**
143
+ * Deletes a custom toolkit owned by the project, with its tools, auth
144
+ * configs and connected accounts. The credentials behind those connected
145
+ * accounts are revoked in background jobs (`revokeJobIds`).
146
+ * **Experimental — custom toolkits are in pilot; shape may change.**
147
+ *
148
+ * Composio-managed toolkits cannot be deleted; the API answers 403.
149
+ *
150
+ * @param {string} slug - The custom toolkit slug (`CUSTOM_...`)
151
+ * @returns {Promise<CustomToolkitDeleteResponse>} What was deleted
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const result = await composio.experimental.customToolkits.delete('CUSTOM_MY_TOOLKIT');
156
+ * console.log(result.connectedAccountsDeleted);
157
+ * ```
158
+ */
159
+ async delete(
160
+ slug: string,
161
+ requestOptions?: ComposioRequestOptions
162
+ ): Promise<CustomToolkitDeleteResponse> {
163
+ const result = await withCancellation(
164
+ () => this.client.custom.deleteToolkit(slug, requestOptions),
165
+ requestOptions?.signal
166
+ );
167
+ return transformCustomToolkitDeleteResponse(result);
168
+ }
169
+ }
@@ -21,6 +21,8 @@ import {
21
21
  import { ValidationError } from '../errors/ValidationErrors';
22
22
  import { ComposioAclOnlyForSharedError } from '../errors';
23
23
  import { telemetry } from '../telemetry/Telemetry';
24
+ import { Usage } from './Usage';
25
+ import { CustomToolkits } from './CustomToolkits';
24
26
 
25
27
  /**
26
28
  * Server-side 400 message the API uses to reject ACL writes against a
@@ -129,8 +131,33 @@ export async function updateConnectedAccountAcl(
129
131
  export class Experimental {
130
132
  private client: ComposioClient;
131
133
 
134
+ /**
135
+ * Project-scoped usage metering (`summary()` / `breakdown()`).
136
+ * **Experimental — shape may change in future releases.**
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const summary = await composio.experimental.usage.summary();
141
+ * const byTool = await composio.experimental.usage.breakdown('tool_calls');
142
+ * ```
143
+ */
144
+ usage: Usage;
145
+
146
+ /**
147
+ * Register and manage project-owned custom toolkits (`upsert()` / `sync()` / `delete()`).
148
+ * **Experimental — custom toolkits are in pilot; shape may change.**
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * await composio.experimental.customToolkits.sync('CUSTOM_MY_TOOLKIT');
153
+ * ```
154
+ */
155
+ customToolkits: CustomToolkits;
156
+
132
157
  constructor(client: ComposioClient) {
133
158
  this.client = client;
159
+ this.usage = new Usage(client);
160
+ this.customToolkits = new CustomToolkits(client);
134
161
  telemetry.instrument(this, 'Experimental');
135
162
  }
136
163
 
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @fileoverview The `composio.keyring` namespace: the public transfer keys of
3
+ * the organization's customer-managed keyring.
4
+ *
5
+ * @module Keyring
6
+ */
7
+ import ComposioClient from '@composio/client';
8
+ import { KeyringTransferKeysResponse } from '../types/keyring.types';
9
+ import { ComposioRequestOptions } from '../types/requestOptions.types';
10
+ import { telemetry } from '../telemetry/Telemetry';
11
+ import { withCancellation } from '../utils/cancellation';
12
+ import { transformKeyringTransferKeysResponse } from '../utils/transformers/keyring';
13
+
14
+ /**
15
+ * `composio.keyring` — the organization's customer-managed keyring.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const { activeKid, keys } = await composio.keyring.listTransferKeys();
20
+ * const sealingKey = keys.find(key => key.kid === activeKid);
21
+ * ```
22
+ */
23
+ export class Keyring {
24
+ private client: ComposioClient;
25
+
26
+ constructor(client: ComposioClient) {
27
+ this.client = client;
28
+ telemetry.instrument(this, 'Keyring');
29
+ }
30
+
31
+ /**
32
+ * Lists the public transfer keys of the organization's active customer
33
+ * keyring, the keys a secret is sealed to before it is sent to Composio.
34
+ *
35
+ * Always seal new secrets to the key whose `kid` is `activeKid`: a JWE with
36
+ * `RSA-OAEP-256` key management, `A256GCM` content encryption, and the
37
+ * `kid` in the protected header. Older keys stay listed so values sealed to
38
+ * them remain openable.
39
+ *
40
+ * The organization behind the API key must have an ACTIVE customer keyring
41
+ * instance; otherwise the API answers 404.
42
+ *
43
+ * @returns {Promise<KeyringTransferKeysResponse>} The active key ID and every accepted public JWK, newest first
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * import { CompactEncrypt, importJWK } from 'jose';
48
+ *
49
+ * const { activeKid, keys } = await composio.keyring.listTransferKeys();
50
+ * const jwk = keys.find(key => key.kid === activeKid)!;
51
+ * const sealed = await new CompactEncrypt(new TextEncoder().encode(secret))
52
+ * .setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM', kid: activeKid })
53
+ * .encrypt(await importJWK(jwk, 'RSA-OAEP-256'));
54
+ * ```
55
+ */
56
+ async listTransferKeys(
57
+ requestOptions?: ComposioRequestOptions
58
+ ): Promise<KeyringTransferKeysResponse> {
59
+ const result = await withCancellation(
60
+ () => this.client.keyring.listTransferKeys(requestOptions),
61
+ requestOptions?.signal
62
+ );
63
+ return transformKeyringTransferKeysResponse(result);
64
+ }
65
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @fileoverview The `composio.logs` namespace: search and inspect
3
+ * tool-execution logs for the project.
4
+ *
5
+ * @module Logs
6
+ */
7
+ import ComposioClient from '@composio/client';
8
+ import {
9
+ LogSearchParams,
10
+ LogSearchParamsSchema,
11
+ LogSearchResponse,
12
+ ToolExecutionLogDetail,
13
+ } from '../types/logs.types';
14
+ import { ComposioRequestOptions } from '../types/requestOptions.types';
15
+ import { ValidationError } from '../errors/ValidationErrors';
16
+ import { telemetry } from '../telemetry/Telemetry';
17
+ import { withCancellation } from '../utils/cancellation';
18
+ import {
19
+ transformLogSearchParams,
20
+ transformLogSearchResponse,
21
+ transformToolExecutionLogDetail,
22
+ } from '../utils/transformers/logs';
23
+
24
+ /**
25
+ * `composio.logs` — tool-execution logs.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const { logs, nextCursor } = await composio.logs.search({
30
+ * filters: [{ field: 'toolkit_slug', operator: '==', value: 'github' }],
31
+ * limit: 20,
32
+ * });
33
+ * const detail = await composio.logs.get(logs[0].id);
34
+ * ```
35
+ */
36
+ export class Logs {
37
+ private client: ComposioClient;
38
+
39
+ constructor(client: ComposioClient) {
40
+ this.client = client;
41
+ telemetry.instrument(this, 'Logs');
42
+ }
43
+
44
+ /**
45
+ * Search tool-execution logs with filters, a time range and cursor
46
+ * pagination.
47
+ *
48
+ * @param {LogSearchParams} [params] - Filters, `timeRange`, `limit` and `cursor`
49
+ * @returns {Promise<LogSearchResponse>} Matching logs and the next cursor
50
+ * @throws {ValidationError} If the params fail validation
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const { logs } = await composio.logs.search({
55
+ * filters: [
56
+ * { field: 'status', operator: '==', value: 'failed' },
57
+ * { field: 'user_id', operator: '==', value: 'user_123' },
58
+ * ],
59
+ * timeRange: { from: Date.now() - 24 * 60 * 60 * 1000, to: Date.now() },
60
+ * });
61
+ * ```
62
+ */
63
+ async search(
64
+ params?: LogSearchParams,
65
+ requestOptions?: ComposioRequestOptions
66
+ ): Promise<LogSearchResponse> {
67
+ const parsedParams = LogSearchParamsSchema.safeParse(params ?? {});
68
+ if (!parsedParams.success) {
69
+ throw new ValidationError('Failed to parse log search params', {
70
+ cause: parsedParams.error,
71
+ });
72
+ }
73
+ const body = transformLogSearchParams(parsedParams.data);
74
+ const result = await withCancellation(
75
+ () => this.client.logs.createToolExecution(body, requestOptions),
76
+ requestOptions?.signal
77
+ );
78
+ return transformLogSearchResponse(result);
79
+ }
80
+
81
+ /**
82
+ * Retrieve one tool-execution log with its full detail (timings, context,
83
+ * source and raw `data`).
84
+ *
85
+ * @param {string} id - The log id
86
+ * @returns {Promise<ToolExecutionLogDetail>} The log detail
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const log = await composio.logs.get('log_abc123');
91
+ * console.log(log.status, log.timings?.endTime);
92
+ * ```
93
+ */
94
+ async get(id: string, requestOptions?: ComposioRequestOptions): Promise<ToolExecutionLogDetail> {
95
+ const result = await withCancellation(
96
+ () => this.client.logs.retrieveToolExecution(id, requestOptions),
97
+ requestOptions?.signal
98
+ );
99
+ return transformToolExecutionLogDetail(result);
100
+ }
101
+ }