@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,23 @@
|
|
|
1
|
+
import { ComposioError, ComposioErrorOptions } from './ComposioError';
|
|
2
|
+
|
|
3
|
+
export const AuthConfigErrorCodes = {
|
|
4
|
+
AUTH_CONFIG_NOT_FOUND: 'AUTH_CONFIG_NOT_FOUND',
|
|
5
|
+
} as const;
|
|
6
|
+
|
|
7
|
+
export class ComposioAuthConfigNotFoundError extends ComposioError {
|
|
8
|
+
constructor(
|
|
9
|
+
message: string = 'Auth config not found',
|
|
10
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
11
|
+
) {
|
|
12
|
+
super(message, {
|
|
13
|
+
...options,
|
|
14
|
+
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
15
|
+
possibleFixes: options.possibleFixes || [
|
|
16
|
+
'Check if the auth config exists',
|
|
17
|
+
'Check if the auth config id is correct',
|
|
18
|
+
'Check if the auth config is enabled',
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
this.name = 'ComposioAuthConfigNotFoundError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -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
|
+
}
|