@composio/core 1.0.0-beta.0 → 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 (82) hide show
  1. package/dist/{CustomTool-l-j5HtEf.mjs → CustomTool-CM-roKk7.mjs} +16 -6
  2. package/dist/{CustomTool-CwpeQhz2.d.mts → CustomTool-yMQjEyMz.d.mts} +1 -1
  3. package/dist/{FileModifierErrors-B8V8_3VE.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-DNJt57GL.mjs → SsrfErrors-DiQldIdC.mjs} +154 -19
  6. package/dist/{Telemetry-DK1uAWnD.mjs → Telemetry-JRJJYS4I.mjs} +28 -44
  7. package/dist/cancellation-BEpFk2S8.mjs +706 -0
  8. package/dist/{composio-XjF7EMEe.d.mts → composio-BVNJTVYa.d.mts} +2450 -119
  9. package/dist/{customTool.types-DpJbYY5m.d.mts → customTool.types-CY5SXFfF.d.mts} +143 -28
  10. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +1 -1
  11. package/dist/docs/reference/sdk-reference/typescript/session.mdx +4 -3
  12. package/dist/{errors-BcEUHZbq.mjs → errors-CvZjP9CH.mjs} +42 -4
  13. package/dist/experimental/index.d.mts +2 -2
  14. package/dist/experimental/index.mjs +1 -1
  15. package/dist/{fileUtils.node-BwpUOF0s.mjs → fileUtils.node-HQsywtTj.mjs} +11 -9
  16. package/dist/index.d.mts +393 -142
  17. package/dist/index.mjs +1945 -171
  18. package/dist/models/Files.node.d.mts +2 -3
  19. package/dist/models/Files.node.mjs +2 -2
  20. package/dist/models/Files.workerd.d.mts +2 -3
  21. package/dist/platform/node.d.mts +2 -3
  22. package/dist/platform/workerd.d.mts +2 -3
  23. package/dist/{sensitiveFileUploadPaths-B0w8dqpv.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
  24. package/dist/{ssrfGuard.node-DlxO8uzr.mjs → ssrfGuard.node-BK50mYTq.mjs} +187 -24
  25. package/dist/{types-C9kJAurw.d.mts → types-CqGfjlZg.d.mts} +2 -2
  26. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
  27. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
  28. package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
  29. package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
  30. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
  31. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  32. package/dist/utils/ssrfGuard.node.d.mts +7 -7
  33. package/dist/utils/ssrfGuard.node.mjs +1 -1
  34. package/dist/utils/ssrfGuard.workerd.d.mts +3 -4
  35. package/dist/utils/ssrfGuard.workerd.mjs +2 -2
  36. package/package.json +25 -7
  37. package/src/composio.ts +86 -2
  38. package/src/errors/ConnectedAccountsErrors.ts +47 -0
  39. package/src/errors/ToolErrors.ts +1 -0
  40. package/src/errors/ValidationErrors.ts +2 -0
  41. package/src/index.ts +21 -0
  42. package/src/models/ConnectedAccounts.ts +118 -2
  43. package/src/models/CustomTool.ts +41 -6
  44. package/src/models/CustomToolkits.ts +169 -0
  45. package/src/models/Experimental.ts +27 -0
  46. package/src/models/Keyring.ts +65 -0
  47. package/src/models/Logs.ts +101 -0
  48. package/src/models/RemoteFile.ts +54 -36
  49. package/src/models/ToolRouterSession.ts +60 -4
  50. package/src/models/Toolkits.ts +180 -0
  51. package/src/models/Tools.ts +3 -1
  52. package/src/models/Triggers.ts +17 -87
  53. package/src/models/Usage.ts +119 -0
  54. package/src/models/Webhooks.ts +520 -0
  55. package/src/services/telemetry/TelemetryService.ts +27 -12
  56. package/src/telemetry/redact.ts +133 -6
  57. package/src/types/authConfigs.types.ts +2 -0
  58. package/src/types/connectedAccounts.types.ts +54 -0
  59. package/src/types/customToolkits.types.ts +102 -0
  60. package/src/types/keyring.types.ts +32 -0
  61. package/src/types/logs.types.ts +108 -0
  62. package/src/types/toolRouter.types.ts +49 -1
  63. package/src/types/toolkit.types.ts +131 -0
  64. package/src/types/usage.types.ts +81 -0
  65. package/src/types/webhooks.types.ts +143 -0
  66. package/src/utils/constants.ts +1 -5
  67. package/src/utils/fileUtils.node.ts +10 -2
  68. package/src/utils/jsonSchema.ts +509 -28
  69. package/src/utils/logger.ts +45 -13
  70. package/src/utils/pinnedDispatcher.node.ts +109 -13
  71. package/src/utils/sdk.ts +1 -1
  72. package/src/utils/ssrfGuard.node.ts +124 -21
  73. package/src/utils/ssrfGuard.workerd.ts +5 -1
  74. package/src/utils/transformers/connectedAccounts.ts +37 -2
  75. package/src/utils/transformers/customToolkits.ts +98 -0
  76. package/src/utils/transformers/keyring.ts +24 -0
  77. package/src/utils/transformers/logs.ts +85 -0
  78. package/src/utils/transformers/toolkits.ts +100 -1
  79. package/src/utils/transformers/triggers.ts +2 -2
  80. package/src/utils/transformers/usage.ts +77 -0
  81. package/src/utils/transformers/webhooks.ts +139 -0
  82. package/dist/cancellation-C-qy8rcj.mjs +0 -364
@@ -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
+ }
@@ -8,7 +8,12 @@ function getParentDir(filePath: string): string {
8
8
  return filePath.slice(0, lastSep);
9
9
  }
10
10
  import { RemoteFileData, RemoteFileDataSchema } from '../types/ToolRouterSessionFilesMount.types';
11
- import { RemoteFileDownloadError, ValidationError } from '../errors';
11
+ import {
12
+ ComposioBlockedInternalUrlError,
13
+ RemoteFileDownloadError,
14
+ ValidationError,
15
+ } from '../errors';
16
+ import { readResponseBodyWithLimit } from '../utils/readResponseBody';
12
17
 
13
18
  /**
14
19
  * Represents a file stored in a tool router session's file mount.
@@ -77,31 +82,58 @@ export class RemoteFile {
77
82
  return platform.basename(this.mountRelativePath);
78
83
  }
79
84
 
85
+ private downloadError(message: string, cause: unknown, response?: Response) {
86
+ return new RemoteFileDownloadError(message, {
87
+ statusCode: response?.status,
88
+ statusText: response?.statusText,
89
+ downloadUrl: this.downloadUrl,
90
+ mountRelativePath: this.mountRelativePath,
91
+ filename: this.filename,
92
+ cause,
93
+ });
94
+ }
95
+
96
+ private async downloadBytes(): Promise<{ content: Uint8Array; contentType: string }> {
97
+ let response: Response;
98
+ try {
99
+ response = await ssrfSafeFetchWhereSupported(this.downloadUrl);
100
+ } catch (error) {
101
+ if (error instanceof ComposioBlockedInternalUrlError) {
102
+ throw error;
103
+ }
104
+ throw this.downloadError('Failed to download file', error);
105
+ }
106
+
107
+ if (!response.ok) {
108
+ await response.body?.cancel().catch(() => undefined);
109
+ throw this.downloadError(
110
+ `Failed to download file: ${response.status} ${response.statusText}`,
111
+ new Error(`HTTP ${response.status}: ${response.statusText}`),
112
+ response
113
+ );
114
+ }
115
+
116
+ try {
117
+ const content = response.body
118
+ ? await readResponseBodyWithLimit(response)
119
+ : new Uint8Array(await response.arrayBuffer());
120
+ return {
121
+ content,
122
+ contentType: response.headers?.get?.('content-type') ?? '',
123
+ };
124
+ } catch (error) {
125
+ await response.body?.cancel().catch(() => undefined);
126
+ throw this.downloadError('Failed to read downloaded file', error, response);
127
+ }
128
+ }
129
+
80
130
  /**
81
131
  * Fetches the file content as a buffer.
82
132
  * @returns The file content as a Uint8Array
83
133
  * @throws RemoteFileDownloadError if the fetch fails
84
134
  */
85
135
  async buffer(): Promise<Uint8Array> {
86
- // SSRF guard: `downloadUrl` is set from an API response, so it is untrusted
87
- // input like every other response field, and its bytes are handed straight
88
- // back to the caller. See ssrfGuard.node.ts.
89
- const response = await ssrfSafeFetchWhereSupported(this.downloadUrl);
90
- if (!response.ok) {
91
- throw new RemoteFileDownloadError(
92
- `Failed to download file: ${response.status} ${response.statusText}`,
93
- {
94
- statusCode: response.status,
95
- statusText: response.statusText,
96
- downloadUrl: this.downloadUrl,
97
- mountRelativePath: this.mountRelativePath,
98
- filename: this.filename,
99
- cause: new Error(`HTTP ${response.status}: ${response.statusText}`),
100
- }
101
- );
102
- }
103
- const arrayBuffer = await response.arrayBuffer();
104
- return new Uint8Array(arrayBuffer);
136
+ return (await this.downloadBytes()).content;
105
137
  }
106
138
 
107
139
  /**
@@ -120,22 +152,8 @@ export class RemoteFile {
120
152
  * @throws RemoteFileDownloadError if the fetch fails
121
153
  */
122
154
  async blob(): Promise<Blob> {
123
- // SSRF guard: see `buffer()`.
124
- const response = await ssrfSafeFetchWhereSupported(this.downloadUrl);
125
- if (!response.ok) {
126
- throw new RemoteFileDownloadError(
127
- `Failed to download file: ${response.status} ${response.statusText}`,
128
- {
129
- statusCode: response.status,
130
- statusText: response.statusText,
131
- downloadUrl: this.downloadUrl,
132
- mountRelativePath: this.mountRelativePath,
133
- filename: this.filename,
134
- cause: new Error(`HTTP ${response.status}: ${response.statusText}`),
135
- }
136
- );
137
- }
138
- return response.blob();
155
+ const { content, contentType } = await this.downloadBytes();
156
+ return new Blob([content as BlobPart], { type: contentType });
139
157
  }
140
158
 
141
159
  /**
@@ -22,6 +22,9 @@ import {
22
22
  ToolRouterSessionWarning,
23
23
  ToolRouterUpdateSessionConfig,
24
24
  ToolRouterUpdateSessionConfigSchema,
25
+ ToolRouterSessionConfigHistoryOptions,
26
+ ToolRouterSessionConfigHistoryOptionsSchema,
27
+ type ToolRouterSessionConfigHistoryResponse,
25
28
  type ToolRouterSessionDeleteResponse,
26
29
  } from '../types/toolRouter.types';
27
30
  import {
@@ -375,9 +378,13 @@ export class ToolRouterSession<
375
378
  tools: tk.tools.map(tool => {
376
379
  // Look up by toolkit + original slug so toolkits can safely reuse common names
377
380
  // like VERSION, CLICK, or SEARCH without losing the backend-assigned final slug.
381
+ // Only trust a bare alias that belongs to this toolkit.
382
+ const bare = this.customToolsMap!.byOriginalSlug.get(tool.slug.toUpperCase());
378
383
  const entry =
379
384
  findCustomToolMapEntryByToolkitAndOriginalSlug(this.customToolsMap, tk.slug, tool.slug) ??
380
- this.customToolsMap!.byOriginalSlug.get(tool.slug.toUpperCase());
385
+ (bare?.toolkit && bare.toolkit.toLowerCase() === tk.slug.toLowerCase()
386
+ ? bare
387
+ : undefined);
381
388
  return {
382
389
  slug: entry?.finalSlug ?? tool.slug,
383
390
  name: tool.name,
@@ -555,9 +562,10 @@ export class ToolRouterSession<
555
562
  /**
556
563
  * Execute a tool within the session.
557
564
  *
558
- * For custom tools, accepts the original slug (e.g. "GREP") or the
559
- * full slug (e.g. "LOCAL_GREP"). Custom tools are executed in-process;
560
- * remote tools are sent to the Composio backend.
565
+ * For custom tools, accepts the full slug (e.g. "LOCAL_GREP") or the
566
+ * original slug (e.g. "GREP") when that original slug is unique across
567
+ * the session's custom tools and toolkits. Custom tools are executed
568
+ * in-process; remote tools are sent to the Composio backend.
561
569
  *
562
570
  * @param toolSlug - The tool slug to execute
563
571
  * @param arguments_ - Optional tool arguments
@@ -687,6 +695,54 @@ export class ToolRouterSession<
687
695
  return deleteToolRouterSession(this.client, this.sessionId, requestOptions);
688
696
  }
689
697
 
698
+ /**
699
+ * Page through this session's configuration history, newest first. The
700
+ * first page starts with the live config (`isCurrent: true`); every
701
+ * `session.update()` archives the previous version as a history row.
702
+ *
703
+ * @param options - Optional `cursor` and `limit` (max 100)
704
+ * @returns The config versions on this page plus pagination info
705
+ * @throws {ValidationError} If the options fail validation
706
+ *
707
+ * @example
708
+ * ```typescript
709
+ * const { items, nextCursor } = await session.configHistory({ limit: 10 });
710
+ * console.log(items[0].version, items[0].isCurrent); // e.g. 3, true
711
+ * console.log(items[1].config.toolkits);
712
+ * ```
713
+ */
714
+ async configHistory(
715
+ options?: ToolRouterSessionConfigHistoryOptions,
716
+ requestOptions?: ComposioRequestOptions
717
+ ): Promise<ToolRouterSessionConfigHistoryResponse> {
718
+ const parsedOptions = ToolRouterSessionConfigHistoryOptionsSchema.safeParse(options ?? {});
719
+ if (!parsedOptions.success) {
720
+ throw new ValidationError('Failed to parse config history options', {
721
+ cause: parsedOptions.error,
722
+ });
723
+ }
724
+ const query = {
725
+ cursor: parsedOptions.data.cursor,
726
+ limit: parsedOptions.data.limit,
727
+ };
728
+ const response = await withCancellation(
729
+ () => this.client.toolRouter.session.configHistory(this.sessionId, query, requestOptions),
730
+ requestOptions?.signal
731
+ );
732
+ return {
733
+ items: response.items.map(item => ({
734
+ version: item.version,
735
+ createdAt: item.created_at,
736
+ isCurrent: item.is_current,
737
+ config: item.config,
738
+ })),
739
+ nextCursor: response.next_cursor ?? null,
740
+ totalPages: response.total_pages,
741
+ currentPage: response.current_page,
742
+ totalItems: response.total_items,
743
+ };
744
+ }
745
+
690
746
  // ── Private helpers ──────────────────────────────────────────
691
747
 
692
748
  /** Check if this session has any custom tools bound. */