@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.
Files changed (144) hide show
  1. package/dist/BaseProvider-Brb3o86-.d.mts +29425 -0
  2. package/dist/{CustomTool-DEB4BQPl.mjs → CustomTool-D9qwyMrv.mjs} +1 -1
  3. package/dist/{CustomTool-DH18rVQu.d.mts → CustomTool-Dmi6ti3I.d.mts} +1 -1
  4. package/dist/CustomTool-DrJpOhY2.d.mts +74 -0
  5. package/dist/{composio-CHnEggnv.d.mts → composio-DHIKRdeG.d.mts} +253 -37
  6. package/dist/composio-vMwhASRc.d.mts +5698 -0
  7. package/dist/{customTool.types-DpIdOJjL.d.mts → customTool.types-CKH2R2ia.d.mts} +344 -25
  8. package/dist/customTool.types-DXin7Cfc.d.mts +2773 -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 +229 -0
  20. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +131 -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 +27 -4
  28. package/dist/index.mjs +423 -123
  29. package/dist/{jsonSchema-daqF3S3d.mjs → jsonSchema-CFKdONpP.mjs} +1 -1
  30. package/dist/{types-CaI5Z4PA.d.mts → types-D4Id3wXA.d.mts} +1 -1
  31. package/dist/types-qTbYYBJw.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.mjs +2 -2
  35. package/docs/error-consistency.md +97 -0
  36. package/package.json +4 -3
  37. package/src/composio.ts +509 -0
  38. package/src/errors/AuthConfigErrors.ts +23 -0
  39. package/src/errors/ComposioError.ts +408 -0
  40. package/src/errors/ConnectedAccountsErrors.ts +158 -0
  41. package/src/errors/ConnectionRequestErrors.ts +32 -0
  42. package/src/errors/FileModifierErrors.ts +100 -0
  43. package/src/errors/PusherErrors.ts +28 -0
  44. package/src/errors/RemoteFileErrors.ts +62 -0
  45. package/src/errors/SDKErrors.ts +92 -0
  46. package/src/errors/ToolErrors.ts +244 -0
  47. package/src/errors/ToolkitErrors.ts +39 -0
  48. package/src/errors/TriggerErrors.ts +120 -0
  49. package/src/errors/ValidationErrors.ts +99 -0
  50. package/src/errors/index.ts +41 -0
  51. package/src/experimental/index.ts +28 -0
  52. package/src/index.ts +64 -0
  53. package/src/lib/toolRouterConstants.ts +1 -0
  54. package/src/lib/toolRouterParams.ts +306 -0
  55. package/src/models/AuthConfigs.ts +398 -0
  56. package/src/models/AuthScheme.ts +206 -0
  57. package/src/models/ConnectedAccounts.ts +735 -0
  58. package/src/models/ConnectionRequest.ts +150 -0
  59. package/src/models/CustomTool.ts +676 -0
  60. package/src/models/Experimental.ts +202 -0
  61. package/src/models/Files.node.ts +93 -0
  62. package/src/models/Files.workerd.ts +49 -0
  63. package/src/models/MCP.ts +478 -0
  64. package/src/models/RemoteFile.ts +172 -0
  65. package/src/models/SessionContext.ts +147 -0
  66. package/src/models/Sessions.ts +21 -0
  67. package/src/models/ToolRouter.ts +391 -0
  68. package/src/models/ToolRouterSession.ts +827 -0
  69. package/src/models/ToolRouterSessionFileMount.ts +389 -0
  70. package/src/models/Toolkits.ts +412 -0
  71. package/src/models/Tools.ts +1260 -0
  72. package/src/models/Triggers.ts +1381 -0
  73. package/src/models/customToolExecution.ts +118 -0
  74. package/src/models/inlineCustomToolsPayload.ts +17 -0
  75. package/src/models/proxyParamsTransform.ts +26 -0
  76. package/src/provider/BaseProvider.ts +138 -0
  77. package/src/provider/ComposioProvider.ts +29 -0
  78. package/src/provider/OpenAIProvider.ts +547 -0
  79. package/src/services/internal/InternalService.ts +50 -0
  80. package/src/services/internal/InternalService.types.ts +14 -0
  81. package/src/services/pusher/Pusher.ts +230 -0
  82. package/src/services/telemetry/TelemetryService.ts +48 -0
  83. package/src/services/telemetry/TelemetryService.types.ts +67 -0
  84. package/src/telemetry/BatchProcessor.ts +77 -0
  85. package/src/telemetry/README.md +123 -0
  86. package/src/telemetry/Telemetry.ts +356 -0
  87. package/src/types/ToolRouterSessionFilesMount.types.ts +96 -0
  88. package/src/types/authConfigs.types.ts +174 -0
  89. package/src/types/composio.types.ts +1 -0
  90. package/src/types/connectedAccountAuthStates.types.ts +852 -0
  91. package/src/types/connectedAccounts.types.ts +395 -0
  92. package/src/types/connectionRequest.types.ts +16 -0
  93. package/src/types/customTool.types.ts +261 -0
  94. package/src/types/files.types.ts +15 -0
  95. package/src/types/mcp.experimental.types.ts +163 -0
  96. package/src/types/mcp.types.ts +362 -0
  97. package/src/types/modifiers.types.ts +663 -0
  98. package/src/types/org.types.ts +0 -0
  99. package/src/types/provider.types.ts +41 -0
  100. package/src/types/pusher.types.ts +18 -0
  101. package/src/types/requestOptions.types.ts +62 -0
  102. package/src/types/telemetry.types.ts +89 -0
  103. package/src/types/tool.types.ts +408 -0
  104. package/src/types/toolRouter.types.ts +761 -0
  105. package/src/types/toolkit.types.ts +130 -0
  106. package/src/types/triggers.types.ts +401 -0
  107. package/src/types/webhookEvents.types.ts +219 -0
  108. package/src/utils/buffer.ts +30 -0
  109. package/src/utils/cancellation.ts +22 -0
  110. package/src/utils/config-defaults/ConfigDefaults.node.ts +7 -0
  111. package/src/utils/config-defaults/ConfigDefaults.workerd.ts +10 -0
  112. package/src/utils/config-defaults/index.ts +1 -0
  113. package/src/utils/config-defaults/types.ts +14 -0
  114. package/src/utils/constants.ts +22 -0
  115. package/src/utils/crypto.ts +34 -0
  116. package/src/utils/env.ts +34 -0
  117. package/src/utils/fileDirs.ts +81 -0
  118. package/src/utils/fileUtils.node.ts +458 -0
  119. package/src/utils/json-schema.ts +1 -0
  120. package/src/utils/jsonSchema.ts +355 -0
  121. package/src/utils/logger.ts +99 -0
  122. package/src/utils/mime.ts +75 -0
  123. package/src/utils/modifiers/FileToolModifier.node.ts +477 -0
  124. package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +132 -0
  125. package/src/utils/modifiers/FileToolModifier.workerd.ts +51 -0
  126. package/src/utils/pagination.ts +73 -0
  127. package/src/utils/pusher.ts +286 -0
  128. package/src/utils/schemaPropertyKeys.ts +433 -0
  129. package/src/utils/sdk.ts +110 -0
  130. package/src/utils/sensitiveFileUploadPaths.node.ts +105 -0
  131. package/src/utils/session.ts +114 -0
  132. package/src/utils/toolArguments.ts +73 -0
  133. package/src/utils/toolkitVersion.ts +26 -0
  134. package/src/utils/transform.ts +42 -0
  135. package/src/utils/transformers/authConfigs.ts +107 -0
  136. package/src/utils/transformers/connectedAccounts.ts +119 -0
  137. package/src/utils/transformers/mcp.ts +164 -0
  138. package/src/utils/transformers/toolRouterResponseTransform.ts +160 -0
  139. package/src/utils/transformers/toolkits.ts +100 -0
  140. package/src/utils/transformers/triggers.ts +118 -0
  141. package/src/utils/uploadDirAllowlist.node.ts +178 -0
  142. package/src/utils/uuid.ts +7 -0
  143. package/src/utils/version.ts +58 -0
  144. package/src/utils/zodSchema.ts +90 -0
@@ -0,0 +1,395 @@
1
+ import { z } from 'zod/v3';
2
+ import { ConnectionDataSchema } from './connectedAccountAuthStates.types';
3
+ import { AuthSchemeEnum } from './authConfigs.types';
4
+
5
+ /**
6
+ * Connected Account create parameters
7
+ */
8
+ export const ConnectedAccountStatuses = {
9
+ INITIALIZING: 'INITIALIZING',
10
+ INITIATED: 'INITIATED',
11
+ ACTIVE: 'ACTIVE',
12
+ FAILED: 'FAILED',
13
+ EXPIRED: 'EXPIRED',
14
+ INACTIVE: 'INACTIVE',
15
+ REVOKED: 'REVOKED',
16
+ } as const;
17
+ export const ConnectedAccountStatusSchema = z.enum([
18
+ ConnectedAccountStatuses.INITIALIZING,
19
+ ConnectedAccountStatuses.INITIATED,
20
+ ConnectedAccountStatuses.ACTIVE,
21
+ ConnectedAccountStatuses.FAILED,
22
+ ConnectedAccountStatuses.EXPIRED,
23
+ ConnectedAccountStatuses.INACTIVE,
24
+ ConnectedAccountStatuses.REVOKED,
25
+ ]);
26
+ export type ConnectedAccountStatus =
27
+ (typeof ConnectedAccountStatuses)[keyof typeof ConnectedAccountStatuses];
28
+ export type ConnectedAccountStatusEnum = z.infer<typeof ConnectedAccountStatusSchema>;
29
+
30
+ /**
31
+ * Sharing model for a connected account.
32
+ *
33
+ * - `PRIVATE` (default): only the owning `userId` can use the connection.
34
+ * - `SHARED`: can be used by other `userId`s, but only when the connection
35
+ * is explicitly pinned in a tool-router session's config and only when
36
+ * the requesting `userId` passes the connection's ACL (see
37
+ * `allowAllUsers` / `allowedUserIds` / `notAllowedUserIds`).
38
+ */
39
+ export const ConnectedAccountTypes = {
40
+ PRIVATE: 'PRIVATE',
41
+ SHARED: 'SHARED',
42
+ } as const;
43
+ export const ConnectedAccountTypeSchema = z.enum([
44
+ ConnectedAccountTypes.PRIVATE,
45
+ ConnectedAccountTypes.SHARED,
46
+ ]);
47
+ export type ConnectedAccountType =
48
+ (typeof ConnectedAccountTypes)[keyof typeof ConnectedAccountTypes];
49
+
50
+ /**
51
+ * Per-user access control for a SHARED connected account. Ignored for
52
+ * PRIVATE.
53
+ *
54
+ * Pass `aclConfigForShared` on create / PATCH to grant access; omit it
55
+ * to leave the ACL unchanged (on PATCH) or to keep the default
56
+ * deny-by-default state (on create). On responses, the field is
57
+ * `undefined` when the caller isn't authorised to see the ACL —
58
+ * distinguish that from an empty/default state explicitly.
59
+ *
60
+ * Resolution rule (deny wins):
61
+ * 1. requesting `userId` in `notAllowedUserIds` → DENY
62
+ * 2. `allowAllUsers === true` → ALLOW
63
+ * 3. requesting `userId` in `allowedUserIds` → ALLOW
64
+ * 4. otherwise → DENY (deny-by-default)
65
+ *
66
+ * Default state (block omitted or `{}`) means only the connection's
67
+ * creator can use it. The creator must grant access explicitly.
68
+ *
69
+ * Limits: each list accepts up to 1000 entries; each `userId` is
70
+ * 1..256 characters.
71
+ */
72
+ const ACL_LIST_MAX_LENGTH = 1000;
73
+ const ACL_USER_ID_MAX_LENGTH = 256;
74
+ const aclUserIdString = z.string().min(1).max(ACL_USER_ID_MAX_LENGTH);
75
+
76
+ export const ConnectedAccountAclConfigSchema = z.object({
77
+ allowAllUsers: z
78
+ .boolean()
79
+ .optional()
80
+ .describe(
81
+ 'When true, any `userId` may use this SHARED connection (subject to the deny list). Default false.'
82
+ ),
83
+ allowedUserIds: z
84
+ .array(aclUserIdString)
85
+ .max(ACL_LIST_MAX_LENGTH)
86
+ .optional()
87
+ .describe(
88
+ 'Explicit list of `userId` strings allowed to use this SHARED connection. Default [].'
89
+ ),
90
+ notAllowedUserIds: z
91
+ .array(aclUserIdString)
92
+ .max(ACL_LIST_MAX_LENGTH)
93
+ .optional()
94
+ .describe(
95
+ 'Explicit list of `userId` strings denied access. Wins over allow on conflict. Default [].'
96
+ ),
97
+ });
98
+ export type ConnectedAccountAclConfig = z.infer<typeof ConnectedAccountAclConfigSchema>;
99
+
100
+ /**
101
+ * Resolved ACL as it appears on responses. All three fields are populated
102
+ * when the field is visible; the field itself is `undefined` for callers
103
+ * not authorised to see it.
104
+ */
105
+ export const ConnectedAccountAclConfigResponseSchema = z.object({
106
+ allowAllUsers: z.boolean(),
107
+ allowedUserIds: z.array(z.string()),
108
+ notAllowedUserIds: z.array(z.string()),
109
+ });
110
+ export type ConnectedAccountAclConfigResponse = z.infer<
111
+ typeof ConnectedAccountAclConfigResponseSchema
112
+ >;
113
+
114
+ /**
115
+ * Experimental options for SHARED connections, passed at create / link time.
116
+ *
117
+ * **Experimental — shape may change in future releases.** Wrapped under a
118
+ * dedicated `experimental` block on every input and response so the
119
+ * experimental status is visible at every call site.
120
+ */
121
+ export const ConnectedAccountExperimentalSchema = z.object({
122
+ accountType: ConnectedAccountTypeSchema.optional(),
123
+ aclConfigForShared: ConnectedAccountAclConfigSchema.optional(),
124
+ });
125
+ export type ConnectedAccountExperimental = z.infer<typeof ConnectedAccountExperimentalSchema>;
126
+
127
+ /**
128
+ * Resolved experimental block on retrieve / list responses. `accountType`
129
+ * is always present when the block is; `aclConfigForShared` is only
130
+ * present when the caller is authorised to see the ACL.
131
+ */
132
+ export const ConnectedAccountExperimentalResponseSchema = z.object({
133
+ accountType: ConnectedAccountTypeSchema.optional(),
134
+ aclConfigForShared: ConnectedAccountAclConfigResponseSchema.optional(),
135
+ });
136
+ export type ConnectedAccountExperimentalResponse = z.infer<
137
+ typeof ConnectedAccountExperimentalResponseSchema
138
+ >;
139
+
140
+ export const CreateConnectedAccountParamsSchema = z.object({
141
+ authConfig: z.object({
142
+ id: z.string(),
143
+ }),
144
+ connection: z.object({
145
+ data: z.record(z.string(), z.unknown()).optional(),
146
+ callbackUrl: z.string().optional(),
147
+ userId: z.string().optional(),
148
+ }),
149
+ });
150
+ export const DefaultCreateConnectedAccountParamsSchema: z.ZodType<{
151
+ auth_config: { id: string };
152
+ connection: {
153
+ state?: z.infer<typeof ConnectionDataSchema>;
154
+ data?: Record<string, unknown>;
155
+ callback_url?: string;
156
+ user_id?: string;
157
+ alias?: string;
158
+ };
159
+ }> = z.object({
160
+ auth_config: z.object({
161
+ id: z.string(),
162
+ }),
163
+ connection: z.object({
164
+ state: ConnectionDataSchema.optional(),
165
+ data: z.record(z.string(), z.unknown()).optional(),
166
+ callback_url: z.string().optional(),
167
+ user_id: z.string().optional(),
168
+ alias: z.string().optional(),
169
+ }),
170
+ });
171
+
172
+ export const CreateConnectedAccountOptionsSchema: z.ZodType<{
173
+ allowMultiple?: boolean;
174
+ callbackUrl?: string;
175
+ config?: z.infer<typeof ConnectionDataSchema>;
176
+ alias?: string;
177
+ }> = z.object({
178
+ allowMultiple: z.boolean().optional(),
179
+ callbackUrl: z.string().optional(),
180
+ config: ConnectionDataSchema.optional(),
181
+ alias: z.string().optional(),
182
+ });
183
+ export type CreateConnectedAccountOptions = z.infer<typeof CreateConnectedAccountOptionsSchema>;
184
+ export type CreateConnectedAccountParams = z.infer<typeof CreateConnectedAccountParamsSchema>;
185
+ /**
186
+ * Connected Account create response
187
+ */
188
+ export const CreateConnectedAccountResponseSchema = z.object({
189
+ id: z.string(),
190
+ status: ConnectedAccountStatusSchema,
191
+ redirectUrl: z.string().nullable(),
192
+ });
193
+ export type CreateConnectedAccountResponse = z.infer<typeof CreateConnectedAccountResponseSchema>;
194
+
195
+ export const ConnectedAccountAuthConfigSchema = z.object({
196
+ id: z.string(),
197
+ /** @deprecated Use `connectedAccount.state.authScheme` instead. */
198
+ authScheme: AuthSchemeEnum.optional(),
199
+ isComposioManaged: z.boolean(),
200
+ isDisabled: z.boolean(),
201
+ });
202
+ export type ConnectedAccountAuthConfig = z.infer<typeof ConnectedAccountAuthConfigSchema>;
203
+
204
+ export const ConnectedAccountRetrieveResponseSchema: z.ZodType<{
205
+ id: string;
206
+ authConfig: z.infer<typeof ConnectedAccountAuthConfigSchema>;
207
+ wordId?: string | null;
208
+ alias?: string | null;
209
+ /** @deprecated Use `connectedAccount.state` instead — `data` is a legacy raw credential field. */
210
+ data?: Record<string, unknown>;
211
+ /** @deprecated Use `connectedAccount.state` instead — `params` is a legacy raw credential field. */
212
+ params?: Record<string, unknown>;
213
+ status: ConnectedAccountStatusEnum;
214
+ statusReason: string | null;
215
+ toolkit: { slug: string };
216
+ state?: z.infer<typeof ConnectionDataSchema>;
217
+ testRequestEndpoint?: string;
218
+ isDisabled: boolean;
219
+ createdAt: string;
220
+ updatedAt: string;
221
+ experimental?: ConnectedAccountExperimentalResponse;
222
+ }> = z.object({
223
+ id: z.string(),
224
+ authConfig: ConnectedAccountAuthConfigSchema,
225
+ wordId: z.string().nullable().optional(),
226
+ alias: z.string().nullable().optional(),
227
+ /**
228
+ * @deprecated Use `connectedAccount.state` instead — `data` is a legacy raw credential field.
229
+ */
230
+ data: z.record(z.string(), z.unknown()).optional(),
231
+ /**
232
+ * @deprecated Use `connectedAccount.state` instead — `params` is a legacy raw credential field.
233
+ */
234
+ params: z.record(z.string(), z.unknown()).optional(),
235
+ status: ConnectedAccountStatusSchema,
236
+ statusReason: z.string().nullable(),
237
+ toolkit: z.object({
238
+ slug: z.string(),
239
+ }),
240
+ state: ConnectionDataSchema.optional(),
241
+ testRequestEndpoint: z.string().optional(),
242
+ isDisabled: z.boolean(),
243
+ createdAt: z.string(),
244
+ updatedAt: z.string(),
245
+ // Experimental — shape may change in future releases. `aclConfigForShared`
246
+ // inside this block is only populated when the caller is authorised to
247
+ // see the ACL.
248
+ experimental: ConnectedAccountExperimentalResponseSchema.optional(),
249
+ });
250
+
251
+ export type ConnectedAccountRetrieveResponse = z.infer<
252
+ typeof ConnectedAccountRetrieveResponseSchema
253
+ >;
254
+
255
+ /**
256
+ * Type for list response item that doesn't include params
257
+ */
258
+ export type ConnectedAccountListResponseItem = Omit<ConnectedAccountRetrieveResponse, 'params'>;
259
+
260
+ export const ConnectedAccountListParamsSchema = z.object({
261
+ authConfigIds: z
262
+ .array(z.string())
263
+ .nullable()
264
+ .optional()
265
+ .describe('The auth config ids of the connected accounts'),
266
+ cursor: z.string().nullish().describe('The cursor to paginate through the connected accounts'),
267
+ limit: z.number().nullable().optional().describe('The limit of the connected accounts to return'),
268
+ orderBy: z
269
+ .enum(['created_at', 'updated_at'])
270
+ .optional()
271
+ .describe('The order by of the connected accounts'),
272
+ statuses: z
273
+ .array(ConnectedAccountStatusSchema)
274
+ .nullable()
275
+ .optional()
276
+ .describe('The statuses of the connected accounts'),
277
+ toolkitSlugs: z
278
+ .array(z.string())
279
+ .nullable()
280
+ .optional()
281
+ .describe('The toolkit slugs of the connected accounts'),
282
+ userIds: z
283
+ .array(z.string())
284
+ .nullable()
285
+ .optional()
286
+ .describe('The user ids of the connected accounts'),
287
+ /**
288
+ * Experimental — shape may change in future releases. Filter by sharing
289
+ * model. Default (omitted) returns PRIVATE only. Pass `'SHARED'` for only
290
+ * shared accounts, or `'ALL'` for `PRIVATE` + `SHARED`. Kept flat because
291
+ * the wire is a query string and can't carry nested objects.
292
+ */
293
+ accountType: z.enum(['PRIVATE', 'SHARED', 'ALL']).optional(),
294
+ });
295
+ export type ConnectedAccountListParams = z.infer<typeof ConnectedAccountListParamsSchema>;
296
+
297
+ export const ConnectedAccountListResponseSchema = z.object({
298
+ items: z.array(ConnectedAccountRetrieveResponseSchema).describe('The list of connected accounts'),
299
+ nextCursor: z
300
+ .string()
301
+ .nullish()
302
+ .describe('The next cursor to paginate through the connected accounts'),
303
+ totalPages: z.number().describe('The total number of pages of connected accounts'),
304
+ });
305
+ export type ConnectedAccountListResponse = z.infer<typeof ConnectedAccountListResponseSchema>;
306
+
307
+ export const CreateConnectedAccountLinkOptionsSchema = z.object({
308
+ /**
309
+ * The url to redirect the user to post connecting their account.
310
+ *
311
+ * For successful connections, you will get a query param called status=success
312
+ * And for failed connections you will get a query param called status=failed
313
+ *
314
+ * @example https://your-app.com/callback
315
+ *
316
+ */
317
+ callbackUrl: z.string().optional(),
318
+ /**
319
+ * Human-readable alias for the connected account. Must be unique per userId and toolkit within the project.
320
+ */
321
+ alias: z.string().optional(),
322
+ /**
323
+ * Whether to allow multiple connected accounts for the same user and auth config.
324
+ * When `false` (default), `link()` throws `ComposioMultipleConnectedAccountsError`
325
+ * if the user already has an `ACTIVE` connection on this auth config — matching
326
+ * the guard on `initiate()`. Pair with `alias` and a session-level
327
+ * `multiAccount` config to disambiguate at execution time.
328
+ */
329
+ allowMultiple: z.boolean().optional(),
330
+ /**
331
+ * Experimental options for SHARED connections. Pass `accountType: 'SHARED'`
332
+ * (and optionally `aclConfigForShared`) to create a connection that can
333
+ * be reached by other `userId`s when pinned in a session.
334
+ *
335
+ * Experimental — shape may change in future releases.
336
+ *
337
+ * `aclConfigForShared` is only valid when `accountType === 'SHARED'`;
338
+ * raises `ComposioAclOnlyForSharedError` on a PRIVATE connection. Omit
339
+ * the inner block (or pass `{}`) to keep the deny-by-default state: only
340
+ * the creator can use the connection. Grant access by setting
341
+ * `allowAllUsers: true` or listing user IDs in `allowedUserIds`.
342
+ * `notAllowedUserIds` always wins over allow.
343
+ */
344
+ experimental: ConnectedAccountExperimentalSchema.optional(),
345
+ });
346
+ export type CreateConnectedAccountLinkOptions = z.infer<
347
+ typeof CreateConnectedAccountLinkOptionsSchema
348
+ >;
349
+
350
+ export const CreateConnectedAccountLinkResponseSchema = z.object({
351
+ redirectUrl: z.string(),
352
+ });
353
+ export type CreateConnectedAccountLinkResponse = z.infer<
354
+ typeof CreateConnectedAccountLinkResponseSchema
355
+ >;
356
+
357
+ export const ConnectedAccountRefreshOptionsSchema = z.object({
358
+ redirectUrl: z.string().optional(),
359
+ validateCredentials: z.boolean().optional(),
360
+ });
361
+ export type ConnectedAccountRefreshOptions = z.infer<typeof ConnectedAccountRefreshOptionsSchema>;
362
+
363
+ // Use the Stainless-generated type as the source of truth for update params.
364
+ export type { ConnectedAccountUpdateStatusParams as UpdateConnectedAccountParams } from '@composio/client/resources/connected-accounts';
365
+
366
+ export const UpdateConnectedAccountParamsSchema = z.object({
367
+ enabled: z.boolean(),
368
+ });
369
+
370
+ /**
371
+ * Params for `composio.connectedAccounts.updateAcl()`. Mirrors the inner
372
+ * shape of the wire's `acl_config_for_shared` block — the SDK adds the
373
+ * outer nesting at the boundary, so callers pass the three fields flat.
374
+ *
375
+ * PATCH-style semantics — omit a field to leave it unchanged; pass an
376
+ * empty array to clear an allow/deny list. Raises
377
+ * `ComposioAclOnlyForSharedError` on a PRIVATE connection.
378
+ *
379
+ * Each field is optional, but at least one must be provided — passing an
380
+ * empty object is rejected as a no-op.
381
+ */
382
+ // NOTE: `UpdateConnectedAccountAclParamsSchema` is a ZodEffects (because of
383
+ // the `.refine` below) — it does not expose `.shape`. If you need to reuse
384
+ // individual ACL fields elsewhere, pull them from
385
+ // `ConnectedAccountAclConfigSchema.shape` (the unrefined base) instead.
386
+ export const UpdateConnectedAccountAclParamsSchema = ConnectedAccountAclConfigSchema.refine(
387
+ acl =>
388
+ acl.allowAllUsers !== undefined ||
389
+ acl.allowedUserIds !== undefined ||
390
+ acl.notAllowedUserIds !== undefined,
391
+ {
392
+ message: 'At least one of allowAllUsers, allowedUserIds, or notAllowedUserIds must be provided',
393
+ }
394
+ );
395
+ export type UpdateConnectedAccountAclParams = z.infer<typeof UpdateConnectedAccountAclParamsSchema>;
@@ -0,0 +1,16 @@
1
+ import {
2
+ ConnectedAccountRetrieveResponse,
3
+ ConnectedAccountStatus,
4
+ } from './connectedAccounts.types';
5
+
6
+ export interface ConnectionRequestState {
7
+ id: string;
8
+ status?: ConnectedAccountStatus;
9
+ redirectUrl?: string | null;
10
+ }
11
+
12
+ export interface ConnectionRequest extends ConnectionRequestState {
13
+ waitForConnection: (timeout?: number) => Promise<ConnectedAccountRetrieveResponse>;
14
+ toJSON: () => ConnectionRequestState;
15
+ toString: () => string;
16
+ }
@@ -0,0 +1,261 @@
1
+ import { z } from 'zod/v3';
2
+ import type { z as z4 } from 'zod/v4';
3
+ import type {
4
+ SessionProxyExecuteParams,
5
+ ToolRouterSessionExecuteResponse,
6
+ ToolRouterSessionProxyExecuteResponse,
7
+ } from './toolRouter.types';
8
+ import type {
9
+ SessionCreateParams,
10
+ SessionCreateResponse,
11
+ } from '@composio/client/resources/tool-router/session/session.mjs';
12
+
13
+ export type AnyZodSchema = z.ZodType | z4.ZodType;
14
+ export type InferZodSchema<T extends AnyZodSchema> = T extends z.ZodType
15
+ ? z.infer<T>
16
+ : T extends z4.ZodType
17
+ ? z4.infer<T>
18
+ : never;
19
+
20
+ // ────────────────────────────────────────────────────────────────
21
+ // New custom tool types (for tool router integration via createCustomTool())
22
+ // ────────────────────────────────────────────────────────────────
23
+
24
+ /**
25
+ * Session context injected into custom tool execute functions at runtime.
26
+ * Provides identity context and methods to call other tools or proxy API requests.
27
+ */
28
+ export interface SessionContext {
29
+ /** The user ID for this session */
30
+ readonly userId: string;
31
+ /** Execute any Composio native tool from within a custom tool. Returns the same shape as session.execute(). */
32
+ execute(
33
+ toolSlug: string,
34
+ arguments_: Record<string, unknown>
35
+ ): Promise<ToolRouterSessionExecuteResponse>;
36
+ /** Proxy API calls through Composio's auth layer (resolved from session toolkit). */
37
+ proxyExecute(params: SessionProxyExecuteParams): Promise<ToolRouterSessionProxyExecuteResponse>;
38
+ /**
39
+ * Caller-supplied AbortSignal forwarded from `session.execute(..., { signal })`.
40
+ * Custom-tool execution is cooperative: long-running user code that respects
41
+ * this signal (e.g. by passing it into `fetch`) can abort mid-execution and
42
+ * surface as `ComposioRequestCancelledError`. Undefined when the caller did
43
+ * not pass `requestOptions`.
44
+ */
45
+ readonly signal?: AbortSignal;
46
+ }
47
+
48
+ /**
49
+ * Execute function for custom tools.
50
+ * Just return the result data, or throw an error. The SDK wraps it internally.
51
+ *
52
+ * Supports two call patterns:
53
+ * - `(input) => data` — for tools that don't need session context
54
+ * - `(input, ctx) => data` — for tools that need to call other tools or proxy APIs
55
+ */
56
+ export type CustomToolExecuteFn<T extends AnyZodSchema> = (
57
+ input: InferZodSchema<T>,
58
+ ctx: SessionContext
59
+ ) => Promise<Record<string, unknown>>;
60
+
61
+ /**
62
+ * Zod schema for validating a custom tool slug.
63
+ * Alphanumeric, underscores, and hyphens only. No `LOCAL_` or `COMPOSIO_` prefix.
64
+ * Length is validated contextually (standalone vs extension vs toolkit) at creation time.
65
+ */
66
+ export const CustomToolSlugSchema = z
67
+ .string()
68
+ .min(1, 'slug is required')
69
+ .regex(
70
+ /^[A-Za-z0-9_-]+$/,
71
+ 'slug must only contain alphanumeric characters, underscores, and hyphens'
72
+ )
73
+ .refine(s => !s.toUpperCase().startsWith('LOCAL_'), {
74
+ message: 'slug must not start with "LOCAL_" — this prefix is reserved for internal routing.',
75
+ })
76
+ .refine(s => !s.toUpperCase().startsWith('COMPOSIO_'), {
77
+ message:
78
+ 'slug must not start with "COMPOSIO_" — this prefix is reserved for Composio meta tools.',
79
+ });
80
+
81
+ /**
82
+ * Zod schema for validating the string/scalar fields of createCustomTool() options.
83
+ * Slug is validated separately as the first argument.
84
+ * Used internally for validation — inputParams, outputParams, and execute are checked manually.
85
+ */
86
+ export const CreateCustomToolBaseSchema = z.object({
87
+ name: z.string().min(1, 'createCustomTool: name is required'),
88
+ description: z.string().min(1, 'createCustomTool: description is required'),
89
+ /**
90
+ * Composio toolkit slug that this tool extends (inherits auth from).
91
+ * Must be a valid Composio toolkit slug (e.g. `'gmail'`, `'github'`, `'meta_ads'`).
92
+ * The backend validates this against the toolkit catalog.
93
+ * Leave empty for tools that don't need any Composio-managed authentication.
94
+ */
95
+ extendsToolkit: z.string().optional(),
96
+ preload: z
97
+ .boolean()
98
+ .optional()
99
+ .describe(
100
+ 'When true, include this custom tool in session.tools() so it can be called without searching first.'
101
+ ),
102
+ });
103
+
104
+ /** Options for creating a custom tool via `createCustomTool()`. */
105
+ export type CreateCustomToolParams<T extends AnyZodSchema> = z.infer<
106
+ typeof CreateCustomToolBaseSchema
107
+ > & {
108
+ /** Zod schema for input parameters */
109
+ inputParams: T;
110
+ /** Optional Zod schema for output parameters (sent to backend for documentation) */
111
+ outputParams?: AnyZodSchema;
112
+ /** The function that executes the tool */
113
+ execute: CustomToolExecuteFn<T>;
114
+ };
115
+
116
+ /**
117
+ * Custom tool definition returned from `createCustomTool()`.
118
+ * Pass to `composio.create(userId, { experimental: { customTools: [...] } })` to bind to a session.
119
+ */
120
+ export interface CustomTool {
121
+ readonly slug: string;
122
+ readonly name: string;
123
+ readonly description: string;
124
+ /**
125
+ * Composio toolkit slug that this tool extends (inherits auth from).
126
+ * Must be a valid Composio toolkit slug. Validated by the backend.
127
+ * Undefined means the tool doesn't need any Composio-managed authentication.
128
+ */
129
+ readonly extendsToolkit?: string;
130
+ /**
131
+ * Include this custom tool in session.tools() so it can be called without
132
+ * searching first.
133
+ */
134
+ readonly preload?: boolean;
135
+ readonly inputSchema: Record<string, unknown>;
136
+ /** JSON Schema representation of the output (for backend documentation) */
137
+ readonly outputSchema?: Record<string, unknown>;
138
+ /** @internal Original Zod schema — used for runtime input validation (defaults, coercions, transforms) */
139
+ readonly inputParams: AnyZodSchema;
140
+ /** Direct reference to the execute function — useful for testing */
141
+ readonly execute: CustomToolExecuteFn<AnyZodSchema>;
142
+ }
143
+
144
+ /** Serialized tool definition sent to backend for search indexing. Uses official client type. */
145
+ export type CustomToolDefinition = SessionCreateParams.Experimental.CustomTool;
146
+
147
+ export type CustomToolWireDefinition = CustomToolDefinition;
148
+
149
+ // ────────────────────────────────────────────────────────────────
150
+ // Custom toolkit types
151
+ // ────────────────────────────────────────────────────────────────
152
+
153
+ /**
154
+ * Zod schema for validating the string/scalar fields of createCustomToolkit() options.
155
+ * Slug is validated separately as the first argument.
156
+ */
157
+ export const CreateCustomToolkitBaseSchema = z.object({
158
+ name: z.string().min(1, 'createCustomToolkit: name is required'),
159
+ description: z.string().min(1, 'createCustomToolkit: description is required'),
160
+ preload: z
161
+ .boolean()
162
+ .optional()
163
+ .describe(
164
+ 'When true, include tools from this custom toolkit in session.tools(). Tool-level preload values override this default.'
165
+ ),
166
+ });
167
+
168
+ /** Options for creating a custom toolkit via `createCustomToolkit()`. */
169
+ export type CreateCustomToolkitParams = z.infer<typeof CreateCustomToolkitBaseSchema> & {
170
+ /** Tools to include in this toolkit. Must not have `extendsToolkit` set. */
171
+ tools: CustomTool[];
172
+ };
173
+
174
+ /**
175
+ * Custom toolkit definition returned from `createCustomToolkit()`.
176
+ * Pass to `composio.create(userId, { experimental: { customToolkits: [...] } })`.
177
+ */
178
+ export interface CustomToolkit {
179
+ readonly slug: string;
180
+ readonly name: string;
181
+ readonly description: string;
182
+ /**
183
+ * Default session.tools() exposure for tools in this custom toolkit.
184
+ * Tool-level preload values override this default.
185
+ */
186
+ readonly preload?: boolean;
187
+ readonly tools: readonly CustomTool[];
188
+ }
189
+
190
+ /** Serialized toolkit definition sent to backend. Uses official client type. */
191
+ export type CustomToolkitDefinition = SessionCreateParams.Experimental.CustomToolkit;
192
+
193
+ export type CustomToolkitWireDefinition = CustomToolkitDefinition;
194
+
195
+ export interface InlineCustomToolsWirePayload {
196
+ custom_tools?: CustomToolWireDefinition[];
197
+ custom_toolkits?: CustomToolkitWireDefinition[];
198
+ }
199
+
200
+ // ────────────────────────────────────────────────────────────────
201
+ // Internal routing types
202
+ // ────────────────────────────────────────────────────────────────
203
+
204
+ /** @internal Entry in the per-session custom tools routing map. */
205
+ export type CustomToolsMapEntry = {
206
+ handle: CustomTool;
207
+ /** @internal The final slug assigned by the prefixing rules (e.g. LOCAL_GREP, LOCAL_GMAIL_GET_EMAILS) */
208
+ finalSlug: string;
209
+ /** Resolved toolkit — from extendsToolkit, parent custom toolkit, or undefined for standalone */
210
+ toolkit?: string;
211
+ };
212
+
213
+ /** @internal Lookup maps used by ToolRouterSession for routing custom tools. */
214
+ export type CustomToolsMap = {
215
+ /** Lookup by final slug (e.g. LOCAL_GET_USER_CONTEXT) — used for agent execution path */
216
+ byFinalSlug: Map<string, CustomToolsMapEntry>;
217
+ /** Lookup by unique original slug (e.g. GET_USER_CONTEXT) — used for programmatic session.execute() */
218
+ byOriginalSlug: Map<string, CustomToolsMapEntry>;
219
+ /** Lookup by resolved toolkit + original slug — used when multiple custom toolkits reuse tool names */
220
+ byToolkitAndOriginalSlug?: Map<string, CustomToolsMapEntry>;
221
+ /** Original slugs that appear in multiple toolkits and cannot be resolved safely without the final slug */
222
+ ambiguousOriginalSlugs?: Set<string>;
223
+ /** The original custom toolkits passed at session creation — used for session.customToolkits() */
224
+ toolkits?: CustomToolkit[];
225
+ /** The original standalone custom tools passed at session creation — kept for inline re-injection on later requests. */
226
+ tools?: CustomTool[];
227
+ };
228
+
229
+ // ────────────────────────────────────────────────────────────────
230
+ // Registered custom tool types (returned by session.customTools())
231
+ // ────────────────────────────────────────────────────────────────
232
+
233
+ /** A custom tool as registered in a session, with its final resolved slug. */
234
+ export interface RegisteredCustomTool {
235
+ /** The final slug as registered with the backend (e.g. LOCAL_GREP, LOCAL_GMAIL_GET_EMAILS) */
236
+ slug: string;
237
+ name: string;
238
+ description: string;
239
+ /** Resolved toolkit — extendsToolkit value, custom toolkit slug, or undefined for standalone */
240
+ toolkit?: string;
241
+ inputSchema: Record<string, unknown>;
242
+ outputSchema?: Record<string, unknown>;
243
+ }
244
+
245
+ /** A custom toolkit as registered in a session, with final slugs on nested tools. */
246
+ export interface RegisteredCustomToolkit {
247
+ slug: string;
248
+ name: string;
249
+ description: string;
250
+ tools: RegisteredCustomTool[];
251
+ }
252
+
253
+ // ────────────────────────────────────────────────────────────────
254
+ // Response types from the backend (slug + original_slug mapping)
255
+ // ────────────────────────────────────────────────────────────────
256
+
257
+ /** Custom tool as returned in the session create response (has prefixed slug + original_slug). */
258
+ export type CustomToolResponse = SessionCreateResponse.Experimental.CustomTool;
259
+
260
+ /** Custom toolkit as returned in the session create response (has prefixed slugs + original_slugs). */
261
+ export type CustomToolkitResponse = SessionCreateResponse.Experimental.CustomToolkit;
@@ -0,0 +1,15 @@
1
+ export type FileUploadData = {
2
+ name: string;
3
+ mimetype: string;
4
+ s3key: string;
5
+ };
6
+
7
+ export type FileDownloadData = {
8
+ name: string;
9
+ mimeType: string;
10
+ s3Url: string;
11
+ /**
12
+ * @todo: actually, this can be null.
13
+ */
14
+ filePath: string;
15
+ };