@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.
- package/dist/BaseProvider-BBnsv9kS.d.mts +29425 -0
- package/dist/{BaseProvider-CVbQxTNa.d.cts → BaseProvider-Brb3o86-.d.mts} +91 -44
- package/dist/CustomTool-D9qwyMrv.mjs +468 -0
- package/dist/{CustomTool-C-IUByoU.d.cts → CustomTool-Dmi6ti3I.d.mts} +2 -4
- package/dist/{CustomTool-CChQSp44.d.mts → CustomTool-DrJpOhY2.d.mts} +2 -4
- package/dist/{FileModifierErrors-C7z16Dfi.mjs → FileModifierErrors-3fSwIWoa.mjs} +35 -36
- package/dist/{Telemetry-DQax33Gh.mjs → Telemetry-DhGI_J4G.mjs} +15 -15
- package/dist/{composio-pcA13w87.d.cts → composio-DHIKRdeG.d.mts} +641 -380
- package/dist/{composio-BlASKqjQ.d.mts → composio-vMwhASRc.d.mts} +1390 -1129
- package/dist/{customTool.types-QtkAZQma.d.cts → customTool.types-CKH2R2ia.d.mts} +487 -189
- package/dist/{customTool.types-DLIORcYN.d.mts → customTool.types-DXin7Cfc.d.mts} +924 -626
- 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/{CustomTool-D5s-aADw.mjs → errors-DSIlYfl5.mjs} +72 -459
- package/dist/experimental/index.d.mts +2 -3
- package/dist/experimental/index.mjs +1 -3
- package/dist/{fileUtils.node-Dq7ebZPC.mjs → fileUtils.node-BiO1JQsJ.mjs} +26 -25
- package/dist/index.d.mts +1708 -2400
- package/dist/index.mjs +2632 -2006
- package/dist/jsonSchema-CFKdONpP.mjs +251 -0
- package/dist/models/Files.node.d.mts +1 -2
- package/dist/models/Files.node.mjs +3 -4
- package/dist/models/Files.workerd.d.mts +0 -1
- package/dist/platform/node.d.mts +1 -2
- package/dist/platform/workerd.d.mts +1 -2
- package/dist/{chunk-CWQeghP5.mjs → rolldown-runtime-w6R9maHv.mjs} +3 -5
- package/dist/{types-J2KCXP8R.d.mts → types-D4Id3wXA.d.mts} +2 -3
- package/dist/{types-DRG5qLxI.d.cts → types-qTbYYBJw.d.mts} +2 -3
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.mjs +3 -0
- package/dist/utils/json-schema.d.mts +2 -0
- package/dist/utils/json-schema.mjs +3 -0
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +44 -24
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -1
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/docs/error-consistency.md +97 -0
- package/package.json +40 -88
- 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/{dist/files.types-lo4zZd87.d.cts → src/types/files.types.ts} +3 -5
- 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
- package/dist/BaseProvider-BvHvJLXc.d.mts +0 -29378
- package/dist/CustomTool-D3-NreIm.cjs +0 -1341
- package/dist/FileModifierErrors-BYJBHiay.cjs +0 -554
- package/dist/FileToolModifier.utils.neutral-DSBQs9-i.cjs +0 -96
- package/dist/Telemetry-BQ_pl5AK.cjs +0 -360
- package/dist/buffer-BjWptbNH.cjs +0 -63
- package/dist/chunk-CQwRTUmo.cjs +0 -53
- package/dist/experimental/index.cjs +0 -5
- package/dist/experimental/index.d.cts +0 -3
- package/dist/fileUtils.node-DtnSRMWa.cjs +0 -462
- package/dist/index.cjs +0 -8523
- package/dist/index.d.cts +0 -6065
- package/dist/models/Files.node.cjs +0 -55
- package/dist/models/Files.node.d.cts +0 -56
- package/dist/models/Files.workerd.cjs +0 -29
- package/dist/models/Files.workerd.d.cts +0 -13
- package/dist/platform/node.cjs +0 -55
- package/dist/platform/node.d.cts +0 -11
- package/dist/platform/workerd.cjs +0 -42
- package/dist/platform/workerd.d.cts +0 -12
- package/dist/types-pDNm1lYs.d.cts +0 -69
- package/dist/utils/config-defaults/ConfigDefaults.node.cjs +0 -10
- package/dist/utils/config-defaults/ConfigDefaults.node.d.cts +0 -7
- package/dist/utils/config-defaults/ConfigDefaults.workerd.cjs +0 -10
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.cts +0 -7
- package/dist/utils/modifiers/FileToolModifier.node.cjs +0 -224
- package/dist/utils/modifiers/FileToolModifier.node.d.cts +0 -22
- package/dist/utils/modifiers/FileToolModifier.workerd.cjs +0 -27
- package/dist/utils/modifiers/FileToolModifier.workerd.d.cts +0 -20
- /package/dist/{FileToolModifier.utils.neutral-BpSceNK8.mjs → FileToolModifier.utils.neutral-B5rT711M.mjs} +0 -0
- /package/dist/{buffer-yOtEsT4J.mjs → buffer-PcbMMsgm.mjs} +0 -0
- /package/dist/{files.types-BXDWA_zS.d.mts → files.types-DeMC_mAW.d.mts} +0 -0
- /package/dist/{types-HpJQ8K9l.d.mts → types-DdoCRzLj.d.mts} +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ComposioError } from './ComposioError';
|
|
2
|
+
|
|
3
|
+
export const PusherErrorCodes = {
|
|
4
|
+
PUSHER_CLIENT_NOT_FOUND: 'PUSHER_CLIENT_NOT_FOUND',
|
|
5
|
+
PUSHER_SUBSCRIPTION_ERROR: 'PUSHER_SUBSCRIPTION_ERROR',
|
|
6
|
+
} as const;
|
|
7
|
+
|
|
8
|
+
export class PusherClientNotFoundError extends ComposioError {
|
|
9
|
+
public name = 'PusherClientNotFoundError';
|
|
10
|
+
public code = PusherErrorCodes.PUSHER_CLIENT_NOT_FOUND;
|
|
11
|
+
public statusCode = 404;
|
|
12
|
+
public possibleFixes = ['Please contact support.'];
|
|
13
|
+
|
|
14
|
+
constructor(message: string, options?: ErrorOptions) {
|
|
15
|
+
super(message, options);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class PusherSubscriptionError extends ComposioError {
|
|
20
|
+
public name = 'PusherSubscriptionError';
|
|
21
|
+
public code = PusherErrorCodes.PUSHER_SUBSCRIPTION_ERROR;
|
|
22
|
+
public statusCode = 400;
|
|
23
|
+
public possibleFixes = ['Please contact support.'];
|
|
24
|
+
|
|
25
|
+
constructor(message: string, options?: ErrorOptions) {
|
|
26
|
+
super(message, options);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ComposioError, ComposioErrorOptions } from './ComposioError';
|
|
2
|
+
|
|
3
|
+
export const RemoteFileErrorCodes = {
|
|
4
|
+
DOWNLOAD_FAILED: 'REMOTE_FILE_DOWNLOAD_FAILED',
|
|
5
|
+
} as const;
|
|
6
|
+
|
|
7
|
+
export interface RemoteFileDownloadErrorOptions extends Omit<ComposioErrorOptions, 'code'> {
|
|
8
|
+
/** HTTP status code from the failed response */
|
|
9
|
+
statusCode?: number;
|
|
10
|
+
/** HTTP status text (e.g. "Not Found", "Forbidden") */
|
|
11
|
+
statusText?: string;
|
|
12
|
+
/** The presigned download URL that failed */
|
|
13
|
+
downloadUrl?: string;
|
|
14
|
+
/** Mount-relative path of the file (e.g. "output/report.pdf") */
|
|
15
|
+
mountRelativePath?: string;
|
|
16
|
+
/** Filename extracted from the mount path */
|
|
17
|
+
filename?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when fetching a remote file from a tool router session mount fails.
|
|
22
|
+
* Includes HTTP status, URL, and file path context for debugging.
|
|
23
|
+
*/
|
|
24
|
+
export class RemoteFileDownloadError extends ComposioError {
|
|
25
|
+
constructor(
|
|
26
|
+
message: string = 'Failed to download remote file',
|
|
27
|
+
options: RemoteFileDownloadErrorOptions = {}
|
|
28
|
+
) {
|
|
29
|
+
const {
|
|
30
|
+
statusCode,
|
|
31
|
+
statusText,
|
|
32
|
+
downloadUrl,
|
|
33
|
+
mountRelativePath,
|
|
34
|
+
filename,
|
|
35
|
+
meta: optionsMeta,
|
|
36
|
+
...rest
|
|
37
|
+
} = options;
|
|
38
|
+
|
|
39
|
+
const meta: Record<string, unknown> = {
|
|
40
|
+
...optionsMeta,
|
|
41
|
+
...(statusCode !== undefined && { statusCode }),
|
|
42
|
+
...(statusText && { statusText }),
|
|
43
|
+
...(downloadUrl && { downloadUrl }),
|
|
44
|
+
...(mountRelativePath && { mountRelativePath }),
|
|
45
|
+
...(filename && { filename }),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
super(message, {
|
|
49
|
+
...rest,
|
|
50
|
+
code: RemoteFileErrorCodes.DOWNLOAD_FAILED,
|
|
51
|
+
statusCode,
|
|
52
|
+
meta: Object.keys(meta).length > 0 ? meta : undefined,
|
|
53
|
+
possibleFixes: options.possibleFixes ?? [
|
|
54
|
+
'Verify the download URL has not expired (check expiresAt)',
|
|
55
|
+
'Ensure the file exists at the specified mount path',
|
|
56
|
+
'Retry the operation; presigned URLs may have transient failures',
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
this.name = 'RemoteFileDownloadError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { APIUserAbortError } from '@composio/client';
|
|
2
|
+
import { ComposioError, ComposioErrorOptions } from './ComposioError';
|
|
3
|
+
|
|
4
|
+
export const SDKErrorCodes = {
|
|
5
|
+
NO_API_KEY_PROVIDED: 'NO_API_KEY_PROVIDED',
|
|
6
|
+
REQUEST_CANCELLED: 'REQUEST_CANCELLED',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export class ComposioNoAPIKeyError extends ComposioError {
|
|
10
|
+
constructor(
|
|
11
|
+
message: string = 'No Composio API key provided',
|
|
12
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
13
|
+
) {
|
|
14
|
+
const defaultCause =
|
|
15
|
+
"Couldn't find an API key in the params, environment variables or in the user config file";
|
|
16
|
+
|
|
17
|
+
super(message, {
|
|
18
|
+
...options,
|
|
19
|
+
code: SDKErrorCodes.NO_API_KEY_PROVIDED,
|
|
20
|
+
cause: options.cause || defaultCause,
|
|
21
|
+
possibleFixes: options.possibleFixes || [
|
|
22
|
+
'Ensure you have an API key passed in the params, or in environment variable (COMPOSIO_API_KEY) or in the user config file',
|
|
23
|
+
'To get an API key, please sign up at https://composio.dev/signup',
|
|
24
|
+
'You can also use the Composio CLI to create a project and get an API key',
|
|
25
|
+
],
|
|
26
|
+
statusCode: 401,
|
|
27
|
+
});
|
|
28
|
+
this.name = 'ComposioNoAPIKeyError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Thrown when an SDK call is cancelled via the caller-supplied `AbortSignal`.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* try {
|
|
38
|
+
* await composio.tools.execute(slug, body, { signal: AbortSignal.timeout(5_000) });
|
|
39
|
+
* } catch (err) {
|
|
40
|
+
* if (err instanceof ComposioRequestCancelledError) return;
|
|
41
|
+
* throw err;
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export class ComposioRequestCancelledError extends ComposioError {
|
|
46
|
+
constructor(
|
|
47
|
+
message: string = 'Request was cancelled by the caller',
|
|
48
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
49
|
+
) {
|
|
50
|
+
super(message, {
|
|
51
|
+
...options,
|
|
52
|
+
code: SDKErrorCodes.REQUEST_CANCELLED,
|
|
53
|
+
possibleFixes: options.possibleFixes ?? [
|
|
54
|
+
'This error is expected when you abort the request via AbortController. Handle it in your catch block to distinguish caller-initiated cancellation from other failures.',
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
this.name = 'ComposioRequestCancelledError';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* `APIUserAbortError` has `.name === "Error"` at runtime (doesn't override it),
|
|
63
|
+
* so we fall back to `constructor.name` for dual-package-hazard cases.
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
export function isRequestAbortError(error: unknown): boolean {
|
|
67
|
+
return _isRequestAbortErrorAt(error, /* depth= */ 0);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function _isRequestAbortErrorAt(error: unknown, depth: number): boolean {
|
|
71
|
+
if (depth > 5) return false;
|
|
72
|
+
if (error instanceof APIUserAbortError) return true;
|
|
73
|
+
if (
|
|
74
|
+
typeof DOMException !== 'undefined' &&
|
|
75
|
+
error instanceof DOMException &&
|
|
76
|
+
error.name === 'AbortError'
|
|
77
|
+
) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
if (!(error instanceof Error)) return false;
|
|
81
|
+
if (
|
|
82
|
+
error.constructor.name === 'APIUserAbortError' ||
|
|
83
|
+
error.name === 'AbortError' ||
|
|
84
|
+
error.name === 'APIUserAbortError'
|
|
85
|
+
) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
if ('cause' in error && error.cause !== undefined && error.cause !== null) {
|
|
89
|
+
return _isRequestAbortErrorAt(error.cause, depth + 1);
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { APIError } from '@composio/client';
|
|
2
|
+
import { ComposioError, ComposioErrorOptions } from './ComposioError';
|
|
3
|
+
import { ComposioConnectedAccountNotFoundError } from './ConnectedAccountsErrors';
|
|
4
|
+
|
|
5
|
+
export const ToolErrorCodes = {
|
|
6
|
+
TOOLSET_NOT_DEFINED: 'TOOLSET_NOT_DEFINED',
|
|
7
|
+
TOOL_NOT_FOUND: 'TOOL_NOT_FOUND',
|
|
8
|
+
INVALID_MODIFIER: 'INVALID_MODIFIER',
|
|
9
|
+
TOOL_EXECUTION_ERROR: 'TOOL_EXECUTION_ERROR',
|
|
10
|
+
INVALID_TOOL_ARGUMENTS: 'INVALID_TOOL_ARGUMENTS',
|
|
11
|
+
INVALID_EXECUTE_FUNCTION: 'INVALID_EXECUTE_FUNCTION',
|
|
12
|
+
GLOBAL_EXECUTE_TOOL_FN_NOT_SET: 'GLOBAL_EXECUTE_TOOL_FN_NOT_SET',
|
|
13
|
+
TOOL_VERSION_REQUIRED: 'TOOL_VERSION_REQUIRED',
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
export class ComposioProviderNotDefinedError extends ComposioError {
|
|
17
|
+
constructor(
|
|
18
|
+
message: string = 'Provider not defined',
|
|
19
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
20
|
+
) {
|
|
21
|
+
super(message, {
|
|
22
|
+
...options,
|
|
23
|
+
code: ToolErrorCodes.TOOLSET_NOT_DEFINED,
|
|
24
|
+
possibleFixes: options.possibleFixes || [
|
|
25
|
+
'Ensure that the provider is defined in the Composio project and passed into the tool instance',
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
this.name = 'ComposioProviderNotDefinedError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class ComposioToolNotFoundError extends ComposioError {
|
|
33
|
+
constructor(
|
|
34
|
+
message: string = 'Tool not found',
|
|
35
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
36
|
+
) {
|
|
37
|
+
super(message, {
|
|
38
|
+
...options,
|
|
39
|
+
code: ToolErrorCodes.TOOL_NOT_FOUND,
|
|
40
|
+
possibleFixes: options.possibleFixes || [
|
|
41
|
+
'Ensure the tool slug is correct and exists in the Composio project',
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
this.name = 'ComposioToolNotFoundError';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class ComposioInvalidModifierError extends ComposioError {
|
|
49
|
+
constructor(
|
|
50
|
+
message: string = 'Invalid modifier',
|
|
51
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
52
|
+
) {
|
|
53
|
+
super(message, {
|
|
54
|
+
...options,
|
|
55
|
+
code: ToolErrorCodes.INVALID_MODIFIER,
|
|
56
|
+
possibleFixes: options.possibleFixes || [
|
|
57
|
+
'Ensure the modifier is a function and returns a valid result',
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
this.name = 'ComposioInvalidModifierError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class ComposioToolExecutionError extends ComposioError {
|
|
65
|
+
constructor(message: string = 'Tool execution error', options: ComposioErrorOptions = {}) {
|
|
66
|
+
super(message, {
|
|
67
|
+
...options,
|
|
68
|
+
code: options.code || ToolErrorCodes.TOOL_EXECUTION_ERROR,
|
|
69
|
+
cause: options.cause,
|
|
70
|
+
possibleFixes: options.possibleFixes || [
|
|
71
|
+
'Ensure the tool is correctly configured and the input is valid',
|
|
72
|
+
'Ensure the userId is correct and has an active connected account for the user in case of non NoAuth toolkits',
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
this.name = 'ComposioToolExecutionError';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class ComposioInvalidToolArgumentsError extends ComposioError {
|
|
81
|
+
constructor(
|
|
82
|
+
message: string = 'Invalid tool arguments',
|
|
83
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
84
|
+
) {
|
|
85
|
+
super(message, {
|
|
86
|
+
...options,
|
|
87
|
+
code: ToolErrorCodes.INVALID_TOOL_ARGUMENTS,
|
|
88
|
+
possibleFixes: options.possibleFixes || [
|
|
89
|
+
'Tool arguments must be a JSON object (or a string that parses to one)',
|
|
90
|
+
'If a model emitted the arguments as a string, ensure it is valid JSON',
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
this.name = 'ComposioInvalidToolArgumentsError';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export class ComposioInvalidExecuteFunctionError extends ComposioError {
|
|
98
|
+
constructor(
|
|
99
|
+
message: string = 'Invalid execute function',
|
|
100
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
101
|
+
) {
|
|
102
|
+
super(message, {
|
|
103
|
+
...options,
|
|
104
|
+
code: ToolErrorCodes.INVALID_EXECUTE_FUNCTION,
|
|
105
|
+
possibleFixes: options.possibleFixes || [
|
|
106
|
+
'Ensure the execute function is a valid function and returns a valid result',
|
|
107
|
+
],
|
|
108
|
+
});
|
|
109
|
+
this.name = 'ComposioInvalidExecuteFunctionError';
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export class ComposioGlobalExecuteToolFnNotSetError extends ComposioError {
|
|
114
|
+
constructor(
|
|
115
|
+
message: string = 'Global execute tool function not set',
|
|
116
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
117
|
+
) {
|
|
118
|
+
super(message, {
|
|
119
|
+
...options,
|
|
120
|
+
code: ToolErrorCodes.GLOBAL_EXECUTE_TOOL_FN_NOT_SET,
|
|
121
|
+
possibleFixes: options.possibleFixes || [
|
|
122
|
+
'Ensure the global execute tool function is set in the provider',
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
this.name = 'ComposioGlobalExecuteToolFnNotSetError';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Error thrown when toolkit version is not specified for manual tool execution.
|
|
131
|
+
*
|
|
132
|
+
* This error is thrown when attempting to execute a tool manually (via `tools.execute()`)
|
|
133
|
+
* and the resolved version is "latest" without `dangerouslySkipVersionCheck` set to true.
|
|
134
|
+
*
|
|
135
|
+
* **Why this error exists:**
|
|
136
|
+
* Using "latest" version in manual execution can lead to unexpected behavior when new
|
|
137
|
+
* toolkit versions are released, potentially breaking your application. For production
|
|
138
|
+
* use, it's recommended to pin specific toolkit versions.
|
|
139
|
+
*
|
|
140
|
+
* **How to fix:**
|
|
141
|
+
* 1. Specify a concrete version in the execute call
|
|
142
|
+
* 2. Configure toolkit versions at SDK initialization
|
|
143
|
+
* 3. Set toolkit version via environment variable
|
|
144
|
+
* 4. Use dangerouslySkipVersionCheck (not recommended for production)
|
|
145
|
+
*
|
|
146
|
+
* @example ❌ This will throw ComposioToolVersionRequiredError if toolkitVersions is 'latest'
|
|
147
|
+
* ```typescript
|
|
148
|
+
* await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
149
|
+
* userId: 'default',
|
|
150
|
+
* arguments: { owner: 'composio' }
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @example ✅ Fix 1: Pass specific version in execute call
|
|
155
|
+
* ```typescript
|
|
156
|
+
* await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
157
|
+
* userId: 'default',
|
|
158
|
+
* version: '20250909_00',
|
|
159
|
+
* arguments: { owner: 'composio' }
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @example ✅ Fix 2: Configure toolkit versions at SDK level
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const composio = new Composio({
|
|
166
|
+
* toolkitVersions: { github: '20250909_00' }
|
|
167
|
+
* });
|
|
168
|
+
* await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
169
|
+
* userId: 'default',
|
|
170
|
+
* arguments: { owner: 'composio' }
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @example ✅ Fix 3: Use environment variable
|
|
175
|
+
* ```typescript
|
|
176
|
+
* // Set: COMPOSIO_TOOLKIT_VERSION_GITHUB=20250909_00
|
|
177
|
+
* await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
178
|
+
* userId: 'default',
|
|
179
|
+
* arguments: { owner: 'composio' }
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @example ⚠️ Fix 4: Skip version check (not recommended for production)
|
|
184
|
+
* ```typescript
|
|
185
|
+
* await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
186
|
+
* userId: 'default',
|
|
187
|
+
* dangerouslySkipVersionCheck: true,
|
|
188
|
+
* arguments: { owner: 'composio' }
|
|
189
|
+
* });
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export class ComposioToolVersionRequiredError extends ComposioError {
|
|
193
|
+
constructor(
|
|
194
|
+
message: string = 'Toolkit version not specified. For manual execution of the tool please pass a specific toolkit version',
|
|
195
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
196
|
+
) {
|
|
197
|
+
super(message, {
|
|
198
|
+
...options,
|
|
199
|
+
code: ToolErrorCodes.TOOL_VERSION_REQUIRED,
|
|
200
|
+
possibleFixes: options.possibleFixes || [
|
|
201
|
+
'Pass the toolkit version as a parameter to the execute function ("latest" is not supported in manual execution)',
|
|
202
|
+
'Set the toolkit versions in the Composio config (toolkitVersions: { <toolkit-slug>: "<toolkit-version>" })',
|
|
203
|
+
'Set the toolkit version in the environment variable (COMPOSIO_TOOLKIT_VERSION_<TOOLKIT_SLUG>)',
|
|
204
|
+
'Set dangerouslySkipVersionCheck to true (this might cause unexpected behavior when new versions of the tools are released)',
|
|
205
|
+
],
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export interface ComposioAPIServerErrorBody {
|
|
210
|
+
error: {
|
|
211
|
+
message: string;
|
|
212
|
+
code: number;
|
|
213
|
+
status: number;
|
|
214
|
+
request_id: string;
|
|
215
|
+
suggested_fix: string;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Map of error codes to their corresponding error constructors
|
|
220
|
+
const ERROR_CODE_HANDLERS = new Map<number, (message: string) => ComposioError>([
|
|
221
|
+
[1803, msg => new ComposioConnectedAccountNotFoundError(msg)],
|
|
222
|
+
// Add more error code handlers here as needed
|
|
223
|
+
]);
|
|
224
|
+
|
|
225
|
+
export const handleToolExecutionError = (tool: string, actualError: Error): ComposioError => {
|
|
226
|
+
// Handle specific API error codes
|
|
227
|
+
if (actualError instanceof APIError && actualError.error) {
|
|
228
|
+
const errorBody = actualError.error as ComposioAPIServerErrorBody;
|
|
229
|
+
const errorCode = errorBody?.error?.code;
|
|
230
|
+
const errorMessage = errorBody?.error?.message;
|
|
231
|
+
|
|
232
|
+
if (errorCode && ERROR_CODE_HANDLERS.has(errorCode)) {
|
|
233
|
+
return ERROR_CODE_HANDLERS.get(errorCode)!(errorMessage || 'An error occurred');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Default error for all other cases
|
|
238
|
+
return new ComposioToolExecutionError(`Error executing the tool ${tool}`, {
|
|
239
|
+
cause: actualError,
|
|
240
|
+
possibleFixes: [
|
|
241
|
+
'Ensure the tool slug is correct and the input arguments for the tool is valid',
|
|
242
|
+
],
|
|
243
|
+
});
|
|
244
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ComposioError, ComposioErrorOptions } from './ComposioError';
|
|
2
|
+
|
|
3
|
+
export const ToolkitErrorCodes = {
|
|
4
|
+
TOOLKIT_NOT_FOUND: 'TOOLKIT_NOT_FOUND',
|
|
5
|
+
} as const;
|
|
6
|
+
|
|
7
|
+
export class ComposioToolkitNotFoundError extends ComposioError {
|
|
8
|
+
constructor(
|
|
9
|
+
message: string = 'Toolkit not found',
|
|
10
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
11
|
+
) {
|
|
12
|
+
super(message, {
|
|
13
|
+
...options,
|
|
14
|
+
code: 'TOOLKIT_NOT_FOUND',
|
|
15
|
+
possibleFixes: options.possibleFixes || [
|
|
16
|
+
'Ensure the toolkit is correctly configured and the slug is valid',
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
this.name = 'ComposioToolkitNotFoundError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class ComposioToolkitFetchError extends ComposioError {
|
|
24
|
+
constructor(
|
|
25
|
+
message: string = 'Failed to fetch toolkit',
|
|
26
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
27
|
+
) {
|
|
28
|
+
super(message, {
|
|
29
|
+
...options,
|
|
30
|
+
code: 'TOOLKIT_FETCH_ERROR',
|
|
31
|
+
possibleFixes: options.possibleFixes || [
|
|
32
|
+
'Ensure the toolkit slug is valid',
|
|
33
|
+
'Ensure you are using the correct API key',
|
|
34
|
+
'Ensure you are using the correct API endpoint / Base URL and it is working',
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
this.name = 'ComposioToolkitFetchError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ComposioError, ComposioErrorOptions } from './ComposioError';
|
|
2
|
+
|
|
3
|
+
export const TriggerErrorCodes = {
|
|
4
|
+
TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS: 'TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS',
|
|
5
|
+
TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT: 'TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT',
|
|
6
|
+
TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL: 'TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL',
|
|
7
|
+
TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL:
|
|
8
|
+
'TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL',
|
|
9
|
+
TRIGGER_TYPE_NOT_FOUND: 'TRIGGER_TYPE_NOT_FOUND',
|
|
10
|
+
WEBHOOK_SIGNATURE_VERIFICATION_FAILED: 'WEBHOOK_SIGNATURE_VERIFICATION_FAILED',
|
|
11
|
+
WEBHOOK_PAYLOAD_INVALID: 'WEBHOOK_PAYLOAD_INVALID',
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
export class ComposioFailedToGetSDKRealtimeCredentialsError extends ComposioError {
|
|
15
|
+
constructor(
|
|
16
|
+
message: string = 'Failed to get SDK realtime credentials',
|
|
17
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
18
|
+
) {
|
|
19
|
+
super(message, {
|
|
20
|
+
...options,
|
|
21
|
+
code: TriggerErrorCodes.TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS,
|
|
22
|
+
possibleFixes: options.possibleFixes || ['Please contact support.'],
|
|
23
|
+
});
|
|
24
|
+
this.name = 'ComposioFailedToGetSDKRealtimeCredentialsError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class ComposioFailedToCreatePusherClientError extends ComposioError {
|
|
29
|
+
constructor(
|
|
30
|
+
message: string = 'Failed to create Pusher client',
|
|
31
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
32
|
+
) {
|
|
33
|
+
super(message, {
|
|
34
|
+
...options,
|
|
35
|
+
code: TriggerErrorCodes.TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT,
|
|
36
|
+
possibleFixes: options.possibleFixes || ['Please contact support.'],
|
|
37
|
+
});
|
|
38
|
+
this.name = 'ComposioFailedToCreatePusherClientError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class ComposioFailedToSubscribeToPusherChannelError extends ComposioError {
|
|
43
|
+
constructor(
|
|
44
|
+
message: string = 'Failed to subscribe to Pusher channel',
|
|
45
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
46
|
+
) {
|
|
47
|
+
super(message, {
|
|
48
|
+
...options,
|
|
49
|
+
code: TriggerErrorCodes.TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL,
|
|
50
|
+
possibleFixes: options.possibleFixes || ['Please contact support.'],
|
|
51
|
+
});
|
|
52
|
+
this.name = 'ComposioFailedToSubscribeToPusherChannelError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class ComposioFailedToUnsubscribeFromPusherChannelError extends ComposioError {
|
|
57
|
+
constructor(
|
|
58
|
+
message: string = 'Failed to unsubscribe from Pusher channel',
|
|
59
|
+
options: Omit<ComposioErrorOptions, 'code'> = {}
|
|
60
|
+
) {
|
|
61
|
+
super(message, {
|
|
62
|
+
...options,
|
|
63
|
+
code: TriggerErrorCodes.TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL,
|
|
64
|
+
possibleFixes: options.possibleFixes || ['Please contact support.'],
|
|
65
|
+
});
|
|
66
|
+
this.name = 'ComposioFailedToUnsubscribeFromPusherChannelError';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export class ComposioTriggerTypeNotFoundError extends ComposioError {
|
|
71
|
+
constructor(
|
|
72
|
+
message: string = 'Trigger type not found',
|
|
73
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
74
|
+
) {
|
|
75
|
+
super(message, {
|
|
76
|
+
...options,
|
|
77
|
+
code: TriggerErrorCodes.TRIGGER_TYPE_NOT_FOUND,
|
|
78
|
+
statusCode: 404,
|
|
79
|
+
possibleFixes: options.possibleFixes || ['Please contact support.'],
|
|
80
|
+
});
|
|
81
|
+
this.name = 'ComposioTriggerTypeNotFoundError';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export class ComposioWebhookSignatureVerificationError extends ComposioError {
|
|
86
|
+
constructor(
|
|
87
|
+
message: string = 'Webhook signature verification failed',
|
|
88
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
89
|
+
) {
|
|
90
|
+
super(message, {
|
|
91
|
+
...options,
|
|
92
|
+
code: TriggerErrorCodes.WEBHOOK_SIGNATURE_VERIFICATION_FAILED,
|
|
93
|
+
statusCode: 401,
|
|
94
|
+
possibleFixes: options.possibleFixes || [
|
|
95
|
+
'Verify that the webhook secret is correct.',
|
|
96
|
+
'Ensure the raw request body is passed without modifications.',
|
|
97
|
+
'Check that the signature header value is being passed correctly.',
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
this.name = 'ComposioWebhookSignatureVerificationError';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export class ComposioWebhookPayloadError extends ComposioError {
|
|
105
|
+
constructor(
|
|
106
|
+
message: string = 'Invalid webhook payload',
|
|
107
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
108
|
+
) {
|
|
109
|
+
super(message, {
|
|
110
|
+
...options,
|
|
111
|
+
code: TriggerErrorCodes.WEBHOOK_PAYLOAD_INVALID,
|
|
112
|
+
statusCode: 400,
|
|
113
|
+
possibleFixes: options.possibleFixes || [
|
|
114
|
+
'Ensure the webhook payload is valid JSON.',
|
|
115
|
+
'Verify the payload structure matches the expected format.',
|
|
116
|
+
],
|
|
117
|
+
});
|
|
118
|
+
this.name = 'ComposioWebhookPayloadError';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// packages/core/src/errors/ValidationError.ts
|
|
2
|
+
|
|
3
|
+
import { ZodError } from 'zod/v3';
|
|
4
|
+
import { ComposioError, ComposioErrorOptions } from './ComposioError';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents an input validation error using Zod.
|
|
8
|
+
*/
|
|
9
|
+
export const ValidationErrorCodes = {
|
|
10
|
+
VALIDATION_ERROR: 'VALIDATION_ERROR',
|
|
11
|
+
JSON_SCHEMA_TO_ZOD_ERROR: 'JSON_SCHEMA_TO_ZOD_ERROR',
|
|
12
|
+
JSON_SCHEMA_REF_RESOLUTION_ERROR: 'JSON_SCHEMA_REF_RESOLUTION_ERROR',
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export class ValidationError extends ComposioError {
|
|
16
|
+
constructor(message: string = 'Input validation failed', options: ComposioErrorOptions = {}) {
|
|
17
|
+
// Extract and process the ZodError
|
|
18
|
+
const { cause: providedZodError, ...restOptions } = options;
|
|
19
|
+
|
|
20
|
+
// Determine the ZodError instance to use
|
|
21
|
+
let zodErrorInstance: ZodError;
|
|
22
|
+
if (providedZodError instanceof ZodError) {
|
|
23
|
+
zodErrorInstance = providedZodError;
|
|
24
|
+
} else {
|
|
25
|
+
zodErrorInstance = new ZodError([
|
|
26
|
+
{
|
|
27
|
+
path: [],
|
|
28
|
+
message: 'Invalid input',
|
|
29
|
+
code: 'custom',
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Format validation issues for the cause
|
|
35
|
+
const issues = zodErrorInstance.issues.map(
|
|
36
|
+
issue => `[${issue.code}] ${issue.path.join('.')} - ${issue.message}`
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
super(message, {
|
|
40
|
+
...restOptions,
|
|
41
|
+
code: options.code || ValidationErrorCodes.VALIDATION_ERROR,
|
|
42
|
+
possibleFixes: issues,
|
|
43
|
+
cause: zodErrorInstance,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
this.name = 'ValidationError';
|
|
47
|
+
|
|
48
|
+
// Create a friendly error message for users
|
|
49
|
+
const userFriendlyMessage = this.generateUserFriendlyMessage();
|
|
50
|
+
this.message = `${message}: ${userFriendlyMessage}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private generateUserFriendlyMessage(): string {
|
|
54
|
+
// Extract the most relevant information from the ZodError
|
|
55
|
+
if (this.cause instanceof ZodError && this.cause.issues.length > 0) {
|
|
56
|
+
const issue = this.cause.issues[0];
|
|
57
|
+
const path = issue.path.join('.');
|
|
58
|
+
const param = path || 'parameter';
|
|
59
|
+
|
|
60
|
+
// Create specific messages based on error code
|
|
61
|
+
if (issue.code === 'invalid_type') {
|
|
62
|
+
return `The ${param} should be a ${issue.expected}, but you provided a ${issue.received}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return issue.message;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return 'Please check your input parameters';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class JsonSchemaToZodError extends ComposioError {
|
|
73
|
+
constructor(
|
|
74
|
+
message: string = 'Failed to convert JSON schema to Zod schema',
|
|
75
|
+
options: ComposioErrorOptions = {}
|
|
76
|
+
) {
|
|
77
|
+
super(message, {
|
|
78
|
+
...options,
|
|
79
|
+
code: options.code || ValidationErrorCodes.JSON_SCHEMA_TO_ZOD_ERROR,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Thrown when a JSON Schema `$ref` pointer cannot be resolved against the
|
|
86
|
+
* document. Used by `dereferenceJsonSchema` to surface malformed pointers,
|
|
87
|
+
* missing `$defs`/`definitions` targets, or chains exceeding the depth cap.
|
|
88
|
+
*/
|
|
89
|
+
export class JsonSchemaRefResolutionError extends ComposioError {
|
|
90
|
+
constructor(
|
|
91
|
+
message: string = 'Failed to resolve JSON Schema $ref',
|
|
92
|
+
options: ComposioErrorOptions = {}
|
|
93
|
+
) {
|
|
94
|
+
super(message, {
|
|
95
|
+
...options,
|
|
96
|
+
code: options.code || ValidationErrorCodes.JSON_SCHEMA_REF_RESOLUTION_ERROR,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|