@composio/core 0.28.0 → 0.30.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/README.md +25 -0
- package/dist/{CustomTool-BYHB7sPs.mjs → CustomTool-9Vlb4XaS.mjs} +12 -14
- package/dist/{CustomTool-DyypijT6.d.mts → CustomTool-Dzk3iqfP.d.mts} +10 -11
- package/dist/FileModifierErrors-WrqokuIF.mjs +199 -0
- package/dist/{FileToolModifier.utils.neutral-DWFpnsj2.mjs → FileToolModifier.utils.neutral-BQP85ZJj.mjs} +1 -2
- package/dist/{SsrfErrors-DiQldIdC.mjs → SsrfErrors-BSVMW915.mjs} +49 -26
- package/dist/{Telemetry-D2PJwXKx.mjs → Telemetry-a7SOQXcg.mjs} +6 -10
- package/dist/{composio-CwHMpKXb.d.mts → composio-DaokW5sV.d.mts} +220 -254
- package/dist/{customTool.types-DoItUHkO.d.mts → customTool.types-CpJbzxT6.d.mts} +255 -274
- package/dist/docs/error-consistency.md +3 -3
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +2 -1
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +88 -10
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +48 -10
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +6 -6
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +4 -4
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +5 -1
- package/dist/{errors-Cly0vXFh.mjs → errors-xC13uvaA.mjs} +116 -135
- package/dist/experimental/index.d.mts +17 -3
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-ILI1IjnZ.mjs → fileUtils.node-CAwIbWYH.mjs} +6 -8
- package/dist/{files.types-DeMC_mAW.d.mts → files.types-Dg6HcEzs.d.mts} +0 -2
- package/dist/index.d.mts +73 -78
- package/dist/index.mjs +393 -290
- package/dist/{cancellation-ZoRh6EJQ.mjs → jsonSchema-Cc4EtHRw.mjs} +5 -22
- package/dist/models/Files.node.d.mts +32 -13
- package/dist/models/Files.node.mjs +36 -19
- package/dist/models/Files.workerd.d.mts +8 -3
- package/dist/models/Files.workerd.mjs +1 -2
- package/dist/platform/node.d.mts +2 -4
- package/dist/platform/node.mjs +15 -16
- package/dist/platform/workerd.d.mts +2 -4
- package/dist/platform/workerd.mjs +1 -2
- package/dist/requestOptions.types-DWrTcbss.d.mts +38 -0
- package/dist/rolldown-runtime-ad2WFvuA.mjs +17 -0
- package/dist/{sensitiveFileUploadPaths-BaEORC7-.mjs → sensitiveFileUploadPaths-CSyJ3Ku8.mjs} +22 -12
- package/dist/{ssrfGuard.node-BZ270bcu.mjs → ssrfGuard.node-CdIkwqVu.mjs} +3 -5
- package/dist/{types-DWZWePfZ.d.mts → types-DQdUb7OG.d.mts} +2 -4
- package/dist/{types-DuVZKrXO.d.mts → types-Ds6XbK1m.d.mts} +0 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +2 -4
- package/dist/utils/config-defaults/ConfigDefaults.node.mjs +1 -2
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +2 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.mjs +1 -2
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +2 -4
- package/dist/utils/modifiers/FileToolModifier.node.mjs +7 -8
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +2 -4
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +2 -3
- package/dist/utils/ssrfGuard.node.d.mts +1 -3
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.d.mts +1 -3
- package/dist/utils/ssrfGuard.workerd.mjs +2 -3
- package/docs/error-consistency.md +3 -3
- package/package.json +12 -13
- package/src/composio.ts +12 -0
- package/src/errors/ComposioError.ts +40 -16
- package/src/errors/ConnectedAccountsErrors.ts +2 -2
- package/src/errors/ToolErrors.ts +177 -28
- package/src/errors/apiErrorDetails.ts +40 -0
- package/src/experimental/index.ts +6 -1
- package/src/lib/toolRouterParams.ts +40 -0
- package/src/models/ConnectedAccounts.ts +2 -2
- package/src/models/ConnectionRequest.ts +44 -32
- package/src/models/CustomTool.ts +25 -30
- package/src/models/CustomToolkits.ts +16 -22
- package/src/models/Experimental.ts +2 -7
- package/src/models/Files.node.ts +68 -37
- package/src/models/RemoteFile.ts +22 -16
- package/src/models/SessionContext.ts +6 -7
- package/src/models/ToolRouter.ts +24 -14
- package/src/models/ToolRouterSession.ts +38 -31
- package/src/models/Tools.ts +274 -30
- package/src/models/Triggers.ts +8 -2
- package/src/types/customTool.types.ts +49 -28
- package/src/types/customToolkits.types.ts +7 -12
- package/src/types/toolRouter.types.ts +39 -17
- package/src/utils/cancellation.ts +5 -1
- package/src/utils/rateLimit.ts +25 -0
- package/src/utils/transformers/customToolkits.ts +2 -2
- package/dist/FileModifierErrors-CdGSABoq.mjs +0 -97
- package/dist/rolldown-runtime-w6R9maHv.mjs +0 -18
- package/src/models/inlineCustomToolsPayload.ts +0 -17
|
@@ -456,8 +456,8 @@ export class ConnectedAccounts {
|
|
|
456
456
|
/**
|
|
457
457
|
* Waits for a connection request to complete and become active.
|
|
458
458
|
*
|
|
459
|
-
* This method
|
|
460
|
-
* until it either becomes active, enters a terminal error state, or times out.
|
|
459
|
+
* This method polls the Composio API, backing off from 1 second to 5 seconds between polls,
|
|
460
|
+
* to check the status of a connection until it either becomes active, enters a terminal error state, or times out.
|
|
461
461
|
*
|
|
462
462
|
* @param {string} connectedAccountId - The ID of the connected account to wait for
|
|
463
463
|
* @param {number} [timeout=60000] - Maximum time to wait in milliseconds (default: 60 seconds)
|
|
@@ -19,6 +19,11 @@ import { ComposioConnectedAccountNotFoundError } from '../errors/ConnectedAccoun
|
|
|
19
19
|
import { telemetry } from '../telemetry/Telemetry';
|
|
20
20
|
import { transformConnectedAccountResponse } from '../utils/transformers/connectedAccounts';
|
|
21
21
|
import { ConnectionRequest, ConnectionRequestState } from '../types/connectionRequest.types';
|
|
22
|
+
import { getRetryAfterSeconds, isRateLimitResponse } from '../utils/rateLimit';
|
|
23
|
+
|
|
24
|
+
const INITIAL_POLL_DELAY_MS = 1000;
|
|
25
|
+
const MAX_POLL_DELAY_MS = 5000;
|
|
26
|
+
const POLL_DELAY_GROWTH = 1.5;
|
|
22
27
|
|
|
23
28
|
/**
|
|
24
29
|
* Creates a connection request object with methods to manage the connection lifecycle.
|
|
@@ -55,8 +60,13 @@ export function createConnectionRequest(
|
|
|
55
60
|
/**
|
|
56
61
|
* Waits for the connection request to complete and become active.
|
|
57
62
|
*
|
|
58
|
-
* This method
|
|
59
|
-
*
|
|
63
|
+
* This method polls the Composio API to check the status of the connection request until it
|
|
64
|
+
* either becomes active, enters a terminal error state, or times out. The delay between polls
|
|
65
|
+
* grows from 1 second to 5 seconds, so a connection can be up to 5 seconds old when this returns.
|
|
66
|
+
* A rate-limited poll doesn't fail the wait: once the client's own retries run out, it waits as
|
|
67
|
+
* long as the response asks before polling again. If that delay reaches the timeout, the wait
|
|
68
|
+
* times out without another poll. The client's retries can carry the wait past the timeout,
|
|
69
|
+
* because they aren't bound by it.
|
|
60
70
|
*
|
|
61
71
|
* @param {number} [timeout=60000] - Maximum time to wait in milliseconds before timing out (default: 60 seconds)
|
|
62
72
|
* @returns {Promise<ConnectedAccountRetrieveResponse>} The final connected account response when successful
|
|
@@ -104,46 +114,48 @@ export function createConnectionRequest(
|
|
|
104
114
|
}
|
|
105
115
|
};
|
|
106
116
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
request.status = response.status;
|
|
110
|
-
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
111
|
-
return transformConnectedAccountResponse(response);
|
|
112
|
-
}
|
|
113
|
-
failIfTerminal(response);
|
|
114
|
-
} catch (error) {
|
|
115
|
-
if (error instanceof ComposioClient.NotFoundError) {
|
|
116
|
-
throw new ComposioConnectedAccountNotFoundError(
|
|
117
|
-
`Connected account with id ${request.id} not found`,
|
|
118
|
-
{
|
|
119
|
-
meta: {
|
|
120
|
-
connectedAccountId: request.id,
|
|
121
|
-
},
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
} else {
|
|
125
|
-
throw error;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
117
|
+
const deadline = Date.now() + timeout;
|
|
118
|
+
let pollDelay = INITIAL_POLL_DELAY_MS;
|
|
128
119
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
while (Date.now() - start < timeout) {
|
|
120
|
+
while (true) {
|
|
121
|
+
let delay = pollDelay;
|
|
122
|
+
let rateLimited = false;
|
|
133
123
|
try {
|
|
134
124
|
const response = await client.connectedAccounts.retrieve(request.id);
|
|
135
|
-
|
|
136
125
|
request.status = response.status;
|
|
137
126
|
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
138
127
|
return transformConnectedAccountResponse(response);
|
|
139
128
|
}
|
|
140
|
-
|
|
141
129
|
failIfTerminal(response);
|
|
142
|
-
|
|
143
|
-
await new Promise(resolve => setTimeout(resolve, pollInterval));
|
|
144
130
|
} catch (error) {
|
|
145
|
-
|
|
131
|
+
if (error instanceof ComposioClient.NotFoundError) {
|
|
132
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
133
|
+
`Connected account with id ${request.id} not found`,
|
|
134
|
+
{
|
|
135
|
+
meta: {
|
|
136
|
+
connectedAccountId: request.id,
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (!isRateLimitResponse(error)) {
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
rateLimited = true;
|
|
145
|
+
delay = Math.max(delay, (getRetryAfterSeconds(error) ?? 0) * 1000);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const remaining = deadline - Date.now();
|
|
149
|
+
// Written so a NaN timeout times out rather than polling forever.
|
|
150
|
+
if (!(remaining > 0)) {
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(delay, remaining)));
|
|
154
|
+
// A rate-limited poll must not start a fresh client retry cycle at the deadline.
|
|
155
|
+
if (rateLimited && Date.now() >= deadline) {
|
|
156
|
+
break;
|
|
146
157
|
}
|
|
158
|
+
pollDelay = Math.min(pollDelay * POLL_DELAY_GROWTH, MAX_POLL_DELAY_MS);
|
|
147
159
|
}
|
|
148
160
|
|
|
149
161
|
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${request.id}`);
|
package/src/models/CustomTool.ts
CHANGED
|
@@ -24,11 +24,11 @@ import {
|
|
|
24
24
|
CreateCustomToolkitBaseSchema,
|
|
25
25
|
CustomToolSlugSchema,
|
|
26
26
|
type AnyZodSchema,
|
|
27
|
-
type
|
|
28
|
-
type
|
|
29
|
-
type
|
|
30
|
-
type
|
|
31
|
-
type
|
|
27
|
+
type CreateLocalToolParams,
|
|
28
|
+
type CreateLocalToolkitParams,
|
|
29
|
+
type LocalTool,
|
|
30
|
+
type LocalToolkit,
|
|
31
|
+
type LocalToolExecuteFn,
|
|
32
32
|
type CustomToolsMap,
|
|
33
33
|
type CustomToolsMapEntry,
|
|
34
34
|
type CustomToolWireDefinition,
|
|
@@ -97,10 +97,10 @@ function validateSlugLength(
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
* Create a
|
|
100
|
+
* Create a local tool for use in tool router sessions.
|
|
101
101
|
*
|
|
102
102
|
* The returned object is a lightweight reference containing the tool's metadata
|
|
103
|
-
* and execute function. Pass it to `composio.create(userId, { experimental: {
|
|
103
|
+
* and execute function. Pass it to `composio.create(userId, { experimental: { localTools: [...] } })`
|
|
104
104
|
* to bind it to a session.
|
|
105
105
|
*
|
|
106
106
|
* Just return the result data from `execute`, or throw an error.
|
|
@@ -113,7 +113,7 @@ function validateSlugLength(
|
|
|
113
113
|
*
|
|
114
114
|
* @param slug - Unique tool identifier (alphanumeric, underscores, hyphens; no LOCAL_ or COMPOSIO_ prefix)
|
|
115
115
|
* @param options - Tool definition including name, schema, and execute function
|
|
116
|
-
* @returns A
|
|
116
|
+
* @returns A LocalTool to pass to session creation
|
|
117
117
|
*
|
|
118
118
|
* @example Standalone tool (no auth)
|
|
119
119
|
* ```typescript
|
|
@@ -142,8 +142,8 @@ function validateSlugLength(
|
|
|
142
142
|
*/
|
|
143
143
|
export function createCustomTool<T extends AnyZodSchema>(
|
|
144
144
|
slug: string,
|
|
145
|
-
options:
|
|
146
|
-
):
|
|
145
|
+
options: CreateLocalToolParams<T>
|
|
146
|
+
): LocalTool {
|
|
147
147
|
// Validate slug separately
|
|
148
148
|
const slugResult = CustomToolSlugSchema.safeParse(slug);
|
|
149
149
|
if (!slugResult.success) {
|
|
@@ -192,12 +192,13 @@ export function createCustomTool<T extends AnyZodSchema>(
|
|
|
192
192
|
inputSchema,
|
|
193
193
|
outputSchema,
|
|
194
194
|
inputParams,
|
|
195
|
-
execute: execute as
|
|
195
|
+
execute: execute as LocalToolExecuteFn<AnyZodSchema>,
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
/**
|
|
200
|
-
* Create a
|
|
200
|
+
* Create a toolkit that groups related local tools. Pass it to
|
|
201
|
+
* `composio.create(userId, { experimental: { localToolkits: [...] } })`.
|
|
201
202
|
*
|
|
202
203
|
* Tools passed here must NOT have `extendsToolkit` set — they inherit the toolkit identity instead.
|
|
203
204
|
*
|
|
@@ -207,7 +208,7 @@ export function createCustomTool<T extends AnyZodSchema>(
|
|
|
207
208
|
*
|
|
208
209
|
* @param slug - Unique toolkit identifier (alphanumeric, underscores, hyphens; no LOCAL_ or COMPOSIO_ prefix)
|
|
209
210
|
* @param options - Toolkit definition including name, description, and tools
|
|
210
|
-
* @returns A
|
|
211
|
+
* @returns A LocalToolkit to pass to session creation
|
|
211
212
|
*
|
|
212
213
|
* @example
|
|
213
214
|
* ```typescript
|
|
@@ -218,10 +219,7 @@ export function createCustomTool<T extends AnyZodSchema>(
|
|
|
218
219
|
* });
|
|
219
220
|
* ```
|
|
220
221
|
*/
|
|
221
|
-
export function createCustomToolkit(
|
|
222
|
-
slug: string,
|
|
223
|
-
options: CreateCustomToolkitParams
|
|
224
|
-
): CustomToolkit {
|
|
222
|
+
export function createCustomToolkit(slug: string, options: CreateLocalToolkitParams): LocalToolkit {
|
|
225
223
|
// Validate slug
|
|
226
224
|
const slugResult = CustomToolSlugSchema.safeParse(slug);
|
|
227
225
|
if (!slugResult.success) {
|
|
@@ -322,16 +320,13 @@ const addOriginalSlugAlias = (params: {
|
|
|
322
320
|
* @returns Maps for O(1) lookup by both final and original slug
|
|
323
321
|
* @throws If duplicate slugs or cross-group collisions
|
|
324
322
|
*/
|
|
325
|
-
export function buildCustomToolsMap(
|
|
326
|
-
tools: CustomTool[],
|
|
327
|
-
toolkits?: CustomToolkit[]
|
|
328
|
-
): CustomToolsMap {
|
|
323
|
+
export function buildCustomToolsMap(tools: LocalTool[], toolkits?: LocalToolkit[]): CustomToolsMap {
|
|
329
324
|
const byFinalSlug = new Map<string, CustomToolsMapEntry>();
|
|
330
325
|
const byOriginalSlug = new Map<string, CustomToolsMapEntry>();
|
|
331
326
|
const byToolkitAndOriginalSlug = new Map<string, CustomToolsMapEntry>();
|
|
332
327
|
const ambiguousOriginalSlugs = new Set<string>();
|
|
333
328
|
|
|
334
|
-
const addEntry = (handle:
|
|
329
|
+
const addEntry = (handle: LocalTool, finalSlug: string, toolkit?: string) => {
|
|
335
330
|
const originalSlug = handle.slug.toUpperCase();
|
|
336
331
|
// Custom tool slugs are matched case-insensitively across local and response maps.
|
|
337
332
|
const finalSlugKey = finalSlug.toUpperCase();
|
|
@@ -426,7 +421,7 @@ function preloadWireProperty(
|
|
|
426
421
|
}
|
|
427
422
|
|
|
428
423
|
export function serializeCustomTools(
|
|
429
|
-
tools:
|
|
424
|
+
tools: LocalTool[],
|
|
430
425
|
options: CustomToolSerializationOptions = {}
|
|
431
426
|
): CustomToolWireDefinition[] {
|
|
432
427
|
const defaultPreload = options.defaultPreload ?? false;
|
|
@@ -449,7 +444,7 @@ export function serializeCustomTools(
|
|
|
449
444
|
* @returns Array of CustomToolkitDefinition for the API payload
|
|
450
445
|
*/
|
|
451
446
|
export function serializeCustomToolkits(
|
|
452
|
-
toolkits:
|
|
447
|
+
toolkits: LocalToolkit[],
|
|
453
448
|
options: CustomToolSerializationOptions = {}
|
|
454
449
|
): CustomToolkitWireDefinition[] {
|
|
455
450
|
const defaultPreload = options.defaultPreload ?? false;
|
|
@@ -480,8 +475,8 @@ export function serializeCustomToolkits(
|
|
|
480
475
|
* @returns Maps for O(1) lookup by both final and original slug
|
|
481
476
|
*/
|
|
482
477
|
export function buildCustomToolsMapFromResponse(
|
|
483
|
-
tools:
|
|
484
|
-
toolkits:
|
|
478
|
+
tools: LocalTool[],
|
|
479
|
+
toolkits: LocalToolkit[] | undefined,
|
|
485
480
|
experimental:
|
|
486
481
|
SessionCreateResponse['experimental'] | SessionRetrieveResponse['experimental'] | undefined
|
|
487
482
|
): CustomToolsMap {
|
|
@@ -490,11 +485,11 @@ export function buildCustomToolsMapFromResponse(
|
|
|
490
485
|
const byToolkitAndOriginalSlug = new Map<string, CustomToolsMapEntry>();
|
|
491
486
|
const ambiguousOriginalSlugs = new Set<string>();
|
|
492
487
|
|
|
493
|
-
type HandleMatch = { handle:
|
|
488
|
+
type HandleMatch = { handle: LocalTool; toolkit?: string };
|
|
494
489
|
const handlesByQualifiedOriginalSlug = new Map<string, HandleMatch>();
|
|
495
490
|
const handlesByOriginalSlug = new Map<string, HandleMatch[]>();
|
|
496
491
|
|
|
497
|
-
const registerHandle = (handle:
|
|
492
|
+
const registerHandle = (handle: LocalTool, toolkit?: string) => {
|
|
498
493
|
const originalSlug = handle.slug.toUpperCase();
|
|
499
494
|
const match = { handle, toolkit };
|
|
500
495
|
handlesByQualifiedOriginalSlug.set(qualifiedOriginalSlugKey(toolkit, originalSlug), match);
|
|
@@ -636,8 +631,8 @@ export function findCustomToolMapEntryByToolkitAndOriginalSlug(
|
|
|
636
631
|
/**
|
|
637
632
|
* Reject legacy attempts to preload custom tools through top-level preload.tools.
|
|
638
633
|
*
|
|
639
|
-
* Custom tool direct exposure is controlled by
|
|
640
|
-
*
|
|
634
|
+
* Custom tool direct exposure is controlled by LocalTool.preload /
|
|
635
|
+
* LocalToolkit.preload so it follows the current SDK-provided custom
|
|
641
636
|
* definitions instead of stale session config.
|
|
642
637
|
*
|
|
643
638
|
* @internal
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview `composio.
|
|
2
|
+
* @fileoverview `composio.customToolkits`: register and manage
|
|
3
3
|
* project-owned custom toolkits.
|
|
4
|
-
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
5
4
|
*
|
|
6
5
|
* @module CustomToolkits
|
|
7
6
|
*/
|
|
@@ -39,14 +38,14 @@ import {
|
|
|
39
38
|
} from '../utils/transformers/customToolkits';
|
|
40
39
|
|
|
41
40
|
const UPSERT_DEPRECATION =
|
|
42
|
-
'[Deprecation] composio.
|
|
41
|
+
'[Deprecation] composio.customToolkits.upsert() is deprecated. ' +
|
|
43
42
|
'Use create() for a new toolkit and update(slug, ...) to change its name, logo or API key field.';
|
|
44
43
|
let _upsertDeprecationWarned = false;
|
|
45
44
|
|
|
46
45
|
/**
|
|
47
|
-
* `composio.
|
|
46
|
+
* `composio.customToolkits` — toolkits your project registers
|
|
48
47
|
* from its own app or MCP server, with their own auth configs and connected
|
|
49
|
-
* accounts.
|
|
48
|
+
* accounts.
|
|
50
49
|
*
|
|
51
50
|
* These live on the Composio platform. They are unrelated to the in-process
|
|
52
51
|
* toolkits built with `experimental_createToolkit()`, which run inside your
|
|
@@ -54,13 +53,13 @@ let _upsertDeprecationWarned = false;
|
|
|
54
53
|
*
|
|
55
54
|
* @example
|
|
56
55
|
* ```typescript
|
|
57
|
-
* const { slug } = await composio.
|
|
56
|
+
* const { slug } = await composio.customToolkits.create({
|
|
58
57
|
* name: 'My Toolkit',
|
|
59
|
-
*
|
|
58
|
+
* mcpUrl: 'https://mcp.example.com/mcp',
|
|
60
59
|
* authSchemes: [{ mode: 'DCR_OAUTH', discoveryUrl: 'https://mcp.example.com/.well-known/oauth-authorization-server' }],
|
|
61
60
|
* userId: 'all',
|
|
62
61
|
* });
|
|
63
|
-
* await composio.
|
|
62
|
+
* await composio.customToolkits.update(slug, { name: 'My Renamed Toolkit' });
|
|
64
63
|
* ```
|
|
65
64
|
*/
|
|
66
65
|
export class CustomToolkits {
|
|
@@ -73,10 +72,9 @@ export class CustomToolkits {
|
|
|
73
72
|
|
|
74
73
|
/**
|
|
75
74
|
* Creates a custom MCP toolkit and returns its generated slug.
|
|
76
|
-
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
77
75
|
*
|
|
78
76
|
* Set `userId` to `'all'` to share the toolkit with every user in the
|
|
79
|
-
* project, or to a user ID to make it private to that user. `
|
|
77
|
+
* project, or to a user ID to make it private to that user. `mcpUrl`,
|
|
80
78
|
* `authSchemes` and `userId` cannot change later: delete and re-create the
|
|
81
79
|
* toolkit instead. For a private toolkit, `connectLink` is where to send
|
|
82
80
|
* that user to connect.
|
|
@@ -87,9 +85,9 @@ export class CustomToolkits {
|
|
|
87
85
|
*
|
|
88
86
|
* @example
|
|
89
87
|
* ```typescript
|
|
90
|
-
* const { slug, connectLink } = await composio.
|
|
88
|
+
* const { slug, connectLink } = await composio.customToolkits.create({
|
|
91
89
|
* name: 'Internal API',
|
|
92
|
-
*
|
|
90
|
+
* mcpUrl: 'https://mcp.internal.example.com/mcp',
|
|
93
91
|
* authSchemes: [
|
|
94
92
|
* { mode: 'API_KEY', headers: { Authorization: 'Bearer {{generic_api_key}}' } },
|
|
95
93
|
* ],
|
|
@@ -118,7 +116,6 @@ export class CustomToolkits {
|
|
|
118
116
|
/**
|
|
119
117
|
* Updates a custom toolkit's name, logo or API key field copy. Omitted
|
|
120
118
|
* fields keep their current value.
|
|
121
|
-
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
122
119
|
*
|
|
123
120
|
* On a project with 2FA enabled, updating a private toolkit requires the
|
|
124
121
|
* `userId` it is private to.
|
|
@@ -130,7 +127,7 @@ export class CustomToolkits {
|
|
|
130
127
|
*
|
|
131
128
|
* @example
|
|
132
129
|
* ```typescript
|
|
133
|
-
* await composio.
|
|
130
|
+
* await composio.customToolkits.update('CUSTOM_INTERNAL_API_K7F2Q', {
|
|
134
131
|
* name: 'Internal API (prod)',
|
|
135
132
|
* userId: 'user_123',
|
|
136
133
|
* });
|
|
@@ -158,9 +155,8 @@ export class CustomToolkits {
|
|
|
158
155
|
/**
|
|
159
156
|
* Creates a custom toolkit, or updates its display metadata (name, API key
|
|
160
157
|
* field copy) when the project already owns a toolkit with this slug.
|
|
161
|
-
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
162
158
|
*
|
|
163
|
-
* `
|
|
159
|
+
* `mcpUrl` and `authSchemes` cannot change on an existing toolkit:
|
|
164
160
|
* re-sending them unchanged is a no-op, and changing them fails with a 409.
|
|
165
161
|
* Delete and re-register the toolkit instead, which revokes its connections.
|
|
166
162
|
*
|
|
@@ -170,11 +166,11 @@ export class CustomToolkits {
|
|
|
170
166
|
*
|
|
171
167
|
* @example
|
|
172
168
|
* ```typescript
|
|
173
|
-
* await composio.
|
|
169
|
+
* await composio.customToolkits.upsert({
|
|
174
170
|
* slug: 'INTERNAL_API',
|
|
175
171
|
* toolkitConfig: {
|
|
176
172
|
* name: 'Internal API',
|
|
177
|
-
*
|
|
173
|
+
* mcpUrl: 'https://mcp.internal.example.com/mcp',
|
|
178
174
|
* authSchemes: [
|
|
179
175
|
* { mode: 'API_KEY', headers: { Authorization: 'Bearer {{generic_api_key}}' } },
|
|
180
176
|
* ],
|
|
@@ -211,7 +207,6 @@ export class CustomToolkits {
|
|
|
211
207
|
/**
|
|
212
208
|
* Re-fetches the tool definitions of a custom toolkit from its remote MCP
|
|
213
209
|
* server. Call it when automatic sync fails or the remote tools change.
|
|
214
|
-
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
215
210
|
*
|
|
216
211
|
* @param {string} slug - The custom toolkit slug (`CUSTOM_...`)
|
|
217
212
|
* @param {CustomToolkitSyncParams} [params] - Optional connected account to fetch the definitions with
|
|
@@ -220,7 +215,7 @@ export class CustomToolkits {
|
|
|
220
215
|
*
|
|
221
216
|
* @example
|
|
222
217
|
* ```typescript
|
|
223
|
-
* const { version, syncedCount } = await composio.
|
|
218
|
+
* const { version, syncedCount } = await composio.customToolkits.sync(
|
|
224
219
|
* 'CUSTOM_MY_TOOLKIT',
|
|
225
220
|
* { connectedAccountId: 'ca_abc123' }
|
|
226
221
|
* );
|
|
@@ -249,7 +244,6 @@ export class CustomToolkits {
|
|
|
249
244
|
* Deletes a custom toolkit owned by the project, with its tools, auth
|
|
250
245
|
* configs and connected accounts. The credentials behind those connected
|
|
251
246
|
* accounts are revoked in background jobs (`revokeJobIds`).
|
|
252
|
-
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
253
247
|
*
|
|
254
248
|
* Composio-managed toolkits cannot be deleted; the API answers 403.
|
|
255
249
|
*
|
|
@@ -258,7 +252,7 @@ export class CustomToolkits {
|
|
|
258
252
|
*
|
|
259
253
|
* @example
|
|
260
254
|
* ```typescript
|
|
261
|
-
* const result = await composio.
|
|
255
|
+
* const result = await composio.customToolkits.delete('CUSTOM_MY_TOOLKIT');
|
|
262
256
|
* console.log(result.connectedAccountsDeleted);
|
|
263
257
|
* ```
|
|
264
258
|
*/
|
|
@@ -144,13 +144,8 @@ export class Experimental {
|
|
|
144
144
|
usage: Usage;
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* await composio.experimental.customToolkits.sync('CUSTOM_MY_TOOLKIT');
|
|
153
|
-
* ```
|
|
147
|
+
* Same object as `composio.customToolkits`.
|
|
148
|
+
* @deprecated Use `composio.customToolkits` instead. Custom toolkits are no longer experimental; this alias is kept for backwards compatibility.
|
|
154
149
|
*/
|
|
155
150
|
customToolkits: CustomToolkits;
|
|
156
151
|
|
package/src/models/Files.node.ts
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import ComposioClient from '@composio/client';
|
|
9
9
|
import { FileDownloadData, FileUploadData } from '../types/files.types';
|
|
10
|
+
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
10
11
|
import { downloadFileFromS3, getFileDataAfterUploadingToS3 } from '../utils/fileUtils.node';
|
|
12
|
+
import { withCancellation } from '../utils/cancellation';
|
|
11
13
|
import { telemetry } from '../telemetry/Telemetry';
|
|
12
14
|
|
|
13
15
|
export class Files {
|
|
@@ -36,58 +38,87 @@ export class Files {
|
|
|
36
38
|
* @param {File | string} params.file - The path to the file to upload, a URL of the file, or a File object.
|
|
37
39
|
* @param {string} params.toolSlug - The slug of the tool that is uploading the file.
|
|
38
40
|
* @param {string} params.toolkitSlug - The slug of the toolkit that is uploading the file.
|
|
41
|
+
* @param {ComposioRequestOptions} [requestOptions] - Optional request options. `signal` cancels
|
|
42
|
+
* the file read from a URL, the presigned-URL request, and the S3 transfer; the call then
|
|
43
|
+
* rejects with {@link ComposioRequestCancelledError}.
|
|
39
44
|
* @returns {Promise<FileUploadData>} The uploaded file data.
|
|
40
45
|
*
|
|
41
46
|
* @example
|
|
42
47
|
*
|
|
43
|
-
* const fileData = await composio.files.upload(
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
+
* const fileData = await composio.files.upload(
|
|
49
|
+
* {
|
|
50
|
+
* file: 'path/to/file.pdf',
|
|
51
|
+
* toolSlug: 'google_drive_upload',
|
|
52
|
+
* toolkitSlug: 'google_drive',
|
|
53
|
+
* },
|
|
54
|
+
* { signal: AbortSignal.timeout(30_000) }
|
|
55
|
+
* );
|
|
48
56
|
* */
|
|
49
|
-
async upload(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
async upload(
|
|
58
|
+
{
|
|
59
|
+
file,
|
|
60
|
+
toolSlug,
|
|
61
|
+
toolkitSlug,
|
|
62
|
+
}: {
|
|
63
|
+
file: File | string;
|
|
64
|
+
toolSlug: string;
|
|
65
|
+
toolkitSlug: string;
|
|
66
|
+
},
|
|
67
|
+
requestOptions?: ComposioRequestOptions
|
|
68
|
+
): Promise<FileUploadData> {
|
|
69
|
+
const signal = requestOptions?.signal;
|
|
58
70
|
// Note: manual `composio.files.upload()` intentionally skips the
|
|
59
71
|
// `fileUploadDirs` allowlist. The allowlist only gates *automatic* upload
|
|
60
72
|
// during tool execution (see FileToolModifier).
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
return withCancellation(
|
|
74
|
+
() =>
|
|
75
|
+
getFileDataAfterUploadingToS3(file, {
|
|
76
|
+
toolSlug,
|
|
77
|
+
toolkitSlug,
|
|
78
|
+
client: this.client,
|
|
79
|
+
sensitiveFileUploadProtection: this.fileOptions.sensitiveFileUploadProtection,
|
|
80
|
+
fileUploadPathDenySegments: this.fileOptions.fileUploadPathDenySegments,
|
|
81
|
+
signal,
|
|
82
|
+
}),
|
|
83
|
+
signal
|
|
84
|
+
);
|
|
69
85
|
}
|
|
70
86
|
|
|
71
87
|
/**
|
|
72
88
|
* Download a file from S3 and return the file data.
|
|
73
|
-
*
|
|
74
|
-
* @
|
|
89
|
+
*
|
|
90
|
+
* @param params - The download parameters.
|
|
91
|
+
* @param {string} params.s3Url - The S3 URL of the file to download.
|
|
92
|
+
* @param {string} params.toolSlug - The slug of the tool the file belongs to, used as the file name prefix.
|
|
93
|
+
* @param {string} params.mimeType - The MIME type of the file, used to pick the file extension.
|
|
94
|
+
* @param {ComposioRequestOptions} [requestOptions] - Optional request options. `signal` cancels
|
|
95
|
+
* the download before the file is written; the call then rejects with
|
|
96
|
+
* {@link ComposioRequestCancelledError}.
|
|
97
|
+
* @returns {Promise<FileDownloadData>} The downloaded file data.
|
|
75
98
|
*/
|
|
76
|
-
async download(
|
|
77
|
-
|
|
78
|
-
s3Url,
|
|
79
|
-
mimeType,
|
|
80
|
-
}: {
|
|
81
|
-
s3Url: string;
|
|
82
|
-
toolSlug: string;
|
|
83
|
-
mimeType: string;
|
|
84
|
-
}): Promise<FileDownloadData> {
|
|
85
|
-
const fileDownloadData = await downloadFileFromS3({
|
|
99
|
+
async download(
|
|
100
|
+
{
|
|
86
101
|
toolSlug,
|
|
87
102
|
s3Url,
|
|
88
103
|
mimeType,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
}: {
|
|
105
|
+
s3Url: string;
|
|
106
|
+
toolSlug: string;
|
|
107
|
+
mimeType: string;
|
|
108
|
+
},
|
|
109
|
+
requestOptions?: ComposioRequestOptions
|
|
110
|
+
): Promise<FileDownloadData> {
|
|
111
|
+
const signal = requestOptions?.signal;
|
|
112
|
+
return withCancellation(
|
|
113
|
+
() =>
|
|
114
|
+
downloadFileFromS3({
|
|
115
|
+
toolSlug,
|
|
116
|
+
s3Url,
|
|
117
|
+
mimeType,
|
|
118
|
+
fileDownloadDir: this.fileOptions.fileDownloadDir,
|
|
119
|
+
signal,
|
|
120
|
+
}),
|
|
121
|
+
signal
|
|
122
|
+
);
|
|
92
123
|
}
|
|
93
124
|
}
|
package/src/models/RemoteFile.ts
CHANGED
|
@@ -175,7 +175,8 @@ export class RemoteFile {
|
|
|
175
175
|
* Downloads and saves the file to the local filesystem.
|
|
176
176
|
* Requires a Node.js runtime with file system support (not available in Cloudflare Workers/Edge).
|
|
177
177
|
*
|
|
178
|
-
* @param path - Local path to save the file.
|
|
178
|
+
* @param path - Local path to save the file. An explicit path does not require a home directory.
|
|
179
|
+
* If omitted, saves to the Composio temp directory using the filename from the mount path.
|
|
179
180
|
* An existing default destination gets a copy number before its extension.
|
|
180
181
|
* @returns The absolute path where the file was saved
|
|
181
182
|
* @throws Error if file system is not supported or the save fails
|
|
@@ -189,30 +190,35 @@ export class RemoteFile {
|
|
|
189
190
|
);
|
|
190
191
|
}
|
|
191
192
|
|
|
193
|
+
// An explicit `path` is the caller's own, so it needs no home directory.
|
|
194
|
+
if (path != null) {
|
|
195
|
+
const content = await this.buffer();
|
|
196
|
+
const dir = getParentDir(path);
|
|
197
|
+
if (dir && !platform.existsSync(dir)) {
|
|
198
|
+
platform.mkdirSync(dir);
|
|
199
|
+
}
|
|
200
|
+
platform.writeFileSync(path, content);
|
|
201
|
+
return path;
|
|
202
|
+
}
|
|
203
|
+
|
|
192
204
|
const homeDir = platform.homedir();
|
|
193
205
|
if (!homeDir) {
|
|
194
206
|
throw new Error('Cannot determine save location: home directory is not available');
|
|
195
207
|
}
|
|
196
208
|
|
|
197
|
-
//
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
// `
|
|
201
|
-
//
|
|
209
|
+
// The default path is built from `mountRelativePath`, a server-controlled
|
|
210
|
+
// response field, so it is validated first (SEC-316, mirroring the Python
|
|
211
|
+
// SDK): a value such as `""`, `"."` or `"foo/.."` would otherwise make
|
|
212
|
+
// `savePath` its own directory or the parent, and fail with a raw `EISDIR`
|
|
213
|
+
// only after `mkdirSync` had run.
|
|
202
214
|
const defaultDir = platform.joinPath(homeDir, COMPOSIO_DIR, TEMP_FILES_DIRECTORY_NAME);
|
|
203
|
-
const defaultName =
|
|
204
|
-
const savePath =
|
|
215
|
+
const defaultName = safeBasename(this.mountRelativePath, 'mount path');
|
|
216
|
+
const savePath = platform.joinPath(defaultDir, defaultName);
|
|
205
217
|
|
|
206
218
|
const content = await this.buffer();
|
|
207
219
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
platform.mkdirSync(dir);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (path != null) {
|
|
214
|
-
platform.writeFileSync(savePath, content);
|
|
215
|
-
return savePath;
|
|
220
|
+
if (!platform.existsSync(defaultDir)) {
|
|
221
|
+
platform.mkdirSync(defaultDir);
|
|
216
222
|
}
|
|
217
223
|
|
|
218
224
|
// Server names can equal a digest-tagged name literally. Reserve a new
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
ToolRouterSessionExecuteResponseSchema,
|
|
18
18
|
} from '../types/toolRouter.types';
|
|
19
19
|
import { ValidationError } from '../errors';
|
|
20
|
+
import { handleToolExecutionError } from '../errors/ToolErrors';
|
|
20
21
|
import { transformProxyParams } from './proxyParamsTransform';
|
|
21
22
|
import {
|
|
22
23
|
assertUnambiguousCustomToolSlug,
|
|
@@ -28,7 +29,6 @@ import {
|
|
|
28
29
|
transformProxyExecuteResponse,
|
|
29
30
|
} from '../utils/transformers/toolRouterResponseTransform';
|
|
30
31
|
import type { SessionExecuteParams } from '@composio/client/resources/tool-router/session';
|
|
31
|
-
import { inlineCustomToolsExperimental } from './inlineCustomToolsPayload';
|
|
32
32
|
import { withCancellation } from '../utils/cancellation';
|
|
33
33
|
import { withoutRetries } from '../utils/retries';
|
|
34
34
|
|
|
@@ -97,11 +97,8 @@ export class SessionContextImpl implements SessionContext {
|
|
|
97
97
|
tool_slug: toolSlug,
|
|
98
98
|
arguments: arguments_,
|
|
99
99
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
>(this.inlineCustomToolsPayload);
|
|
103
|
-
if (experimental) {
|
|
104
|
-
executeParams.experimental = experimental;
|
|
100
|
+
if (this.inlineCustomToolsPayload) {
|
|
101
|
+
executeParams.experimental = this.inlineCustomToolsPayload;
|
|
105
102
|
}
|
|
106
103
|
|
|
107
104
|
const response = await withCancellation(
|
|
@@ -112,7 +109,9 @@ export class SessionContextImpl implements SessionContext {
|
|
|
112
109
|
withoutRetries(requestOptions)
|
|
113
110
|
),
|
|
114
111
|
requestOptions?.signal
|
|
115
|
-
)
|
|
112
|
+
).catch((error: unknown) => {
|
|
113
|
+
throw handleToolExecutionError(toolSlug, error as Error);
|
|
114
|
+
});
|
|
116
115
|
return ToolRouterSessionExecuteResponseSchema.parse(
|
|
117
116
|
transformExecuteResponse(response, toolSlug)
|
|
118
117
|
);
|