@composio/core 0.11.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 (193) hide show
  1. package/dist/BaseProvider-BBnsv9kS.d.mts +29425 -0
  2. package/dist/{BaseProvider-CVbQxTNa.d.cts → BaseProvider-Brb3o86-.d.mts} +91 -44
  3. package/dist/CustomTool-D9qwyMrv.mjs +468 -0
  4. package/dist/{CustomTool-C-IUByoU.d.cts → CustomTool-Dmi6ti3I.d.mts} +2 -4
  5. package/dist/{CustomTool-CChQSp44.d.mts → CustomTool-DrJpOhY2.d.mts} +2 -4
  6. package/dist/{FileModifierErrors-C7z16Dfi.mjs → FileModifierErrors-3fSwIWoa.mjs} +35 -36
  7. package/dist/{Telemetry-DQax33Gh.mjs → Telemetry-DhGI_J4G.mjs} +15 -15
  8. package/dist/{composio-pcA13w87.d.cts → composio-DHIKRdeG.d.mts} +641 -380
  9. package/dist/{composio-BlASKqjQ.d.mts → composio-vMwhASRc.d.mts} +1390 -1129
  10. package/dist/{customTool.types-QtkAZQma.d.cts → customTool.types-CKH2R2ia.d.mts} +487 -189
  11. package/dist/{customTool.types-DLIORcYN.d.mts → customTool.types-DXin7Cfc.d.mts} +924 -626
  12. package/dist/docs/error-consistency.md +97 -0
  13. package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +306 -0
  14. package/dist/docs/reference/sdk-reference/typescript/composio.mdx +205 -0
  15. package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +488 -0
  16. package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +94 -0
  17. package/dist/docs/reference/sdk-reference/typescript/index.mdx +67 -0
  18. package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +304 -0
  19. package/dist/docs/reference/sdk-reference/typescript/meta.json +17 -0
  20. package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +107 -0
  21. package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +163 -0
  22. package/dist/docs/reference/sdk-reference/typescript/session.mdx +229 -0
  23. package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +131 -0
  24. package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +169 -0
  25. package/dist/docs/reference/sdk-reference/typescript/tools.mdx +453 -0
  26. package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +434 -0
  27. package/dist/{CustomTool-D5s-aADw.mjs → errors-DSIlYfl5.mjs} +72 -459
  28. package/dist/experimental/index.d.mts +2 -3
  29. package/dist/experimental/index.mjs +1 -3
  30. package/dist/{fileUtils.node-Dq7ebZPC.mjs → fileUtils.node-BiO1JQsJ.mjs} +26 -25
  31. package/dist/index.d.mts +1708 -2400
  32. package/dist/index.mjs +2632 -2006
  33. package/dist/jsonSchema-CFKdONpP.mjs +251 -0
  34. package/dist/models/Files.node.d.mts +1 -2
  35. package/dist/models/Files.node.mjs +3 -4
  36. package/dist/models/Files.workerd.d.mts +0 -1
  37. package/dist/platform/node.d.mts +1 -2
  38. package/dist/platform/workerd.d.mts +1 -2
  39. package/dist/{chunk-CWQeghP5.mjs → rolldown-runtime-w6R9maHv.mjs} +3 -5
  40. package/dist/{types-J2KCXP8R.d.mts → types-D4Id3wXA.d.mts} +2 -3
  41. package/dist/{types-DRG5qLxI.d.cts → types-qTbYYBJw.d.mts} +2 -3
  42. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -4
  43. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -4
  44. package/dist/utils/config-defaults/ConfigDefaults.workerd.mjs +3 -0
  45. package/dist/utils/json-schema.d.mts +2 -0
  46. package/dist/utils/json-schema.mjs +3 -0
  47. package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -1
  48. package/dist/utils/modifiers/FileToolModifier.node.mjs +44 -24
  49. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -1
  50. package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
  51. package/docs/error-consistency.md +97 -0
  52. package/package.json +40 -88
  53. package/src/composio.ts +509 -0
  54. package/src/errors/AuthConfigErrors.ts +23 -0
  55. package/src/errors/ComposioError.ts +408 -0
  56. package/src/errors/ConnectedAccountsErrors.ts +158 -0
  57. package/src/errors/ConnectionRequestErrors.ts +32 -0
  58. package/src/errors/FileModifierErrors.ts +100 -0
  59. package/src/errors/PusherErrors.ts +28 -0
  60. package/src/errors/RemoteFileErrors.ts +62 -0
  61. package/src/errors/SDKErrors.ts +92 -0
  62. package/src/errors/ToolErrors.ts +244 -0
  63. package/src/errors/ToolkitErrors.ts +39 -0
  64. package/src/errors/TriggerErrors.ts +120 -0
  65. package/src/errors/ValidationErrors.ts +99 -0
  66. package/src/errors/index.ts +41 -0
  67. package/src/experimental/index.ts +28 -0
  68. package/src/index.ts +64 -0
  69. package/src/lib/toolRouterConstants.ts +1 -0
  70. package/src/lib/toolRouterParams.ts +306 -0
  71. package/src/models/AuthConfigs.ts +398 -0
  72. package/src/models/AuthScheme.ts +206 -0
  73. package/src/models/ConnectedAccounts.ts +735 -0
  74. package/src/models/ConnectionRequest.ts +150 -0
  75. package/src/models/CustomTool.ts +676 -0
  76. package/src/models/Experimental.ts +202 -0
  77. package/src/models/Files.node.ts +93 -0
  78. package/src/models/Files.workerd.ts +49 -0
  79. package/src/models/MCP.ts +478 -0
  80. package/src/models/RemoteFile.ts +172 -0
  81. package/src/models/SessionContext.ts +147 -0
  82. package/src/models/Sessions.ts +21 -0
  83. package/src/models/ToolRouter.ts +391 -0
  84. package/src/models/ToolRouterSession.ts +827 -0
  85. package/src/models/ToolRouterSessionFileMount.ts +389 -0
  86. package/src/models/Toolkits.ts +412 -0
  87. package/src/models/Tools.ts +1260 -0
  88. package/src/models/Triggers.ts +1381 -0
  89. package/src/models/customToolExecution.ts +118 -0
  90. package/src/models/inlineCustomToolsPayload.ts +17 -0
  91. package/src/models/proxyParamsTransform.ts +26 -0
  92. package/src/provider/BaseProvider.ts +138 -0
  93. package/src/provider/ComposioProvider.ts +29 -0
  94. package/src/provider/OpenAIProvider.ts +547 -0
  95. package/src/services/internal/InternalService.ts +50 -0
  96. package/src/services/internal/InternalService.types.ts +14 -0
  97. package/src/services/pusher/Pusher.ts +230 -0
  98. package/src/services/telemetry/TelemetryService.ts +48 -0
  99. package/src/services/telemetry/TelemetryService.types.ts +67 -0
  100. package/src/telemetry/BatchProcessor.ts +77 -0
  101. package/src/telemetry/README.md +123 -0
  102. package/src/telemetry/Telemetry.ts +356 -0
  103. package/src/types/ToolRouterSessionFilesMount.types.ts +96 -0
  104. package/src/types/authConfigs.types.ts +174 -0
  105. package/src/types/composio.types.ts +1 -0
  106. package/src/types/connectedAccountAuthStates.types.ts +852 -0
  107. package/src/types/connectedAccounts.types.ts +395 -0
  108. package/src/types/connectionRequest.types.ts +16 -0
  109. package/src/types/customTool.types.ts +261 -0
  110. package/{dist/files.types-lo4zZd87.d.cts → src/types/files.types.ts} +3 -5
  111. package/src/types/mcp.experimental.types.ts +163 -0
  112. package/src/types/mcp.types.ts +362 -0
  113. package/src/types/modifiers.types.ts +663 -0
  114. package/src/types/org.types.ts +0 -0
  115. package/src/types/provider.types.ts +41 -0
  116. package/src/types/pusher.types.ts +18 -0
  117. package/src/types/requestOptions.types.ts +62 -0
  118. package/src/types/telemetry.types.ts +89 -0
  119. package/src/types/tool.types.ts +408 -0
  120. package/src/types/toolRouter.types.ts +761 -0
  121. package/src/types/toolkit.types.ts +130 -0
  122. package/src/types/triggers.types.ts +401 -0
  123. package/src/types/webhookEvents.types.ts +219 -0
  124. package/src/utils/buffer.ts +30 -0
  125. package/src/utils/cancellation.ts +22 -0
  126. package/src/utils/config-defaults/ConfigDefaults.node.ts +7 -0
  127. package/src/utils/config-defaults/ConfigDefaults.workerd.ts +10 -0
  128. package/src/utils/config-defaults/index.ts +1 -0
  129. package/src/utils/config-defaults/types.ts +14 -0
  130. package/src/utils/constants.ts +22 -0
  131. package/src/utils/crypto.ts +34 -0
  132. package/src/utils/env.ts +34 -0
  133. package/src/utils/fileDirs.ts +81 -0
  134. package/src/utils/fileUtils.node.ts +458 -0
  135. package/src/utils/json-schema.ts +1 -0
  136. package/src/utils/jsonSchema.ts +355 -0
  137. package/src/utils/logger.ts +99 -0
  138. package/src/utils/mime.ts +75 -0
  139. package/src/utils/modifiers/FileToolModifier.node.ts +477 -0
  140. package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +132 -0
  141. package/src/utils/modifiers/FileToolModifier.workerd.ts +51 -0
  142. package/src/utils/pagination.ts +73 -0
  143. package/src/utils/pusher.ts +286 -0
  144. package/src/utils/schemaPropertyKeys.ts +433 -0
  145. package/src/utils/sdk.ts +110 -0
  146. package/src/utils/sensitiveFileUploadPaths.node.ts +105 -0
  147. package/src/utils/session.ts +114 -0
  148. package/src/utils/toolArguments.ts +73 -0
  149. package/src/utils/toolkitVersion.ts +26 -0
  150. package/src/utils/transform.ts +42 -0
  151. package/src/utils/transformers/authConfigs.ts +107 -0
  152. package/src/utils/transformers/connectedAccounts.ts +119 -0
  153. package/src/utils/transformers/mcp.ts +164 -0
  154. package/src/utils/transformers/toolRouterResponseTransform.ts +160 -0
  155. package/src/utils/transformers/toolkits.ts +100 -0
  156. package/src/utils/transformers/triggers.ts +118 -0
  157. package/src/utils/uploadDirAllowlist.node.ts +178 -0
  158. package/src/utils/uuid.ts +7 -0
  159. package/src/utils/version.ts +58 -0
  160. package/src/utils/zodSchema.ts +90 -0
  161. package/dist/BaseProvider-BvHvJLXc.d.mts +0 -29378
  162. package/dist/CustomTool-D3-NreIm.cjs +0 -1341
  163. package/dist/FileModifierErrors-BYJBHiay.cjs +0 -554
  164. package/dist/FileToolModifier.utils.neutral-DSBQs9-i.cjs +0 -96
  165. package/dist/Telemetry-BQ_pl5AK.cjs +0 -360
  166. package/dist/buffer-BjWptbNH.cjs +0 -63
  167. package/dist/chunk-CQwRTUmo.cjs +0 -53
  168. package/dist/experimental/index.cjs +0 -5
  169. package/dist/experimental/index.d.cts +0 -3
  170. package/dist/fileUtils.node-DtnSRMWa.cjs +0 -462
  171. package/dist/index.cjs +0 -8523
  172. package/dist/index.d.cts +0 -6065
  173. package/dist/models/Files.node.cjs +0 -55
  174. package/dist/models/Files.node.d.cts +0 -56
  175. package/dist/models/Files.workerd.cjs +0 -29
  176. package/dist/models/Files.workerd.d.cts +0 -13
  177. package/dist/platform/node.cjs +0 -55
  178. package/dist/platform/node.d.cts +0 -11
  179. package/dist/platform/workerd.cjs +0 -42
  180. package/dist/platform/workerd.d.cts +0 -12
  181. package/dist/types-pDNm1lYs.d.cts +0 -69
  182. package/dist/utils/config-defaults/ConfigDefaults.node.cjs +0 -10
  183. package/dist/utils/config-defaults/ConfigDefaults.node.d.cts +0 -7
  184. package/dist/utils/config-defaults/ConfigDefaults.workerd.cjs +0 -10
  185. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.cts +0 -7
  186. package/dist/utils/modifiers/FileToolModifier.node.cjs +0 -224
  187. package/dist/utils/modifiers/FileToolModifier.node.d.cts +0 -22
  188. package/dist/utils/modifiers/FileToolModifier.workerd.cjs +0 -27
  189. package/dist/utils/modifiers/FileToolModifier.workerd.d.cts +0 -20
  190. /package/dist/{FileToolModifier.utils.neutral-BpSceNK8.mjs → FileToolModifier.utils.neutral-B5rT711M.mjs} +0 -0
  191. /package/dist/{buffer-yOtEsT4J.mjs → buffer-PcbMMsgm.mjs} +0 -0
  192. /package/dist/{files.types-BXDWA_zS.d.mts → files.types-DeMC_mAW.d.mts} +0 -0
  193. /package/dist/{types-HpJQ8K9l.d.mts → types-DdoCRzLj.d.mts} +0 -0
@@ -0,0 +1,408 @@
1
+ /**
2
+ * @fileoverview Error class for Composio.
3
+ *
4
+ * This error class is used to create custom errors for Composio.
5
+ * It extends the built-in Error class and adds additional properties for code, status code, cause, meta, and possible fixes.
6
+ *
7
+ * @author Musthaq Ahamad <musthaq@composio.dev>
8
+ * @module errors/ComposioError
9
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error}
10
+ */
11
+ import pc from 'picocolors';
12
+ import { ZodError } from 'zod/v3';
13
+ import { BadRequestError } from '@composio/client';
14
+ import logger from '../utils/logger';
15
+
16
+ /**
17
+ * Options for error handling
18
+ */
19
+ export interface ErrorHandleOptions {
20
+ /** Whether to include the stack trace in the output */
21
+ includeStack?: boolean;
22
+ /** @deprecated Use ComposioError.handleAndThrow() instead. This option will be removed in a future version. */
23
+ exitProcess?: boolean;
24
+ /** @deprecated This option is no longer used. */
25
+ exitCode?: number;
26
+ }
27
+
28
+ /**
29
+ * Options for creating a ComposioError
30
+ */
31
+ export type ComposioErrorOptions = {
32
+ /** Error code for categorizing errors */
33
+ code?: string;
34
+ /** HTTP status code associated with the error */
35
+ statusCode?: number;
36
+ /** The underlying cause of the error */
37
+ cause?: unknown;
38
+ /** Additional metadata associated with the error */
39
+ meta?: Record<string, unknown>;
40
+ /** Suggested fixes for the error */
41
+ possibleFixes?: string[];
42
+ /** Custom stack trace */
43
+ stack?: string;
44
+ };
45
+
46
+ /**
47
+ * Structure containing the error data used for formatting
48
+ * @private
49
+ */
50
+ interface ErrorFormatData {
51
+ name: string;
52
+ message: string;
53
+ code?: string;
54
+ statusCode?: number;
55
+ cause?: string;
56
+ meta?: Record<string, unknown>;
57
+ possibleFixes?: string[];
58
+ stack?: string[];
59
+ }
60
+
61
+ /**
62
+ * Base error class for all Composio errors
63
+ */
64
+ export class ComposioError extends Error {
65
+ /** @readonly Error name */
66
+ public name = 'ComposioError';
67
+ public code?: string;
68
+ public possibleFixes?: string[];
69
+ public errorId?: string;
70
+
71
+ /**
72
+ * Creates a new ComposioError
73
+ * @param message Error message
74
+ * @param options Additional error options
75
+ */
76
+ constructor(message: string, options: ComposioErrorOptions = {}) {
77
+ super(message);
78
+
79
+ // Captures stack trace excluding the constructor frame first
80
+ if (Error.captureStackTrace) {
81
+ Error.captureStackTrace(this, this.constructor);
82
+ }
83
+
84
+ // Process the status code - either from options or from the cause if it's a BadRequestError
85
+ const statusCode =
86
+ options.statusCode ||
87
+ (options.cause instanceof BadRequestError ? options.cause.status : undefined);
88
+
89
+ this.code = `TS-SDK::${options.code}`;
90
+ // format the possible fixes
91
+ this.possibleFixes = options.possibleFixes;
92
+
93
+ // Only define properties that have values to avoid showing undefined in error display
94
+ // Node.js by default shows all the properties of the error object, so we are doing it conditionally
95
+ this.definePropertyIfExists('statusCode', statusCode);
96
+ this.definePropertyIfExists('cause', options.cause);
97
+
98
+ const combinedStack =
99
+ options.cause instanceof Error
100
+ ? ComposioError.combineStackTraces(options.cause.stack, this.stack)
101
+ : (options.stack ?? this.stack);
102
+ this.definePropertyIfExists('stack', combinedStack);
103
+
104
+ if (options.meta && Object.keys(options.meta).length > 0) {
105
+ this.definePropertyIfExists('meta', options.meta);
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Helper method to define a property only if it has a value
111
+ * @param propertyName Name of the property to define
112
+ * @param value Value to assign to the property
113
+ * @private
114
+ */
115
+ private definePropertyIfExists(propertyName: string, value: unknown): void {
116
+ if (value !== undefined) {
117
+ Object.defineProperty(this, propertyName, {
118
+ value,
119
+ enumerable: true,
120
+ writable: false,
121
+ configurable: true,
122
+ });
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Helper method to combine stack traces when wrapping errors
128
+ * This ensures the full call chain is preserved
129
+ * @param originalStack The stack of the error being wrapped
130
+ * @param currentStack The stack of the wrapper error
131
+ * @returns Combined stack trace
132
+ * @private
133
+ */
134
+ private static combineStackTraces(
135
+ originalStack?: string,
136
+ currentStack?: string
137
+ ): string | undefined {
138
+ if (!originalStack) return currentStack;
139
+ if (!currentStack) return originalStack;
140
+
141
+ const currentHeader = currentStack.split('\n')[0];
142
+ const originalStackBody = originalStack.split('\n').slice(1).join('\n');
143
+
144
+ return `${currentHeader}\n${currentStack.split('\n').slice(1).join('\n')}\n\nCaused by:\n${originalStackBody}`;
145
+ }
146
+
147
+ /**
148
+ * Extract and normalize error data for formatting
149
+ * @param includeStack Whether to include stack trace information
150
+ * @returns Structured error data for formatting
151
+ * @private
152
+ */
153
+ private getErrorData(includeStack = false): ErrorFormatData {
154
+ const data: ErrorFormatData = {
155
+ name: this.name,
156
+ message: this.message,
157
+ };
158
+
159
+ const { cause, code, stack, statusCode, meta, possibleFixes } = this as unknown as {
160
+ cause: unknown;
161
+ code: string | undefined;
162
+ stack: string | undefined;
163
+ statusCode: number | undefined;
164
+ meta: Record<string, unknown> | undefined;
165
+ possibleFixes: string[] | undefined;
166
+ };
167
+
168
+ // Format cause properly if it exists
169
+ if (cause !== undefined) {
170
+ const rawCause = cause;
171
+ data.cause = rawCause instanceof Error ? rawCause.message : String(rawCause);
172
+ }
173
+
174
+ // Add code if exists
175
+ if (code) {
176
+ data.code = code;
177
+ }
178
+
179
+ // Add status code if exists
180
+ if (statusCode !== undefined) {
181
+ data.statusCode = statusCode;
182
+ }
183
+
184
+ // Add meta if exists
185
+ if (meta) {
186
+ data.meta = meta;
187
+ }
188
+
189
+ // Add possible fixes if exists
190
+ if (possibleFixes) {
191
+ data.possibleFixes = possibleFixes;
192
+ }
193
+
194
+ // Add stack trace if requested
195
+ if (includeStack && stack) {
196
+ if (stack.includes('Caused by:')) {
197
+ const [currentStack, causeStack] = stack.split('Caused by:');
198
+ data.stack = [
199
+ ...currentStack.split('\n').slice(1),
200
+ 'Caused by:',
201
+ ...causeStack.split('\n'),
202
+ ];
203
+ } else {
204
+ data.stack = stack.split('\n').slice(1);
205
+ }
206
+ }
207
+
208
+ return data;
209
+ }
210
+
211
+ /**
212
+ * Prints a user-friendly, colorful representation of the error to the logger
213
+ * @param includeStack Whether to include the stack trace in the output (default: false)
214
+ */
215
+ prettyPrint(includeStack = false): void {
216
+ const data = this.getErrorData(includeStack);
217
+
218
+ let output =
219
+ '\n' + pc.bgRed(pc.white(pc.bold(' ERROR '))) + ' ' + pc.white(pc.bold(data.message)) + '\n';
220
+
221
+ if (data.code) {
222
+ output += pc.yellow(`Error Code: ${data.code}`) + '\n';
223
+ }
224
+
225
+ if (data.statusCode !== undefined) {
226
+ output += pc.yellow(`Status: ${data.statusCode}`) + '\n';
227
+ }
228
+
229
+ if (data.cause) {
230
+ output += pc.gray('Reason:') + '\n';
231
+ output += ' ' + pc.white(data.cause) + '\n';
232
+ }
233
+
234
+ if (data.meta) {
235
+ output += pc.gray('Additional Information:') + '\n';
236
+ output += ' ' + pc.white(JSON.stringify(data.meta, null, 2).replace(/\n/g, '\n ')) + '\n';
237
+ }
238
+
239
+ if (data.possibleFixes?.length) {
240
+ output += '\n' + pc.cyan(pc.bold('Try the following:')) + '\n';
241
+ const fixes = data.possibleFixes?.map((fix, index) => ` ${index + 1}. ` + pc.white(fix));
242
+ output += fixes?.join('\n') + '\n';
243
+ }
244
+
245
+ if (data.stack?.length) {
246
+ output += '\n' + pc.gray('Stack Trace:') + '\n';
247
+ output += pc.gray(data.stack.join('\n')) + '\n';
248
+ }
249
+
250
+ output += '\n'; // Add a trailing empty line
251
+
252
+ logger.error(output);
253
+ }
254
+
255
+ /**
256
+ * Static factory method to create and pretty print an error in one step
257
+ * @param message Error message
258
+ * @param options Error options
259
+ * @param includeStack Whether to include the stack trace in the output
260
+ * @returns The created error instance
261
+ */
262
+ static createAndPrint(
263
+ message: string,
264
+ options: ComposioErrorOptions = {},
265
+ includeStack = false
266
+ ): ComposioError {
267
+ const error = new ComposioError(message, options);
268
+ error.prettyPrint(includeStack);
269
+ return error;
270
+ }
271
+
272
+ /**
273
+ * Utility function to handle errors in a consistent way
274
+ * This properly displays the error without throwing
275
+ * @param error The error to handle
276
+ * @param options Options for error handling
277
+ */
278
+ static handle(error: unknown, options: ErrorHandleOptions = {}): void {
279
+ const { includeStack = false, exitProcess = false } = options;
280
+
281
+ if (error instanceof ComposioError) {
282
+ // For Composio errors, use pretty printing
283
+ error.prettyPrint(includeStack);
284
+ } else if (error instanceof ZodError) {
285
+ // For Zod errors, create a specialized formatted output
286
+ this.handleZodError(error, includeStack);
287
+ } else if (error instanceof Error) {
288
+ // For standard errors, create a basic formatted output
289
+ this.handleStandardError(error, includeStack);
290
+ } else {
291
+ // For unknown errors
292
+ this.handleUnknownError(error);
293
+ }
294
+
295
+ // @deprecated - exitProcess is deprecated, use handleAndThrow() instead
296
+ if (exitProcess) {
297
+ this.throwError(error);
298
+ }
299
+ }
300
+
301
+ /**
302
+ * Utility function to handle errors and then throw them
303
+ * This properly displays the error and then throws it, allowing callers to catch it.
304
+ * Use this for fatal errors that should stop execution.
305
+ * @param error The error to handle and throw
306
+ * @param includeStack Whether to include the stack trace in the output
307
+ * @throws ComposioError - Always throws after displaying the error
308
+ */
309
+ static handleAndThrow(error: unknown, includeStack = false): never {
310
+ this.handle(error, { includeStack });
311
+ this.throwError(error);
312
+ }
313
+
314
+ /**
315
+ * Helper method to throw an error as a ComposioError
316
+ * @param error The error to throw
317
+ * @private
318
+ */
319
+ private static throwError(error: unknown): never {
320
+ if (error instanceof ComposioError) {
321
+ throw error;
322
+ } else if (error instanceof Error) {
323
+ throw new ComposioError(error.message, { cause: error });
324
+ } else {
325
+ throw new ComposioError(String(error));
326
+ }
327
+ }
328
+
329
+ /**
330
+ * Helper method to handle Zod validation errors
331
+ * @param error The Zod error to handle
332
+ * @param includeStack Whether to include the stack trace
333
+ * @private
334
+ */
335
+ private static handleZodError(error: ZodError, includeStack: boolean): void {
336
+ logger.error(
337
+ '\n' + pc.bgRed(pc.white(pc.bold(' ERROR '))) + ' ' + pc.white(pc.bold(error.message))
338
+ );
339
+
340
+ // print the invalid parameters
341
+ logger.error(pc.gray('Invalid parameters:'));
342
+ error.errors.forEach(err => {
343
+ logger.error(pc.yellow(err.path.join('.')) + ' ' + pc.white(err.message));
344
+ });
345
+
346
+ logger.error(pc.gray('Expected parameters:'));
347
+ error.errors.forEach(err => {
348
+ logger.error(pc.yellow(err.path.join('.')) + ' ' + pc.white(err.message));
349
+ });
350
+
351
+ if (includeStack) {
352
+ logger.error('\n' + pc.gray('Validation Errors:'));
353
+ error.errors.forEach(err => {
354
+ const path = err.path.join('.');
355
+ logger.error(pc.gray(' • ') + pc.yellow(path ? `${path}: ` : '') + pc.white(err.message));
356
+ });
357
+
358
+ if (error.stack) {
359
+ logger.error('\n' + pc.gray('Stack Trace:'));
360
+ const stackLines = error.stack.split('\n').slice(1);
361
+ logger.error(pc.gray(stackLines.join('\n')));
362
+ }
363
+ }
364
+
365
+ logger.error(''); // Add a trailing empty line
366
+ }
367
+
368
+ /**
369
+ * Helper method to handle standard Error objects
370
+ * @param error The standard error to handle
371
+ * @param includeStack Whether to include the stack trace
372
+ * @private
373
+ */
374
+ private static handleStandardError(error: Error, includeStack: boolean): void {
375
+ logger.error(
376
+ '\n' + pc.bgRed(pc.white(pc.bold(' ERROR '))) + ' ' + pc.white(pc.bold(error.message))
377
+ );
378
+
379
+ if (includeStack && error.stack) {
380
+ logger.error('\n' + pc.gray('Stack Trace:'));
381
+ const stackLines = error.stack.split('\n').slice(1);
382
+ logger.error(pc.gray(stackLines.join('\n')));
383
+ }
384
+
385
+ logger.error(''); // Add a trailing empty line
386
+ }
387
+
388
+ /**
389
+ * Helper method to handle unknown error types
390
+ * @param error The unknown error value
391
+ * @private
392
+ */
393
+ private static handleUnknownError(error: unknown): void {
394
+ logger.error(
395
+ '\n' +
396
+ pc.bgRed(pc.white(pc.bold(' ERROR '))) +
397
+ ' ' +
398
+ pc.white(pc.bold('Unknown error occurred'))
399
+ );
400
+
401
+ if (error !== null && error !== undefined) {
402
+ logger.error(pc.gray('Error details:'));
403
+ logger.error(' ' + pc.white(String(error)));
404
+ }
405
+
406
+ logger.error(''); // Add a trailing empty line
407
+ }
408
+ }
@@ -0,0 +1,158 @@
1
+ import { ComposioError, ComposioErrorOptions } from './ComposioError';
2
+
3
+ export const ConnectedAccountErrorCodes = {
4
+ CONNECTED_ACCOUNT_NOT_FOUND: 'CONNECTED_ACCOUNT_NOT_FOUND',
5
+ MULTIPLE_CONNECTED_ACCOUNTS: 'MULTIPLE_CONNECTED_ACCOUNTS',
6
+ FAILED_TO_CREATE_CONNECTED_ACCOUNT_LINK: 'FAILED_TO_CREATE_CONNECTED_ACCOUNT_LINK',
7
+ LEGACY_CONNECTED_ACCOUNTS_ENDPOINT_RETIRED: 'LEGACY_CONNECTED_ACCOUNTS_ENDPOINT_RETIRED',
8
+ SHARED_ACCESS_DENIED: 'SHARED_ACCESS_DENIED',
9
+ ACL_ONLY_FOR_SHARED: 'ACL_ONLY_FOR_SHARED',
10
+ SHARED_CONNECTION_NOT_ACCESSIBLE: 'SHARED_CONNECTION_NOT_ACCESSIBLE',
11
+ } as const;
12
+
13
+ export class ComposioConnectedAccountNotFoundError extends ComposioError {
14
+ constructor(
15
+ message: string = 'Connected account not found',
16
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
17
+ ) {
18
+ super(message, {
19
+ ...options,
20
+ code: ConnectedAccountErrorCodes.CONNECTED_ACCOUNT_NOT_FOUND,
21
+ statusCode: 404,
22
+ possibleFixes: options.possibleFixes || [
23
+ 'Ensure the connected account exists and is active in your Composio dashboard',
24
+ ],
25
+ });
26
+ this.name = 'ComposioConnectedAccountNotFoundError';
27
+ }
28
+ }
29
+
30
+ export class ComposioMultipleConnectedAccountsError extends ComposioError {
31
+ constructor(
32
+ message: string = 'Multiple connected accounts found',
33
+ options: Omit<ComposioErrorOptions, 'code'> = {}
34
+ ) {
35
+ super(message, {
36
+ ...options,
37
+ code: ConnectedAccountErrorCodes.MULTIPLE_CONNECTED_ACCOUNTS,
38
+ possibleFixes: options.possibleFixes || [
39
+ 'Use the allowMultiple flag to allow multiple connected accounts per user for an auth config',
40
+ ],
41
+ });
42
+ this.name = 'ComposioMultipleConnectedAccountsError';
43
+ }
44
+ }
45
+
46
+ export class ComposioFailedToCreateConnectedAccountLink extends ComposioError {
47
+ constructor(
48
+ message: string = 'Failed to create connected account link',
49
+ options: Omit<ComposioErrorOptions, 'code'> = {}
50
+ ) {
51
+ super(message, {
52
+ ...options,
53
+ code: ConnectedAccountErrorCodes.FAILED_TO_CREATE_CONNECTED_ACCOUNT_LINK,
54
+ });
55
+ this.name = 'ComposioFailedToCreateConnectedAccountLink';
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Thrown when a tool execution attempts to use a SHARED connected account
61
+ * but the requesting `userId` is not allowed by the connection's ACL.
62
+ *
63
+ * Surfaces when a SHARED connection is reached directly (e.g. via
64
+ * `composio.tools.execute(slug, { connectedAccountId })`) without going
65
+ * through a tool-router session.
66
+ */
67
+ export class ComposioSharedAccessDeniedError extends ComposioError {
68
+ constructor(
69
+ message: string = 'Access denied: this SHARED connected account is not available to the requesting user',
70
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
71
+ ) {
72
+ super(message, {
73
+ ...options,
74
+ code: ConnectedAccountErrorCodes.SHARED_ACCESS_DENIED,
75
+ statusCode: 403,
76
+ possibleFixes: options.possibleFixes || [
77
+ "Ask the connection's creator to grant access via composio.connectedAccounts.updateAcl() — set allowAllUsers, add the userId to allowedUserIds, or remove it from notAllowedUserIds.",
78
+ ],
79
+ });
80
+ this.name = 'ComposioSharedAccessDeniedError';
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Thrown when ACL fields (`allowAllUsers`, `allowedUserIds`,
86
+ * `notAllowedUserIds`) are sent on a `PRIVATE` connection — at create
87
+ * time or via PATCH. ACL is only meaningful for `SHARED` connections.
88
+ */
89
+ export class ComposioAclOnlyForSharedError extends ComposioError {
90
+ constructor(
91
+ message: string = 'ACL fields are only valid on SHARED connected accounts',
92
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
93
+ ) {
94
+ super(message, {
95
+ ...options,
96
+ code: ConnectedAccountErrorCodes.ACL_ONLY_FOR_SHARED,
97
+ statusCode: 400,
98
+ possibleFixes: options.possibleFixes || [
99
+ 'Use accountType: "SHARED", or omit ACL fields when creating/updating a PRIVATE connection.',
100
+ ],
101
+ });
102
+ this.name = 'ComposioAclOnlyForSharedError';
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Thrown by `toolRouter.session.create()` / `session.patch()` when the
108
+ * session's `userId` cannot use a pinned SHARED connection. Raised at
109
+ * session-create time so the session never enters a state that fails
110
+ * mid-execution.
111
+ */
112
+ export class ComposioSharedConnectionNotAccessibleError extends ComposioError {
113
+ constructor(
114
+ message: string = 'A SHARED connected account pinned in the session config is not accessible to the session user',
115
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
116
+ ) {
117
+ super(message, {
118
+ ...options,
119
+ code: ConnectedAccountErrorCodes.SHARED_CONNECTION_NOT_ACCESSIBLE,
120
+ statusCode: 400,
121
+ possibleFixes: options.possibleFixes || [
122
+ 'Grant the session user access via composio.connectedAccounts.updateAcl() on the pinned connection, or pin a different connection the user can use.',
123
+ ],
124
+ });
125
+ this.name = 'ComposioSharedConnectionNotAccessibleError';
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Thrown by `composio.connectedAccounts.initiate()` when the legacy
131
+ * `POST /api/v3/connected_accounts` endpoint rejects a Composio-managed
132
+ * OAuth (OAuth1, OAuth2, DCR_OAUTH) auth-config request.
133
+ *
134
+ * The retiring path is being phased out — new orgs from 2026-05-08 and
135
+ * all remaining orgs from 2026-07-03. Migrate the call to
136
+ * `composio.connectedAccounts.link()`, which works for every redirectable
137
+ * scheme regardless of whether the auth config is Composio-managed or
138
+ * custom.
139
+ *
140
+ * See: https://docs.composio.dev/docs/changelog/2026/04/24
141
+ */
142
+ export class ComposioLegacyConnectedAccountsEndpointRetiredError extends ComposioError {
143
+ constructor(
144
+ message: string = 'POST /api/v3/connected_accounts is no longer supported for Composio-managed OAuth auth configs. Use composio.connectedAccounts.link() instead.',
145
+ options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
146
+ ) {
147
+ super(message, {
148
+ ...options,
149
+ code: ConnectedAccountErrorCodes.LEGACY_CONNECTED_ACCOUNTS_ENDPOINT_RETIRED,
150
+ statusCode: 400,
151
+ possibleFixes: options.possibleFixes || [
152
+ 'Replace `composio.connectedAccounts.initiate(userId, authConfigId, options)` with `composio.connectedAccounts.link(userId, authConfigId, options)`. The return shape (id, redirectUrl, waitForConnection()) is the same.',
153
+ 'Migration guide: https://docs.composio.dev/docs/changelog/2026/04/24',
154
+ ],
155
+ });
156
+ this.name = 'ComposioLegacyConnectedAccountsEndpointRetiredError';
157
+ }
158
+ }
@@ -0,0 +1,32 @@
1
+ import { ComposioError, ComposioErrorOptions } from './ComposioError';
2
+
3
+ export const ConnectionRequestErrorCodes = {
4
+ CONNECTION_REQUEST_TIMEOUT: 'CONNECTION_REQUEST_TIMEOUT',
5
+ CONNECTION_REQUEST_FAILED: 'CONNECTION_REQUEST_FAILED',
6
+ } as const;
7
+
8
+ export class ConnectionRequestTimeoutError extends ComposioError {
9
+ constructor(
10
+ message: string = 'Connection request timed out',
11
+ options: Omit<ComposioErrorOptions, 'code'> = {}
12
+ ) {
13
+ super(message, {
14
+ ...options,
15
+ code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
16
+ });
17
+ this.name = 'ConnectionRequestTimeoutError';
18
+ }
19
+ }
20
+
21
+ export class ConnectionRequestFailedError extends ComposioError {
22
+ constructor(
23
+ message: string = 'Connection request failed',
24
+ options: Omit<ComposioErrorOptions, 'code'> = {}
25
+ ) {
26
+ super(message, {
27
+ ...options,
28
+ code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED,
29
+ });
30
+ this.name = 'ConnectionRequestFailedError';
31
+ }
32
+ }
@@ -0,0 +1,100 @@
1
+ import { ComposioError, ComposioErrorOptions } from './ComposioError';
2
+
3
+ export const FileModifierErrorCodes = {
4
+ FILE_UPLOAD_FAILED: 'FILE_UPLOAD_FAILED',
5
+ SENSITIVE_FILE_PATH_BLOCKED: 'SENSITIVE_FILE_PATH_BLOCKED',
6
+ FILE_UPLOAD_ABORTED: 'FILE_UPLOAD_ABORTED',
7
+ FILE_UPLOAD_PATH_NOT_ALLOWED: 'FILE_UPLOAD_PATH_NOT_ALLOWED',
8
+ FILE_NOT_FOUND: 'FILE_NOT_FOUND',
9
+ } as const;
10
+
11
+ export class ComposioFileUploadError extends ComposioError {
12
+ constructor(message: string = 'Failed to upload file', options: ComposioErrorOptions = {}) {
13
+ super(message, {
14
+ ...options,
15
+ code: options.code ?? FileModifierErrorCodes.FILE_UPLOAD_FAILED,
16
+ possibleFixes: options.possibleFixes || ['Check if the file exists in the location provided'],
17
+ });
18
+ this.name = 'ComposioFileUploadError';
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Thrown when a local file path is refused before upload (sensitive directory or
24
+ * credential-like file name). Subclass of {@link ComposioFileUploadError} so existing
25
+ * `instanceof ComposioFileUploadError` handlers still apply.
26
+ */
27
+ export class ComposioSensitiveFilePathBlockedError extends ComposioFileUploadError {
28
+ constructor(message: string, options: ComposioErrorOptions = {}) {
29
+ super(message, {
30
+ ...options,
31
+ code: FileModifierErrorCodes.SENSITIVE_FILE_PATH_BLOCKED,
32
+ possibleFixes: options.possibleFixes ?? [
33
+ 'Use a file outside ~/.ssh, ~/.aws, and other credential locations',
34
+ 'Set sensitiveFileUploadProtection: false only if you understand the risk',
35
+ 'Add path segments to block with fileUploadPathDenySegments',
36
+ ],
37
+ });
38
+ this.name = 'ComposioSensitiveFilePathBlockedError';
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Thrown when a `beforeFileUpload` hook returns `false`.
44
+ */
45
+ export class ComposioFileUploadAbortedError extends ComposioFileUploadError {
46
+ constructor(message: string, options: ComposioErrorOptions = {}) {
47
+ super(message, {
48
+ ...options,
49
+ code: FileModifierErrorCodes.FILE_UPLOAD_ABORTED,
50
+ possibleFixes: options.possibleFixes ?? [
51
+ 'Change beforeFileUpload to return a file path to upload, or allow the upload to proceed',
52
+ ],
53
+ });
54
+ this.name = 'ComposioFileUploadAbortedError';
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Thrown when automatic file upload during tool execution is attempted from a path
60
+ * that is outside the configured {@link ComposioConfig.fileUploadDirs} allowlist.
61
+ *
62
+ * This only fires for auto-upload (enabled via
63
+ * `dangerouslyAllowAutoUploadDownloadFiles: true`). Manual `composio.files.upload()`
64
+ * calls are never subject to this check.
65
+ */
66
+ export class ComposioFileUploadPathNotAllowedError extends ComposioFileUploadError {
67
+ constructor(message: string, options: ComposioErrorOptions = {}) {
68
+ super(message, {
69
+ ...options,
70
+ code: FileModifierErrorCodes.FILE_UPLOAD_PATH_NOT_ALLOWED,
71
+ possibleFixes: options.possibleFixes ?? [
72
+ 'Move the file under one of the directories in `fileUploadDirs`',
73
+ 'Stage the file under the default upload dir (`~/.composio/temp`)',
74
+ 'Add the containing directory to `fileUploadDirs` when constructing Composio',
75
+ 'Pass the file by URL or as a File/Blob object instead of a filesystem path',
76
+ ],
77
+ });
78
+ this.name = 'ComposioFileUploadPathNotAllowedError';
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Thrown when a local file path passed for upload does not exist on disk.
84
+ * Provides extra debugging context (resolved absolute path, cwd, allowlist state)
85
+ * to help the caller distinguish between "typo" and "not-allowlisted" failures.
86
+ */
87
+ export class ComposioFileNotFoundError extends ComposioFileUploadError {
88
+ constructor(message: string, options: ComposioErrorOptions = {}) {
89
+ super(message, {
90
+ ...options,
91
+ code: FileModifierErrorCodes.FILE_NOT_FOUND,
92
+ possibleFixes: options.possibleFixes ?? [
93
+ 'Double-check the path for typos',
94
+ 'Remember relative paths are resolved against process.cwd() at upload time',
95
+ 'Verify the file exists and the process has read permission',
96
+ ],
97
+ });
98
+ this.name = 'ComposioFileNotFoundError';
99
+ }
100
+ }