@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
package/src/composio.ts
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import type { BaseComposioProvider } from './provider/BaseProvider';
|
|
2
|
+
import ComposioClient from '@composio/client';
|
|
3
|
+
import { Tools } from './models/Tools';
|
|
4
|
+
import { Toolkits } from './models/Toolkits';
|
|
5
|
+
import { Triggers } from './models/Triggers';
|
|
6
|
+
import { AuthConfigs } from './models/AuthConfigs';
|
|
7
|
+
import { ConnectedAccounts } from './models/ConnectedAccounts';
|
|
8
|
+
import { Experimental } from './models/Experimental';
|
|
9
|
+
import { MCP } from './models/MCP';
|
|
10
|
+
import { telemetry } from './telemetry/Telemetry';
|
|
11
|
+
import { getSDKConfig, getToolkitVersionsFromEnv } from './utils/sdk';
|
|
12
|
+
import logger from './utils/logger';
|
|
13
|
+
import { COMPOSIO_LOG_LEVEL, IS_DEVELOPMENT_OR_CI } from './utils/constants';
|
|
14
|
+
import { checkForLatestVersionFromNPM } from './utils/version';
|
|
15
|
+
import { OpenAIProvider } from './provider/OpenAIProvider';
|
|
16
|
+
import { version } from '../package.json';
|
|
17
|
+
import type { ComposioRequestHeaders } from './types/composio.types';
|
|
18
|
+
import type { ComposioRequestOptions } from './types/requestOptions.types';
|
|
19
|
+
import { Files } from '#files';
|
|
20
|
+
import { getDefaultHeaders } from './utils/session';
|
|
21
|
+
import { ToolkitVersionParam } from './types/tool.types';
|
|
22
|
+
import { ToolRouter } from './models/ToolRouter';
|
|
23
|
+
import { Sessions } from './models/Sessions';
|
|
24
|
+
import { CONFIG_DEFAULTS } from './utils/config-defaults';
|
|
25
|
+
import { expandHomeAndResolve, expandHomeAndResolveMany } from './utils/fileDirs';
|
|
26
|
+
export type ComposioConfig<
|
|
27
|
+
TProvider extends BaseComposioProvider<unknown, unknown, unknown> = OpenAIProvider,
|
|
28
|
+
> = {
|
|
29
|
+
/**
|
|
30
|
+
* The API key for the Composio API.
|
|
31
|
+
* @example 'sk-1234567890'
|
|
32
|
+
*/
|
|
33
|
+
apiKey?: string | null;
|
|
34
|
+
/**
|
|
35
|
+
* The base URL of the Composio API.
|
|
36
|
+
* @example 'https://backend.composio.dev'
|
|
37
|
+
*/
|
|
38
|
+
baseURL?: string | null;
|
|
39
|
+
/**
|
|
40
|
+
* Whether to allow tracking for the Composio instance.
|
|
41
|
+
* @example true, false
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
allowTracking?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Opt in to automatic file upload and download during tool execution (reads local paths
|
|
47
|
+
* and fetches URLs marked as file-uploadable in tool schemas). Disabled by default.
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
dangerouslyAllowAutoUploadDownloadFiles?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* When true, local file paths for auto-upload and `files.upload` are checked against
|
|
53
|
+
* a built-in denylist of sensitive path segments (e.g. `.ssh`, `.aws`) and
|
|
54
|
+
* credential-like file names (e.g. `.env`, default SSH private key names). URLs and
|
|
55
|
+
* {@link File} objects are not path-checked.
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
sensitiveFileUploadProtection?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Extra path components (a single directory or file name) to treat as sensitive when
|
|
61
|
+
* they appear anywhere in the resolved path. Merged with the built-in list.
|
|
62
|
+
*/
|
|
63
|
+
fileUploadPathDenySegments?: string[];
|
|
64
|
+
/**
|
|
65
|
+
* Allowlist of directories from which the SDK is allowed to read local files
|
|
66
|
+
* during **automatic** file upload (when
|
|
67
|
+
* `dangerouslyAllowAutoUploadDownloadFiles: true`). Manual
|
|
68
|
+
* `composio.files.upload()` calls are NOT subject to this allowlist.
|
|
69
|
+
*
|
|
70
|
+
* - `undefined` (default) → `[<home>/.composio/temp]`.
|
|
71
|
+
* - `false` → reject every local path during auto-upload. URLs
|
|
72
|
+
* (`http(s)://...`) and `File`/`Blob` objects continue to work.
|
|
73
|
+
* - `string[]` (non-empty) → use as the allowlist. A file is accepted iff
|
|
74
|
+
* its symlink-resolved absolute path is inside one of these directories
|
|
75
|
+
* on a path-component boundary (so `/tmp/foo` allows `/tmp/foo/bar` but
|
|
76
|
+
* NOT `/tmp/foo-bar`).
|
|
77
|
+
* - `[]` → behaves like `false` (kept as an alias; prefer `false` for
|
|
78
|
+
* readability).
|
|
79
|
+
* - Providing any value **replaces** the default. Include `~/.composio/temp`
|
|
80
|
+
* in your list if you want the default staging dir to keep working.
|
|
81
|
+
* - On Windows, entries are compared case-insensitively.
|
|
82
|
+
*/
|
|
83
|
+
fileUploadDirs?: string[] | false;
|
|
84
|
+
/**
|
|
85
|
+
* Directory where files downloaded during tool execution (and
|
|
86
|
+
* `composio.files.download()`) are written. Defaults to
|
|
87
|
+
* `<home>/.composio/files`. Path is expanded at SDK-init time; relative
|
|
88
|
+
* paths resolve against `process.cwd()`.
|
|
89
|
+
*/
|
|
90
|
+
fileDownloadDir?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The tool provider to use for this Composio instance.
|
|
93
|
+
* @example new OpenAIProvider()
|
|
94
|
+
*/
|
|
95
|
+
provider?: TProvider;
|
|
96
|
+
/**
|
|
97
|
+
* The host service name of the SDK where the SDK is running.
|
|
98
|
+
* This is used to identify the host for telemetry. Ignore it if you are not using telemetry.
|
|
99
|
+
* @example 'mcp', 'apollo', ' etc
|
|
100
|
+
*/
|
|
101
|
+
host?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Request options to be passed to the Composio API client.
|
|
104
|
+
* This is useful for passing in a custom fetch implementation.
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const composio = new Composio({
|
|
108
|
+
* defaultHeaders: {
|
|
109
|
+
* 'x-request-id': '1234567890',
|
|
110
|
+
* },
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
defaultHeaders?: ComposioRequestHeaders;
|
|
115
|
+
/**
|
|
116
|
+
* Whether to disable version check for the Composio SDK.
|
|
117
|
+
* @example true, false
|
|
118
|
+
* @default false
|
|
119
|
+
*/
|
|
120
|
+
disableVersionCheck?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* The versions of the toolkits to use for tool execution and retrieval.
|
|
123
|
+
* Omit to use 'latest' for all toolkits.
|
|
124
|
+
*
|
|
125
|
+
* **Version Control:**
|
|
126
|
+
* When executing tools manually (via `tools.execute()`), if this resolves to "latest",
|
|
127
|
+
* you must either:
|
|
128
|
+
* - Set `dangerouslySkipVersionCheck: true` in the execute params (not recommended for production)
|
|
129
|
+
* - Specify a concrete version here or in environment variables
|
|
130
|
+
* - Pass a specific `version` parameter to the execute call
|
|
131
|
+
*
|
|
132
|
+
* Defaults to 'latest' if nothing is provided.
|
|
133
|
+
* You can specify individual toolkit versions via environment variables: `COMPOSIO_TOOLKIT_VERSION_GITHUB=20250902_00`
|
|
134
|
+
*
|
|
135
|
+
* @example Global version for all toolkits, omit to use 'latest'
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const composio = new Composio();
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @example Specific versions for different toolkits (recommended for production)
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const composio = new Composio({
|
|
143
|
+
* toolkitVersions: {
|
|
144
|
+
* github: '20250909_00',
|
|
145
|
+
* slack: '20250902_00'
|
|
146
|
+
* }
|
|
147
|
+
* });
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @example Set via environment variables
|
|
151
|
+
* ```typescript
|
|
152
|
+
* // Set environment variables:
|
|
153
|
+
* // COMPOSIO_TOOLKIT_VERSION_GITHUB=20250909_00
|
|
154
|
+
* // COMPOSIO_TOOLKIT_VERSION_SLACK=20250902_00
|
|
155
|
+
* const composio = new Composio(); // Will use env variables
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
toolkitVersions?: ToolkitVersionParam;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* This is the core class for Composio.
|
|
163
|
+
* It is used to initialize the Composio SDK and provide a global configuration.
|
|
164
|
+
*/
|
|
165
|
+
export class Composio<
|
|
166
|
+
TProvider extends BaseComposioProvider<unknown, unknown, unknown> = OpenAIProvider,
|
|
167
|
+
> {
|
|
168
|
+
/**
|
|
169
|
+
* The Composio API client.
|
|
170
|
+
* @type {ComposioClient}
|
|
171
|
+
*/
|
|
172
|
+
protected client: ComposioClient;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The configuration for the Composio SDK.
|
|
176
|
+
* @type {ComposioConfig<TProvider>}
|
|
177
|
+
*/
|
|
178
|
+
private config: ComposioConfig<TProvider>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Core models for Composio.
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
/** List, retrieve, and execute tools */
|
|
185
|
+
tools: Tools<unknown, unknown, TProvider>;
|
|
186
|
+
/** Retrieve toolkit metadata and authorize user connections */
|
|
187
|
+
toolkits: Toolkits;
|
|
188
|
+
/** Manage webhook triggers and event subscriptions */
|
|
189
|
+
triggers: Triggers<TProvider>;
|
|
190
|
+
/** The tool provider instance used for wrapping tools in framework-specific formats */
|
|
191
|
+
provider: TProvider;
|
|
192
|
+
/** Upload and download files */
|
|
193
|
+
files: Files;
|
|
194
|
+
/** Manage authentication configurations for toolkits */
|
|
195
|
+
authConfigs: AuthConfigs;
|
|
196
|
+
/** Manage authenticated connections */
|
|
197
|
+
connectedAccounts: ConnectedAccounts;
|
|
198
|
+
/**
|
|
199
|
+
* Experimental SDK methods whose shape may change in future releases.
|
|
200
|
+
* Prefer domain-specific mounts (for example
|
|
201
|
+
* `composio.connectedAccounts.updateAcl(...)`) when available; this
|
|
202
|
+
* namespace keeps compatibility aliases while APIs are experimental.
|
|
203
|
+
* Stateless experimental factories (e.g. `experimental_createTool`) stay
|
|
204
|
+
* at the top level.
|
|
205
|
+
* @experimental
|
|
206
|
+
*/
|
|
207
|
+
experimental: Experimental;
|
|
208
|
+
/**
|
|
209
|
+
* Model Context Protocol server management.
|
|
210
|
+
* @deprecated Use a session's MCP endpoint instead: `composio.create(userId, { mcp: true })`
|
|
211
|
+
* returns a session that exposes `session.mcp.url` / `session.mcp.headers`. MCP is now opt-in
|
|
212
|
+
* per session; this standalone server-management API is kept only for backwards compatibility.
|
|
213
|
+
* Prefer the session MCP endpoint; do not generate new code against `composio.mcp`.
|
|
214
|
+
* See https://docs.composio.dev/docs/sessions-via-mcp
|
|
215
|
+
*/
|
|
216
|
+
mcp: MCP;
|
|
217
|
+
/**
|
|
218
|
+
* Create and reuse Composio sessions.
|
|
219
|
+
*
|
|
220
|
+
* Prefer `composio.sessions.create(...)` for new code. The top-level
|
|
221
|
+
* `composio.create(...)` method is kept as an alias.
|
|
222
|
+
*/
|
|
223
|
+
sessions: Sessions<unknown, unknown, TProvider>;
|
|
224
|
+
/**
|
|
225
|
+
* Legacy alias for `composio.sessions`.
|
|
226
|
+
* @deprecated Use `composio.sessions` instead — `toolRouter` was renamed to `sessions` and is kept only for backwards compatibility. Prefer `composio.sessions`; do not generate new code against `composio.toolRouter`.
|
|
227
|
+
*/
|
|
228
|
+
toolRouter: ToolRouter<unknown, unknown, TProvider>;
|
|
229
|
+
/**
|
|
230
|
+
* Creates a new tool router session for a user.
|
|
231
|
+
* Use `sessionPreset: SessionPreset.DIRECT_TOOLS` when all needed tools
|
|
232
|
+
* should be exposed directly; see `ToolRouterCreateSessionConfig`.
|
|
233
|
+
*
|
|
234
|
+
* @param userId {string} The user id to create the session for
|
|
235
|
+
* @param config {ToolRouterConfig} The config for the tool router session
|
|
236
|
+
* @returns {Promise<Session<TToolCollection, TTool, TProvider>>} The tool router session
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* import { Composio } from '@composio/core';
|
|
241
|
+
*
|
|
242
|
+
* const composio = new Composio();
|
|
243
|
+
* const userId = 'user_123';
|
|
244
|
+
*
|
|
245
|
+
* const session = await composio.sessions.create(userId, {
|
|
246
|
+
* manageConnections: true,
|
|
247
|
+
* });
|
|
248
|
+
*
|
|
249
|
+
* // Backwards-compatible alias:
|
|
250
|
+
* const same = await composio.create(userId, {
|
|
251
|
+
* manageConnections: true,
|
|
252
|
+
* });
|
|
253
|
+
*
|
|
254
|
+
* console.log(session.sessionId);
|
|
255
|
+
* console.log(session.url);
|
|
256
|
+
* console.log(session.tools());
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
create: Sessions<unknown, unknown, TProvider>['create'];
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Use an existing tool router session
|
|
263
|
+
*
|
|
264
|
+
* @param id {string} The id of the session to use
|
|
265
|
+
* @param options {object} Custom tools / toolkits to attach to the session
|
|
266
|
+
* @param requestOptions {ComposioRequestOptions} Per-request cancellation
|
|
267
|
+
* options. The supplied AbortSignal aborts the underlying session
|
|
268
|
+
* retrieve/attach call only. Subsequent session method calls accept
|
|
269
|
+
* their own per-call requestOptions.
|
|
270
|
+
* @returns {Promise<Session<TToolCollection, TTool, TProvider>>} The tool router session
|
|
271
|
+
*/
|
|
272
|
+
use: Sessions<unknown, unknown, TProvider>['use'];
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Creates a new instance of the Composio SDK.
|
|
276
|
+
*
|
|
277
|
+
* The constructor initializes the SDK with the provided configuration options,
|
|
278
|
+
* sets up the API client, and initializes all core models (tools, toolkits, etc.).
|
|
279
|
+
*
|
|
280
|
+
* @param {ComposioConfig<TProvider>} config - Configuration options for the Composio SDK
|
|
281
|
+
* @param {string} [config.apiKey] - The API key for authenticating with the Composio API
|
|
282
|
+
* @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
|
|
283
|
+
* @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
|
|
284
|
+
* @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* // Initialize with default configuration
|
|
289
|
+
* const composio = new Composio();
|
|
290
|
+
*
|
|
291
|
+
* // Initialize with custom API key and base URL
|
|
292
|
+
* const composio = new Composio({
|
|
293
|
+
* apiKey: 'your-api-key',
|
|
294
|
+
* baseURL: 'https://api.composio.dev'
|
|
295
|
+
* });
|
|
296
|
+
*
|
|
297
|
+
* // Initialize with custom provider
|
|
298
|
+
* const composio = new Composio({
|
|
299
|
+
* apiKey: 'your-api-key',
|
|
300
|
+
* provider: new CustomProvider()
|
|
301
|
+
* });
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
constructor(config?: ComposioConfig<TProvider>) {
|
|
305
|
+
const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getSDKConfig(
|
|
306
|
+
config?.baseURL,
|
|
307
|
+
config?.apiKey
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
if (IS_DEVELOPMENT_OR_CI) {
|
|
311
|
+
logger.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Set the default provider, if not provided by the user.
|
|
316
|
+
*/
|
|
317
|
+
this.provider = (config?.provider ?? new OpenAIProvider()) as TProvider;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Keep a reference to the config object.
|
|
321
|
+
* This is useful for creating a builder pattern, debugging and logging.
|
|
322
|
+
*/
|
|
323
|
+
this.config = {
|
|
324
|
+
...config,
|
|
325
|
+
baseURL: baseURLParsed,
|
|
326
|
+
apiKey: apiKeyParsed,
|
|
327
|
+
toolkitVersions: getToolkitVersionsFromEnv(config?.toolkitVersions),
|
|
328
|
+
allowTracking: config?.allowTracking ?? CONFIG_DEFAULTS.allowTracking,
|
|
329
|
+
dangerouslyAllowAutoUploadDownloadFiles:
|
|
330
|
+
config?.dangerouslyAllowAutoUploadDownloadFiles ??
|
|
331
|
+
CONFIG_DEFAULTS.dangerouslyAllowAutoUploadDownloadFiles,
|
|
332
|
+
sensitiveFileUploadProtection: config?.sensitiveFileUploadProtection,
|
|
333
|
+
fileUploadPathDenySegments: config?.fileUploadPathDenySegments,
|
|
334
|
+
fileUploadDirs: expandHomeAndResolveMany(config?.fileUploadDirs),
|
|
335
|
+
fileDownloadDir: expandHomeAndResolve(config?.fileDownloadDir),
|
|
336
|
+
provider: config?.provider ?? this.provider,
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const defaultHeaders = getDefaultHeaders(this.config.defaultHeaders, this.provider);
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Initialize the Composio SDK client.
|
|
343
|
+
* The client is used to make API calls to the Composio API.
|
|
344
|
+
*/
|
|
345
|
+
this.client = new ComposioClient({
|
|
346
|
+
apiKey: apiKeyParsed,
|
|
347
|
+
baseURL: baseURLParsed,
|
|
348
|
+
defaultHeaders: defaultHeaders,
|
|
349
|
+
logLevel: COMPOSIO_LOG_LEVEL,
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
this.tools = new Tools(this.client, this.config);
|
|
353
|
+
this.mcp = new MCP(this.client);
|
|
354
|
+
this.toolkits = new Toolkits(this.client);
|
|
355
|
+
this.triggers = new Triggers(this.client, this.config);
|
|
356
|
+
this.authConfigs = new AuthConfigs(this.client);
|
|
357
|
+
this.files = new Files(this.client, {
|
|
358
|
+
sensitiveFileUploadProtection: this.config.sensitiveFileUploadProtection,
|
|
359
|
+
fileUploadPathDenySegments: this.config.fileUploadPathDenySegments,
|
|
360
|
+
fileDownloadDir: this.config.fileDownloadDir,
|
|
361
|
+
});
|
|
362
|
+
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
363
|
+
this.experimental = new Experimental(this.client);
|
|
364
|
+
this.sessions = new Sessions(this.client, this.config);
|
|
365
|
+
this.toolRouter = this.sessions;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Initialize session aliases.
|
|
369
|
+
* Properly bind the methods to maintain the correct 'this' context.
|
|
370
|
+
*/
|
|
371
|
+
// Cast: Function.prototype.bind collapses the create/use overloads to a
|
|
372
|
+
// single signature; re-assert the overloaded type. Runtime behaviour is
|
|
373
|
+
// unchanged — bind only rebinds `this`.
|
|
374
|
+
this.create = this.sessions.create.bind(this.sessions) as Composio<TProvider>['create'];
|
|
375
|
+
this.use = this.sessions.use.bind(this.sessions) as Composio<TProvider>['use'];
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Initialize the client telemetry.
|
|
379
|
+
*/
|
|
380
|
+
if (this.config.allowTracking) {
|
|
381
|
+
telemetry.setup({
|
|
382
|
+
apiKey: apiKeyParsed ?? '',
|
|
383
|
+
baseUrl: baseURLParsed ?? '',
|
|
384
|
+
isAgentic: this.provider?._isAgentic || false,
|
|
385
|
+
version: version,
|
|
386
|
+
isBrowser: typeof window !== 'undefined',
|
|
387
|
+
provider: this.provider?.name ?? 'openai',
|
|
388
|
+
host: this.config.host,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
// instrument the composio instance
|
|
392
|
+
telemetry.instrument(this, 'Composio');
|
|
393
|
+
// instrument the provider since we are not using the provider class directly
|
|
394
|
+
telemetry.instrument(
|
|
395
|
+
this.provider,
|
|
396
|
+
this.provider.name ?? this.provider.constructor.name ?? 'unknown'
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
// Check for the latest version of the Composio SDK from NPM.
|
|
400
|
+
if (!this.config.disableVersionCheck) {
|
|
401
|
+
checkForLatestVersionFromNPM(version);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Get the Composio SDK client.
|
|
407
|
+
* @returns {ComposioClient} The Composio API client.
|
|
408
|
+
*/
|
|
409
|
+
getClient(): ComposioClient {
|
|
410
|
+
if (!this.client) {
|
|
411
|
+
throw new Error('Composio client is not initialized. Please initialize it first.');
|
|
412
|
+
}
|
|
413
|
+
return this.client;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Get the configuration SDK is initialized with.
|
|
418
|
+
*
|
|
419
|
+
* Returns a frozen shallow clone — the SDK has already snapshotted
|
|
420
|
+
* configuration values such as `dangerouslyAllowAutoUploadDownloadFiles`,
|
|
421
|
+
* `fileUploadDirs`, and `fileDownloadDir` into its internal models, so
|
|
422
|
+
* mutating the live config object would silently no-op. Freezing makes
|
|
423
|
+
* that contract visible at the call site instead of letting the mutation
|
|
424
|
+
* appear successful.
|
|
425
|
+
*
|
|
426
|
+
* @returns {Readonly<ComposioConfig<TProvider>>} The frozen configuration
|
|
427
|
+
* the SDK is initialized with.
|
|
428
|
+
*/
|
|
429
|
+
getConfig(): Readonly<ComposioConfig<TProvider>> {
|
|
430
|
+
return Object.freeze({ ...this.config });
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Creates a new instance of the Composio SDK with custom request options while preserving the existing configuration.
|
|
435
|
+
* This method is particularly useful when you need to:
|
|
436
|
+
* - Add custom headers for specific requests
|
|
437
|
+
* - Track request contexts with unique identifiers
|
|
438
|
+
* - Override default request behavior for a subset of operations
|
|
439
|
+
*
|
|
440
|
+
* The new instance inherits all configuration from the parent instance (apiKey, baseURL, provider, etc.)
|
|
441
|
+
* but allows you to specify custom request options that will be used for all API calls made through this session.
|
|
442
|
+
*
|
|
443
|
+
* @deprecated Will be removed in a future version of the SDK. Instead, construct a new
|
|
444
|
+
* instance directly with the headers you need: `new Composio({ ...existingConfig, defaultHeaders })`.
|
|
445
|
+
* For one-off overrides, pass per-call `requestOptions` where supported.
|
|
446
|
+
*
|
|
447
|
+
* @param {MergedRequestInit} fetchOptions - Custom request options to be used for all API calls in this session.
|
|
448
|
+
* This follows the Fetch API RequestInit interface with additional options.
|
|
449
|
+
* @returns {Composio<TProvider>} A new Composio instance with the custom request options applied.
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```typescript
|
|
453
|
+
* // Create a base Composio instance
|
|
454
|
+
* const composio = new Composio({
|
|
455
|
+
* apiKey: 'your-api-key'
|
|
456
|
+
* });
|
|
457
|
+
*
|
|
458
|
+
* // Create a session with request tracking headers
|
|
459
|
+
* const composioWithCustomHeaders = composio.createSession({
|
|
460
|
+
* headers: {
|
|
461
|
+
* 'x-request-id': '1234567890',
|
|
462
|
+
* 'x-correlation-id': 'session-abc-123',
|
|
463
|
+
* 'x-custom-header': 'custom-value'
|
|
464
|
+
* }
|
|
465
|
+
* });
|
|
466
|
+
*
|
|
467
|
+
* // Use the session for making API calls with the custom headers
|
|
468
|
+
* await composioWithCustomHeaders.tools.list();
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
createSession(options?: { headers?: ComposioRequestHeaders }): Composio<TProvider> {
|
|
472
|
+
const sessionHeaders = getDefaultHeaders(options?.headers, this.provider);
|
|
473
|
+
return new Composio({
|
|
474
|
+
...this.config,
|
|
475
|
+
defaultHeaders: sessionHeaders,
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Flush any pending telemetry and wait for it to complete.
|
|
481
|
+
*
|
|
482
|
+
* In Node.js-compatible environments, telemetry is automatically flushed on process exit.
|
|
483
|
+
* However, in environments like Cloudflare Workers that don't support process exit events,
|
|
484
|
+
* you should call this method manually to ensure all telemetry is sent.
|
|
485
|
+
*
|
|
486
|
+
* @returns {Promise<void>} A promise that resolves when all pending telemetry has been sent.
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* // In a Cloudflare Worker, use ctx.waitUntil to ensure telemetry is flushed
|
|
491
|
+
* export default {
|
|
492
|
+
* async fetch(request: Request, env: Env, ctx: ExecutionContext) {
|
|
493
|
+
* const composio = new Composio({ apiKey: env.COMPOSIO_API_KEY });
|
|
494
|
+
*
|
|
495
|
+
* // Do your work...
|
|
496
|
+
* const result = await composio.tools.execute(...);
|
|
497
|
+
*
|
|
498
|
+
* // Ensure telemetry flushes before worker terminates
|
|
499
|
+
* ctx.waitUntil(composio.flush());
|
|
500
|
+
*
|
|
501
|
+
* return new Response(JSON.stringify(result));
|
|
502
|
+
* }
|
|
503
|
+
* };
|
|
504
|
+
* ```
|
|
505
|
+
*/
|
|
506
|
+
async flush(): Promise<void> {
|
|
507
|
+
await telemetry.flush();
|
|
508
|
+
}
|
|
509
|
+
}
|
|
@@ -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
|
+
}
|