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