@composio/core 0.18.1 → 0.20.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 (100) hide show
  1. package/dist/{CustomTool-VRfWzMix.d.mts → CustomTool-B3m-188G.d.mts} +1 -1
  2. package/dist/{CustomTool-Bz0f52QR.mjs → CustomTool-fYEFjSLM.mjs} +1 -1
  3. package/dist/{FileModifierErrors-CwB-Inm9.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
  4. package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
  5. package/dist/{SsrfErrors-xhdVE4yw.mjs → SsrfErrors-DiQldIdC.mjs} +32 -17
  6. package/dist/{Telemetry-Dw9W5RSp.mjs → Telemetry-JRJJYS4I.mjs} +2 -2
  7. package/dist/{cancellation-P5YUlcfz.mjs → cancellation-Dwa9lGHA.mjs} +7 -5
  8. package/dist/{composio-Cb3d1jFe.d.mts → composio-B36OXii1.d.mts} +3017 -144
  9. package/dist/{customTool.types-B6ej_8XZ.d.mts → customTool.types-C436M_D0.d.mts} +525 -101
  10. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
  11. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +8 -15
  12. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +101 -18
  13. package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +123 -0
  14. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +9 -2
  15. package/dist/docs/reference/sdk-reference/typescript/index.mdx +7 -0
  16. package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +56 -0
  17. package/dist/docs/reference/sdk-reference/typescript/logs.mdx +78 -0
  18. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
  19. package/dist/docs/reference/sdk-reference/typescript/meta.json +8 -1
  20. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
  21. package/dist/docs/reference/sdk-reference/typescript/session.mdx +117 -24
  22. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +24 -10
  23. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +151 -14
  24. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +50 -40
  25. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +26 -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-Ue9wMrPK.mjs → errors-D_A4b2c2.mjs} +143 -4
  31. package/dist/experimental/index.d.mts +2 -2
  32. package/dist/experimental/index.mjs +1 -1
  33. package/dist/{fileUtils.node-KE5Fa-af.mjs → fileUtils.node-DNLhLg0W.mjs} +8 -6
  34. package/dist/index.d.mts +418 -146
  35. package/dist/index.mjs +2728 -349
  36. package/dist/models/Files.node.d.mts +2 -3
  37. package/dist/models/Files.node.mjs +2 -2
  38. package/dist/models/Files.workerd.d.mts +2 -3
  39. package/dist/platform/node.d.mts +2 -3
  40. package/dist/platform/workerd.d.mts +2 -3
  41. package/dist/{sensitiveFileUploadPaths-QN7w4n8v.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
  42. package/dist/{ssrfGuard.node-BLX6b-Rf.mjs → ssrfGuard.node-BZ270bcu.mjs} +104 -14
  43. package/dist/{types-CGdgK442.d.mts → types-Br3GBya5.d.mts} +2 -2
  44. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
  45. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
  46. package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
  47. package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
  48. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
  49. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  50. package/dist/utils/ssrfGuard.node.d.mts +19 -10
  51. package/dist/utils/ssrfGuard.node.mjs +1 -1
  52. package/dist/utils/ssrfGuard.workerd.d.mts +12 -4
  53. package/dist/utils/ssrfGuard.workerd.mjs +2 -2
  54. package/package.json +9 -9
  55. package/src/composio.ts +207 -10
  56. package/src/errors/ConnectedAccountsErrors.ts +47 -0
  57. package/src/errors/SDKErrors.ts +52 -0
  58. package/src/errors/ToolErrors.ts +24 -0
  59. package/src/errors/ToolRouterErrors.ts +57 -0
  60. package/src/errors/index.ts +3 -0
  61. package/src/index.ts +15 -0
  62. package/src/lib/toolRouterMcp.ts +132 -0
  63. package/src/lib/toolRouterParams.ts +116 -29
  64. package/src/models/ConnectedAccounts.ts +118 -2
  65. package/src/models/CustomToolkits.ts +169 -0
  66. package/src/models/Experimental.ts +27 -0
  67. package/src/models/Keyring.ts +65 -0
  68. package/src/models/Logs.ts +101 -0
  69. package/src/models/MCP.ts +29 -15
  70. package/src/models/ToolRouter.ts +43 -14
  71. package/src/models/ToolRouterSession.ts +224 -16
  72. package/src/models/Toolkits.ts +181 -2
  73. package/src/models/Tools.ts +58 -26
  74. package/src/models/Triggers.ts +10 -90
  75. package/src/models/Usage.ts +119 -0
  76. package/src/models/Webhooks.ts +520 -0
  77. package/src/services/pusher/Pusher.ts +46 -16
  78. package/src/types/authConfigs.types.ts +2 -0
  79. package/src/types/connectedAccounts.types.ts +54 -0
  80. package/src/types/customToolkits.types.ts +102 -0
  81. package/src/types/keyring.types.ts +32 -0
  82. package/src/types/logs.types.ts +108 -0
  83. package/src/types/toolRouter.types.ts +259 -14
  84. package/src/types/toolkit.types.ts +161 -0
  85. package/src/types/usage.types.ts +81 -0
  86. package/src/types/webhooks.types.ts +143 -0
  87. package/src/utils/constants.ts +1 -5
  88. package/src/utils/jsonSchema.ts +4 -1
  89. package/src/utils/logger.ts +39 -7
  90. package/src/utils/sdk.ts +385 -22
  91. package/src/utils/ssrfGuard.node.ts +127 -13
  92. package/src/utils/ssrfGuard.workerd.ts +11 -1
  93. package/src/utils/transformers/connectedAccounts.ts +37 -2
  94. package/src/utils/transformers/customToolkits.ts +98 -0
  95. package/src/utils/transformers/keyring.ts +24 -0
  96. package/src/utils/transformers/logs.ts +85 -0
  97. package/src/utils/transformers/toolkits.ts +183 -3
  98. package/src/utils/transformers/triggers.ts +2 -2
  99. package/src/utils/transformers/usage.ts +77 -0
  100. package/src/utils/transformers/webhooks.ts +139 -0
@@ -356,6 +356,10 @@ export type CreateConnectedAccountLinkResponse = z.infer<
356
356
 
357
357
  export const ConnectedAccountRefreshOptionsSchema = z.object({
358
358
  redirectUrl: z.string().optional(),
359
+ /**
360
+ * @deprecated The Composio API no longer accepts this field. It is ignored
361
+ * and `refresh()` logs a warning when it is set.
362
+ */
359
363
  validateCredentials: z.boolean().optional(),
360
364
  });
361
365
  export type ConnectedAccountRefreshOptions = z.infer<typeof ConnectedAccountRefreshOptionsSchema>;
@@ -393,3 +397,53 @@ export const UpdateConnectedAccountAclParamsSchema = ConnectedAccountAclConfigSc
393
397
  }
394
398
  );
395
399
  export type UpdateConnectedAccountAclParams = z.infer<typeof UpdateConnectedAccountAclParamsSchema>;
400
+
401
+ /**
402
+ * Response of `composio.connectedAccounts.revoke()`.
403
+ */
404
+ export const ConnectedAccountRevokedTokenSchema = z.enum([
405
+ 'access_token',
406
+ 'refresh_token',
407
+ 'credential',
408
+ ]);
409
+ export type ConnectedAccountRevokedToken = z.infer<typeof ConnectedAccountRevokedTokenSchema>;
410
+
411
+ export const ConnectedAccountRevokeResponseSchema = z.object({
412
+ /**
413
+ * Tokens revoked at the provider on this call. An empty array means the
414
+ * connection was already revoked (no upstream dispatch).
415
+ */
416
+ revokedTokens: z.array(ConnectedAccountRevokedTokenSchema),
417
+ connectedAccount: z.object({
418
+ id: z.string(),
419
+ /** The connection status after this call (`REVOKED` on success). */
420
+ status: ConnectedAccountStatusSchema,
421
+ }),
422
+ });
423
+ export type ConnectedAccountRevokeResponse = z.infer<typeof ConnectedAccountRevokeResponseSchema>;
424
+
425
+ /**
426
+ * Params for `composio.connectedAccounts.completeAuth()`.
427
+ */
428
+ export const ConnectedAccountCompleteAuthParamsSchema = z.object({
429
+ /** The user the connection was initiated for. Must match the connection owner. */
430
+ userId: z.string().min(1),
431
+ /** The opaque, single-use session URI your OAuth callback verifier received. */
432
+ sessionUri: z.string().min(1),
433
+ });
434
+ export type ConnectedAccountCompleteAuthParams = z.infer<
435
+ typeof ConnectedAccountCompleteAuthParamsSchema
436
+ >;
437
+
438
+ /**
439
+ * Response of `composio.connectedAccounts.completeAuth()`.
440
+ */
441
+ export const ConnectedAccountCompleteAuthResponseSchema = z.object({
442
+ /** The connection that was completed; it is now `ACTIVE`. */
443
+ connectedAccountId: z.string(),
444
+ /** The toolkit the connection belongs to. */
445
+ toolkitSlug: z.string(),
446
+ });
447
+ export type ConnectedAccountCompleteAuthResponse = z.infer<
448
+ typeof ConnectedAccountCompleteAuthResponseSchema
449
+ >;
@@ -0,0 +1,102 @@
1
+ import { z } from 'zod/v3';
2
+
3
+ /**
4
+ * How end users authenticate to a custom toolkit.
5
+ * **Experimental — custom toolkits are in pilot; shape may change.**
6
+ */
7
+ export const CustomToolkitAuthSchemeSchema = z.discriminatedUnion('mode', [
8
+ z.object({ mode: z.literal('NO_AUTH') }),
9
+ z.object({
10
+ mode: z.literal('API_KEY'),
11
+ /**
12
+ * Headers sent with each request. Write `{{generic_api_key}}` where the
13
+ * end user's API key goes, for example
14
+ * `{ Authorization: 'Bearer {{generic_api_key}}' }`.
15
+ */
16
+ headers: z.record(z.string(), z.string()),
17
+ /** End-user copy for the API key input on the connect page. */
18
+ apiKeyField: z
19
+ .object({
20
+ displayName: z.string().min(1).max(100).optional(),
21
+ description: z.string().min(1).max(500).optional(),
22
+ })
23
+ .optional(),
24
+ }),
25
+ z.object({
26
+ mode: z.literal('DCR_OAUTH'),
27
+ /**
28
+ * Where to fetch the full auth scheme, usually the
29
+ * `/.well-known/oauth-authorization-server` path of your MCP URL.
30
+ */
31
+ discoveryUrl: z.string().url(),
32
+ }),
33
+ ]);
34
+ export type CustomToolkitAuthScheme = z.infer<typeof CustomToolkitAuthSchemeSchema>;
35
+
36
+ /**
37
+ * Params for `composio.experimental.customToolkits.upsert()`.
38
+ * **Experimental — custom toolkits are in pilot; shape may change.**
39
+ */
40
+ export const CustomToolkitUpsertParamsSchema = z.object({
41
+ /**
42
+ * Letters, digits, underscores or spaces, up to 30 characters. The API
43
+ * prefixes it with `CUSTOM_` and turns spaces into underscores.
44
+ */
45
+ slug: z
46
+ .string()
47
+ .min(1)
48
+ .max(30)
49
+ .regex(/^[a-zA-Z0-9_\s]+$/),
50
+ toolkitConfig: z.object({
51
+ /** Human-readable toolkit name. */
52
+ name: z.string().min(1).max(200),
53
+ /** The app URL. For an MCP app, the MCP server URL. */
54
+ appUrl: z.string().url(),
55
+ /** Square PNG or JPEG logo (256-1024px, max 3MB), base64-encoded. Defaults to the Composio logo. */
56
+ logoFile: z
57
+ .object({
58
+ content: z.string().min(1),
59
+ mimeType: z.enum(['image/png', 'image/jpeg']),
60
+ })
61
+ .optional(),
62
+ /** At least one scheme. The schemes cannot change once the toolkit exists. */
63
+ authSchemes: z.array(CustomToolkitAuthSchemeSchema).min(1),
64
+ }),
65
+ });
66
+ export type CustomToolkitUpsertParams = z.infer<typeof CustomToolkitUpsertParamsSchema>;
67
+
68
+ export const CustomToolkitUpsertResponseSchema = z.object({
69
+ /** Slug of the created or updated toolkit. */
70
+ slug: z.string(),
71
+ });
72
+ export type CustomToolkitUpsertResponse = z.infer<typeof CustomToolkitUpsertResponseSchema>;
73
+
74
+ /**
75
+ * Params for `composio.experimental.customToolkits.sync()`.
76
+ * **Experimental — custom toolkits are in pilot; shape may change.**
77
+ */
78
+ export const CustomToolkitSyncParamsSchema = z.object({
79
+ /** Connected account to use when fetching the remote tool definitions. */
80
+ connectedAccountId: z.string().optional(),
81
+ });
82
+ export type CustomToolkitSyncParams = z.infer<typeof CustomToolkitSyncParamsSchema>;
83
+
84
+ export const CustomToolkitSyncResponseSchema = z.object({
85
+ slug: z.string(),
86
+ /** Toolkit version after the sync. */
87
+ version: z.string(),
88
+ /** Number of tools synced. */
89
+ syncedCount: z.number(),
90
+ });
91
+ export type CustomToolkitSyncResponse = z.infer<typeof CustomToolkitSyncResponseSchema>;
92
+
93
+ export const CustomToolkitDeleteResponseSchema = z.object({
94
+ /** Slug of the deleted toolkit. */
95
+ slug: z.string(),
96
+ deleted: z.boolean(),
97
+ /** Background jobs revoking the credentials of the toolkit's connected accounts. */
98
+ revokeJobIds: z.array(z.string()),
99
+ authConfigsDeleted: z.number(),
100
+ connectedAccountsDeleted: z.number(),
101
+ });
102
+ export type CustomToolkitDeleteResponse = z.infer<typeof CustomToolkitDeleteResponseSchema>;
@@ -0,0 +1,32 @@
1
+ import { z } from 'zod/v3';
2
+
3
+ /**
4
+ * A public JWK a secret can be sealed to. Fields keep their JWK names so a
5
+ * key can be handed straight to WebCrypto or a JOSE library.
6
+ */
7
+ export const KeyringTransferKeySchema = z.object({
8
+ /** Key type. Always `RSA`. */
9
+ kty: z.string(),
10
+ /** RSA modulus, base64url-encoded. */
11
+ n: z.string(),
12
+ /** RSA public exponent, base64url-encoded. */
13
+ e: z.string(),
14
+ /** Key-management algorithm for the JWE (`RSA-OAEP-256`). Pair it with `A256GCM` content encryption. */
15
+ alg: z.string(),
16
+ /** Key use. Always `enc`. */
17
+ use: z.string(),
18
+ /** Key identifier. Put it in the JWE protected header. */
19
+ kid: z.string(),
20
+ });
21
+ export type KeyringTransferKey = z.infer<typeof KeyringTransferKeySchema>;
22
+
23
+ /**
24
+ * Response of `composio.keyring.listTransferKeys()`.
25
+ */
26
+ export const KeyringTransferKeysResponseSchema = z.object({
27
+ /** The `kid` of the key to seal new secrets to. */
28
+ activeKid: z.string(),
29
+ /** Every currently accepted transfer key, newest first. */
30
+ keys: z.array(KeyringTransferKeySchema),
31
+ });
32
+ export type KeyringTransferKeysResponse = z.infer<typeof KeyringTransferKeysResponseSchema>;
@@ -0,0 +1,108 @@
1
+ import { z } from 'zod/v3';
2
+
3
+ /**
4
+ * Fields a tool-execution log search can filter on.
5
+ */
6
+ export const LogSearchFilterFieldSchema = z.enum([
7
+ 'tool_slug',
8
+ 'toolkit_slug',
9
+ 'connected_account_id',
10
+ 'auth_config_id',
11
+ 'status',
12
+ 'user_id',
13
+ 'session_id',
14
+ 'sandbox_id',
15
+ 'request_id',
16
+ 'log_id',
17
+ ]);
18
+ export type LogSearchFilterField = z.infer<typeof LogSearchFilterFieldSchema>;
19
+
20
+ export const LogSearchFilterOperatorSchema = z.enum(['==', '!=', 'contains', 'not_contains']);
21
+ export type LogSearchFilterOperator = z.infer<typeof LogSearchFilterOperatorSchema>;
22
+
23
+ export const LogSearchFilterSchema = z.object({
24
+ field: LogSearchFilterFieldSchema,
25
+ operator: LogSearchFilterOperatorSchema,
26
+ value: z.string(),
27
+ });
28
+ export type LogSearchFilter = z.infer<typeof LogSearchFilterSchema>;
29
+
30
+ export const LogSearchTimeRangeSchema = z.object({
31
+ /** Start time in epoch milliseconds (inclusive). */
32
+ from: z.number(),
33
+ /** End time in epoch milliseconds. */
34
+ to: z.number(),
35
+ });
36
+ export type LogSearchTimeRange = z.infer<typeof LogSearchTimeRangeSchema>;
37
+
38
+ /**
39
+ * Params for `composio.logs.search()`.
40
+ */
41
+ export const LogSearchParamsSchema = z.object({
42
+ limit: z.number().optional(),
43
+ cursor: z.string().nullable().optional(),
44
+ filters: z.array(LogSearchFilterSchema).optional(),
45
+ timeRange: LogSearchTimeRangeSchema.optional(),
46
+ });
47
+ export type LogSearchParams = z.infer<typeof LogSearchParamsSchema>;
48
+
49
+ export const ToolExecutionLogStatusSchema = z.enum(['success', 'failed']);
50
+ export const ToolExecutionLogLevelSchema = z.enum(['info', 'error', 'warn']);
51
+
52
+ export const ToolExecutionLogParentSchema = z
53
+ .object({
54
+ logId: z.string(),
55
+ toolSlug: z.string(),
56
+ })
57
+ .nullable();
58
+
59
+ /**
60
+ * A tool-execution log entry as returned by `composio.logs.search()`.
61
+ */
62
+ export const ToolExecutionLogSchema = z.object({
63
+ id: z.string(),
64
+ /** ISO 8601 timestamp. */
65
+ timestamp: z.string(),
66
+ /** Log event type, e.g. `tool.execution`. */
67
+ type: z.string(),
68
+ status: ToolExecutionLogStatusSchema,
69
+ level: ToolExecutionLogLevelSchema,
70
+ message: z.string().optional(),
71
+ metadata: z.record(z.string(), z.unknown()),
72
+ metrics: z.record(z.string(), z.unknown()),
73
+ parent: ToolExecutionLogParentSchema,
74
+ });
75
+ export type ToolExecutionLog = z.infer<typeof ToolExecutionLogSchema>;
76
+
77
+ export const LogSearchResponseSchema = z.object({
78
+ logs: z.array(ToolExecutionLogSchema),
79
+ nextCursor: z.string().nullable(),
80
+ });
81
+ export type LogSearchResponse = z.infer<typeof LogSearchResponseSchema>;
82
+
83
+ /**
84
+ * A single tool-execution log with its full detail, as returned by
85
+ * `composio.logs.get()`.
86
+ */
87
+ export const ToolExecutionLogDetailSchema = ToolExecutionLogSchema.extend({
88
+ timings: z
89
+ .object({
90
+ /** Epoch milliseconds. */
91
+ startTime: z.number(),
92
+ /** Epoch milliseconds. */
93
+ endTime: z.number(),
94
+ })
95
+ .optional(),
96
+ context: z.object({
97
+ sessionId: z.string().optional(),
98
+ traceId: z.string().optional(),
99
+ requestId: z.string().optional(),
100
+ }),
101
+ source: z.object({
102
+ host: z.string().optional(),
103
+ framework: z.string().optional(),
104
+ language: z.string().optional(),
105
+ }),
106
+ data: z.record(z.string(), z.unknown()),
107
+ });
108
+ export type ToolExecutionLogDetail = z.infer<typeof ToolExecutionLogDetailSchema>;
@@ -4,7 +4,11 @@ import { SessionMetaToolOptions } from './modifiers.types';
4
4
  import { ConnectionRequest } from './connectionRequest.types';
5
5
  import type { ComposioRequestOptions } from './requestOptions.types';
6
6
  import type { ToolRouterSessionFilesMount } from '../models/ToolRouterSessionFileMount';
7
- import type { SessionCreateResponse } from '@composio/client/resources/tool-router/session/session.mjs';
7
+ import { ConnectedAccountExperimentalSchema } from './connectedAccounts.types';
8
+ import type {
9
+ SessionConfigHistoryResponse,
10
+ SessionCreateResponse,
11
+ } from '@composio/client/resources/tool-router/session/session.mjs';
8
12
  import type {
9
13
  CustomTool,
10
14
  CustomToolkit,
@@ -213,7 +217,7 @@ const ToolRouterCreateSessionConfigBaseSchema = z
213
217
  .boolean()
214
218
  .optional()
215
219
  .describe(
216
- 'When true, the returned session surfaces its hosted MCP endpoint (`session.mcp.url` / `session.mcp.headers`) in the type. The endpoint exists on every session at runtime regardless of this flag, but is only typed when `mcp: true` is passed. Default native tools (`session.tools()`) are unaffected. See https://docs.composio.dev/docs/sessions-via-mcp'
220
+ 'When true, the returned session surfaces its hosted MCP endpoint (`session.mcp.url` / `session.mcp.headers`) in the type, and an MCP URL that is not on the API base URL origin throws `ComposioMCPDestinationError` instead of leaving `session.mcp.headers` empty with a warning. The endpoint exists on every session at runtime regardless of this flag, but is only typed when `mcp: true` is passed. Default native tools (`session.tools()`) are unaffected. See https://docs.composio.dev/docs/sessions-via-mcp'
217
221
  ),
218
222
 
219
223
  tools: z
@@ -591,7 +595,9 @@ export type ToolRouterSessionExecuteFn = (
591
595
 
592
596
  export interface ToolRouterSessionExecuteOptions {
593
597
  /**
594
- * Account identifier for direct app tool execution in multi-account sessions.
598
+ * Account identifier for direct app tool execution. Accepted on every project:
599
+ * in multi-account sessions it picks the account; on single-account projects it
600
+ * must match one of the session's active connections for the toolkit.
595
601
  * Meta/helper tools either ignore this top-level field or define
596
602
  * their own account-selection fields, for example
597
603
  * COMPOSIO_MULTI_EXECUTE_TOOL.tools[].account.
@@ -605,7 +611,16 @@ export type ToolRouterSessionWorkbenchConfig = SessionCreateResponse.Config.Work
605
611
 
606
612
  export type ToolRouterSessionWarning = SessionCreateResponse.Warning;
607
613
 
614
+ /**
615
+ * Server-side session configuration as returned by the API: toolkit and tool
616
+ * allowlists, tags, auth configs, connected accounts, manage_connections,
617
+ * preload, sandbox (`workbench`), search and execute settings.
618
+ */
619
+ export type ToolRouterSessionConfig = SessionCreateResponse.Config;
620
+
608
621
  export interface ToolRouterSessionMetadata {
622
+ /** Present on every session built from an API response; the constructor synthesises a minimal config when absent. */
623
+ config?: ToolRouterSessionConfig;
609
624
  preload?: ToolRouterSessionPreloadConfig;
610
625
  workbench?: ToolRouterSessionWorkbenchConfig;
611
626
  configVersion?: number;
@@ -640,6 +655,107 @@ export type ToolRouterSessionProxyExecuteFn = (
640
655
  params: SessionProxyExecuteParams
641
656
  ) => Promise<ToolRouterSessionProxyExecuteResponse>;
642
657
 
658
+ /**
659
+ * `manageConnections` shape accepted by `session.update()`. Unlike the create
660
+ * schema, `callbackUrl: null` removes the stored callback URL while leaving
661
+ * the sibling connection settings untouched.
662
+ */
663
+ export const ToolRouterUpdateManageConnectionsSchema = z
664
+ .object({
665
+ enable: z
666
+ .boolean()
667
+ .optional()
668
+ .describe(
669
+ 'Whether to use tools to manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually'
670
+ ),
671
+ callbackUrl: z
672
+ .string()
673
+ .nullable()
674
+ .optional()
675
+ .describe(
676
+ 'The callback url to use in the tool router session. `null` removes the stored callback url; sibling settings are untouched'
677
+ ),
678
+ waitForConnections: z
679
+ .boolean()
680
+ .optional()
681
+ .describe(
682
+ 'Whether to wait for users to finish authenticating connections before proceeding to the next step. Defaults to false, if set to true, a wait for connections tool call will happen and finish when the connections are ready'
683
+ ),
684
+ enableConnectionRemoval: z
685
+ .boolean()
686
+ .nullable()
687
+ .optional()
688
+ .describe(
689
+ 'Whether the session exposes the connection removal tool. `null` removes the stored override'
690
+ ),
691
+ })
692
+ .strict();
693
+ export type ToolRouterUpdateManageConnectionsConfig = z.infer<
694
+ typeof ToolRouterUpdateManageConnectionsSchema
695
+ >;
696
+
697
+ const ToolRouterElicitationDefaultSchema = z.enum([
698
+ 'allow_all',
699
+ 'ask_every_call',
700
+ 'ask_once_per_session',
701
+ ]);
702
+ const ToolRouterElicitationOverrideSchema = z.enum([
703
+ 'always_allow',
704
+ 'always_deny',
705
+ 'ask_once',
706
+ 'ask_always',
707
+ ]);
708
+
709
+ /**
710
+ * `experimental` block accepted by `session.update()`. Each leaf follows the
711
+ * PATCH contract of the API: omit to keep the stored value, `null` to remove
712
+ * it, a value to replace it.
713
+ */
714
+ export const ToolRouterUpdateExperimentalSchema = z
715
+ .object({
716
+ permissions: z
717
+ .object({
718
+ default: ToolRouterElicitationDefaultSchema,
719
+ overrides: z.record(z.string(), ToolRouterElicitationOverrideSchema).optional(),
720
+ })
721
+ .strict()
722
+ .nullable()
723
+ .optional()
724
+ .describe('Per-tool elicitation permission config. `null` removes the stored block'),
725
+ linkUrlOverwrite: z
726
+ .string()
727
+ .nullable()
728
+ .optional()
729
+ .describe(
730
+ 'Base URL override for connection link redirects. `null` removes the stored override'
731
+ ),
732
+ fastMode: z
733
+ .boolean()
734
+ .nullable()
735
+ .optional()
736
+ .describe('Fast search mode. `null` removes the stored override'),
737
+ submitFeedback: z
738
+ .object({ enable: z.boolean() })
739
+ .strict()
740
+ .nullable()
741
+ .optional()
742
+ .describe(
743
+ 'Exposes the COMPOSIO_SUBMIT_FEEDBACK helper tool. `null` removes the stored block'
744
+ ),
745
+ sessionConfigId: z
746
+ .string()
747
+ .optional()
748
+ .describe('Apply the latest active Session config from this project to this session'),
749
+ })
750
+ .strict();
751
+ export type ToolRouterUpdateExperimentalConfig = z.infer<typeof ToolRouterUpdateExperimentalSchema>;
752
+
753
+ /**
754
+ * Options for `session.update()`. For every policy block, omitting the key
755
+ * preserves the stored value and `null` removes the stored override (which can
756
+ * increase access: `toolkits: null` restores the unrestricted default, unlike
757
+ * `toolkits: []`, which denies every app toolkit).
758
+ */
643
759
  export const ToolRouterUpdateSessionConfigSchema = z
644
760
  .object({
645
761
  toolkits: z
@@ -648,12 +764,24 @@ export const ToolRouterUpdateSessionConfigSchema = z
648
764
  ToolRouterToolkitsDisabledConfigSchema,
649
765
  ToolRouterToolkitsEnabledConfigSchema,
650
766
  ])
651
- .optional(),
767
+ .nullable()
768
+ .optional()
769
+ .describe(
770
+ 'Toolkit policy. An empty allowlist (`[]` or `{ enable: [] }`) is sent as-is and denies every app toolkit; `null` removes the stored policy and restores the unrestricted default'
771
+ ),
652
772
  tools: z
653
773
  .record(z.string(), z.union([ToolRouterToolsParamSchema, ToolRouterConfigToolsSchema]))
654
- .optional(),
655
- tags: ToolRouterConfigTagsSchema.optional(),
656
- authConfigs: z.record(z.string(), z.string()).optional(),
774
+ .nullable()
775
+ .optional()
776
+ .describe('Replaces the entire stored tools map; `null` removes the override'),
777
+ tags: ToolRouterConfigTagsSchema.nullable()
778
+ .optional()
779
+ .describe('Replaces the global tag policy; `null` removes the override'),
780
+ authConfigs: z
781
+ .record(z.string(), z.string())
782
+ .nullable()
783
+ .optional()
784
+ .describe('Replaces the entire stored auth config map; `null` removes the override'),
657
785
  connectedAccounts: z
658
786
  .record(z.string(), z.union([z.string(), z.array(z.string())]))
659
787
  .transform(rec => {
@@ -663,9 +791,11 @@ export const ToolRouterUpdateSessionConfigSchema = z
663
791
  }
664
792
  return out;
665
793
  })
666
- .optional(),
794
+ .nullable()
795
+ .optional()
796
+ .describe('Replaces the entire stored connected accounts map; `null` removes the override'),
667
797
  manageConnections: z
668
- .union([z.boolean(), ToolRouterConfigManageConnectionsSchema])
798
+ .union([z.boolean(), ToolRouterUpdateManageConnectionsSchema])
669
799
  .nullable()
670
800
  .optional(),
671
801
  sandbox: ToolRouterSandboxConfigSchema.partial().nullable().optional(),
@@ -673,17 +803,48 @@ export const ToolRouterUpdateSessionConfigSchema = z
673
803
  multiAccount: z
674
804
  .object({
675
805
  enable: z.boolean().optional(),
676
- maxAccountsPerToolkit: z.number().int().min(2).max(10).optional(),
806
+ maxAccountsPerToolkit: z
807
+ .number()
808
+ .int()
809
+ .min(2)
810
+ .max(10)
811
+ .nullable()
812
+ .optional()
813
+ .describe('`null` removes the stored maximum so the default applies again'),
677
814
  requireExplicitSelection: z.boolean().optional(),
678
815
  })
679
816
  .nullable()
680
- .optional(),
817
+ .optional()
818
+ .describe('`null` removes the session override; the mode then resolves to disabled'),
681
819
  preload: z
682
820
  .object({
683
821
  tools: z.union([z.array(z.string()), z.literal('all')]).optional(),
684
822
  })
685
823
  .strict()
686
- .optional(),
824
+ .nullable()
825
+ .optional()
826
+ .describe('Replaces the stored preload; `null` removes it'),
827
+ search: z
828
+ .object({ enable: z.boolean().optional() })
829
+ .strict()
830
+ .nullable()
831
+ .optional()
832
+ .describe('Replaces the search block; `null` removes it and restores the defaults'),
833
+ execute: z
834
+ .object({ enableMultiExecute: z.boolean().optional() })
835
+ .strict()
836
+ .nullable()
837
+ .optional()
838
+ .describe('Replaces the execute block; `null` removes it and restores the defaults'),
839
+ experimental: ToolRouterUpdateExperimentalSchema.nullable()
840
+ .optional()
841
+ .describe('Experimental settings; `null` removes the stored block'),
842
+ expectedConfigVersion: z
843
+ .union([z.number().int().positive(), z.literal(false)])
844
+ .optional()
845
+ .describe(
846
+ 'Precondition sent as `expected_config_version`. Omitted: the session sends the configVersion it last observed, so a concurrent change surfaces as ComposioSessionConfigConflictError instead of being overwritten. A positive integer sends that version instead. `false` sends no precondition (last writer wins)'
847
+ ),
687
848
  })
688
849
  .partial()
689
850
  .superRefine((config, ctx) => {
@@ -699,7 +860,9 @@ export const ToolRouterUpdateSessionConfigSchema = z
699
860
 
700
861
  export type ToolRouterUpdateSessionConfig = z.infer<typeof ToolRouterUpdateSessionConfigSchema>;
701
862
 
702
- export type ToolRouterSessionUpdateFn = (config: ToolRouterUpdateSessionConfig) => Promise<void>;
863
+ export type ToolRouterSessionUpdateFn = (
864
+ config: ToolRouterUpdateSessionConfig
865
+ ) => Promise<ToolRouterSessionConfig>;
703
866
 
704
867
  export const ToolRouterSessionDeleteResponseSchema = z.object({
705
868
  sessionId: z.string(),
@@ -707,10 +870,82 @@ export const ToolRouterSessionDeleteResponseSchema = z.object({
707
870
  });
708
871
  export type ToolRouterSessionDeleteResponse = z.infer<typeof ToolRouterSessionDeleteResponseSchema>;
709
872
 
873
+ /**
874
+ * Options for `session.listConfigHistory()`.
875
+ */
876
+ export const ToolRouterSessionListConfigHistoryOptionsSchema = z.object({
877
+ /** Cursor from a previous response's `nextCursor`. */
878
+ cursor: z.string().optional(),
879
+ /** Number of items per page, max allowed is 100. */
880
+ limit: z.number().optional(),
881
+ });
882
+ export type ToolRouterSessionListConfigHistoryOptions = z.infer<
883
+ typeof ToolRouterSessionListConfigHistoryOptionsSchema
884
+ >;
885
+
886
+ /**
887
+ * The session configuration at one version, as stored by the API. This is
888
+ * the wire shape (snake_case), typed from the generated client.
889
+ */
890
+ export type ToolRouterSessionConfigHistoryConfig = SessionConfigHistoryResponse.Item.Config;
891
+
892
+ export type ToolRouterSessionConfigHistoryItem = {
893
+ /** The config version this entry represents. */
894
+ version: number;
895
+ /** ISO timestamp — for archived rows, when the version was superseded by an update. */
896
+ createdAt: string;
897
+ /** True only for the live (current) config, present on the first page. */
898
+ isCurrent: boolean;
899
+ /** The session configuration at this version. */
900
+ config: ToolRouterSessionConfigHistoryConfig;
901
+ };
902
+
903
+ export type ToolRouterSessionListConfigHistoryResponse = {
904
+ items: ToolRouterSessionConfigHistoryItem[];
905
+ nextCursor: string | null;
906
+ totalPages: number;
907
+ currentPage: number;
908
+ totalItems: number;
909
+ };
910
+
911
+ export type ToolRouterSessionListConfigHistoryFn = (
912
+ options?: ToolRouterSessionListConfigHistoryOptions,
913
+ requestOptions?: ComposioRequestOptions
914
+ ) => Promise<ToolRouterSessionListConfigHistoryResponse>;
915
+
710
916
  export type ToolRouterSessionDeleteFn = (
711
917
  requestOptions?: ComposioRequestOptions
712
918
  ) => Promise<ToolRouterSessionDeleteResponse>;
713
919
 
920
+ export const ToolRouterSessionEnsureConnectedOptionsSchema = z.object({
921
+ callbackUrl: z.string().optional(),
922
+ alias: z.string().optional(),
923
+ experimental: ConnectedAccountExperimentalSchema.optional(),
924
+ /** Max time to wait for a newly-initiated connection to become active, in milliseconds. Defaults to 60000. */
925
+ timeout: z.number().int().positive().optional(),
926
+ });
927
+ export type ToolRouterSessionEnsureConnectedOptions = z.infer<
928
+ typeof ToolRouterSessionEnsureConnectedOptionsSchema
929
+ >;
930
+
931
+ export type ToolRouterSessionEnsureConnectedResult = {
932
+ /** Canonical slug of the toolkit this call ensured. */
933
+ toolkit: string;
934
+ /** True when the session already had an active connection (or a no-auth toolkit) — no link was created. */
935
+ wasConnected: boolean;
936
+ /** The active connected account backing the toolkit. Omitted for no-auth toolkits. */
937
+ connectedAccount?: {
938
+ id: string;
939
+ status: string;
940
+ };
941
+ };
942
+
943
+ export type ToolRouterSessionEnsureConnectedFn = (
944
+ toolkit: string,
945
+ options?: ToolRouterSessionEnsureConnectedOptions,
946
+ requestOptions?: ComposioRequestOptions
947
+ ) => Promise<ToolRouterSessionEnsureConnectedResult>;
948
+
714
949
  /** Session type returned by ToolRouter.create() and ToolRouter.use() */
715
950
  export interface Session<
716
951
  TToolCollection,
@@ -719,6 +954,12 @@ export interface Session<
719
954
  > {
720
955
  sessionId: string;
721
956
  mcp: ToolRouterMCPServerConfig;
957
+ /**
958
+ * Server-side session configuration (toolkit/tool allowlists, tags, preload,
959
+ * sandbox, manage_connections) as returned by the API. Refreshed in place by
960
+ * `update()`.
961
+ */
962
+ config: ToolRouterSessionConfig;
722
963
  /** Stored preload configuration for this session. */
723
964
  preload: ToolRouterSessionPreloadConfig;
724
965
  /**
@@ -739,15 +980,19 @@ export interface Session<
739
980
  warnings: ToolRouterSessionWarning[];
740
981
  tools: ToolRouterToolsFn<TToolCollection, TTool, TProvider>;
741
982
  authorize: ToolRouterAuthorizeFn;
983
+ /** Ensure a toolkit has an active connection, linking and waiting only when needed. */
984
+ ensureConnected: ToolRouterSessionEnsureConnectedFn;
742
985
  toolkits: ToolRouterToolkitsFn;
743
986
  /** Search for tools by semantic use case */
744
987
  search: ToolRouterSessionSearchFn;
745
988
  /** Execute a tool within the session */
746
989
  execute: ToolRouterSessionExecuteFn;
747
- /** Update the session configuration. Mutates this session in-place. */
990
+ /** Update the session configuration. Mutates this session in-place and resolves to the updated `config`. */
748
991
  update: ToolRouterSessionUpdateFn;
749
992
  /** Delete the session. Deleted sessions are no longer retrievable or executable. */
750
993
  delete: ToolRouterSessionDeleteFn;
994
+ /** Page through the session's configuration history (newest first). */
995
+ listConfigHistory: ToolRouterSessionListConfigHistoryFn;
751
996
  /** Proxy an API call through Composio's auth layer using the session's connected account */
752
997
  proxyExecute: ToolRouterSessionProxyExecuteFn;
753
998
  /** List custom tools registered in this session, with their final slugs and schemas */