@composio/core 0.12.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist/{BaseProvider-BBnsv9kS.d.mts → BaseProvider-Brb3o86-.d.mts} +80 -80
  2. package/dist/{CustomTool-DEB4BQPl.mjs → CustomTool-D9qwyMrv.mjs} +1 -1
  3. package/dist/{CustomTool-DH18rVQu.d.mts → CustomTool-DLf7JeKt.d.mts} +1 -1
  4. package/dist/CustomTool-NpHpqdnU.d.mts +74 -0
  5. package/dist/{composio-CHnEggnv.d.mts → composio-BHSQwOUz.d.mts} +503 -319
  6. package/dist/composio-DfPD7BAi.d.mts +5666 -0
  7. package/dist/{customTool.types-DpIdOJjL.d.mts → customTool.types-9yFqPjdw.d.mts} +448 -76
  8. package/dist/customTool.types-D-6YqFdW.d.mts +2826 -0
  9. package/dist/docs/error-consistency.md +97 -0
  10. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +306 -0
  11. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +205 -0
  12. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +488 -0
  13. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +94 -0
  14. package/dist/docs/reference/sdk-reference/typescript/index.mdx +67 -0
  15. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +304 -0
  16. package/dist/docs/reference/sdk-reference/typescript/meta.json +17 -0
  17. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +107 -0
  18. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +163 -0
  19. package/dist/docs/reference/sdk-reference/typescript/session.mdx +252 -0
  20. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +155 -0
  21. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +169 -0
  22. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +453 -0
  23. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +434 -0
  24. package/dist/{errors-D5f4pfvI.mjs → errors-DSIlYfl5.mjs} +2 -2
  25. package/dist/experimental/index.d.mts +2 -2
  26. package/dist/experimental/index.mjs +1 -1
  27. package/dist/index.d.mts +36 -6
  28. package/dist/index.mjs +455 -123
  29. package/dist/{jsonSchema-daqF3S3d.mjs → jsonSchema-CFKdONpP.mjs} +1 -1
  30. package/dist/{types-CaI5Z4PA.d.mts → types-BJLCRj9q.d.mts} +2 -2
  31. package/dist/types-CCh8qvui.d.mts +12 -0
  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/docs/error-consistency.md +97 -0
  38. package/package.json +4 -3
  39. package/src/composio.ts +509 -0
  40. package/src/errors/AuthConfigErrors.ts +23 -0
  41. package/src/errors/ComposioError.ts +408 -0
  42. package/src/errors/ConnectedAccountsErrors.ts +158 -0
  43. package/src/errors/ConnectionRequestErrors.ts +32 -0
  44. package/src/errors/FileModifierErrors.ts +100 -0
  45. package/src/errors/PusherErrors.ts +28 -0
  46. package/src/errors/RemoteFileErrors.ts +62 -0
  47. package/src/errors/SDKErrors.ts +92 -0
  48. package/src/errors/ToolErrors.ts +244 -0
  49. package/src/errors/ToolkitErrors.ts +39 -0
  50. package/src/errors/TriggerErrors.ts +120 -0
  51. package/src/errors/ValidationErrors.ts +99 -0
  52. package/src/errors/index.ts +41 -0
  53. package/src/experimental/index.ts +28 -0
  54. package/src/index.ts +64 -0
  55. package/src/lib/toolRouterConstants.ts +1 -0
  56. package/src/lib/toolRouterParams.ts +306 -0
  57. package/src/lib/toolRouterSessionDelete.ts +30 -0
  58. package/src/models/AuthConfigs.ts +398 -0
  59. package/src/models/AuthScheme.ts +206 -0
  60. package/src/models/ConnectedAccounts.ts +735 -0
  61. package/src/models/ConnectionRequest.ts +150 -0
  62. package/src/models/CustomTool.ts +676 -0
  63. package/src/models/Experimental.ts +202 -0
  64. package/src/models/Files.node.ts +93 -0
  65. package/src/models/Files.workerd.ts +49 -0
  66. package/src/models/MCP.ts +478 -0
  67. package/src/models/RemoteFile.ts +172 -0
  68. package/src/models/SessionContext.ts +147 -0
  69. package/src/models/Sessions.ts +21 -0
  70. package/src/models/ToolRouter.ts +406 -0
  71. package/src/models/ToolRouterSession.ts +839 -0
  72. package/src/models/ToolRouterSessionFileMount.ts +389 -0
  73. package/src/models/Toolkits.ts +412 -0
  74. package/src/models/Tools.ts +1260 -0
  75. package/src/models/Triggers.ts +1381 -0
  76. package/src/models/customToolExecution.ts +118 -0
  77. package/src/models/inlineCustomToolsPayload.ts +17 -0
  78. package/src/models/proxyParamsTransform.ts +26 -0
  79. package/src/provider/BaseProvider.ts +138 -0
  80. package/src/provider/ComposioProvider.ts +29 -0
  81. package/src/provider/OpenAIProvider.ts +547 -0
  82. package/src/services/internal/InternalService.ts +50 -0
  83. package/src/services/internal/InternalService.types.ts +14 -0
  84. package/src/services/pusher/Pusher.ts +230 -0
  85. package/src/services/telemetry/TelemetryService.ts +48 -0
  86. package/src/services/telemetry/TelemetryService.types.ts +67 -0
  87. package/src/telemetry/BatchProcessor.ts +77 -0
  88. package/src/telemetry/README.md +123 -0
  89. package/src/telemetry/Telemetry.ts +356 -0
  90. package/src/types/ToolRouterSessionFilesMount.types.ts +96 -0
  91. package/src/types/authConfigs.types.ts +174 -0
  92. package/src/types/composio.types.ts +1 -0
  93. package/src/types/connectedAccountAuthStates.types.ts +852 -0
  94. package/src/types/connectedAccounts.types.ts +395 -0
  95. package/src/types/connectionRequest.types.ts +16 -0
  96. package/src/types/customTool.types.ts +261 -0
  97. package/src/types/files.types.ts +15 -0
  98. package/src/types/mcp.experimental.types.ts +163 -0
  99. package/src/types/mcp.types.ts +362 -0
  100. package/src/types/modifiers.types.ts +663 -0
  101. package/src/types/org.types.ts +0 -0
  102. package/src/types/provider.types.ts +41 -0
  103. package/src/types/pusher.types.ts +18 -0
  104. package/src/types/requestOptions.types.ts +62 -0
  105. package/src/types/telemetry.types.ts +89 -0
  106. package/src/types/tool.types.ts +408 -0
  107. package/src/types/toolRouter.types.ts +774 -0
  108. package/src/types/toolkit.types.ts +130 -0
  109. package/src/types/triggers.types.ts +401 -0
  110. package/src/types/webhookEvents.types.ts +219 -0
  111. package/src/utils/buffer.ts +30 -0
  112. package/src/utils/cancellation.ts +22 -0
  113. package/src/utils/config-defaults/ConfigDefaults.node.ts +7 -0
  114. package/src/utils/config-defaults/ConfigDefaults.workerd.ts +10 -0
  115. package/src/utils/config-defaults/index.ts +1 -0
  116. package/src/utils/config-defaults/types.ts +14 -0
  117. package/src/utils/constants.ts +22 -0
  118. package/src/utils/crypto.ts +34 -0
  119. package/src/utils/env.ts +34 -0
  120. package/src/utils/fileDirs.ts +81 -0
  121. package/src/utils/fileUtils.node.ts +458 -0
  122. package/src/utils/json-schema.ts +1 -0
  123. package/src/utils/jsonSchema.ts +355 -0
  124. package/src/utils/logger.ts +99 -0
  125. package/src/utils/mime.ts +75 -0
  126. package/src/utils/modifiers/FileToolModifier.node.ts +477 -0
  127. package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +132 -0
  128. package/src/utils/modifiers/FileToolModifier.workerd.ts +51 -0
  129. package/src/utils/pagination.ts +73 -0
  130. package/src/utils/pusher.ts +286 -0
  131. package/src/utils/schemaPropertyKeys.ts +433 -0
  132. package/src/utils/sdk.ts +110 -0
  133. package/src/utils/sensitiveFileUploadPaths.node.ts +105 -0
  134. package/src/utils/session.ts +114 -0
  135. package/src/utils/toolArguments.ts +73 -0
  136. package/src/utils/toolkitVersion.ts +26 -0
  137. package/src/utils/transform.ts +42 -0
  138. package/src/utils/transformers/authConfigs.ts +107 -0
  139. package/src/utils/transformers/connectedAccounts.ts +119 -0
  140. package/src/utils/transformers/mcp.ts +164 -0
  141. package/src/utils/transformers/toolRouterResponseTransform.ts +160 -0
  142. package/src/utils/transformers/toolkits.ts +100 -0
  143. package/src/utils/transformers/triggers.ts +118 -0
  144. package/src/utils/uploadDirAllowlist.node.ts +178 -0
  145. package/src/utils/uuid.ts +7 -0
  146. package/src/utils/version.ts +58 -0
  147. package/src/utils/zodSchema.ts +90 -0
@@ -0,0 +1,774 @@
1
+ import z from 'zod/v3';
2
+ import type { BaseComposioProvider } from '../provider/BaseProvider';
3
+ import { SessionMetaToolOptions } from './modifiers.types';
4
+ import { ConnectionRequest } from './connectionRequest.types';
5
+ import type { ComposioRequestOptions } from './requestOptions.types';
6
+ import type { ToolRouterSessionFilesMount } from '../models/ToolRouterSessionFileMount';
7
+ import type { SessionCreateResponse } from '@composio/client/resources/tool-router/session/session.mjs';
8
+ import type {
9
+ CustomTool,
10
+ CustomToolkit,
11
+ InlineCustomToolsWirePayload,
12
+ RegisteredCustomTool,
13
+ RegisteredCustomToolkit,
14
+ } from './customTool.types';
15
+ import { PRELOAD_TOOLS_ALL } from '../lib/toolRouterConstants';
16
+
17
+ export const SessionPreset = {
18
+ DIRECT_TOOLS: 'direct_tools',
19
+ } as const;
20
+ export type SessionPreset = (typeof SessionPreset)[keyof typeof SessionPreset];
21
+
22
+ export const MCPServerTypeSchema = z.enum(['http', 'sse']);
23
+ export type MCPServerType = z.infer<typeof MCPServerTypeSchema>;
24
+
25
+ /**
26
+ * Sandbox compute tier for the session sandbox.
27
+ *
28
+ * | Tier | vCPU | RAM |
29
+ * | -------- | ---- | ----- |
30
+ * | standard | 1 | 1 GB |
31
+ * | medium | 2 | 2 GB |
32
+ * | large | 4 | 4 GB |
33
+ * | xlarge | 8 | 8 GB |
34
+ *
35
+ * Defaults to `standard` server-side when omitted.
36
+ */
37
+ export const SandboxSizeSchema = z.enum(['standard', 'medium', 'large', 'xlarge']);
38
+ export type SandboxSize = z.infer<typeof SandboxSizeSchema>;
39
+
40
+ export const ToolRouterSandboxConfigSchema = z.object({
41
+ enable: z
42
+ .boolean()
43
+ .default(true)
44
+ .describe(
45
+ 'Whether to enable the sandbox entirely. Defaults to true. When set to false, no code execution tools (COMPOSIO_REMOTE_WORKBENCH, COMPOSIO_REMOTE_BASH_TOOL) are available in the session.'
46
+ ),
47
+ enableProxyExecution: z
48
+ .boolean()
49
+ .optional()
50
+ .describe('Whether to enable proxy execution in the session sandbox'),
51
+ autoOffloadThreshold: z
52
+ .number()
53
+ .optional()
54
+ .describe(
55
+ 'The auto offload threshold in characters for tool execution to move into the sandbox'
56
+ ),
57
+ sandboxSize: SandboxSizeSchema.optional().describe(
58
+ 'Sandbox compute tier. One of "standard" (1 vCPU / 1 GB), "medium" (2 vCPU / 2 GB), "large" (4 vCPU / 4 GB), or "xlarge" (8 vCPU / 8 GB). Defaults to "standard" server-side. Changing this on an existing session recreates the session sandbox on next access; the in-memory FS is lost, but /mnt/files/ persists.'
59
+ ),
60
+ });
61
+ export type ToolRouterSandboxConfig = z.infer<typeof ToolRouterSandboxConfigSchema>;
62
+
63
+ // manage connections
64
+ export const ToolRouterConfigManageConnectionsSchema = z
65
+ .object({
66
+ enable: z
67
+ .boolean()
68
+ .default(true)
69
+ .optional()
70
+ .describe(
71
+ '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'
72
+ ),
73
+ callbackUrl: z
74
+ .string()
75
+ .optional()
76
+ .describe('The callback uri to use in the tool router session'),
77
+ waitForConnections: z
78
+ .boolean()
79
+ .optional()
80
+ .describe(
81
+ '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'
82
+ ),
83
+ })
84
+ .strict();
85
+
86
+ // toolkits
87
+ export const ToolRouterToolkitsParamSchema = z
88
+ .array(z.string())
89
+ .describe('List of toolkits to enable in the tool router session');
90
+
91
+ export const ToolRouterToolkitsDisabledConfigSchema = z
92
+ .object({
93
+ disable: ToolRouterToolkitsParamSchema.describe(
94
+ 'List of toolkits to disable in the tool router session'
95
+ ),
96
+ })
97
+ .strict();
98
+ export const ToolRouterToolkitsEnabledConfigSchema = z
99
+ .object({
100
+ enable: ToolRouterToolkitsParamSchema.describe(
101
+ 'List of toolkits to enable in the tool router session'
102
+ ),
103
+ })
104
+ .strict();
105
+
106
+ export const ToolRouterManageConnectionsConfigSchema = z.object({
107
+ enable: z
108
+ .boolean()
109
+ .optional()
110
+ .describe(
111
+ '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'
112
+ )
113
+ .default(true),
114
+ callbackUrl: z.string().optional().describe('The callback url to use in the tool router session'),
115
+ });
116
+
117
+ // Tags
118
+ export const ToolRouterTagsParamSchema = z
119
+ .array(z.enum(['readOnlyHint', 'destructiveHint', 'idempotentHint', 'openWorldHint']))
120
+ .describe('The tags to filter the tools by');
121
+ export const ToolRouterTagsEnableDisableSchema = z
122
+ .object({
123
+ enable: ToolRouterTagsParamSchema.optional().describe(
124
+ 'The tags to enable in the tool router session'
125
+ ),
126
+ disable: ToolRouterTagsParamSchema.optional().describe(
127
+ 'The tags to disable in the tool router session'
128
+ ),
129
+ })
130
+ .strict();
131
+ export const ToolRouterConfigTagsSchema = z
132
+ .union([ToolRouterTagsParamSchema, ToolRouterTagsEnableDisableSchema])
133
+ .describe('The tags to use in the tool router session');
134
+ export type ToolRouterConfigTags = z.infer<typeof ToolRouterConfigTagsSchema>;
135
+
136
+ /**
137
+ * Tools config - Configure tools per toolkit using toolkit slug as key
138
+ * @example
139
+ * ```typescript
140
+ * {
141
+ * gmail: {
142
+ * enable: ['gmail_search', 'gmail_send']
143
+ * },
144
+ * slack: {
145
+ * disable: ['slack_delete_message']
146
+ * }
147
+ * }
148
+ * ```
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * {
153
+ * gmail: ['gmail_search', 'gmail_send'],
154
+ * slack: { tags: ['readOnlyHint'] }
155
+ * }
156
+ * ```
157
+ */
158
+ export const ToolRouterToolsParamSchema = z
159
+ .array(z.string())
160
+ .describe('The tools to use in the tool router session');
161
+ export type ToolRouterToolsParam = z.infer<typeof ToolRouterToolsParamSchema>;
162
+
163
+ export const ToolRouterConfigToolsSchema = z
164
+ .union([
165
+ ToolRouterToolsParamSchema,
166
+ z
167
+ .object({
168
+ enable: ToolRouterToolsParamSchema.describe(
169
+ 'The tools to enable in the tool router session'
170
+ ),
171
+ })
172
+ .strict(),
173
+ z
174
+ .object({
175
+ disable: ToolRouterToolsParamSchema.describe(
176
+ 'The tools to disable in the tool router session'
177
+ ),
178
+ })
179
+ .strict(),
180
+ z
181
+ .object({
182
+ tags: ToolRouterConfigTagsSchema.describe(
183
+ 'The tags to filter the tools by, this will override the global tags'
184
+ ),
185
+ })
186
+ .strict(),
187
+ ])
188
+ .superRefine((val, ctx) => {
189
+ // If it's an object (not an array), ensure only one property is present
190
+ if (typeof val === 'object' && !Array.isArray(val)) {
191
+ const keys = Object.keys(val);
192
+ if (keys.length > 1) {
193
+ ctx.addIssue({
194
+ code: z.ZodIssueCode.custom,
195
+ message: `Only one of 'enable', 'disable', or 'tags' can be specified, but found: ${keys.join(', ')}`,
196
+ path: keys,
197
+ });
198
+ }
199
+ }
200
+ });
201
+ export type ToolRouterConfigTools = z.infer<typeof ToolRouterConfigToolsSchema>;
202
+
203
+ const ToolRouterCreateSessionConfigBaseSchema = z
204
+ .object({
205
+ sessionPreset: z
206
+ .literal(SessionPreset.DIRECT_TOOLS)
207
+ .optional()
208
+ .describe(
209
+ 'Shortcut to expose every tool allowed by the session filters directly in session.tools() and the MCP tool list. This disables meta tools by default (search, multi-execute, manage-connections, and workbench). Use when all tools are known upfront and helper/meta tools are not needed. Without this preset, ToolRouter uses its default configuration with meta tools enabled.'
210
+ ),
211
+
212
+ mcp: z
213
+ .boolean()
214
+ .optional()
215
+ .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'
217
+ ),
218
+
219
+ tools: z
220
+ .record(z.string(), z.union([ToolRouterToolsParamSchema, ToolRouterConfigToolsSchema]))
221
+ .optional()
222
+ .describe('The tools to use in the tool router session'),
223
+
224
+ tags: ToolRouterConfigTagsSchema.optional().describe('Global tags to filter the tools by'),
225
+
226
+ toolkits: z
227
+ .union([
228
+ ToolRouterToolkitsParamSchema,
229
+ ToolRouterToolkitsDisabledConfigSchema,
230
+ ToolRouterToolkitsEnabledConfigSchema,
231
+ ])
232
+ .optional()
233
+ .describe('The toolkits to use in the tool router session'),
234
+
235
+ authConfigs: z
236
+ .record(z.string(), z.string())
237
+ .describe(
238
+ 'The auth configs to use in the tool router session. The key is the toolkit slug, the value is the auth config id.'
239
+ )
240
+ .default({}),
241
+ connectedAccounts: z
242
+ .record(z.string(), z.union([z.string(), z.array(z.string())]))
243
+ .describe(
244
+ 'The connected accounts to use in the tool router session. The key is the toolkit slug, the value is a connected account id or an array of ids. Only one account per toolkit is allowed when multi-account mode is disabled.'
245
+ )
246
+ .default({}),
247
+ manageConnections: z
248
+ .union([z.boolean(), ToolRouterConfigManageConnectionsSchema])
249
+ .optional()
250
+ .default(true)
251
+ .describe(
252
+ 'The config for the manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually. If set to an object, you can configure the manage connections settings.'
253
+ ),
254
+ sandbox: ToolRouterSandboxConfigSchema.optional().describe(
255
+ 'The sandbox config for this session. Prefer this over workbench.'
256
+ ),
257
+ workbench: ToolRouterSandboxConfigSchema.optional().describe(
258
+ 'Deprecated alias for sandbox. Accepted for backwards compatibility.'
259
+ ),
260
+ multiAccount: z
261
+ .object({
262
+ enable: z
263
+ .boolean()
264
+ .default(false)
265
+ .describe('When true, enables multi-account mode for this session. Defaults to false.'),
266
+ maxAccountsPerToolkit: z
267
+ .number()
268
+ .int()
269
+ .min(2)
270
+ .max(10)
271
+ .optional()
272
+ .describe(
273
+ 'Maximum number of connected accounts allowed per toolkit. Defaults to 5 when multi-account is enabled.'
274
+ ),
275
+ requireExplicitSelection: z
276
+ .boolean()
277
+ .optional()
278
+ .describe(
279
+ 'When true, require explicit account selection when multiple accounts are connected. When false (default), use the first/default account.'
280
+ ),
281
+ })
282
+ .optional()
283
+ .describe('Multi-account configuration for this session'),
284
+
285
+ preload: z
286
+ .object({
287
+ tools: z
288
+ .union([z.array(z.string()), z.literal(PRELOAD_TOOLS_ALL)])
289
+ .optional()
290
+ .describe(
291
+ 'Tool slugs to preload into session.tools() and the MCP tool list, or "all" to preload every app tool allowed by the session filters. "all" requires a positive filter such as toolkits, tools, or tags; the backend validates and caps the final tool set.'
292
+ ),
293
+ })
294
+ .strict()
295
+ .optional()
296
+ .describe('Preload configuration for tools that should be exposed without search.'),
297
+
298
+ experimental: z
299
+ .object({
300
+ assistivePrompt: z
301
+ .object({
302
+ userTimezone: z
303
+ .string()
304
+ .optional()
305
+ .describe(
306
+ 'IANA timezone identifier (e.g., "America/New_York", "Europe/London") for timezone-aware assistive prompts'
307
+ ),
308
+ })
309
+ .optional()
310
+ .describe('Configuration for assistive prompt generation'),
311
+ customTools: z
312
+ .array(z.custom<CustomTool>())
313
+ .optional()
314
+ .describe(
315
+ 'Custom tools to include in this session. Created via createCustomTool() from @composio/core/experimental.'
316
+ ),
317
+ customToolkits: z
318
+ .array(z.custom<CustomToolkit>())
319
+ .optional()
320
+ .describe(
321
+ 'Custom toolkits to include in this session. Created via createCustomToolkit() from @composio/core/experimental.'
322
+ ),
323
+ })
324
+ .optional()
325
+ .describe('Experimental features configuration - not stable, may be modified or removed'),
326
+ })
327
+ .partial()
328
+ .superRefine((config, ctx) => {
329
+ if (config.sandbox !== undefined && config.workbench !== undefined) {
330
+ ctx.addIssue({
331
+ code: z.ZodIssueCode.custom,
332
+ message:
333
+ 'Pass either sandbox or workbench, not both. workbench is a backwards-compatible alias for sandbox.',
334
+ path: ['sandbox'],
335
+ });
336
+ }
337
+ })
338
+ .describe('The config for the tool router session');
339
+
340
+ const applyDirectToolsPresetDefaults = (value: unknown): unknown => {
341
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
342
+ return value;
343
+ }
344
+
345
+ const config = value as Record<string, unknown>;
346
+ if (config.sessionPreset !== SessionPreset.DIRECT_TOOLS) {
347
+ return value;
348
+ }
349
+
350
+ const hasSandboxConfig = config.sandbox !== undefined || config.workbench !== undefined;
351
+
352
+ return {
353
+ ...config,
354
+ manageConnections: config.manageConnections === undefined ? false : config.manageConnections,
355
+ ...(hasSandboxConfig ? {} : { sandbox: { enable: false } }),
356
+ preload: config.preload === undefined ? { tools: PRELOAD_TOOLS_ALL } : config.preload,
357
+ };
358
+ };
359
+
360
+ export const ToolRouterCreateSessionConfigSchema = z
361
+ .preprocess(applyDirectToolsPresetDefaults, ToolRouterCreateSessionConfigBaseSchema)
362
+ .describe('The config for the tool router session');
363
+ /**
364
+ * The config for the tool router session.
365
+ *
366
+ * @param {SessionPreset} [sessionPreset] - Shortcut that exposes every tool allowed by the session filters directly in session.tools() and the MCP tool list. Disables search, multi-execute, manage-connections, and sandbox by default; explicit overrides for supported fields still win. Without this preset, ToolRouter uses the default configuration with meta tools enabled.
367
+ * @param {ToolRouterToolkitsParamSchema | ToolRouterToolkitsDisabledConfigSchema | ToolRouterToolkitsEnabledConfigSchema} toolkits - The toolkits to use in the tool router session
368
+ * @param {Record<string, ToolRouterToolsParam | ToolRouterConfigTools>} tools - The tools to configure per toolkit (key is toolkit slug)
369
+ * @param {Array<'readOnlyHint' | 'destructiveHint' | 'idempotentHint' | 'openWorldHint'>} tags - Global tags to filter tools by behavior
370
+ * @param {Record<string, string>} authConfigs - The auth configs to use in the tool router session
371
+ * @param {Record<string, string | string[]>} connectedAccounts - The connected accounts to use in the tool router session. A single string is coerced to a single-element array before being sent to the backend.
372
+ * @param {ToolRouterConfigManageConnectionsSchema | boolean} manageConnections - The config for the manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually. If set to an object, you can configure the manage connections settings.
373
+ * @param {boolean} [manageConnections.enable] - Whether to use tools to manage connections in the tool router session @default true
374
+ * @param {string} [manageConnections.callbackUrl] - The callback url to use in the tool router session
375
+ * @param {object} sandbox - Sandbox configuration for code execution. Preferred over workbench.
376
+ * @param {boolean} [sandbox.enable] - Whether to enable the sandbox entirely. Defaults to true. When false, no code execution tools are available.
377
+ * @param {boolean} [sandbox.enableProxyExecution] - Whether to enable proxy execution
378
+ * @param {number} [sandbox.autoOffloadThreshold] - Auto offload threshold in characters for moving execution to the sandbox
379
+ * @param {SandboxSize} [sandbox.sandboxSize] - Sandbox compute tier: 'standard' (1 vCPU/1 GB, default), 'medium' (2 vCPU/2 GB), 'large' (4 vCPU/4 GB), or 'xlarge' (8 vCPU/8 GB)
380
+ * @param {object} workbench - Deprecated alias for sandbox. Accepted for backwards compatibility.
381
+ * @param {object} [multiAccount] - Multi-account configuration for this session
382
+ * @param {boolean} [multiAccount.enable] - When true, enables multi-account mode. Falls back to org/project-level config when not set.
383
+ * @param {number} [multiAccount.maxAccountsPerToolkit] - Max connected accounts per toolkit (2-10, default 5)
384
+ * @param {boolean} [multiAccount.requireExplicitSelection] - When true, require explicit account selection when multiple accounts are connected
385
+ * @param {object} [preload] - Tools to preload into session.tools() and the MCP tool list
386
+ * @param {string[] | 'all'} [preload.tools] - Tool slugs to preload, or "all" to preload every app tool allowed by the session filters. "all" requires a positive filter such as toolkits, tools, or tags; the backend validates and caps the final tool set.
387
+ */
388
+ export type ToolRouterCreateSessionConfig = z.infer<typeof ToolRouterCreateSessionConfigSchema>;
389
+
390
+ export const ToolkitConnectionStateSchema = z
391
+ .object({
392
+ slug: z.string().describe('The slug of a toolkit'),
393
+ name: z.string().describe('The name of a toolkit'),
394
+ logo: z.string().optional().describe('The logo of a toolkit'),
395
+ isNoAuth: z.boolean().default(false).describe('Whether the toolkit is no auth or not'),
396
+ connection: z
397
+ .object({
398
+ isActive: z.boolean().describe('Whether the connection is active or not'),
399
+ authConfig: z
400
+ .object({
401
+ id: z.string().describe('The id of the auth config'),
402
+ mode: z.string().describe('The auth scheme used by the auth config'),
403
+ isComposioManaged: z
404
+ .boolean()
405
+ .describe('Whether the auth config is managed by Composio'),
406
+ })
407
+ .nullish()
408
+ .describe('The auth config of a toolkit'),
409
+ connectedAccount: z
410
+ .object({
411
+ id: z.string().describe('The id of the connected account'),
412
+ status: z.string().describe('The status of the connected account'),
413
+ })
414
+ .optional()
415
+ .describe('The connected account of a toolkit'),
416
+ })
417
+ .optional()
418
+ .describe('The connection of a toolkit'),
419
+ })
420
+ .describe('The connection state of a toolkit');
421
+
422
+ export const ToolkitConnectionsDetailsSchema = z.object({
423
+ items: z.array(ToolkitConnectionStateSchema),
424
+ cursor: z.string().optional(),
425
+ totalPages: z.number(),
426
+ });
427
+ export type ToolkitConnectionsDetails = z.infer<typeof ToolkitConnectionsDetailsSchema>;
428
+
429
+ export type ToolkitConnectionState = z.infer<typeof ToolkitConnectionStateSchema>;
430
+
431
+ export const ToolRouterMCPServerConfigSchema = z.object({
432
+ type: MCPServerTypeSchema,
433
+ url: z.string(),
434
+ headers: z.record(z.string(), z.string()).optional(),
435
+ });
436
+ export type ToolRouterMCPServerConfig = z.infer<typeof ToolRouterMCPServerConfigSchema>;
437
+
438
+ export type ToolRouterToolsFn<
439
+ TToolCollection,
440
+ TTool,
441
+ TProvider extends BaseComposioProvider<TToolCollection, TTool, unknown>,
442
+ > = (modifiers?: SessionMetaToolOptions) => Promise<ReturnType<TProvider['wrapTools']>>;
443
+
444
+ export type ToolRouterAuthorizeFn = (
445
+ toolkit: string,
446
+ options?: { callbackUrl?: string; alias?: string }
447
+ ) => Promise<ConnectionRequest>;
448
+
449
+ export const ToolRouterToolkitsOptionsSchema = z.object({
450
+ toolkits: z.array(z.string()).optional(),
451
+ cursor: z.string().optional(),
452
+ limit: z.number().optional(),
453
+ isConnected: z.boolean().optional(),
454
+ search: z.string().optional(),
455
+ });
456
+ export type ToolRouterToolkitsOptions = z.infer<typeof ToolRouterToolkitsOptionsSchema>;
457
+
458
+ export type ToolRouterToolkitsFn = (
459
+ options?: ToolRouterToolkitsOptions
460
+ ) => Promise<ToolkitConnectionsDetails>;
461
+
462
+ // --- Session search response schemas (camelCase) ---
463
+
464
+ const ToolRouterSessionSearchResultReferenceWorkbenchSnippetSchema = z.object({
465
+ code: z.string(),
466
+ description: z.string(),
467
+ });
468
+
469
+ const ToolRouterSessionSearchResultSchema = z.object({
470
+ index: z.number(),
471
+ useCase: z.string(),
472
+ primaryToolSlugs: z.array(z.string()),
473
+ relatedToolSlugs: z.array(z.string()),
474
+ toolkits: z.array(z.string()),
475
+ difficulty: z.string().optional(),
476
+ error: z.string().nullable().optional(),
477
+ executionGuidance: z.string().optional(),
478
+ knownPitfalls: z.array(z.string()).optional(),
479
+ memory: z.record(z.string(), z.array(z.string())).optional(),
480
+ planId: z.string().optional(),
481
+ recommendedPlanSteps: z.array(z.string()).optional(),
482
+ referenceWorkbenchSnippets: z
483
+ .array(ToolRouterSessionSearchResultReferenceWorkbenchSnippetSchema)
484
+ .optional(),
485
+ });
486
+
487
+ const ToolRouterSessionSearchSessionSchema = z.object({
488
+ id: z.string(),
489
+ generateId: z.boolean(),
490
+ instructions: z.string(),
491
+ });
492
+
493
+ const ToolRouterSessionSearchTimeInfoSchema = z.object({
494
+ currentTimeUtc: z.string(),
495
+ currentTimeUtcEpochSeconds: z.number(),
496
+ message: z.string(),
497
+ });
498
+
499
+ const ToolRouterSessionSearchToolSchemasSchemaRefSchema = z.object({
500
+ args: z.object({ toolSlugs: z.array(z.string()) }),
501
+ message: z.string().optional(),
502
+ tool: z.literal('COMPOSIO_GET_TOOL_SCHEMAS'),
503
+ });
504
+
505
+ const ToolRouterSessionSearchToolSchemaSchema = z.object({
506
+ toolSlug: z.string(),
507
+ toolkit: z.string(),
508
+ description: z.string().optional(),
509
+ hasFullSchema: z.boolean().optional(),
510
+ inputSchema: z.record(z.string(), z.unknown()).optional(),
511
+ outputSchema: z.record(z.string(), z.unknown()).optional(),
512
+ schemaRef: ToolRouterSessionSearchToolSchemasSchemaRefSchema.optional(),
513
+ });
514
+
515
+ const ToolRouterSessionSearchToolkitConnectionStatusSchema = z.object({
516
+ toolkit: z.string(),
517
+ description: z.string(),
518
+ hasActiveConnection: z.boolean(),
519
+ statusMessage: z.string(),
520
+ connectionDetails: z.record(z.string(), z.unknown()).optional(),
521
+ currentUserInfo: z.record(z.string(), z.unknown()).optional(),
522
+ });
523
+
524
+ export const ToolRouterSessionSearchResponseSchema = z.object({
525
+ success: z.boolean(),
526
+ error: z.string().nullable(),
527
+ results: z.array(ToolRouterSessionSearchResultSchema),
528
+ toolSchemas: z.record(z.string(), ToolRouterSessionSearchToolSchemaSchema),
529
+ toolkitConnectionStatuses: z.array(ToolRouterSessionSearchToolkitConnectionStatusSchema),
530
+ nextStepsGuidance: z.array(z.string()),
531
+ session: ToolRouterSessionSearchSessionSchema,
532
+ timeInfo: ToolRouterSessionSearchTimeInfoSchema,
533
+ });
534
+ export type ToolRouterSessionSearchResponse = z.infer<typeof ToolRouterSessionSearchResponseSchema>;
535
+
536
+ // --- Session execute response schema (camelCase) ---
537
+
538
+ export const ToolRouterSessionExecuteResponseSchema = z.object({
539
+ data: z.record(z.string(), z.unknown()),
540
+ error: z.string().nullable(),
541
+ logId: z.string(),
542
+ });
543
+ export type ToolRouterSessionExecuteResponse = z.infer<
544
+ typeof ToolRouterSessionExecuteResponseSchema
545
+ >;
546
+
547
+ // --- Session proxy execute response (matches ToolProxyResponse from client) ---
548
+
549
+ export interface ToolRouterSessionProxyExecuteResponse {
550
+ /** The HTTP status code returned from the proxied API */
551
+ status: number;
552
+ /** The response data from the proxied API */
553
+ data?: unknown;
554
+ /** HTTP headers from the proxied API */
555
+ headers?: Record<string, string>;
556
+ /** Binary response data (present when response is a file) */
557
+ binaryData?: {
558
+ contentType: string;
559
+ size: number;
560
+ url: string;
561
+ expiresAt?: string;
562
+ };
563
+ }
564
+
565
+ /**
566
+ * Experimental features on a tool router session.
567
+ * Contains features that may be modified or removed in future versions.
568
+ */
569
+ export interface SessionExperimental {
570
+ /**
571
+ * The assistive system prompt to inject into your agent for optimal tool router usage.
572
+ * Only returned on session creation, not on GET.
573
+ */
574
+ assistivePrompt?: string;
575
+ /**
576
+ * File mount operations (list, upload, download, delete) for the session's virtual filesystem.
577
+ */
578
+ files: ToolRouterSessionFilesMount;
579
+ }
580
+
581
+ export type ToolRouterSessionSearchFn = (params: {
582
+ query: string;
583
+ toolkits?: string[];
584
+ }) => Promise<ToolRouterSessionSearchResponse>;
585
+
586
+ export type ToolRouterSessionExecuteFn = (
587
+ toolSlug: string,
588
+ arguments_?: Record<string, unknown>,
589
+ options?: ToolRouterSessionExecuteOptions
590
+ ) => Promise<ToolRouterSessionExecuteResponse>;
591
+
592
+ export interface ToolRouterSessionExecuteOptions {
593
+ /**
594
+ * Account identifier for direct app tool execution in multi-account sessions.
595
+ * Meta/helper tools either ignore this top-level field or define
596
+ * their own account-selection fields, for example
597
+ * COMPOSIO_MULTI_EXECUTE_TOOL.tools[].account.
598
+ */
599
+ account?: string;
600
+ }
601
+
602
+ export type ToolRouterSessionPreloadConfig = SessionCreateResponse.Config.Preload;
603
+
604
+ export type ToolRouterSessionWorkbenchConfig = SessionCreateResponse.Config.Workbench;
605
+
606
+ export type ToolRouterSessionWarning = SessionCreateResponse.Warning;
607
+
608
+ export interface ToolRouterSessionMetadata {
609
+ preload?: ToolRouterSessionPreloadConfig;
610
+ workbench?: ToolRouterSessionWorkbenchConfig;
611
+ configVersion?: number;
612
+ warnings?: ToolRouterSessionWarning[];
613
+ preloadedCustomToolSlugs?: string[];
614
+ inlineCustomToolsPayload?: InlineCustomToolsWirePayload;
615
+ }
616
+
617
+ export const SessionProxyExecuteParamsSchema = z.object({
618
+ /** The toolkit whose connected account to use for auth (e.g. 'gmail', 'github') */
619
+ toolkit: z.string(),
620
+ /** The API endpoint URL to call */
621
+ endpoint: z.string(),
622
+ /** HTTP method */
623
+ method: z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH']),
624
+ /** Request body (for POST/PUT/PATCH) */
625
+ body: z.unknown().optional(),
626
+ /** Query params or headers to include */
627
+ parameters: z
628
+ .array(
629
+ z.object({
630
+ in: z.enum(['query', 'header']),
631
+ name: z.string(),
632
+ value: z.union([z.string(), z.number()]),
633
+ })
634
+ )
635
+ .optional(),
636
+ });
637
+ export type SessionProxyExecuteParams = z.infer<typeof SessionProxyExecuteParamsSchema>;
638
+
639
+ export type ToolRouterSessionProxyExecuteFn = (
640
+ params: SessionProxyExecuteParams
641
+ ) => Promise<ToolRouterSessionProxyExecuteResponse>;
642
+
643
+ export const ToolRouterUpdateSessionConfigSchema = z
644
+ .object({
645
+ toolkits: z
646
+ .union([
647
+ ToolRouterToolkitsParamSchema,
648
+ ToolRouterToolkitsDisabledConfigSchema,
649
+ ToolRouterToolkitsEnabledConfigSchema,
650
+ ])
651
+ .optional(),
652
+ tools: z
653
+ .record(z.string(), z.union([ToolRouterToolsParamSchema, ToolRouterConfigToolsSchema]))
654
+ .optional(),
655
+ tags: ToolRouterConfigTagsSchema.optional(),
656
+ authConfigs: z.record(z.string(), z.string()).optional(),
657
+ connectedAccounts: z
658
+ .record(z.string(), z.union([z.string(), z.array(z.string())]))
659
+ .transform(rec => {
660
+ const out: Record<string, string[]> = {};
661
+ for (const [k, v] of Object.entries(rec)) {
662
+ out[k] = typeof v === 'string' ? [v] : v;
663
+ }
664
+ return out;
665
+ })
666
+ .optional(),
667
+ manageConnections: z
668
+ .union([z.boolean(), ToolRouterConfigManageConnectionsSchema])
669
+ .nullable()
670
+ .optional(),
671
+ sandbox: ToolRouterSandboxConfigSchema.partial().nullable().optional(),
672
+ workbench: ToolRouterSandboxConfigSchema.partial().nullable().optional(),
673
+ multiAccount: z
674
+ .object({
675
+ enable: z.boolean().optional(),
676
+ maxAccountsPerToolkit: z.number().int().min(2).max(10).optional(),
677
+ requireExplicitSelection: z.boolean().optional(),
678
+ })
679
+ .nullable()
680
+ .optional(),
681
+ preload: z
682
+ .object({
683
+ tools: z.union([z.array(z.string()), z.literal('all')]).optional(),
684
+ })
685
+ .strict()
686
+ .optional(),
687
+ })
688
+ .partial()
689
+ .superRefine((config, ctx) => {
690
+ if (config.sandbox !== undefined && config.workbench !== undefined) {
691
+ ctx.addIssue({
692
+ code: z.ZodIssueCode.custom,
693
+ message:
694
+ 'Pass either sandbox or workbench, not both. workbench is a backwards-compatible alias for sandbox.',
695
+ path: ['sandbox'],
696
+ });
697
+ }
698
+ });
699
+
700
+ export type ToolRouterUpdateSessionConfig = z.infer<typeof ToolRouterUpdateSessionConfigSchema>;
701
+
702
+ export type ToolRouterSessionUpdateFn = (config: ToolRouterUpdateSessionConfig) => Promise<void>;
703
+
704
+ export const ToolRouterSessionDeleteResponseSchema = z.object({
705
+ sessionId: z.string(),
706
+ deleted: z.literal(true),
707
+ });
708
+ export type ToolRouterSessionDeleteResponse = z.infer<typeof ToolRouterSessionDeleteResponseSchema>;
709
+
710
+ export type ToolRouterSessionDeleteFn = (
711
+ requestOptions?: ComposioRequestOptions
712
+ ) => Promise<ToolRouterSessionDeleteResponse>;
713
+
714
+ /** Session type returned by ToolRouter.create() and ToolRouter.use() */
715
+ export interface Session<
716
+ TToolCollection,
717
+ TTool,
718
+ TProvider extends BaseComposioProvider<TToolCollection, TTool, unknown>,
719
+ > {
720
+ sessionId: string;
721
+ mcp: ToolRouterMCPServerConfig;
722
+ /** Stored preload configuration for this session. */
723
+ preload: ToolRouterSessionPreloadConfig;
724
+ /**
725
+ * Resolved sandbox (code-execution) config returned by the API. `enable` defaults to `true` server-side.
726
+ *
727
+ * This is the read-side counterpart to the `sandbox` key you pass into `create()`.
728
+ */
729
+ sandbox?: ToolRouterSessionWorkbenchConfig;
730
+ /**
731
+ * Resolved sandbox config for the session.
732
+ *
733
+ * @deprecated Use `sandbox` instead. `workbench` is a backwards-compatible alias and will be removed in a future release.
734
+ */
735
+ workbench?: ToolRouterSessionWorkbenchConfig;
736
+ /** Server-side config version when returned by the API. */
737
+ configVersion?: number;
738
+ /** Non-blocking session creation warnings returned by the API. */
739
+ warnings: ToolRouterSessionWarning[];
740
+ tools: ToolRouterToolsFn<TToolCollection, TTool, TProvider>;
741
+ authorize: ToolRouterAuthorizeFn;
742
+ toolkits: ToolRouterToolkitsFn;
743
+ /** Search for tools by semantic use case */
744
+ search: ToolRouterSessionSearchFn;
745
+ /** Execute a tool within the session */
746
+ execute: ToolRouterSessionExecuteFn;
747
+ /** Update the session configuration. Mutates this session in-place. */
748
+ update: ToolRouterSessionUpdateFn;
749
+ /** Delete the session. Deleted sessions are no longer retrievable or executable. */
750
+ delete: ToolRouterSessionDeleteFn;
751
+ /** Proxy an API call through Composio's auth layer using the session's connected account */
752
+ proxyExecute: ToolRouterSessionProxyExecuteFn;
753
+ /** List custom tools registered in this session, with their final slugs and schemas */
754
+ customTools: (options?: { toolkit?: string }) => RegisteredCustomTool[];
755
+ /** List custom toolkits registered in this session, with final slugs on nested tools */
756
+ customToolkits: () => RegisteredCustomToolkit[];
757
+ /** Experimental features (files, assistive prompt, etc.) */
758
+ experimental: SessionExperimental;
759
+ }
760
+
761
+ /**
762
+ * Session type without the typed `mcp` endpoint.
763
+ *
764
+ * Returned by `create()` / `use()` when `{ mcp: true }` is not passed. The
765
+ * hosted MCP endpoint still exists on the underlying session at runtime — this
766
+ * only hides it from the type so MCP is an explicit opt-in. Pass `{ mcp: true }`
767
+ * to get a `Session` with `session.mcp` surfaced. See
768
+ * https://docs.composio.dev/docs/sessions-via-mcp
769
+ */
770
+ export type SessionWithoutMcp<
771
+ TToolCollection,
772
+ TTool,
773
+ TProvider extends BaseComposioProvider<TToolCollection, TTool, unknown>,
774
+ > = Omit<Session<TToolCollection, TTool, TProvider>, 'mcp'>;