@composio/core 0.24.0 → 0.26.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 (59) hide show
  1. package/dist/{CustomTool-CnJxXr07.mjs → CustomTool-BYHB7sPs.mjs} +1 -1
  2. package/dist/{CustomTool-CNJysHMK.d.mts → CustomTool-DfP4ldQl.d.mts} +1 -1
  3. package/dist/{cancellation-BQibgpRG.mjs → cancellation-ZoRh6EJQ.mjs} +55 -3
  4. package/dist/{composio-BFTtZj82.d.mts → composio-BMDH-1Qj.d.mts} +35 -15
  5. package/dist/{customTool.types-D57QrTns.d.mts → customTool.types-BoOELgJF.d.mts} +346 -23
  6. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
  7. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +2 -2
  8. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +22 -22
  9. package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +8 -8
  10. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +2 -2
  11. package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -1
  12. package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +2 -2
  13. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +5 -5
  14. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
  15. package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -1
  16. package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +5 -5
  17. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
  18. package/dist/docs/reference/sdk-reference/typescript/session.mdx +56 -21
  19. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +6 -6
  20. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +22 -22
  21. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +18 -18
  22. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +25 -25
  23. package/dist/docs/reference/sdk-reference/typescript/usage.mdx +6 -6
  24. package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +14 -14
  25. package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +13 -13
  26. package/dist/{errors-BN15NcCW.mjs → errors-Cly0vXFh.mjs} +5 -5
  27. package/dist/experimental/index.d.mts +2 -2
  28. package/dist/experimental/index.mjs +1 -1
  29. package/dist/index.d.mts +19 -11
  30. package/dist/index.mjs +693 -196
  31. package/dist/{types-q8TwAngA.d.mts → types-DHNV_T_z.d.mts} +2 -2
  32. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  33. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  34. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  35. package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
  36. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  37. package/package.json +5 -5
  38. package/src/composio.ts +81 -67
  39. package/src/errors/ToolRouterErrors.ts +5 -5
  40. package/src/lib/toolRouterMcp.ts +2 -0
  41. package/src/lib/toolRouterParams.ts +28 -16
  42. package/src/models/ConnectedAccounts.ts +7 -16
  43. package/src/models/ToolRouter.ts +8 -1
  44. package/src/models/ToolRouterSession.ts +17 -0
  45. package/src/models/Tools.ts +1 -4
  46. package/src/models/Triggers.ts +14 -7
  47. package/src/services/internal/InternalService.ts +3 -4
  48. package/src/services/pusher/Pusher.ts +170 -92
  49. package/src/types/connectedAccountAuthStates.types.ts +2 -1
  50. package/src/types/pusher.types.ts +2 -0
  51. package/src/types/requestOptions.types.ts +1 -10
  52. package/src/types/toolRouter.types.ts +104 -18
  53. package/src/utils/jsonSchema.ts +76 -4
  54. package/src/utils/sdk.ts +172 -11
  55. package/src/utils/session.ts +25 -47
  56. package/src/utils/toolkitDeprecation.ts +271 -0
  57. package/src/utils/transformers/connectedAccounts.ts +9 -20
  58. package/src/utils/transformers/mcp.ts +3 -10
  59. package/src/utils/userCallback.ts +41 -0
@@ -1,5 +1,5 @@
1
- import { lr as BaseComposioProvider } from "./customTool.types-D57QrTns.mjs";
2
- import { n as ComposioConfig } from "./composio-BFTtZj82.mjs";
1
+ import { dr as BaseComposioProvider } from "./customTool.types-BoOELgJF.mjs";
2
+ import { n as ComposioConfig } from "./composio-BMDH-1Qj.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-q8TwAngA.mjs";
1
+ import { t as ConfigDefaults } from "../../types-DHNV_T_z.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-q8TwAngA.mjs";
1
+ import { t as ConfigDefaults } from "../../types-DHNV_T_z.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 { Aa as ToolExecuteResponse, Oa as ToolExecuteParams, Ta as Tool } from "../../customTool.types-D57QrTns.mjs";
1
+ import { Aa as ToolExecuteParams, Da as Tool, Ma as ToolExecuteResponse } from "../../customTool.types-BoOELgJF.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,8 +1,8 @@
1
1
  import { i as logger } from "../../SsrfErrors-DiQldIdC.mjs";
2
- import { _ as ComposioRequestCancelledError } from "../../errors-BN15NcCW.mjs";
2
+ import { _ as ComposioRequestCancelledError } from "../../errors-Cly0vXFh.mjs";
3
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-BQibgpRG.mjs";
5
+ import { r as dereferenceJsonSchema, t as withCancellation } from "../../cancellation-ZoRh6EJQ.mjs";
6
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
@@ -1,4 +1,4 @@
1
- import { Aa as ToolExecuteResponse, Oa as ToolExecuteParams, Ta as Tool } from "../../customTool.types-D57QrTns.mjs";
1
+ import { Aa as ToolExecuteParams, Da as Tool, Ma as ToolExecuteResponse } from "../../customTool.types-BoOELgJF.mjs";
2
2
  import ComposioClient from "@composio/client";
3
3
  //#region src/utils/modifiers/FileToolModifier.workerd.d.ts
4
4
  export declare class FileToolModifier {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "engines": {
5
5
  "node": ">=22.22.3"
6
6
  },
7
- "version": "0.24.0",
7
+ "version": "0.26.0",
8
8
  "description": "",
9
9
  "main": "dist/index.mjs",
10
10
  "publishConfig": {
@@ -117,7 +117,7 @@
117
117
  "ajv": "^8.20.0",
118
118
  "fast-check": "^4.10.2",
119
119
  "hono": "^4.13.13",
120
- "tsdown": "^0.23.0",
120
+ "tsdown": "^0.23.1",
121
121
  "tsx": "^4.23.15",
122
122
  "typedoc": "^0.28.20",
123
123
  "typescript": "npm:@typescript/typescript6@^6.0.2",
@@ -128,16 +128,16 @@
128
128
  "zod": ">=3.25.76 <5"
129
129
  },
130
130
  "dependencies": {
131
- "@composio/client": "2.0.0-rc.14",
131
+ "@composio/client": "2.0.0-rc.19",
132
132
  "@types/json-schema": "^7.0.15",
133
133
  "is-fs-case-sensitive": "^2.0.0",
134
- "openai": "^7.31.0",
134
+ "openai": "^7.32.0",
135
135
  "picocolors": "^1.1.1",
136
136
  "pusher-js": "^8.6.0",
137
137
  "semver": "^7.8.5",
138
138
  "undici": "^7.30.0",
139
139
  "zod-to-json-schema": "^3.25.2",
140
- "@composio/json-schema-to-zod": "0.3.4"
140
+ "@composio/json-schema-to-zod": "0.4.0"
141
141
  },
142
142
  "gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064",
143
143
  "repository": {
package/src/composio.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { getEnvVariable } from './utils/env';
1
2
  import type { BaseComposioProvider } from './provider/BaseProvider';
2
- import ComposioClient from '@composio/client';
3
- import type { Logger as ClientLogger, LogLevel as ClientLogLevel } from '@composio/client';
3
+ import ComposioClient, { createFetchTransport } from '@composio/client';
4
+ import type { LogLevel as ClientLogLevel } from '@composio/client';
4
5
  import { Tools } from './models/Tools';
5
6
  import { Toolkits } from './models/Toolkits';
6
7
  import { Triggers } from './models/Triggers';
@@ -14,13 +15,13 @@ import { SessionConfigs } from './models/SessionConfigs';
14
15
  import { Keyring } from './models/Keyring';
15
16
  import { telemetry } from './telemetry/Telemetry';
16
17
  import {
17
- getScopeHeaders,
18
18
  getSDKConfig,
19
19
  getToolkitVersionsFromEnv,
20
- getUserApiKeyHeader,
20
+ resolveSDKCredentials,
21
21
  resolveSDKScope,
22
- resolveUserApiKey,
23
- USER_API_KEY_HEADER,
22
+ toClientAuth,
23
+ toClientScope,
24
+ withoutSDKOwnedHeaders,
24
25
  } from './utils/sdk';
25
26
  import logger from './utils/logger';
26
27
  import type { ComposioLogger, LogLevel } from './utils/logger';
@@ -31,12 +32,13 @@ import { version } from '../package.json';
31
32
  import type { ComposioRequestHeaders } from './types/composio.types';
32
33
  import type { ComposioRequestOptions } from './types/requestOptions.types';
33
34
  import { Files } from '#files';
34
- import { getDefaultHeaders } from './utils/session';
35
+ import { getClientIdentity } from './utils/session';
35
36
  import { ToolkitVersionParam } from './types/tool.types';
36
37
  import { ToolRouter } from './models/ToolRouter';
37
38
  import { Sessions } from './models/Sessions';
38
39
  import { CONFIG_DEFAULTS } from './utils/config-defaults';
39
40
  import { expandHomeAndResolve, expandHomeAndResolveMany } from './utils/fileDirs';
41
+ import { createToolkitDeprecationFetch } from './utils/toolkitDeprecation';
40
42
  export type ComposioConfig<
41
43
  TProvider extends BaseComposioProvider<unknown, unknown, unknown> = OpenAIProvider,
42
44
  > = {
@@ -49,8 +51,10 @@ export type ComposioConfig<
49
51
  * project key; the SDK throws instead of sending it.
50
52
  * - `null`: disables project-key authentication entirely, including both fallbacks. The SDK
51
53
  * 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
+ * or `x-org-api-key` entry in `defaultHeaders`) and sends no `x-api-key`; an `x-api-key` entry in
55
+ * `defaultHeaders` is rejected, also on `createSession()` clones. The user API key
56
+ * then authenticates every request; the organization API key does when it is the
57
+ * only credential held.
54
58
  *
55
59
  * @example 'ak_1234567890'
56
60
  */
@@ -71,7 +75,8 @@ export type ComposioConfig<
71
75
  * Sent as `x-org-api-key` only on operations whose security scheme accepts
72
76
  * it, never alongside the project key. Falls back to
73
77
  * `process.env['COMPOSIO_ORG_API_KEY']`; `null` disables that fallback.
74
- * Combine with `apiKey: null` to authenticate with the organization key alone.
78
+ * Combine with `apiKey: null` (and no user API key) to authenticate every
79
+ * request with the organization key alone.
75
80
  * @example 'oak_1234567890'
76
81
  */
77
82
  orgApiKey?: string | null;
@@ -168,11 +173,22 @@ export type ComposioConfig<
168
173
  /**
169
174
  * Default headers attached to every request made through this instance.
170
175
  *
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.
176
+ * Credential and scope headers are not forwarded as headers: the SDK folds
177
+ * them into its own options, which `getConfig()` then reports.
178
+ * A non-empty `x-user-api-key` (or `x-org-api-key`) entry becomes the
179
+ * credential every request carries, in place of the configured keys; together
180
+ * with `apiKey: null` it authenticates with that key instead of a project key.
181
+ * An `x-api-key` entry replaces the project key, and is rejected when `apiKey`
182
+ * is `null`. At most one of the three may be set. `x-org-id` / `x-project-id`
183
+ * entries supply `orgId` / `projectId`.
184
+ *
185
+ * The SDK reports itself through the API client's identity headers
186
+ * (`x-client-provenance`, `x-client-version`, `x-client-library`,
187
+ * `x-client-library-version`, `x-client-language`, `x-client-runtime`,
188
+ * `x-sdk-version`, `x-source`, `x-framework`, `x-runtime` and
189
+ * `x-runtime-version`); an entry naming one of them is rejected with a
190
+ * `ComposioError` from `@composio/client`. Every other header is passed
191
+ * through untouched.
176
192
  * @example
177
193
  * ```typescript
178
194
  * const composio = new Composio({
@@ -284,11 +300,11 @@ const toClientLogLevel = (level: LogLevel): ClientLogLevel => {
284
300
  * at call time so a later `logger.configure()` is honoured. The client's
285
301
  * `info` records (per-request lifecycle) are forwarded as SDK `debug`.
286
302
  */
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),
303
+ const clientLogForwarder: Pick<Console, 'debug' | 'info' | 'warn' | 'error'> = {
304
+ error: (...args: unknown[]) => logger.error(...args),
305
+ warn: (...args: unknown[]) => logger.warn(...args),
306
+ info: (...args: unknown[]) => logger.debug(...args),
307
+ debug: (...args: unknown[]) => logger.debug(...args),
292
308
  };
293
309
 
294
310
  /**
@@ -465,16 +481,20 @@ export class Composio<
465
481
  }
466
482
  );
467
483
 
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;
484
+ // The SDK owns the credential: it resolves the keys (with their
485
+ // environment fallbacks) and folds a credential default header into them,
486
+ // so the API client receives one `auth` and never a credential header.
487
+ // The resolved keys are stored on the config, so clones, the MCP export
488
+ // and trigger subscriptions read the same values.
489
+ const credentials = resolveSDKCredentials({
490
+ apiKey: apiKeyParsed,
491
+ userApiKey: config?.userApiKey,
492
+ orgApiKey: config?.orgApiKey,
493
+ defaultHeaders: config?.defaultHeaders,
494
+ });
495
+ // Credential and scope entries travel as `auth` and `scope`; the client
496
+ // refuses them in `defaultHeaders`.
497
+ const defaultHeaders = withoutSDKOwnedHeaders(config?.defaultHeaders);
478
498
 
479
499
  if (config?.logger !== undefined || config?.logLevel !== undefined) {
480
500
  logger.configure({ level: config.logLevel, sink: config.logger });
@@ -496,8 +516,10 @@ export class Composio<
496
516
  this.config = {
497
517
  ...config,
498
518
  baseURL: baseURLParsed,
499
- apiKey: apiKeyParsed,
500
- defaultHeaders: defaultHeadersInput,
519
+ apiKey: credentials.apiKey,
520
+ userApiKey: credentials.userApiKey,
521
+ orgApiKey: credentials.orgApiKey,
522
+ defaultHeaders,
501
523
  toolkitVersions: getToolkitVersionsFromEnv(config?.toolkitVersions),
502
524
  allowTracking: config?.allowTracking ?? CONFIG_DEFAULTS.allowTracking,
503
525
  dangerouslyAllowAutoUploadDownloadFiles:
@@ -512,33 +534,33 @@ export class Composio<
512
534
  projectId: scope.projectId,
513
535
  };
514
536
 
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
- );
521
-
522
537
  /**
523
538
  * Initialize the Composio SDK client.
524
- * The client is used to make API calls to the Composio API.
539
+ * The client is used to make API calls to the Composio API. It sends the
540
+ * credential from `auth`, the resolved org/project scope from `scope`, and
541
+ * the SDK's identity headers from `identity`, and refuses all three in
542
+ * `defaultHeaders`.
525
543
  */
526
544
  this.client = new ComposioClient({
527
- apiKey: apiKeyParsed,
528
- userApiKey: config?.userApiKey,
529
- orgApiKey: config?.orgApiKey,
545
+ auth: toClientAuth(credentials),
546
+ scope: toClientScope(scope),
530
547
  baseURL: baseURLParsed,
531
- defaultHeaders: defaultHeaders,
532
- logger: clientLoggerAdapter,
548
+ // The client stopped reading the process environment in rc.18; this
549
+ // opt-in for a plain-HTTP development origin is the one setting of its
550
+ // own that core forwards.
551
+ ...(getEnvVariable('COMPOSIO_ALLOW_INSECURE_HTTP') === '1'
552
+ ? { allowInsecureHTTP: true }
553
+ : {}),
554
+ defaultHeaders,
555
+ identity: getClientIdentity(this.provider),
556
+ logger: clientLogForwarder,
533
557
  logLevel: toClientLogLevel(logger.getLevel()),
558
+ // Warns once per deprecated toolkit version reported through the
559
+ // `Composio-Deprecated-Toolkits` response header. `createSession()`
560
+ // clones go through this same constructor and inherit it.
561
+ transport: createFetchTransport({ fetch: createToolkitDeprecationFetch() }),
534
562
  });
535
563
 
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
-
542
564
  this.tools = new Tools(this.client, this.config);
543
565
  this.mcp = new MCP(this.client);
544
566
  this.toolkits = new Toolkits(this.client);
@@ -573,7 +595,7 @@ export class Composio<
573
595
  */
574
596
  if (this.config.allowTracking) {
575
597
  telemetry.setup({
576
- apiKey: apiKeyParsed ?? '',
598
+ apiKey: credentials.apiKey ?? '',
577
599
  baseUrl: baseURLParsed ?? '',
578
600
  isAgentic: this.provider?._isAgentic || false,
579
601
  version: version,
@@ -638,8 +660,8 @@ export class Composio<
638
660
  * instance directly with the headers you need: `new Composio({ ...existingConfig, defaultHeaders })`.
639
661
  * For one-off overrides, pass per-call `requestOptions` where supported.
640
662
  *
641
- * @param {MergedRequestInit} fetchOptions - Custom request options to be used for all API calls in this session.
642
- * This follows the Fetch API RequestInit interface with additional options.
663
+ * @param {object} [options] - Options for the new instance.
664
+ * @param {ComposioRequestHeaders} [options.headers] - Headers sent with every API call the new instance makes.
643
665
  * @returns {Composio<TProvider>} A new Composio instance with the custom request options applied.
644
666
  *
645
667
  * @example
@@ -663,21 +685,13 @@ export class Composio<
663
685
  * ```
664
686
  */
665
687
  createSession(options?: { headers?: ComposioRequestHeaders }): Composio<TProvider> {
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
- );
688
+ // The clone inherits the resolved credentials and scope through
689
+ // `this.config`, where a credential or scope default header has already
690
+ // been folded in; `headers` replaces the default headers, and a
691
+ // credential or scope header in it is folded in the same way.
678
692
  return new Composio({
679
693
  ...this.config,
680
- defaultHeaders: sessionHeaders,
694
+ defaultHeaders: options?.headers,
681
695
  });
682
696
  }
683
697
 
@@ -80,9 +80,9 @@ export class ComposioSessionConfigConflictError extends ComposioError {
80
80
  *
81
81
  * `inputRequests` holds the questions, keyed by the ID the answers must
82
82
  * reuse. `requestState` is the opaque `request_state` the API returned; when
83
- * present it must be sent back unchanged together with the answers. The SDK
84
- * does not submit answers yet, so nothing was executed and the call is not
85
- * retried.
83
+ * present it must be sent back unchanged together with the answers. Nothing
84
+ * was executed and the call is not retried: to answer, repeat the same call
85
+ * with `inputResponses` and `requestState` in its options.
86
86
  */
87
87
  export class ComposioToolInputRequiredError extends ComposioError {
88
88
  /** Questions for the user, keyed by the ID the answers must reuse. */
@@ -104,12 +104,12 @@ export class ComposioToolInputRequiredError extends ComposioError {
104
104
  const count = Object.keys(details.inputRequests).length;
105
105
  super(
106
106
  `${subject} requires user input before it can run (${count} input request${count === 1 ? '' : 's'}) and was not executed. ` +
107
- 'The questions are on `inputRequests` and the opaque `request_state` to send back with the answers is on `requestState`.',
107
+ "The questions are on `inputRequests`. Repeat the call with the answers in `inputResponses` and this error's `requestState`.",
108
108
  {
109
109
  ...options,
110
110
  code: ToolRouterErrorCodes.TOOL_INPUT_REQUIRED,
111
111
  possibleFixes: options.possibleFixes ?? [
112
- 'Collect the answers described by `inputRequests`, then call the session execute endpoint again with `input_responses` and the unchanged `request_state`',
112
+ 'Collect the answers described by `inputRequests`, then repeat the same call with `{ inputResponses, requestState }` in its options',
113
113
  'Remove the tool, its toolkit or its tags from the `require_approval` lists of the session configuration if no approval is intended',
114
114
  ],
115
115
  }
@@ -71,6 +71,8 @@ export type MCPServerConfigInput = {
71
71
  apiKey: string | null | undefined;
72
72
  /** The user API key the client resolved (`userApiKey` option or `COMPOSIO_USER_API_KEY`). */
73
73
  userApiKey: string | null | undefined;
74
+ /** The organization API key the client resolved (`orgApiKey` option or `COMPOSIO_ORG_API_KEY`). */
75
+ orgApiKey?: string | null;
74
76
  /** The default headers configured on the SDK instance; only `x-user-api-key` is consulted. */
75
77
  defaultHeaders: ComposioRequestHeaders | undefined;
76
78
  /** Organization nano ID the instance is scoped to, if any. */
@@ -29,14 +29,18 @@ type ParsedCreateSessionConfig = TypeOf<typeof ToolRouterCreateSessionConfigSche
29
29
  /** Parsed update input; the public `ToolRouterUpdateSessionConfig` is a union over it. */
30
30
  type ParsedUpdateSessionConfig = TypeOf<typeof ToolRouterUpdateSessionConfigSchema>;
31
31
 
32
+ /** A toolkit's entry in the session `tools` map, as sent on create and update. */
33
+ type SessionToolsEntry = NonNullable<SessionCreateParams['tools']>[string];
34
+
35
+ /** `require_approval` when the caller set an approval list, nothing otherwise. */
36
+ const requireApprovalParam = <T extends string>(
37
+ requireApproval: T[] | undefined
38
+ ): { require_approval?: T[] } =>
39
+ requireApproval !== undefined ? { require_approval: requireApproval } : {};
40
+
32
41
  export const transformToolRouterToolsParams = (
33
42
  params?: Record<string, ToolRouterToolsParam | ToolRouterConfigTools> | undefined
34
- ):
35
- | Record<
36
- string,
37
- SessionCreateParams.Enable | SessionCreateParams.Disable | SessionCreateParams.Tags
38
- >
39
- | undefined => {
43
+ ): Record<string, SessionToolsEntry> | undefined => {
40
44
  if (!params) {
41
45
  return undefined;
42
46
  }
@@ -53,14 +57,16 @@ export const transformToolRouterToolsParams = (
53
57
  if (Array.isArray(data)) {
54
58
  acc[key] = { enable: data };
55
59
  } else if ('enable' in data) {
56
- acc[key] = { enable: data.enable };
60
+ acc[key] = { enable: data.enable, ...requireApprovalParam(data.requireApproval) };
57
61
  } else if ('disable' in data) {
58
- acc[key] = { disable: data.disable };
62
+ acc[key] = { disable: data.disable, ...requireApprovalParam(data.requireApproval) };
59
63
  } else if ('tags' in data) {
60
64
  const tags = transformToolRouterTagsParams(data.tags);
61
65
  if (tags) {
62
- acc[key] = { tags };
66
+ acc[key] = { tags, ...requireApprovalParam(data.requireApproval) };
63
67
  }
68
+ } else {
69
+ acc[key] = { require_approval: data.requireApproval };
64
70
  }
65
71
  } else {
66
72
  throw new ValidationError(parsedResult.error.message);
@@ -70,10 +76,7 @@ export const transformToolRouterToolsParams = (
70
76
  }
71
77
  return acc;
72
78
  },
73
- {} as Record<
74
- string,
75
- SessionCreateParams.Enable | SessionCreateParams.Disable | SessionCreateParams.Tags
76
- >
79
+ {} as Record<string, SessionToolsEntry>
77
80
  );
78
81
  return result;
79
82
  }
@@ -91,6 +94,7 @@ export const transformToolRouterTagsParams = (
91
94
  return {
92
95
  enable: params.enable,
93
96
  disable: params.disable,
97
+ ...requireApprovalParam(params.requireApproval),
94
98
  };
95
99
  }
96
100
  };
@@ -276,6 +280,9 @@ const transformToolRouterUpdateExperimentalParams = (
276
280
  if (config.sessionConfigId !== undefined) {
277
281
  result.session_config_id = config.sessionConfigId;
278
282
  }
283
+ if (config.noElicitationSupportFallback !== undefined) {
284
+ result.no_elicitation_support_fallback = config.noElicitationSupportFallback;
285
+ }
279
286
  return result;
280
287
  };
281
288
 
@@ -332,7 +339,7 @@ export const transformToolRouterMultiAccountParams = (
332
339
 
333
340
  export const transformToolRouterToolkitsParams = (
334
341
  params?: ParsedCreateSessionConfig['toolkits']
335
- ): SessionCreateParams.Enable | SessionCreateParams.Disable | undefined => {
342
+ ): NonNullable<SessionCreateParams['toolkits']> | undefined => {
336
343
  if (!params) {
337
344
  return undefined;
338
345
  }
@@ -342,8 +349,13 @@ export const transformToolRouterToolkitsParams = (
342
349
  return { enable: params };
343
350
  }
344
351
 
345
- // Otherwise return as-is (already in enable/disable format)
346
- return params as SessionCreateParams.Enable | SessionCreateParams.Disable;
352
+ if ('enable' in params) {
353
+ return { enable: params.enable, ...requireApprovalParam(params.requireApproval) };
354
+ }
355
+ if ('disable' in params) {
356
+ return { disable: params.disable, ...requireApprovalParam(params.requireApproval) };
357
+ }
358
+ return { require_approval: params.requireApproval };
347
359
  };
348
360
 
349
361
  /**
@@ -6,6 +6,7 @@
6
6
  * @module ConnectedAccounts
7
7
  */
8
8
  import ComposioClient, { BadRequestError, ConflictError } from '@composio/client';
9
+ import type { APIPromise } from '@composio/client';
9
10
  import {
10
11
  ConnectedAccountCreateResponse,
11
12
  ConnectedAccountDeleteResponse,
@@ -126,11 +127,7 @@ export class ConnectedAccounts {
126
127
  cursor: parsedQuery.data.cursor?.toString(),
127
128
  limit: parsedQuery.data.limit,
128
129
  order_by: parsedQuery.data.orderBy,
129
- // Cast widens to match the Stainless-generated client params, which
130
- // lag behind the live API enum. Apollo accepts the union value at
131
- // runtime (`z.nativeEnum(ConnectionStatusEnum)` on the query param);
132
- // remove the cast once `@composio/client` is regenerated.
133
- statuses: parsedQuery.data.statuses as ConnectedAccountListParamsRaw['statuses'],
130
+ statuses: parsedQuery.data.statuses,
134
131
  toolkit_slugs: parsedQuery.data.toolkitSlugs,
135
132
  user_ids: parsedQuery.data.userIds,
136
133
  ...(parsedQuery.data.accountType !== undefined && {
@@ -271,18 +268,12 @@ export class ConnectedAccounts {
271
268
  // caller needs to migrate. Custom auth configs and non-OAuth schemes
272
269
  // never see the header, eliminating the false-positive warning that
273
270
  // an `auth_scheme`-only check produced for `link()`-unaffected callers.
274
- const apiCall = this.client.connectedAccounts.create(createParams, requestOptions);
275
- if (typeof (apiCall as { withResponse?: unknown }).withResponse === 'function') {
271
+ const apiCall: APIPromise<ConnectedAccountCreateResponse> =
272
+ this.client.connectedAccounts.create(createParams, requestOptions);
273
+ // Checked at runtime: test mocks may return a plain Promise.
274
+ if (typeof apiCall.withResponse === 'function') {
276
275
  const resolved = await withCancellation(
277
- () =>
278
- (
279
- apiCall as unknown as {
280
- withResponse: () => Promise<{
281
- data: ConnectedAccountCreateResponse;
282
- response: Response;
283
- }>;
284
- }
285
- ).withResponse(),
276
+ () => apiCall.withResponse(),
286
277
  requestOptions?.signal
287
278
  );
288
279
  response = resolved.data;
@@ -139,7 +139,8 @@ export class ToolRouter<
139
139
  /**
140
140
  * Derives the MCP config for a session from the auth context the session
141
141
  * request was made with: the project key when one is configured, otherwise
142
- * the resolved user API key, plus the org/project scope when configured.
142
+ * the resolved user API key, otherwise the organization API key, plus the
143
+ * org/project scope when configured.
143
144
  * Headers are only attached when the MCP URL shares the client's API
144
145
  * origin. Any other destination throws when the caller passed `mcp: true`
145
146
  * and otherwise yields empty headers plus a warning; see
@@ -155,6 +156,7 @@ export class ToolRouter<
155
156
  apiBaseURL: this.client.baseURL,
156
157
  apiKey: this.config?.apiKey,
157
158
  userApiKey: this.config?.userApiKey,
159
+ orgApiKey: this.config?.orgApiKey,
158
160
  defaultHeaders: this.config?.defaultHeaders,
159
161
  orgId: this.config?.orgId,
160
162
  projectId: this.config?.projectId,
@@ -240,6 +242,11 @@ export class ToolRouter<
240
242
  experimentalPayload.session_config_id = routerConfig.experimental.sessionConfigId;
241
243
  }
242
244
 
245
+ if (routerConfig.experimental?.noElicitationSupportFallback !== undefined) {
246
+ experimentalPayload.no_elicitation_support_fallback =
247
+ routerConfig.experimental.noElicitationSupportFallback;
248
+ }
249
+
243
250
  if (routerConfig.experimental?.assistivePrompt?.userTimezone) {
244
251
  experimentalPayload.assistive_prompt_config = {
245
252
  user_timezone: routerConfig.experimental.assistivePrompt.userTimezone,
@@ -21,6 +21,7 @@ import {
21
21
  ToolRouterSessionExecuteResponseSchema,
22
22
  ToolRouterSessionProxyExecuteResponse,
23
23
  ToolRouterSessionExecuteOptions,
24
+ ToolRouterSessionExecuteMetaOptions,
24
25
  ToolRouterSessionMetaToolSlug,
25
26
  ToolRouterSessionConfig,
26
27
  ToolRouterSessionMetadata,
@@ -98,6 +99,16 @@ import { getSourceSessionConfig } from '../lib/toolRouterSourceSessionConfig';
98
99
  import { deleteToolRouterSession } from '../lib/toolRouterSessionDelete';
99
100
 
100
101
  const COMPOSIO_MULTI_EXECUTE_TOOL = 'COMPOSIO_MULTI_EXECUTE_TOOL';
102
+
103
+ /** The request fields that carry the user's answers to an earlier `input_required` call. */
104
+ function inputResponseParams(
105
+ options: ToolRouterSessionExecuteMetaOptions | undefined
106
+ ): Pick<SessionExecuteParams, 'input_responses' | 'request_state'> {
107
+ return {
108
+ ...(options?.inputResponses !== undefined && { input_responses: options.inputResponses }),
109
+ ...(options?.requestState !== undefined && { request_state: options.requestState }),
110
+ };
111
+ }
101
112
  export const DIRECT_CUSTOM_TOOL_DESCRIPTION_PREFIX =
102
113
  '[Direct tool - call directly, no search needed beforehand.]';
103
114
 
@@ -684,6 +695,8 @@ export class ToolRouterSession<
684
695
  * @param arguments_ - Optional tool arguments
685
696
  * @param options - Optional execution options
686
697
  * @param options.account - Account identifier for direct app tool execution. Accepted on every project: in multi-account sessions it picks the account; on single-account projects it must match one of the session's active connections for the toolkit. Helper/meta tools either ignore this top-level field or define their own account-selection fields.
698
+ * @param options.inputResponses - Experimental. The user's answers to an earlier `ComposioToolInputRequiredError`, keyed by the IDs in its `inputRequests`. Repeat the same call with them.
699
+ * @param options.requestState - Experimental. The `requestState` of that error, sent back unchanged.
687
700
  * @returns The tool execution result
688
701
  * @throws {ComposioToolInputRequiredError} If the tool needs input from the user (for example an approval) before it can run
689
702
  */
@@ -720,6 +733,7 @@ export class ToolRouterSession<
720
733
  const executeParams: SessionExecuteParams = {
721
734
  tool_slug: toolSlug,
722
735
  arguments: arguments_ ?? {},
736
+ ...inputResponseParams(options),
723
737
  };
724
738
  if (options?.account) {
725
739
  executeParams.account = options.account;
@@ -754,6 +768,7 @@ export class ToolRouterSession<
754
768
  *
755
769
  * @param slug - The meta tool slug to execute
756
770
  * @param arguments_ - Optional meta tool arguments
771
+ * @param options - Experimental. The user's answers to an earlier `ComposioToolInputRequiredError` (`inputResponses`) and its `requestState`, as in `session.execute()`
757
772
  * @returns The tool execution result, in the same shape as `session.execute()`
758
773
  * @throws {ComposioToolInputRequiredError} If the tool needs input from the user (for example an approval) before it can run
759
774
  *
@@ -767,11 +782,13 @@ export class ToolRouterSession<
767
782
  async executeMeta(
768
783
  slug: ToolRouterSessionMetaToolSlug,
769
784
  arguments_?: Record<string, unknown>,
785
+ options?: ToolRouterSessionExecuteMetaOptions,
770
786
  requestOptions?: ComposioRequestOptions
771
787
  ): Promise<ToolRouterSessionExecuteResponse> {
772
788
  const executeMetaParams: SessionExecuteMetaParams = {
773
789
  slug,
774
790
  arguments: arguments_ ?? {},
791
+ ...inputResponseParams(options),
775
792
  };
776
793
  const experimental = inlineCustomToolsExperimental<SessionExecuteMetaParams.Experimental>(
777
794
  this.inlineCustomToolsPayload
@@ -992,8 +992,7 @@ export class Tools<
992
992
  * @deprecated The `customConnectionData` execute param is deprecated and will be
993
993
  * removed in a future release. Use `customAuthParams` instead.
994
994
  */
995
- custom_connection_data:
996
- body.customConnectionData as ComposioToolExecuteParams['custom_connection_data'],
995
+ custom_connection_data: body.customConnectionData,
997
996
  arguments: body.arguments,
998
997
  user_id: body.userId,
999
998
  version: toolkitVersion,
@@ -1390,8 +1389,6 @@ export class Tools<
1390
1389
  * @deprecated The `customConnectionData` proxy param is deprecated and will be
1391
1390
  * removed in a future release. Use `customAuthParams` instead.
1392
1391
  */
1393
- // oxlint-disable-next-line typescript/ban-ts-comment -- generated client versions disagree about this deprecated field
1394
- // @ts-ignore
1395
1392
  custom_connection_data: toolProxyParams.data.customConnectionData,
1396
1393
  } as ComposioToolProxyParams;
1397
1394
  return withCancellation(