@composio/core 0.18.1 → 0.20.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/{CustomTool-VRfWzMix.d.mts → CustomTool-B3m-188G.d.mts} +1 -1
- package/dist/{CustomTool-Bz0f52QR.mjs → CustomTool-fYEFjSLM.mjs} +1 -1
- package/dist/{FileModifierErrors-CwB-Inm9.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
- package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
- package/dist/{SsrfErrors-xhdVE4yw.mjs → SsrfErrors-DiQldIdC.mjs} +32 -17
- package/dist/{Telemetry-Dw9W5RSp.mjs → Telemetry-JRJJYS4I.mjs} +2 -2
- package/dist/{cancellation-P5YUlcfz.mjs → cancellation-Dwa9lGHA.mjs} +7 -5
- package/dist/{composio-Cb3d1jFe.d.mts → composio-B36OXii1.d.mts} +3017 -144
- package/dist/{customTool.types-B6ej_8XZ.d.mts → customTool.types-C436M_D0.d.mts} +525 -101
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +8 -15
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +101 -18
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +123 -0
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +9 -2
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +7 -0
- package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +56 -0
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +78 -0
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
- package/dist/docs/reference/sdk-reference/typescript/meta.json +8 -1
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +117 -24
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +24 -10
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +151 -14
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +50 -40
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +26 -25
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +78 -0
- package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +162 -0
- package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +218 -0
- package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +20 -0
- package/dist/{errors-Ue9wMrPK.mjs → errors-D_A4b2c2.mjs} +143 -4
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-KE5Fa-af.mjs → fileUtils.node-DNLhLg0W.mjs} +8 -6
- package/dist/index.d.mts +418 -146
- package/dist/index.mjs +2728 -349
- package/dist/models/Files.node.d.mts +2 -3
- package/dist/models/Files.node.mjs +2 -2
- package/dist/models/Files.workerd.d.mts +2 -3
- package/dist/platform/node.d.mts +2 -3
- package/dist/platform/workerd.d.mts +2 -3
- package/dist/{sensitiveFileUploadPaths-QN7w4n8v.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
- package/dist/{ssrfGuard.node-BLX6b-Rf.mjs → ssrfGuard.node-BZ270bcu.mjs} +104 -14
- package/dist/{types-CGdgK442.d.mts → types-Br3GBya5.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +19 -10
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.d.mts +12 -4
- package/dist/utils/ssrfGuard.workerd.mjs +2 -2
- package/package.json +9 -9
- package/src/composio.ts +207 -10
- package/src/errors/ConnectedAccountsErrors.ts +47 -0
- package/src/errors/SDKErrors.ts +52 -0
- package/src/errors/ToolErrors.ts +24 -0
- package/src/errors/ToolRouterErrors.ts +57 -0
- package/src/errors/index.ts +3 -0
- package/src/index.ts +15 -0
- package/src/lib/toolRouterMcp.ts +132 -0
- package/src/lib/toolRouterParams.ts +116 -29
- package/src/models/ConnectedAccounts.ts +118 -2
- package/src/models/CustomToolkits.ts +169 -0
- package/src/models/Experimental.ts +27 -0
- package/src/models/Keyring.ts +65 -0
- package/src/models/Logs.ts +101 -0
- package/src/models/MCP.ts +29 -15
- package/src/models/ToolRouter.ts +43 -14
- package/src/models/ToolRouterSession.ts +224 -16
- package/src/models/Toolkits.ts +181 -2
- package/src/models/Tools.ts +58 -26
- package/src/models/Triggers.ts +10 -90
- package/src/models/Usage.ts +119 -0
- package/src/models/Webhooks.ts +520 -0
- package/src/services/pusher/Pusher.ts +46 -16
- package/src/types/authConfigs.types.ts +2 -0
- package/src/types/connectedAccounts.types.ts +54 -0
- package/src/types/customToolkits.types.ts +102 -0
- package/src/types/keyring.types.ts +32 -0
- package/src/types/logs.types.ts +108 -0
- package/src/types/toolRouter.types.ts +259 -14
- package/src/types/toolkit.types.ts +161 -0
- package/src/types/usage.types.ts +81 -0
- package/src/types/webhooks.types.ts +143 -0
- package/src/utils/constants.ts +1 -5
- package/src/utils/jsonSchema.ts +4 -1
- package/src/utils/logger.ts +39 -7
- package/src/utils/sdk.ts +385 -22
- package/src/utils/ssrfGuard.node.ts +127 -13
- package/src/utils/ssrfGuard.workerd.ts +11 -1
- package/src/utils/transformers/connectedAccounts.ts +37 -2
- package/src/utils/transformers/customToolkits.ts +98 -0
- package/src/utils/transformers/keyring.ts +24 -0
- package/src/utils/transformers/logs.ts +85 -0
- package/src/utils/transformers/toolkits.ts +183 -3
- package/src/utils/transformers/triggers.ts +2 -2
- package/src/utils/transformers/usage.ts +77 -0
- package/src/utils/transformers/webhooks.ts +139 -0
package/src/composio.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BaseComposioProvider } from './provider/BaseProvider';
|
|
2
2
|
import ComposioClient from '@composio/client';
|
|
3
|
+
import type { Logger as ClientLogger, LogLevel as ClientLogLevel } from '@composio/client';
|
|
3
4
|
import { Tools } from './models/Tools';
|
|
4
5
|
import { Toolkits } from './models/Toolkits';
|
|
5
6
|
import { Triggers } from './models/Triggers';
|
|
@@ -7,10 +8,22 @@ import { AuthConfigs } from './models/AuthConfigs';
|
|
|
7
8
|
import { ConnectedAccounts } from './models/ConnectedAccounts';
|
|
8
9
|
import { Experimental } from './models/Experimental';
|
|
9
10
|
import { MCP } from './models/MCP';
|
|
11
|
+
import { Webhooks } from './models/Webhooks';
|
|
12
|
+
import { Logs } from './models/Logs';
|
|
13
|
+
import { Keyring } from './models/Keyring';
|
|
10
14
|
import { telemetry } from './telemetry/Telemetry';
|
|
11
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
getScopeHeaders,
|
|
17
|
+
getSDKConfig,
|
|
18
|
+
getToolkitVersionsFromEnv,
|
|
19
|
+
getUserApiKeyHeader,
|
|
20
|
+
resolveSDKScope,
|
|
21
|
+
resolveUserApiKey,
|
|
22
|
+
USER_API_KEY_HEADER,
|
|
23
|
+
} from './utils/sdk';
|
|
12
24
|
import logger from './utils/logger';
|
|
13
|
-
import {
|
|
25
|
+
import type { ComposioLogger, LogLevel } from './utils/logger';
|
|
26
|
+
import { IS_DEVELOPMENT_OR_CI } from './utils/constants';
|
|
14
27
|
import { checkForLatestVersionFromNPM } from './utils/version';
|
|
15
28
|
import { OpenAIProvider } from './provider/OpenAIProvider';
|
|
16
29
|
import { version } from '../package.json';
|
|
@@ -27,10 +40,62 @@ export type ComposioConfig<
|
|
|
27
40
|
TProvider extends BaseComposioProvider<unknown, unknown, unknown> = OpenAIProvider,
|
|
28
41
|
> = {
|
|
29
42
|
/**
|
|
30
|
-
* The API key for the Composio API.
|
|
31
|
-
*
|
|
43
|
+
* The project API key for the Composio API, sent as the `x-api-key` header.
|
|
44
|
+
*
|
|
45
|
+
* - A string is used as-is; the environment and the CLI user config file are not consulted.
|
|
46
|
+
* - Omitted: falls back to `COMPOSIO_API_KEY`, then to the project key stored by the Composio
|
|
47
|
+
* CLI in `~/.composio/user_data.json`. A stored user key (`uak_...`) is never used as a
|
|
48
|
+
* project key; the SDK throws instead of sending it.
|
|
49
|
+
* - `null`: disables project-key authentication entirely, including both fallbacks. The SDK
|
|
50
|
+
* then requires another credential (`userApiKey`, `orgApiKey`, or an `x-user-api-key`
|
|
51
|
+
* entry in `defaultHeaders`) and sends no `x-api-key`; an `x-api-key` entry in
|
|
52
|
+
* `defaultHeaders` is rejected, also on `createSession()` clones.
|
|
53
|
+
*
|
|
54
|
+
* @example 'ak_1234567890'
|
|
32
55
|
*/
|
|
33
56
|
apiKey?: string | null;
|
|
57
|
+
/**
|
|
58
|
+
* User API key (`uak_*`) for the organization, consumer, and user-scoped
|
|
59
|
+
* endpoints reached through `getClient()` (for example `client.org.list()`).
|
|
60
|
+
* Sent as `x-user-api-key` only on operations whose security scheme accepts
|
|
61
|
+
* it, never alongside the project key. Falls back to
|
|
62
|
+
* `process.env['COMPOSIO_USER_API_KEY']`; `null` disables that fallback.
|
|
63
|
+
* Combine with `apiKey: null` to authenticate with the user key alone.
|
|
64
|
+
* @example 'uak_1234567890'
|
|
65
|
+
*/
|
|
66
|
+
userApiKey?: string | null;
|
|
67
|
+
/**
|
|
68
|
+
* Organization API key (`oak_*`) for the organization-owner endpoints reached
|
|
69
|
+
* through `getClient()` (for example `client.org.owner.project.list()`).
|
|
70
|
+
* Sent as `x-org-api-key` only on operations whose security scheme accepts
|
|
71
|
+
* it, never alongside the project key. Falls back to
|
|
72
|
+
* `process.env['COMPOSIO_ORG_API_KEY']`; `null` disables that fallback.
|
|
73
|
+
* Combine with `apiKey: null` to authenticate with the organization key alone.
|
|
74
|
+
* @example 'oak_1234567890'
|
|
75
|
+
*/
|
|
76
|
+
orgApiKey?: string | null;
|
|
77
|
+
/**
|
|
78
|
+
* Organization nano ID that scopes user-key requests, sent as the
|
|
79
|
+
* `x-org-id` header on every request and exported with the session MCP
|
|
80
|
+
* config. This is the short public identifier the API returns as `org_id`
|
|
81
|
+
* (for example from the consumer project resolve endpoint), not a UUID.
|
|
82
|
+
* Must be supplied together with `projectId`; without an explicit scope a
|
|
83
|
+
* user API key addresses the API default (the developer project). May also
|
|
84
|
+
* be supplied as the `x-org-id` entry in `defaultHeaders`; the two must
|
|
85
|
+
* agree.
|
|
86
|
+
* @example 'org_9f2k1x'
|
|
87
|
+
*/
|
|
88
|
+
orgId?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Project nano ID that scopes user-key requests, sent as the
|
|
91
|
+
* `x-project-id` header on every request and exported with the session MCP
|
|
92
|
+
* config. This is the short public identifier the API returns as
|
|
93
|
+
* `project_nano_id`, not the project UUID. Must be supplied together with
|
|
94
|
+
* `orgId`. May also be supplied as the `x-project-id` entry in
|
|
95
|
+
* `defaultHeaders`; the two must agree.
|
|
96
|
+
* @example 'proj_4b8m2q'
|
|
97
|
+
*/
|
|
98
|
+
projectId?: string;
|
|
34
99
|
/**
|
|
35
100
|
* The base URL of the Composio API.
|
|
36
101
|
* @example 'https://backend.composio.dev'
|
|
@@ -100,8 +165,13 @@ export type ComposioConfig<
|
|
|
100
165
|
*/
|
|
101
166
|
host?: string;
|
|
102
167
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
168
|
+
* Default headers attached to every request made through this instance.
|
|
169
|
+
*
|
|
170
|
+
* `x-user-api-key` is the one header the SDK treats as a credential: together
|
|
171
|
+
* with `apiKey: null` it authenticates requests with a Composio user API key
|
|
172
|
+
* instead of a project key. The project key is only ever set from `apiKey`:
|
|
173
|
+
* an `x-api-key` entry is rejected when `apiKey` is `null`. Every other
|
|
174
|
+
* header is passed through untouched.
|
|
105
175
|
* @example
|
|
106
176
|
* ```typescript
|
|
107
177
|
* const composio = new Composio({
|
|
@@ -156,6 +226,68 @@ export type ComposioConfig<
|
|
|
156
226
|
* ```
|
|
157
227
|
*/
|
|
158
228
|
toolkitVersions?: ToolkitVersionParam;
|
|
229
|
+
/**
|
|
230
|
+
* Destination for SDK log output. Messages are formatted and have
|
|
231
|
+
* credential-shaped values redacted before they reach the sink, so any
|
|
232
|
+
* object with `error`/`warn`/`info`/`debug` methods works (`console`, pino,
|
|
233
|
+
* winston, ...).
|
|
234
|
+
*
|
|
235
|
+
* Runtime deprecation warnings raised by the underlying API client (response
|
|
236
|
+
* `Deprecation`/`Sunset` headers and deprecated request inputs) are routed
|
|
237
|
+
* through this logger as well.
|
|
238
|
+
*
|
|
239
|
+
* The SDK logger is process-wide: configuring it on one `Composio` instance
|
|
240
|
+
* affects every instance, and the last configured instance wins.
|
|
241
|
+
*
|
|
242
|
+
* @default console
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* const composio = new Composio({
|
|
246
|
+
* apiKey: 'your-api-key',
|
|
247
|
+
* logger: pino(),
|
|
248
|
+
* logLevel: 'warn',
|
|
249
|
+
* });
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
logger?: ComposioLogger;
|
|
253
|
+
/**
|
|
254
|
+
* Minimum level to emit: `'silent' | 'error' | 'warn' | 'info' | 'debug'`.
|
|
255
|
+
* Takes precedence over the `COMPOSIO_LOG_LEVEL` environment variable.
|
|
256
|
+
* Also gates the API client's runtime deprecation warnings (`'silent'` turns
|
|
257
|
+
* them off). The client's per-request lifecycle logs are emitted at
|
|
258
|
+
* `'debug'` only.
|
|
259
|
+
*
|
|
260
|
+
* Like `logger`, this applies process-wide and the last configured instance
|
|
261
|
+
* wins. The API client's own level is fixed when each instance is created.
|
|
262
|
+
*
|
|
263
|
+
* @default 'info' (or `COMPOSIO_LOG_LEVEL` when set)
|
|
264
|
+
*/
|
|
265
|
+
logLevel?: LogLevel;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Level for the API client given the SDK level. The client logs each request's
|
|
270
|
+
* lifecycle at `info`, which is debug-grade for SDK users, so the client stays
|
|
271
|
+
* at `warn` unless the SDK is at `debug`. The client's `LogLevel` has
|
|
272
|
+
* `'off'` where the SDK has `'silent'`.
|
|
273
|
+
*/
|
|
274
|
+
const toClientLogLevel = (level: LogLevel): ClientLogLevel => {
|
|
275
|
+
if (level === 'silent') return 'off';
|
|
276
|
+
if (level === 'info') return 'warn';
|
|
277
|
+
return level;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Forwards the API client's log records to the SDK singleton so they pick up
|
|
282
|
+
* the SDK's formatting, redaction, and configured sink. Methods are looked up
|
|
283
|
+
* at call time so a later `logger.configure()` is honoured. The client's
|
|
284
|
+
* `info` records (per-request lifecycle) are forwarded as SDK `debug`.
|
|
285
|
+
*/
|
|
286
|
+
const clientLoggerAdapter: ClientLogger = {
|
|
287
|
+
error: (...args) => logger.error(...args),
|
|
288
|
+
warn: (...args) => logger.warn(...args),
|
|
289
|
+
info: (...args) => logger.debug(...args),
|
|
290
|
+
debug: (...args) => logger.debug(...args),
|
|
159
291
|
};
|
|
160
292
|
|
|
161
293
|
/**
|
|
@@ -195,6 +327,15 @@ export class Composio<
|
|
|
195
327
|
authConfigs: AuthConfigs;
|
|
196
328
|
/** Manage authenticated connections */
|
|
197
329
|
connectedAccounts: ConnectedAccounts;
|
|
330
|
+
/**
|
|
331
|
+
* Manage the project's webhook subscription (`webhooks.subscriptions`) and
|
|
332
|
+
* inbound per-toolkit webhook endpoints (`webhooks.endpoints`).
|
|
333
|
+
*/
|
|
334
|
+
webhooks: Webhooks;
|
|
335
|
+
/** Search and inspect tool-execution logs */
|
|
336
|
+
logs: Logs;
|
|
337
|
+
/** Public transfer keys of the organization's customer-managed keyring */
|
|
338
|
+
keyring: Keyring;
|
|
198
339
|
/**
|
|
199
340
|
* Experimental SDK methods whose shape may change in future releases.
|
|
200
341
|
* Prefer domain-specific mounts (for example
|
|
@@ -302,11 +443,36 @@ export class Composio<
|
|
|
302
443
|
* ```
|
|
303
444
|
*/
|
|
304
445
|
constructor(config?: ComposioConfig<TProvider>) {
|
|
446
|
+
const scope = resolveSDKScope({
|
|
447
|
+
orgId: config?.orgId,
|
|
448
|
+
projectId: config?.projectId,
|
|
449
|
+
defaultHeaders: config?.defaultHeaders,
|
|
450
|
+
});
|
|
305
451
|
const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getSDKConfig(
|
|
306
452
|
config?.baseURL,
|
|
307
|
-
config?.apiKey
|
|
453
|
+
config?.apiKey,
|
|
454
|
+
{
|
|
455
|
+
defaultHeaders: config?.defaultHeaders,
|
|
456
|
+
userApiKey: config?.userApiKey,
|
|
457
|
+
orgApiKey: config?.orgApiKey,
|
|
458
|
+
}
|
|
308
459
|
);
|
|
309
460
|
|
|
461
|
+
// The API client sends its user key only on operations whose security
|
|
462
|
+
// scheme names it, which excludes sessions. With the project key disabled
|
|
463
|
+
// the resolved user key is placed as the `x-user-api-key` default header
|
|
464
|
+
// instead, so every request carries exactly that credential and clones,
|
|
465
|
+
// the MCP export, and trigger subscriptions read the same header.
|
|
466
|
+
const userApiKey = apiKeyParsed === null ? resolveUserApiKey(config?.userApiKey) : undefined;
|
|
467
|
+
const defaultHeadersInput =
|
|
468
|
+
userApiKey !== undefined && !getUserApiKeyHeader(config?.defaultHeaders)
|
|
469
|
+
? { ...config?.defaultHeaders, [USER_API_KEY_HEADER]: userApiKey }
|
|
470
|
+
: config?.defaultHeaders;
|
|
471
|
+
|
|
472
|
+
if (config?.logger !== undefined || config?.logLevel !== undefined) {
|
|
473
|
+
logger.configure({ level: config.logLevel, sink: config.logger });
|
|
474
|
+
}
|
|
475
|
+
|
|
310
476
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
311
477
|
logger.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
312
478
|
}
|
|
@@ -324,6 +490,7 @@ export class Composio<
|
|
|
324
490
|
...config,
|
|
325
491
|
baseURL: baseURLParsed,
|
|
326
492
|
apiKey: apiKeyParsed,
|
|
493
|
+
defaultHeaders: defaultHeadersInput,
|
|
327
494
|
toolkitVersions: getToolkitVersionsFromEnv(config?.toolkitVersions),
|
|
328
495
|
allowTracking: config?.allowTracking ?? CONFIG_DEFAULTS.allowTracking,
|
|
329
496
|
dangerouslyAllowAutoUploadDownloadFiles:
|
|
@@ -334,9 +501,16 @@ export class Composio<
|
|
|
334
501
|
fileUploadDirs: expandHomeAndResolveMany(config?.fileUploadDirs),
|
|
335
502
|
fileDownloadDir: expandHomeAndResolve(config?.fileDownloadDir),
|
|
336
503
|
provider: config?.provider ?? this.provider,
|
|
504
|
+
orgId: scope.orgId,
|
|
505
|
+
projectId: scope.projectId,
|
|
337
506
|
};
|
|
338
507
|
|
|
339
|
-
|
|
508
|
+
// The resolved scope is the single source of the x-org-id / x-project-id
|
|
509
|
+
// headers: it travels via `this.config` to clones and to the MCP export.
|
|
510
|
+
const defaultHeaders = getDefaultHeaders(
|
|
511
|
+
{ ...this.config.defaultHeaders, ...getScopeHeaders(scope) },
|
|
512
|
+
this.provider
|
|
513
|
+
);
|
|
340
514
|
|
|
341
515
|
/**
|
|
342
516
|
* Initialize the Composio SDK client.
|
|
@@ -344,11 +518,20 @@ export class Composio<
|
|
|
344
518
|
*/
|
|
345
519
|
this.client = new ComposioClient({
|
|
346
520
|
apiKey: apiKeyParsed,
|
|
521
|
+
userApiKey: config?.userApiKey,
|
|
522
|
+
orgApiKey: config?.orgApiKey,
|
|
347
523
|
baseURL: baseURLParsed,
|
|
348
524
|
defaultHeaders: defaultHeaders,
|
|
349
|
-
|
|
525
|
+
logger: clientLoggerAdapter,
|
|
526
|
+
logLevel: toClientLogLevel(logger.getLevel()),
|
|
350
527
|
});
|
|
351
528
|
|
|
529
|
+
// Store the resolved values, as with `apiKey`, so `getConfig()` and the
|
|
530
|
+
// `createSession()` clone carry whatever the client resolved from env
|
|
531
|
+
// rather than re-reading the environment later.
|
|
532
|
+
this.config.userApiKey = this.client.userApiKey;
|
|
533
|
+
this.config.orgApiKey = this.client.orgApiKey;
|
|
534
|
+
|
|
352
535
|
this.tools = new Tools(this.client, this.config);
|
|
353
536
|
this.mcp = new MCP(this.client);
|
|
354
537
|
this.toolkits = new Toolkits(this.client);
|
|
@@ -360,6 +543,9 @@ export class Composio<
|
|
|
360
543
|
fileDownloadDir: this.config.fileDownloadDir,
|
|
361
544
|
});
|
|
362
545
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
546
|
+
this.webhooks = new Webhooks(this.client);
|
|
547
|
+
this.logs = new Logs(this.client);
|
|
548
|
+
this.keyring = new Keyring(this.client);
|
|
363
549
|
this.experimental = new Experimental(this.client);
|
|
364
550
|
this.sessions = new Sessions(this.client, this.config);
|
|
365
551
|
this.toolRouter = this.sessions;
|
|
@@ -469,7 +655,18 @@ export class Composio<
|
|
|
469
655
|
* ```
|
|
470
656
|
*/
|
|
471
657
|
createSession(options?: { headers?: ComposioRequestHeaders }): Composio<TProvider> {
|
|
472
|
-
|
|
658
|
+
// The clone inherits the resolved credentials: the project, user, and
|
|
659
|
+
// organization keys travel via `this.config`; a user API key placed in the
|
|
660
|
+
// default headers travels via its header unless the caller overrides it.
|
|
661
|
+
const userApiKeyHeader = getUserApiKeyHeader(options?.headers)
|
|
662
|
+
? undefined
|
|
663
|
+
: getUserApiKeyHeader(this.config.defaultHeaders);
|
|
664
|
+
const sessionHeaders = getDefaultHeaders(
|
|
665
|
+
userApiKeyHeader
|
|
666
|
+
? { [userApiKeyHeader.name]: userApiKeyHeader.value, ...options?.headers }
|
|
667
|
+
: options?.headers,
|
|
668
|
+
this.provider
|
|
669
|
+
);
|
|
473
670
|
return new Composio({
|
|
474
671
|
...this.config,
|
|
475
672
|
defaultHeaders: sessionHeaders,
|
|
@@ -8,6 +8,8 @@ export const ConnectedAccountErrorCodes = {
|
|
|
8
8
|
SHARED_ACCESS_DENIED: 'SHARED_ACCESS_DENIED',
|
|
9
9
|
ACL_ONLY_FOR_SHARED: 'ACL_ONLY_FOR_SHARED',
|
|
10
10
|
SHARED_CONNECTION_NOT_ACCESSIBLE: 'SHARED_CONNECTION_NOT_ACCESSIBLE',
|
|
11
|
+
REVOCATION_NOT_SUPPORTED: 'CONNECTED_ACCOUNT_REVOCATION_NOT_SUPPORTED',
|
|
12
|
+
NOT_REVOKABLE: 'CONNECTED_ACCOUNT_NOT_REVOKABLE',
|
|
11
13
|
} as const;
|
|
12
14
|
|
|
13
15
|
export class ComposioConnectedAccountNotFoundError extends ComposioError {
|
|
@@ -156,3 +158,48 @@ export class ComposioLegacyConnectedAccountsEndpointRetiredError extends Composi
|
|
|
156
158
|
this.name = 'ComposioLegacyConnectedAccountsEndpointRetiredError';
|
|
157
159
|
}
|
|
158
160
|
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Thrown by `composio.connectedAccounts.revoke()` when the toolkit behind the
|
|
164
|
+
* connection does not support programmatic revocation at the provider (API
|
|
165
|
+
* 400).
|
|
166
|
+
*/
|
|
167
|
+
export class ComposioConnectedAccountRevocationNotSupportedError extends ComposioError {
|
|
168
|
+
constructor(
|
|
169
|
+
message: string = 'This toolkit does not support programmatic revocation of connected accounts',
|
|
170
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
171
|
+
) {
|
|
172
|
+
super(message, {
|
|
173
|
+
...options,
|
|
174
|
+
code: ConnectedAccountErrorCodes.REVOCATION_NOT_SUPPORTED,
|
|
175
|
+
statusCode: 400,
|
|
176
|
+
possibleFixes: options.possibleFixes || [
|
|
177
|
+
"Revoke the grant from the provider's own settings page, then disable or delete the connected account with composio.connectedAccounts.disable() / delete().",
|
|
178
|
+
],
|
|
179
|
+
});
|
|
180
|
+
this.name = 'ComposioConnectedAccountRevocationNotSupportedError';
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Thrown by `composio.connectedAccounts.revoke()` when the connection is not
|
|
186
|
+
* in a state that can be revoked (API 409), for example it never completed
|
|
187
|
+
* authentication. Revoking an already revoked connection is not an error: it
|
|
188
|
+
* returns an empty `revokedTokens` list.
|
|
189
|
+
*/
|
|
190
|
+
export class ComposioConnectedAccountNotRevokableError extends ComposioError {
|
|
191
|
+
constructor(
|
|
192
|
+
message: string = 'The connected account is not in a revokable state',
|
|
193
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
194
|
+
) {
|
|
195
|
+
super(message, {
|
|
196
|
+
...options,
|
|
197
|
+
code: ConnectedAccountErrorCodes.NOT_REVOKABLE,
|
|
198
|
+
statusCode: 409,
|
|
199
|
+
possibleFixes: options.possibleFixes || [
|
|
200
|
+
'Check the connection status with composio.connectedAccounts.get(); only ACTIVE connections can be revoked.',
|
|
201
|
+
],
|
|
202
|
+
});
|
|
203
|
+
this.name = 'ComposioConnectedAccountNotRevokableError';
|
|
204
|
+
}
|
|
205
|
+
}
|
package/src/errors/SDKErrors.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { ComposioError, ComposioErrorOptions } from './ComposioError';
|
|
|
3
3
|
|
|
4
4
|
export const SDKErrorCodes = {
|
|
5
5
|
NO_API_KEY_PROVIDED: 'NO_API_KEY_PROVIDED',
|
|
6
|
+
API_KEY_KIND_MISMATCH: 'API_KEY_KIND_MISMATCH',
|
|
7
|
+
SCOPE_CONFIG_INVALID: 'SCOPE_CONFIG_INVALID',
|
|
6
8
|
REQUEST_CANCELLED: 'REQUEST_CANCELLED',
|
|
7
9
|
};
|
|
8
10
|
|
|
@@ -29,6 +31,56 @@ export class ComposioNoAPIKeyError extends ComposioError {
|
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Thrown when the organization/project scope of an SDK instance is
|
|
36
|
+
* inconsistent: only one of `orgId` / `projectId` was supplied, or a scope
|
|
37
|
+
* option disagrees with the same header placed in `defaultHeaders`.
|
|
38
|
+
*/
|
|
39
|
+
export class ComposioScopeConfigError extends ComposioError {
|
|
40
|
+
constructor(
|
|
41
|
+
message: string = 'Invalid organization/project scope configuration',
|
|
42
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
43
|
+
) {
|
|
44
|
+
super(message, {
|
|
45
|
+
...options,
|
|
46
|
+
code: SDKErrorCodes.SCOPE_CONFIG_INVALID,
|
|
47
|
+
possibleFixes: options.possibleFixes || [
|
|
48
|
+
'Pass both `orgId` and `projectId` (the organization and consumer project nano IDs), or neither',
|
|
49
|
+
'Supply the scope through the options or through the `x-org-id` / `x-project-id` default headers, not both with different values',
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
this.name = 'ComposioScopeConfigError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Thrown when the only API key the SDK could find is a Composio user key
|
|
58
|
+
* (`uak_...`, as stored by `composio login`) rather than a project key.
|
|
59
|
+
* User keys authenticate a person, not a project, so the SDK refuses to send
|
|
60
|
+
* one as `x-api-key`. The error never includes the key value.
|
|
61
|
+
*/
|
|
62
|
+
export class ComposioAPIKeyKindError extends ComposioError {
|
|
63
|
+
constructor(
|
|
64
|
+
message: string = 'The stored Composio API key is a user API key, not a project API key',
|
|
65
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
66
|
+
) {
|
|
67
|
+
super(message, {
|
|
68
|
+
...options,
|
|
69
|
+
code: SDKErrorCodes.API_KEY_KIND_MISMATCH,
|
|
70
|
+
cause:
|
|
71
|
+
options.cause ||
|
|
72
|
+
'The user config file holds a user API key written by the Composio CLI; it cannot authenticate SDK requests as a project',
|
|
73
|
+
possibleFixes: options.possibleFixes || [
|
|
74
|
+
'Pass a project API key via `apiKey` or the COMPOSIO_API_KEY environment variable',
|
|
75
|
+
'Create a project API key in the Composio dashboard at https://platform.composio.dev',
|
|
76
|
+
'To authenticate with the user API key instead, pass `apiKey: null` together with `userApiKey`',
|
|
77
|
+
],
|
|
78
|
+
statusCode: 401,
|
|
79
|
+
});
|
|
80
|
+
this.name = 'ComposioAPIKeyKindError';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
32
84
|
/**
|
|
33
85
|
* Thrown when an SDK call is cancelled via the caller-supplied `AbortSignal`.
|
|
34
86
|
*
|
package/src/errors/ToolErrors.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { ComposioConnectedAccountNotFoundError } from './ConnectedAccountsErrors
|
|
|
5
5
|
export const ToolErrorCodes = {
|
|
6
6
|
TOOLSET_NOT_DEFINED: 'TOOLSET_NOT_DEFINED',
|
|
7
7
|
TOOL_NOT_FOUND: 'TOOL_NOT_FOUND',
|
|
8
|
+
TOOL_FETCH_ERROR: 'TOOL_FETCH_ERROR',
|
|
8
9
|
INVALID_MODIFIER: 'INVALID_MODIFIER',
|
|
9
10
|
TOOL_EXECUTION_ERROR: 'TOOL_EXECUTION_ERROR',
|
|
10
11
|
INVALID_TOOL_ARGUMENTS: 'INVALID_TOOL_ARGUMENTS',
|
|
@@ -45,6 +46,29 @@ export class ComposioToolNotFoundError extends ComposioError {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Error thrown when a tool schema could not be fetched for a reason other than
|
|
51
|
+
* the tool not existing (for example an invalid API key, a server error, or a
|
|
52
|
+
* network failure). The underlying client error is preserved as `cause`.
|
|
53
|
+
*/
|
|
54
|
+
export class ComposioToolFetchError extends ComposioError {
|
|
55
|
+
constructor(
|
|
56
|
+
message: string = 'Failed to fetch tool',
|
|
57
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
58
|
+
) {
|
|
59
|
+
super(message, {
|
|
60
|
+
...options,
|
|
61
|
+
code: ToolErrorCodes.TOOL_FETCH_ERROR,
|
|
62
|
+
possibleFixes: options.possibleFixes || [
|
|
63
|
+
'Ensure the tool slug is valid',
|
|
64
|
+
'Ensure you are using the correct API key',
|
|
65
|
+
'Ensure you are using the correct API endpoint / Base URL and it is working',
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
this.name = 'ComposioToolFetchError';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
48
72
|
export class ComposioInvalidModifierError extends ComposioError {
|
|
49
73
|
constructor(
|
|
50
74
|
message: string = 'Invalid modifier',
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ComposioError, ComposioErrorOptions } from './ComposioError';
|
|
2
|
+
|
|
3
|
+
export const ToolRouterErrorCodes = {
|
|
4
|
+
MCP_DESTINATION_REJECTED: 'MCP_DESTINATION_REJECTED',
|
|
5
|
+
SESSION_CONFIG_CONFLICT: 'SESSION_CONFIG_CONFLICT',
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Thrown when a session's hosted MCP endpoint is not a destination the SDK
|
|
10
|
+
* will hand the session credential to. The SDK only attaches its credential
|
|
11
|
+
* and scope headers when the MCP URL shares the origin of the API base URL
|
|
12
|
+
* the session was created against. The error is raised only when the caller
|
|
13
|
+
* asked for the endpoint with `mcp: true`; otherwise the session is returned
|
|
14
|
+
* with empty `mcp.headers` and a warning is logged instead. The error names
|
|
15
|
+
* both origins and never includes a credential value.
|
|
16
|
+
*/
|
|
17
|
+
export class ComposioMCPDestinationError extends ComposioError {
|
|
18
|
+
constructor(
|
|
19
|
+
message: string = 'The session MCP endpoint is not a trusted destination for the session credential',
|
|
20
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
21
|
+
) {
|
|
22
|
+
super(message, {
|
|
23
|
+
...options,
|
|
24
|
+
code: ToolRouterErrorCodes.MCP_DESTINATION_REJECTED,
|
|
25
|
+
possibleFixes: options.possibleFixes ?? [
|
|
26
|
+
'Point `baseURL` at the API origin that serves the session MCP endpoint; a custom base URL yields a matching MCP origin',
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
this.name = 'ComposioMCPDestinationError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Thrown when a session update is rejected with HTTP 409 because the session
|
|
35
|
+
* configuration changed since it was last read: the `expected_config_version`
|
|
36
|
+
* precondition (the session's last observed `configVersion` by default) is
|
|
37
|
+
* stale. The local session object is left as it was before the call.
|
|
38
|
+
* Re-fetch the session with `sessions.use(sessionId)` and retry the update
|
|
39
|
+
* against the fresh `configVersion`.
|
|
40
|
+
*/
|
|
41
|
+
export class ComposioSessionConfigConflictError extends ComposioError {
|
|
42
|
+
constructor(
|
|
43
|
+
message: string = 'The session configuration changed since it was last read; re-fetch the session and retry the update',
|
|
44
|
+
options: Omit<ComposioErrorOptions, 'code' | 'statusCode'> = {}
|
|
45
|
+
) {
|
|
46
|
+
super(message, {
|
|
47
|
+
...options,
|
|
48
|
+
code: ToolRouterErrorCodes.SESSION_CONFIG_CONFLICT,
|
|
49
|
+
statusCode: 409,
|
|
50
|
+
possibleFixes: options.possibleFixes ?? [
|
|
51
|
+
'Re-fetch the session with `composio.sessions.use(sessionId)` to observe the current configVersion, then retry the update',
|
|
52
|
+
'Pass `expectedConfigVersion: false` to apply the update regardless of concurrent changes (last writer wins)',
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
this.name = 'ComposioSessionConfigConflictError';
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/errors/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -33,6 +33,10 @@ export {
|
|
|
33
33
|
isBlockedSensitiveFileUploadPath,
|
|
34
34
|
BUILTIN_FILE_UPLOAD_PATH_DENY_SEGMENTS,
|
|
35
35
|
} from './utils/sensitiveFileUploadPaths';
|
|
36
|
+
// Bounded response reader for files fetched from user-supplied URLs. Exported
|
|
37
|
+
// for the same reason as the denylist guard above: downstream packages read
|
|
38
|
+
// remote files too, and every such read must enforce the same size cap.
|
|
39
|
+
export { readResponseBodyWithLimit, MAX_URL_UPLOAD_SIZE_BYTES } from './utils/readResponseBody';
|
|
36
40
|
export {
|
|
37
41
|
sanitizeSchemaPropertyKeys,
|
|
38
42
|
restoreOriginalKeys,
|
|
@@ -41,6 +45,11 @@ export {
|
|
|
41
45
|
export type { KeyMapping, KeySanitizationPolicy } from './utils/schemaPropertyKeys';
|
|
42
46
|
export { AuthScheme } from './models/AuthScheme';
|
|
43
47
|
export { MCP } from './models/MCP';
|
|
48
|
+
export { Webhooks, WebhookSubscriptions, WebhookEndpoints } from './models/Webhooks';
|
|
49
|
+
export { Logs } from './models/Logs';
|
|
50
|
+
export { Usage } from './models/Usage';
|
|
51
|
+
export { Keyring } from './models/Keyring';
|
|
52
|
+
export { CustomToolkits } from './models/CustomToolkits';
|
|
44
53
|
export { RemoteFile } from './models/RemoteFile';
|
|
45
54
|
export { createConnectionRequest } from './models/ConnectionRequest';
|
|
46
55
|
export { ToolRouterSession } from './models/ToolRouterSession';
|
|
@@ -55,6 +64,11 @@ export * from './types/connectedAccounts.types';
|
|
|
55
64
|
export * from './types/toolkit.types';
|
|
56
65
|
export * from './types/triggers.types';
|
|
57
66
|
export * from './types/webhookEvents.types';
|
|
67
|
+
export * from './types/webhooks.types';
|
|
68
|
+
export * from './types/logs.types';
|
|
69
|
+
export * from './types/usage.types';
|
|
70
|
+
export * from './types/keyring.types';
|
|
71
|
+
export * from './types/customToolkits.types';
|
|
58
72
|
export * from './types/mcp.types';
|
|
59
73
|
export * from './types/files.types';
|
|
60
74
|
export * from './types/connectionRequest.types';
|
|
@@ -64,6 +78,7 @@ export * from './types/requestOptions.types';
|
|
|
64
78
|
export * as constants from './utils/constants';
|
|
65
79
|
|
|
66
80
|
export { default as logger } from './utils/logger';
|
|
81
|
+
export type { ComposioLogger, LogLevel } from './utils/logger';
|
|
67
82
|
export { telemetry } from './telemetry/Telemetry';
|
|
68
83
|
|
|
69
84
|
// Experimental custom tools — exported with experimental_ prefix for top-level import
|