@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
@@ -1,5 +1,5 @@
1
- import { t as telemetry } from "../Telemetry-HlftxMx6.mjs";
2
- import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-L7XD8UPr.mjs";
1
+ import { t as telemetry } from "../Telemetry-JRJJYS4I.mjs";
2
+ import { n as getFileDataAfterUploadingToS3, t as downloadFileFromS3 } from "../fileUtils.node-DNLhLg0W.mjs";
3
3
 
4
4
  //#region src/models/Files.node.ts
5
5
  var Files = class {
@@ -1,4 +1,4 @@
1
- import { a as ComposioSensitiveFilePathBlockedError } from "./FileModifierErrors-BqFmpRsm.mjs";
1
+ import { a as ComposioSensitiveFilePathBlockedError } from "./FileModifierErrors-CdGSABoq.mjs";
2
2
  import { platform } from "#platform";
3
3
 
4
4
  //#region src/utils/uuid.ts
@@ -1,4 +1,4 @@
1
- import { t as ComposioBlockedInternalUrlError } from "./SsrfErrors-C91YhASE.mjs";
1
+ import { t as ComposioBlockedInternalUrlError } from "./SsrfErrors-DiQldIdC.mjs";
2
2
  import { lookup } from "node:dns/promises";
3
3
  import { isIP } from "node:net";
4
4
  import { request } from "node:http";
@@ -1,5 +1,5 @@
1
- import { Ln as BaseComposioProvider } from "./customTool.types-BAmEh3MB.mjs";
2
- import { n as ComposioConfig } from "./composio-DLGaeN70.mjs";
1
+ import { rr as BaseComposioProvider } from "./customTool.types-D_w21L56.mjs";
2
+ import { n as ComposioConfig } from "./composio-BTZsFajb.mjs";
3
3
  //#region src/utils/config-defaults/types.d.ts
4
4
  /**
5
5
  * Configuration defaults for Composio.
@@ -1,4 +1,4 @@
1
- import { t as ConfigDefaults } from "../../types-CxLPO0Xq.mjs";
1
+ import { t as ConfigDefaults } from "../../types-CgRsUGqm.mjs";
2
2
  //#region src/utils/config-defaults/ConfigDefaults.node.d.ts
3
3
  export declare const CONFIG_DEFAULTS: ConfigDefaults;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { t as ConfigDefaults } from "../../types-CxLPO0Xq.mjs";
1
+ import { t as ConfigDefaults } from "../../types-CgRsUGqm.mjs";
2
2
  //#region src/utils/config-defaults/ConfigDefaults.workerd.d.ts
3
3
  export declare const CONFIG_DEFAULTS: ConfigDefaults;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { $i as Tool, ia as ToolExecuteResponse, na as ToolExecuteParams } from "../../customTool.types-BAmEh3MB.mjs";
1
+ import { Sa as ToolExecuteParams, wa as ToolExecuteResponse, ya as Tool } from "../../customTool.types-D_w21L56.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  //#region src/utils/modifiers/FileToolModifier.node.d.ts
4
4
  export declare class FileToolModifier {
@@ -1,9 +1,9 @@
1
- import { i as logger } from "../../SsrfErrors-C91YhASE.mjs";
2
- import { f as ComposioRequestCancelledError } from "../../errors-BuEKehbI.mjs";
3
- import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, n as ComposioFileUploadAbortedError, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "../../FileModifierErrors-BqFmpRsm.mjs";
1
+ import { i as logger } from "../../SsrfErrors-DiQldIdC.mjs";
2
+ import { g as ComposioRequestCancelledError } from "../../errors-Dyiu3ifQ.mjs";
3
+ import { a as ComposioSensitiveFilePathBlockedError, i as ComposioFileUploadPathNotAllowedError, n as ComposioFileUploadAbortedError, r as ComposioFileUploadError, t as ComposioFileNotFoundError } from "../../FileModifierErrors-CdGSABoq.mjs";
4
4
  import { a as isEmptyFileValue, c as transformProperties, i as getSchemaVariants, l as walkFileUploadableLeaves, o as isPlainObject, r as findSchemaVariantWithFileProperty, t as DELETE_VALUE } from "../../FileToolModifier.utils.neutral-DWFpnsj2.mjs";
5
- import { r as dereferenceJsonSchema, t as withCancellation } from "../../cancellation-CXpfmiVo.mjs";
6
- import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-L7XD8UPr.mjs";
5
+ import { r as dereferenceJsonSchema, t as withCancellation } from "../../cancellation-DV8CIi52.mjs";
6
+ import { n as getFileDataAfterUploadingToS3, r as isHttpUrl, t as downloadFileFromS3 } from "../../fileUtils.node-DNLhLg0W.mjs";
7
7
 
8
8
  //#region src/utils/modifiers/FileToolModifier.node.ts
9
9
  /**
@@ -1,4 +1,4 @@
1
- import { $i as Tool, ia as ToolExecuteResponse, na as ToolExecuteParams } from "../../customTool.types-BAmEh3MB.mjs";
1
+ import { Sa as ToolExecuteParams, wa as ToolExecuteResponse, ya as Tool } from "../../customTool.types-D_w21L56.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  //#region src/utils/modifiers/FileToolModifier.workerd.d.ts
4
4
  export declare class FileToolModifier {
@@ -1,3 +1,3 @@
1
- import { i as ssrfSafeFetchWhereSupported, n as isBlockedIp, r as ssrfSafeFetch, t as assertSafeFetchTarget } from "../ssrfGuard.node-B9xQB4za.mjs";
1
+ import { i as ssrfSafeFetchWhereSupported, n as isBlockedIp, r as ssrfSafeFetch, t as assertSafeFetchTarget } from "../ssrfGuard.node-BZ270bcu.mjs";
2
2
 
3
3
  export { assertSafeFetchTarget, isBlockedIp, ssrfSafeFetch, ssrfSafeFetchWhereSupported };
@@ -1,4 +1,4 @@
1
- import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-C91YhASE.mjs";
1
+ import { t as ComposioBlockedInternalUrlError } from "../SsrfErrors-DiQldIdC.mjs";
2
2
 
3
3
  //#region src/utils/ssrfGuard.workerd.ts
4
4
  /**
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "engines": {
5
5
  "node": ">=22.22.3"
6
6
  },
7
- "version": "0.19.0",
7
+ "version": "0.21.0",
8
8
  "description": "",
9
9
  "main": "dist/index.mjs",
10
10
  "publishConfig": {
@@ -110,8 +110,10 @@
110
110
  ],
111
111
  "license": "ISC",
112
112
  "devDependencies": {
113
+ "@hono/node-server": "^2.1.1",
113
114
  "@type-challenges/utils": "^0.1.1",
114
115
  "@types/semver": "^7.8.0",
116
+ "hono": "^4.13.7",
115
117
  "tsdown": "^0.23.0",
116
118
  "tsx": "^4.23.13",
117
119
  "typedoc": "^0.28.20",
@@ -123,7 +125,7 @@
123
125
  "zod": ">=3.25.76 <5"
124
126
  },
125
127
  "dependencies": {
126
- "@composio/client": "0.1.0-alpha.76",
128
+ "@composio/client": "2.0.0-rc.8",
127
129
  "@types/json-schema": "^7.0.15",
128
130
  "is-fs-case-sensitive": "^2.0.0",
129
131
  "openai": "^7.15.0",
package/src/composio.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { BaseComposioProvider } from './provider/BaseProvider';
2
2
  import ComposioClient from '@composio/client';
3
+ import type { Logger as ClientLogger, LogLevel as ClientLogLevel } from '@composio/client';
3
4
  import { Tools } from './models/Tools';
4
5
  import { Toolkits } from './models/Toolkits';
5
6
  import { Triggers } from './models/Triggers';
@@ -7,10 +8,23 @@ import { AuthConfigs } from './models/AuthConfigs';
7
8
  import { ConnectedAccounts } from './models/ConnectedAccounts';
8
9
  import { Experimental } from './models/Experimental';
9
10
  import { MCP } from './models/MCP';
11
+ import { Webhooks } from './models/Webhooks';
12
+ import { Logs } from './models/Logs';
13
+ import { SessionConfigs } from './models/SessionConfigs';
14
+ import { Keyring } from './models/Keyring';
10
15
  import { telemetry } from './telemetry/Telemetry';
11
- import { getSDKConfig, getToolkitVersionsFromEnv } from './utils/sdk';
16
+ import {
17
+ getScopeHeaders,
18
+ getSDKConfig,
19
+ getToolkitVersionsFromEnv,
20
+ getUserApiKeyHeader,
21
+ resolveSDKScope,
22
+ resolveUserApiKey,
23
+ USER_API_KEY_HEADER,
24
+ } from './utils/sdk';
12
25
  import logger from './utils/logger';
13
- import { COMPOSIO_LOG_LEVEL, IS_DEVELOPMENT_OR_CI } from './utils/constants';
26
+ import type { ComposioLogger, LogLevel } from './utils/logger';
27
+ import { IS_DEVELOPMENT_OR_CI } from './utils/constants';
14
28
  import { checkForLatestVersionFromNPM } from './utils/version';
15
29
  import { OpenAIProvider } from './provider/OpenAIProvider';
16
30
  import { version } from '../package.json';
@@ -27,10 +41,62 @@ export type ComposioConfig<
27
41
  TProvider extends BaseComposioProvider<unknown, unknown, unknown> = OpenAIProvider,
28
42
  > = {
29
43
  /**
30
- * The API key for the Composio API.
31
- * @example 'sk-1234567890'
44
+ * The project API key for the Composio API, sent as the `x-api-key` header.
45
+ *
46
+ * - A string is used as-is; the environment and the CLI user config file are not consulted.
47
+ * - Omitted: falls back to `COMPOSIO_API_KEY`, then to the project key stored by the Composio
48
+ * CLI in `~/.composio/user_data.json`. A stored user key (`uak_...`) is never used as a
49
+ * project key; the SDK throws instead of sending it.
50
+ * - `null`: disables project-key authentication entirely, including both fallbacks. The SDK
51
+ * then requires another credential (`userApiKey`, `orgApiKey`, or an `x-user-api-key`
52
+ * entry in `defaultHeaders`) and sends no `x-api-key`; an `x-api-key` entry in
53
+ * `defaultHeaders` is rejected, also on `createSession()` clones.
54
+ *
55
+ * @example 'ak_1234567890'
32
56
  */
33
57
  apiKey?: string | null;
58
+ /**
59
+ * User API key (`uak_*`) for the organization, consumer, and user-scoped
60
+ * endpoints reached through `getClient()` (for example `client.org.list()`).
61
+ * Sent as `x-user-api-key` only on operations whose security scheme accepts
62
+ * it, never alongside the project key. Falls back to
63
+ * `process.env['COMPOSIO_USER_API_KEY']`; `null` disables that fallback.
64
+ * Combine with `apiKey: null` to authenticate with the user key alone.
65
+ * @example 'uak_1234567890'
66
+ */
67
+ userApiKey?: string | null;
68
+ /**
69
+ * Organization API key (`oak_*`) for the organization-owner endpoints reached
70
+ * through `getClient()` (for example `client.org.owner.project.list()`).
71
+ * Sent as `x-org-api-key` only on operations whose security scheme accepts
72
+ * it, never alongside the project key. Falls back to
73
+ * `process.env['COMPOSIO_ORG_API_KEY']`; `null` disables that fallback.
74
+ * Combine with `apiKey: null` to authenticate with the organization key alone.
75
+ * @example 'oak_1234567890'
76
+ */
77
+ orgApiKey?: string | null;
78
+ /**
79
+ * Organization nano ID that scopes user-key requests, sent as the
80
+ * `x-org-id` header on every request and exported with the session MCP
81
+ * config. This is the short public identifier the API returns as `org_id`
82
+ * (for example from the consumer project resolve endpoint), not a UUID.
83
+ * Must be supplied together with `projectId`; without an explicit scope a
84
+ * user API key addresses the API default (the developer project). May also
85
+ * be supplied as the `x-org-id` entry in `defaultHeaders`; the two must
86
+ * agree.
87
+ * @example 'org_9f2k1x'
88
+ */
89
+ orgId?: string;
90
+ /**
91
+ * Project nano ID that scopes user-key requests, sent as the
92
+ * `x-project-id` header on every request and exported with the session MCP
93
+ * config. This is the short public identifier the API returns as
94
+ * `project_nano_id`, not the project UUID. Must be supplied together with
95
+ * `orgId`. May also be supplied as the `x-project-id` entry in
96
+ * `defaultHeaders`; the two must agree.
97
+ * @example 'proj_4b8m2q'
98
+ */
99
+ projectId?: string;
34
100
  /**
35
101
  * The base URL of the Composio API.
36
102
  * @example 'https://backend.composio.dev'
@@ -100,8 +166,13 @@ export type ComposioConfig<
100
166
  */
101
167
  host?: string;
102
168
  /**
103
- * Request options to be passed to the Composio API client.
104
- * This is useful for passing in a custom fetch implementation.
169
+ * Default headers attached to every request made through this instance.
170
+ *
171
+ * `x-user-api-key` is the one header the SDK treats as a credential: together
172
+ * with `apiKey: null` it authenticates requests with a Composio user API key
173
+ * instead of a project key. The project key is only ever set from `apiKey`:
174
+ * an `x-api-key` entry is rejected when `apiKey` is `null`. Every other
175
+ * header is passed through untouched.
105
176
  * @example
106
177
  * ```typescript
107
178
  * const composio = new Composio({
@@ -156,6 +227,68 @@ export type ComposioConfig<
156
227
  * ```
157
228
  */
158
229
  toolkitVersions?: ToolkitVersionParam;
230
+ /**
231
+ * Destination for SDK log output. Messages are formatted and have
232
+ * credential-shaped values redacted before they reach the sink, so any
233
+ * object with `error`/`warn`/`info`/`debug` methods works (`console`, pino,
234
+ * winston, ...).
235
+ *
236
+ * Runtime deprecation warnings raised by the underlying API client (response
237
+ * `Deprecation`/`Sunset` headers and deprecated request inputs) are routed
238
+ * through this logger as well.
239
+ *
240
+ * The SDK logger is process-wide: configuring it on one `Composio` instance
241
+ * affects every instance, and the last configured instance wins.
242
+ *
243
+ * @default console
244
+ * @example
245
+ * ```typescript
246
+ * const composio = new Composio({
247
+ * apiKey: 'your-api-key',
248
+ * logger: pino(),
249
+ * logLevel: 'warn',
250
+ * });
251
+ * ```
252
+ */
253
+ logger?: ComposioLogger;
254
+ /**
255
+ * Minimum level to emit: `'silent' | 'error' | 'warn' | 'info' | 'debug'`.
256
+ * Takes precedence over the `COMPOSIO_LOG_LEVEL` environment variable.
257
+ * Also gates the API client's runtime deprecation warnings (`'silent'` turns
258
+ * them off). The client's per-request lifecycle logs are emitted at
259
+ * `'debug'` only.
260
+ *
261
+ * Like `logger`, this applies process-wide and the last configured instance
262
+ * wins. The API client's own level is fixed when each instance is created.
263
+ *
264
+ * @default 'info' (or `COMPOSIO_LOG_LEVEL` when set)
265
+ */
266
+ logLevel?: LogLevel;
267
+ };
268
+
269
+ /**
270
+ * Level for the API client given the SDK level. The client logs each request's
271
+ * lifecycle at `info`, which is debug-grade for SDK users, so the client stays
272
+ * at `warn` unless the SDK is at `debug`. The client's `LogLevel` has
273
+ * `'off'` where the SDK has `'silent'`.
274
+ */
275
+ const toClientLogLevel = (level: LogLevel): ClientLogLevel => {
276
+ if (level === 'silent') return 'off';
277
+ if (level === 'info') return 'warn';
278
+ return level;
279
+ };
280
+
281
+ /**
282
+ * Forwards the API client's log records to the SDK singleton so they pick up
283
+ * the SDK's formatting, redaction, and configured sink. Methods are looked up
284
+ * at call time so a later `logger.configure()` is honoured. The client's
285
+ * `info` records (per-request lifecycle) are forwarded as SDK `debug`.
286
+ */
287
+ const clientLoggerAdapter: ClientLogger = {
288
+ error: (...args) => logger.error(...args),
289
+ warn: (...args) => logger.warn(...args),
290
+ info: (...args) => logger.debug(...args),
291
+ debug: (...args) => logger.debug(...args),
159
292
  };
160
293
 
161
294
  /**
@@ -195,6 +328,15 @@ export class Composio<
195
328
  authConfigs: AuthConfigs;
196
329
  /** Manage authenticated connections */
197
330
  connectedAccounts: ConnectedAccounts;
331
+ /**
332
+ * Manage the project's webhook subscription (`webhooks.subscriptions`) and
333
+ * inbound per-toolkit webhook endpoints (`webhooks.endpoints`).
334
+ */
335
+ webhooks: Webhooks;
336
+ /** Search and inspect tool-execution logs */
337
+ logs: Logs;
338
+ /** Public transfer keys of the organization's customer-managed keyring */
339
+ keyring: Keyring;
198
340
  /**
199
341
  * Experimental SDK methods whose shape may change in future releases.
200
342
  * Prefer domain-specific mounts (for example
@@ -221,6 +363,12 @@ export class Composio<
221
363
  * `composio.create(...)` method is kept as an alias.
222
364
  */
223
365
  sessions: Sessions<unknown, unknown, TProvider>;
366
+ /**
367
+ * Read the project's saved Session configs. Apply one with
368
+ * `experimental.sessionConfigId` on `sessions.create()` or `session.update()`.
369
+ * Requires Session configs to be enabled for the project.
370
+ */
371
+ sessionConfigs: SessionConfigs;
224
372
  /**
225
373
  * Legacy alias for `composio.sessions`.
226
374
  * @deprecated Use `composio.sessions` instead — `toolRouter` was renamed to `sessions` and is kept only for backwards compatibility. Prefer `composio.sessions`; do not generate new code against `composio.toolRouter`.
@@ -302,11 +450,36 @@ export class Composio<
302
450
  * ```
303
451
  */
304
452
  constructor(config?: ComposioConfig<TProvider>) {
453
+ const scope = resolveSDKScope({
454
+ orgId: config?.orgId,
455
+ projectId: config?.projectId,
456
+ defaultHeaders: config?.defaultHeaders,
457
+ });
305
458
  const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getSDKConfig(
306
459
  config?.baseURL,
307
- config?.apiKey
460
+ config?.apiKey,
461
+ {
462
+ defaultHeaders: config?.defaultHeaders,
463
+ userApiKey: config?.userApiKey,
464
+ orgApiKey: config?.orgApiKey,
465
+ }
308
466
  );
309
467
 
468
+ // The API client sends its user key only on operations whose security
469
+ // scheme names it, which excludes sessions. With the project key disabled
470
+ // the resolved user key is placed as the `x-user-api-key` default header
471
+ // instead, so every request carries exactly that credential and clones,
472
+ // the MCP export, and trigger subscriptions read the same header.
473
+ const userApiKey = apiKeyParsed === null ? resolveUserApiKey(config?.userApiKey) : undefined;
474
+ const defaultHeadersInput =
475
+ userApiKey !== undefined && !getUserApiKeyHeader(config?.defaultHeaders)
476
+ ? { ...config?.defaultHeaders, [USER_API_KEY_HEADER]: userApiKey }
477
+ : config?.defaultHeaders;
478
+
479
+ if (config?.logger !== undefined || config?.logLevel !== undefined) {
480
+ logger.configure({ level: config.logLevel, sink: config.logger });
481
+ }
482
+
310
483
  if (IS_DEVELOPMENT_OR_CI) {
311
484
  logger.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
312
485
  }
@@ -324,6 +497,7 @@ export class Composio<
324
497
  ...config,
325
498
  baseURL: baseURLParsed,
326
499
  apiKey: apiKeyParsed,
500
+ defaultHeaders: defaultHeadersInput,
327
501
  toolkitVersions: getToolkitVersionsFromEnv(config?.toolkitVersions),
328
502
  allowTracking: config?.allowTracking ?? CONFIG_DEFAULTS.allowTracking,
329
503
  dangerouslyAllowAutoUploadDownloadFiles:
@@ -334,9 +508,16 @@ export class Composio<
334
508
  fileUploadDirs: expandHomeAndResolveMany(config?.fileUploadDirs),
335
509
  fileDownloadDir: expandHomeAndResolve(config?.fileDownloadDir),
336
510
  provider: config?.provider ?? this.provider,
511
+ orgId: scope.orgId,
512
+ projectId: scope.projectId,
337
513
  };
338
514
 
339
- const defaultHeaders = getDefaultHeaders(this.config.defaultHeaders, this.provider);
515
+ // The resolved scope is the single source of the x-org-id / x-project-id
516
+ // headers: it travels via `this.config` to clones and to the MCP export.
517
+ const defaultHeaders = getDefaultHeaders(
518
+ { ...this.config.defaultHeaders, ...getScopeHeaders(scope) },
519
+ this.provider
520
+ );
340
521
 
341
522
  /**
342
523
  * Initialize the Composio SDK client.
@@ -344,11 +525,20 @@ export class Composio<
344
525
  */
345
526
  this.client = new ComposioClient({
346
527
  apiKey: apiKeyParsed,
528
+ userApiKey: config?.userApiKey,
529
+ orgApiKey: config?.orgApiKey,
347
530
  baseURL: baseURLParsed,
348
531
  defaultHeaders: defaultHeaders,
349
- logLevel: COMPOSIO_LOG_LEVEL,
532
+ logger: clientLoggerAdapter,
533
+ logLevel: toClientLogLevel(logger.getLevel()),
350
534
  });
351
535
 
536
+ // Store the resolved values, as with `apiKey`, so `getConfig()` and the
537
+ // `createSession()` clone carry whatever the client resolved from env
538
+ // rather than re-reading the environment later.
539
+ this.config.userApiKey = this.client.userApiKey;
540
+ this.config.orgApiKey = this.client.orgApiKey;
541
+
352
542
  this.tools = new Tools(this.client, this.config);
353
543
  this.mcp = new MCP(this.client);
354
544
  this.toolkits = new Toolkits(this.client);
@@ -360,9 +550,13 @@ export class Composio<
360
550
  fileDownloadDir: this.config.fileDownloadDir,
361
551
  });
362
552
  this.connectedAccounts = new ConnectedAccounts(this.client);
553
+ this.webhooks = new Webhooks(this.client);
554
+ this.logs = new Logs(this.client);
555
+ this.keyring = new Keyring(this.client);
363
556
  this.experimental = new Experimental(this.client);
364
557
  this.sessions = new Sessions(this.client, this.config);
365
558
  this.toolRouter = this.sessions;
559
+ this.sessionConfigs = new SessionConfigs(this.client);
366
560
 
367
561
  /**
368
562
  * Initialize session aliases.
@@ -469,7 +663,18 @@ export class Composio<
469
663
  * ```
470
664
  */
471
665
  createSession(options?: { headers?: ComposioRequestHeaders }): Composio<TProvider> {
472
- const sessionHeaders = getDefaultHeaders(options?.headers, this.provider);
666
+ // The clone inherits the resolved credentials: the project, user, and
667
+ // organization keys travel via `this.config`; a user API key placed in the
668
+ // default headers travels via its header unless the caller overrides it.
669
+ const userApiKeyHeader = getUserApiKeyHeader(options?.headers)
670
+ ? undefined
671
+ : getUserApiKeyHeader(this.config.defaultHeaders);
672
+ const sessionHeaders = getDefaultHeaders(
673
+ userApiKeyHeader
674
+ ? { [userApiKeyHeader.name]: userApiKeyHeader.value, ...options?.headers }
675
+ : options?.headers,
676
+ this.provider
677
+ );
473
678
  return new Composio({
474
679
  ...this.config,
475
680
  defaultHeaders: sessionHeaders,
@@ -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
+ }
@@ -3,6 +3,8 @@ import { ComposioError, ComposioErrorOptions } from './ComposioError';
3
3
 
4
4
  export const SDKErrorCodes = {
5
5
  NO_API_KEY_PROVIDED: 'NO_API_KEY_PROVIDED',
6
+ API_KEY_KIND_MISMATCH: 'API_KEY_KIND_MISMATCH',
7
+ SCOPE_CONFIG_INVALID: 'SCOPE_CONFIG_INVALID',
6
8
  REQUEST_CANCELLED: 'REQUEST_CANCELLED',
7
9
  };
8
10
 
@@ -29,6 +31,56 @@ export class ComposioNoAPIKeyError extends ComposioError {
29
31
  }
30
32
  }
31
33
 
34
+ /**
35
+ * Thrown when the organization/project scope of an SDK instance is
36
+ * inconsistent: only one of `orgId` / `projectId` was supplied, or a scope
37
+ * option disagrees with the same header placed in `defaultHeaders`.
38
+ */
39
+ export class ComposioScopeConfigError extends ComposioError {
40
+ constructor(
41
+ message: string = 'Invalid organization/project scope configuration',
42
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
43
+ ) {
44
+ super(message, {
45
+ ...options,
46
+ code: SDKErrorCodes.SCOPE_CONFIG_INVALID,
47
+ possibleFixes: options.possibleFixes || [
48
+ 'Pass both `orgId` and `projectId` (the organization and consumer project nano IDs), or neither',
49
+ 'Supply the scope through the options or through the `x-org-id` / `x-project-id` default headers, not both with different values',
50
+ ],
51
+ });
52
+ this.name = 'ComposioScopeConfigError';
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Thrown when the only API key the SDK could find is a Composio user key
58
+ * (`uak_...`, as stored by `composio login`) rather than a project key.
59
+ * User keys authenticate a person, not a project, so the SDK refuses to send
60
+ * one as `x-api-key`. The error never includes the key value.
61
+ */
62
+ export class ComposioAPIKeyKindError extends ComposioError {
63
+ constructor(
64
+ message: string = 'The stored Composio API key is a user API key, not a project API key',
65
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
66
+ ) {
67
+ super(message, {
68
+ ...options,
69
+ code: SDKErrorCodes.API_KEY_KIND_MISMATCH,
70
+ cause:
71
+ options.cause ||
72
+ 'The user config file holds a user API key written by the Composio CLI; it cannot authenticate SDK requests as a project',
73
+ possibleFixes: options.possibleFixes || [
74
+ 'Pass a project API key via `apiKey` or the COMPOSIO_API_KEY environment variable',
75
+ 'Create a project API key in the Composio dashboard at https://platform.composio.dev',
76
+ 'To authenticate with the user API key instead, pass `apiKey: null` together with `userApiKey`',
77
+ ],
78
+ statusCode: 401,
79
+ });
80
+ this.name = 'ComposioAPIKeyKindError';
81
+ }
82
+ }
83
+
32
84
  /**
33
85
  * Thrown when an SDK call is cancelled via the caller-supplied `AbortSignal`.
34
86
  *
@@ -0,0 +1,61 @@
1
+ import { ComposioError, ComposioErrorOptions } from './ComposioError';
2
+
3
+ export const ToolRouterErrorCodes = {
4
+ MCP_DESTINATION_REJECTED: 'MCP_DESTINATION_REJECTED',
5
+ SESSION_CONFIG_CONFLICT: 'SESSION_CONFIG_CONFLICT',
6
+ };
7
+
8
+ /**
9
+ * Thrown when a session's hosted MCP endpoint is not a destination the SDK
10
+ * will hand the session credential to. The SDK only attaches its credential
11
+ * and scope headers when the MCP URL shares the origin of the API base URL
12
+ * the session was created against. The error is raised only when the caller
13
+ * asked for the endpoint with `mcp: true`; otherwise the session is returned
14
+ * with empty `mcp.headers` and a warning is logged instead. The error names
15
+ * both origins and never includes a credential value.
16
+ */
17
+ export class ComposioMCPDestinationError extends ComposioError {
18
+ constructor(
19
+ message: string = 'The session MCP endpoint is not a trusted destination for the session credential',
20
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
21
+ ) {
22
+ super(message, {
23
+ ...options,
24
+ code: ToolRouterErrorCodes.MCP_DESTINATION_REJECTED,
25
+ possibleFixes: options.possibleFixes ?? [
26
+ 'Point `baseURL` at the API origin that serves the session MCP endpoint; a custom base URL yields a matching MCP origin',
27
+ ],
28
+ });
29
+ this.name = 'ComposioMCPDestinationError';
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Thrown when a session update is rejected with HTTP 409 because the session
35
+ * configuration changed since it was last read, for example when an
36
+ * `expectedConfigVersion` precondition passed to `update()` is stale. The
37
+ * local session object is left as it was before the call. Re-fetch the session
38
+ * with `sessions.use(sessionId)` and retry the update against the fresh
39
+ * `configVersion`.
40
+ *
41
+ * Applying a saved Session config with `experimental.sessionConfigId` can
42
+ * also conflict when the session or the config changes while the update is
43
+ * applied; `meta.sessionConfigId` then names the config.
44
+ */
45
+ export class ComposioSessionConfigConflictError extends ComposioError {
46
+ constructor(
47
+ message: string = 'The session configuration changed since it was last read; re-fetch the session and retry the update',
48
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
49
+ ) {
50
+ super(message, {
51
+ ...options,
52
+ code: ToolRouterErrorCodes.SESSION_CONFIG_CONFLICT,
53
+ statusCode: 409,
54
+ possibleFixes: options.possibleFixes ?? [
55
+ 'Re-fetch the session with `composio.sessions.use(sessionId)` to observe the current configVersion, then retry the update',
56
+ 'Omit `expectedConfigVersion` to apply the update regardless of concurrent changes (last writer wins)',
57
+ ],
58
+ });
59
+ this.name = 'ComposioSessionConfigConflictError';
60
+ }
61
+ }
@@ -42,3 +42,6 @@ export * from './FileModifierErrors';
42
42
 
43
43
  // SSRF guard (URL file inputs)
44
44
  export * from './SsrfErrors';
45
+
46
+ // Session (tool router) errors
47
+ export * from './ToolRouterErrors';