@composio/core 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/{CustomTool-BMlZfJVz.mjs → CustomTool-B-_VjWpy.mjs} +1 -1
  2. package/dist/{CustomTool-CB5vm1Jc.d.mts → CustomTool-BHOYxLZX.d.mts} +1 -1
  3. package/dist/{FileModifierErrors-BqFmpRsm.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
  4. package/dist/{SsrfErrors-C91YhASE.mjs → SsrfErrors-DiQldIdC.mjs} +18 -7
  5. package/dist/{Telemetry-HlftxMx6.mjs → Telemetry-JRJJYS4I.mjs} +2 -2
  6. package/dist/{cancellation-CXpfmiVo.mjs → cancellation-DV8CIi52.mjs} +2 -2
  7. package/dist/{composio-DLGaeN70.d.mts → composio-BTZsFajb.d.mts} +3149 -117
  8. package/dist/{customTool.types-BAmEh3MB.d.mts → customTool.types-D_w21L56.d.mts} +784 -56
  9. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
  10. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +7 -3
  11. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +101 -18
  12. package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +123 -0
  13. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +9 -2
  14. package/dist/docs/reference/sdk-reference/typescript/index.mdx +8 -0
  15. package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +56 -0
  16. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +78 -0
  17. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
  18. package/dist/docs/reference/sdk-reference/typescript/meta.json +9 -1
  19. package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +83 -0
  20. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
  21. package/dist/docs/reference/sdk-reference/typescript/session.mdx +86 -27
  22. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +26 -6
  23. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +149 -12
  24. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +18 -18
  25. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +25 -25
  26. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +78 -0
  27. package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +162 -0
  28. package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +218 -0
  29. package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +20 -0
  30. package/dist/{errors-BuEKehbI.mjs → errors-Dyiu3ifQ.mjs} +127 -4
  31. package/dist/experimental/index.d.mts +2 -2
  32. package/dist/experimental/index.mjs +1 -1
  33. package/dist/{fileUtils.node-L7XD8UPr.mjs → fileUtils.node-DNLhLg0W.mjs} +4 -4
  34. package/dist/index.d.mts +281 -55
  35. package/dist/index.mjs +3552 -949
  36. package/dist/models/Files.node.mjs +2 -2
  37. package/dist/{sensitiveFileUploadPaths-B6pBt9lO.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +1 -1
  38. package/dist/{ssrfGuard.node-B9xQB4za.mjs → ssrfGuard.node-BZ270bcu.mjs} +1 -1
  39. package/dist/{types-CxLPO0Xq.d.mts → types-CgRsUGqm.d.mts} +2 -2
  40. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  41. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  42. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  43. package/dist/utils/modifiers/FileToolModifier.node.mjs +5 -5
  44. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  45. package/dist/utils/ssrfGuard.node.mjs +1 -1
  46. package/dist/utils/ssrfGuard.workerd.mjs +1 -1
  47. package/package.json +4 -2
  48. package/src/composio.ts +215 -10
  49. package/src/errors/ConnectedAccountsErrors.ts +47 -0
  50. package/src/errors/SDKErrors.ts +52 -0
  51. package/src/errors/ToolRouterErrors.ts +61 -0
  52. package/src/errors/index.ts +3 -0
  53. package/src/index.ts +13 -0
  54. package/src/lib/sessionConfigConflict.ts +43 -0
  55. package/src/lib/toolRouterMcp.ts +132 -0
  56. package/src/lib/toolRouterParams.ts +149 -37
  57. package/src/lib/toolRouterSourceSessionConfig.ts +12 -0
  58. package/src/models/ConnectedAccounts.ts +118 -2
  59. package/src/models/CustomToolkits.ts +169 -0
  60. package/src/models/Experimental.ts +27 -0
  61. package/src/models/Keyring.ts +65 -0
  62. package/src/models/Logs.ts +101 -0
  63. package/src/models/RemoteFile.ts +25 -8
  64. package/src/models/SessionConfigs.ts +117 -0
  65. package/src/models/ToolRouter.ts +61 -17
  66. package/src/models/ToolRouterSession.ts +149 -14
  67. package/src/models/Toolkits.ts +180 -0
  68. package/src/models/Tools.ts +10 -6
  69. package/src/models/Triggers.ts +3 -88
  70. package/src/models/Usage.ts +119 -0
  71. package/src/models/Webhooks.ts +520 -0
  72. package/src/services/pusher/Pusher.ts +17 -6
  73. package/src/types/authConfigs.types.ts +2 -0
  74. package/src/types/connectedAccounts.types.ts +54 -0
  75. package/src/types/customToolkits.types.ts +102 -0
  76. package/src/types/keyring.types.ts +32 -0
  77. package/src/types/logs.types.ts +108 -0
  78. package/src/types/sessionConfigs.types.ts +81 -0
  79. package/src/types/tool.types.ts +2 -0
  80. package/src/types/toolRouter.types.ts +352 -16
  81. package/src/types/toolkit.types.ts +144 -0
  82. package/src/types/usage.types.ts +81 -0
  83. package/src/types/webhooks.types.ts +143 -0
  84. package/src/utils/constants.ts +1 -5
  85. package/src/utils/logger.ts +39 -7
  86. package/src/utils/safePath.ts +172 -0
  87. package/src/utils/sdk.ts +385 -22
  88. package/src/utils/transformers/connectedAccounts.ts +37 -2
  89. package/src/utils/transformers/customToolkits.ts +98 -0
  90. package/src/utils/transformers/keyring.ts +24 -0
  91. package/src/utils/transformers/logs.ts +85 -0
  92. package/src/utils/transformers/sessionConfigs.ts +54 -0
  93. package/src/utils/transformers/toolRouterResponseTransform.ts +6 -0
  94. package/src/utils/transformers/toolkits.ts +106 -3
  95. package/src/utils/transformers/triggers.ts +2 -2
  96. package/src/utils/transformers/usage.ts +77 -0
  97. package/src/utils/transformers/webhooks.ts +139 -0
@@ -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
+ }
@@ -14,6 +14,7 @@ import {
14
14
  ValidationError,
15
15
  } from '../errors';
16
16
  import { readResponseBodyWithLimit } from '../utils/readResponseBody';
17
+ import { safeBasename, untrustedBasename } from '../utils/safePath';
17
18
 
18
19
  /**
19
20
  * Represents a file stored in a tool router session's file mount.
@@ -77,9 +78,20 @@ export class RemoteFile {
77
78
  return new RemoteFile(parsed.data);
78
79
  }
79
80
 
80
- /** Filename extracted from the mount path (e.g. "report.pdf" from "output/report.pdf") */
81
+ /**
82
+ * Filename extracted from the mount path (e.g. "report.pdf" from "output/report.pdf").
83
+ *
84
+ * Deliberately non-throwing: this is a display value, and `downloadBytes()`
85
+ * reads it while constructing `RemoteFileDownloadError`. A validator here
86
+ * would replace a genuine download error with a validation error thrown from
87
+ * inside the error constructor. {@link save} validates instead, at the point
88
+ * the value actually becomes a path.
89
+ *
90
+ * Both `/` and `\` count as separators, as in the Python SDK, so a mount path
91
+ * crafted for a Windows target is reduced the same way on every platform.
92
+ */
81
93
  get filename(): string {
82
- return platform.basename(this.mountRelativePath);
94
+ return untrustedBasename(this.mountRelativePath);
83
95
  }
84
96
 
85
97
  private downloadError(message: string, cause: unknown, response?: Response) {
@@ -163,6 +175,7 @@ export class RemoteFile {
163
175
  * @param path - Local path to save the file. If omitted, saves to the Composio temp directory using the filename from the mount path.
164
176
  * @returns The absolute path where the file was saved
165
177
  * @throws Error if file system is not supported or the save fails
178
+ * @throws ValidationError if `path` is omitted and the mount path yields no usable filename
166
179
  */
167
180
  async save(path?: string): Promise<string> {
168
181
  if (!platform.supportsFileSystem) {
@@ -172,19 +185,23 @@ export class RemoteFile {
172
185
  );
173
186
  }
174
187
 
175
- const content = await this.buffer();
176
188
  const homeDir = platform.homedir();
177
189
  if (!homeDir) {
178
190
  throw new Error('Cannot determine save location: home directory is not available');
179
191
  }
180
192
 
193
+ // An explicit `path` is the caller's own. The default branch builds a path
194
+ // out of `mountRelativePath`, a server-controlled response field, so it is
195
+ // validated first (SEC-316, mirroring the Python SDK): a value such as `""`,
196
+ // `"."` or `"foo/.."` would otherwise make `savePath` its own directory or
197
+ // the parent, and fail with a raw `EISDIR` only after `mkdirSync` had run.
198
+ const defaultDir = platform.joinPath(homeDir, COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
181
199
  const savePath =
182
- path ?? platform.joinPath(homeDir, COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME, this.filename);
200
+ path ?? platform.joinPath(defaultDir, safeBasename(this.mountRelativePath, 'mount path'));
201
+
202
+ const content = await this.buffer();
183
203
 
184
- const dir =
185
- path != null
186
- ? getParentDir(savePath)
187
- : platform.joinPath(homeDir, COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
204
+ const dir = path != null ? getParentDir(savePath) : defaultDir;
188
205
  if (dir && !platform.existsSync(dir)) {
189
206
  platform.mkdirSync(dir);
190
207
  }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * @fileoverview The `composio.sessionConfigs` namespace: read the saved
3
+ * Session configs of the project.
4
+ *
5
+ * @module SessionConfigs
6
+ */
7
+ import ComposioClient from '@composio/client';
8
+ import {
9
+ SessionConfig,
10
+ SessionConfigListParams,
11
+ SessionConfigListParamsSchema,
12
+ SessionConfigListResponse,
13
+ } from '../types/sessionConfigs.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
+ transformSessionConfig,
20
+ transformSessionConfigListResponse,
21
+ } from '../utils/transformers/sessionConfigs';
22
+
23
+ /**
24
+ * `composio.sessionConfigs` — saved, reusable Session configs.
25
+ *
26
+ * A Session config is a named access policy (`sc_…`) built in the Composio
27
+ * Dashboard under Sessions → Configs. Pass its id as
28
+ * `experimental.sessionConfigId` to `composio.sessions.create()` or
29
+ * `session.update()` to apply it.
30
+ *
31
+ * These endpoints require Session configs to be enabled for the project;
32
+ * otherwise the backend returns 403.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const { items } = await composio.sessionConfigs.list({ search: 'support' });
37
+ * const sessionConfig = await composio.sessionConfigs.get(items[0].id);
38
+ * const session = await composio.sessions.create('user_123', {
39
+ * experimental: { sessionConfigId: sessionConfig.id },
40
+ * });
41
+ * ```
42
+ */
43
+ export class SessionConfigs {
44
+ private client: ComposioClient;
45
+
46
+ constructor(client: ComposioClient) {
47
+ this.client = client;
48
+ telemetry.instrument(this, 'SessionConfigs');
49
+ }
50
+
51
+ /**
52
+ * List the project's saved Session configs with cursor pagination.
53
+ *
54
+ * Omitting `archived` returns active configs; `archived: true` returns only
55
+ * archived ones. The backend defaults `limit` to 20 and caps it at 100.
56
+ *
57
+ * Requires Session configs to be enabled for the project.
58
+ *
59
+ * @param {SessionConfigListParams} [params] - `search`, `archived`, `limit` and `cursor`
60
+ * @returns {Promise<SessionConfigListResponse>} Config summaries and the next cursor
61
+ * @throws {ValidationError} If the params fail validation
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * let cursor: string | undefined;
66
+ * do {
67
+ * const page = await composio.sessionConfigs.list({ cursor });
68
+ * for (const item of page.items) console.log(item.id, item.name);
69
+ * cursor = page.nextCursor ?? undefined;
70
+ * } while (cursor);
71
+ * ```
72
+ */
73
+ async list(
74
+ params?: SessionConfigListParams,
75
+ requestOptions?: ComposioRequestOptions
76
+ ): Promise<SessionConfigListResponse> {
77
+ const parsedParams = SessionConfigListParamsSchema.safeParse(params ?? {});
78
+ if (!parsedParams.success) {
79
+ throw new ValidationError('Failed to parse session config list params', {
80
+ cause: parsedParams.error,
81
+ });
82
+ }
83
+ const result = await withCancellation(
84
+ () => this.client.sessionConfigs.list(parsedParams.data, requestOptions),
85
+ requestOptions?.signal
86
+ );
87
+ return transformSessionConfigListResponse(result);
88
+ }
89
+
90
+ /**
91
+ * Retrieve one saved Session config with its description and access
92
+ * policy. A missing or cross-project id surfaces as the backend's 404.
93
+ *
94
+ * Requires Session configs to be enabled for the project.
95
+ *
96
+ * @param {string} id - The `sc_…` id of the Session config
97
+ * @returns {Promise<SessionConfig>} The config and its policy
98
+ * @throws {ValidationError} If `id` is empty
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const sessionConfig = await composio.sessionConfigs.get('sc_abc123');
103
+ * console.log(sessionConfig.config.toolkits);
104
+ * ```
105
+ */
106
+ async get(id: string, requestOptions?: ComposioRequestOptions): Promise<SessionConfig> {
107
+ // An empty id would request the collection path and return a list page.
108
+ if (id.trim() === '') {
109
+ throw new ValidationError('Session config id must be a non-empty string');
110
+ }
111
+ const result = await withCancellation(
112
+ () => this.client.sessionConfigs.retrieve(id, requestOptions),
113
+ requestOptions?.signal
114
+ );
115
+ return transformSessionConfig(result);
116
+ }
117
+ }