@composio/core 0.28.0 → 0.29.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 +2 -0
- package/dist/{CustomTool-BYHB7sPs.mjs → CustomTool-Bd1KdWvo.mjs} +9 -8
- package/dist/{CustomTool-DyypijT6.d.mts → CustomTool-CMW-d2ZN.d.mts} +9 -8
- package/dist/{cancellation-ZoRh6EJQ.mjs → cancellation-BoJjs34Y.mjs} +1 -1
- package/dist/{composio-CwHMpKXb.d.mts → composio-D5UV5HXN.d.mts} +107 -86
- package/dist/{customTool.types-DoItUHkO.d.mts → customTool.types-B9fs34dv.d.mts} +94 -50
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +86 -3
- package/dist/docs/reference/sdk-reference/typescript/experimental.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-BK6Xc7Ia.mjs} +65 -1
- package/dist/experimental/index.d.mts +3 -3
- package/dist/experimental/index.mjs +1 -1
- package/dist/index.d.mts +46 -16
- package/dist/index.mjs +122 -57
- package/dist/{types-DWZWePfZ.d.mts → types-CaP2SytR.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/package.json +2 -2
- package/src/errors/ToolErrors.ts +73 -1
- 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 +38 -34
- package/src/models/CustomTool.ts +25 -30
- package/src/models/CustomToolkits.ts +5 -5
- package/src/models/ToolRouter.ts +24 -14
- package/src/models/ToolRouterSession.ts +22 -8
- package/src/models/Tools.ts +57 -11
- package/src/types/customTool.types.ts +49 -28
- package/src/types/customToolkits.types.ts +3 -3
- package/src/types/toolRouter.types.ts +39 -17
- package/src/utils/rateLimit.ts +25 -0
- package/src/utils/transformers/customToolkits.ts +2 -2
|
@@ -19,10 +19,15 @@ export {
|
|
|
19
19
|
createCustomToolkit as experimental_createToolkit,
|
|
20
20
|
} from '../models/CustomTool';
|
|
21
21
|
export type {
|
|
22
|
+
LocalTool,
|
|
23
|
+
CreateLocalToolParams,
|
|
24
|
+
LocalToolExecuteFn,
|
|
25
|
+
SessionContext,
|
|
26
|
+
LocalToolkit,
|
|
27
|
+
CreateLocalToolkitParams,
|
|
22
28
|
CustomTool,
|
|
23
29
|
CreateCustomToolParams,
|
|
24
30
|
CustomToolExecuteFn,
|
|
25
|
-
SessionContext,
|
|
26
31
|
CustomToolkit,
|
|
27
32
|
CreateCustomToolkitParams,
|
|
28
33
|
} from '../types/customTool.types';
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
ToolRouterProxyExecute,
|
|
22
22
|
ToolRouterHook,
|
|
23
23
|
} from '../types/toolRouter.types';
|
|
24
|
+
import type { LocalTool, LocalToolkit } from '../types/customTool.types';
|
|
24
25
|
import { ValidationError } from '../errors';
|
|
25
26
|
import { z } from 'zod';
|
|
26
27
|
import type { TypeOf } from 'zod/v3';
|
|
@@ -145,6 +146,45 @@ export const resolveToolRouterSandboxConfig = (
|
|
|
145
146
|
return config.sandbox ?? config.workbench;
|
|
146
147
|
};
|
|
147
148
|
|
|
149
|
+
/** Local tools options, accepted under their current names and the deprecated `custom*` aliases. */
|
|
150
|
+
export type LocalToolsOptions = {
|
|
151
|
+
localTools?: LocalTool[];
|
|
152
|
+
localToolkits?: LocalToolkit[];
|
|
153
|
+
/** @deprecated Use `localTools` instead. */
|
|
154
|
+
customTools?: LocalTool[];
|
|
155
|
+
/** @deprecated Use `localToolkits` instead. */
|
|
156
|
+
customToolkits?: LocalToolkit[];
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Resolves local tools and toolkits from `localTools` / `localToolkits` or
|
|
161
|
+
* their deprecated `customTools` / `customToolkits` aliases. `source` picks
|
|
162
|
+
* the option path named in the error: `experimental.*` on create, bare on use.
|
|
163
|
+
*/
|
|
164
|
+
export const resolveLocalToolsOptions = (
|
|
165
|
+
options: LocalToolsOptions | undefined,
|
|
166
|
+
source: 'create' | 'use'
|
|
167
|
+
): { tools?: LocalTool[]; toolkits?: LocalToolkit[] } => {
|
|
168
|
+
if (options?.localTools !== undefined && options.customTools !== undefined) {
|
|
169
|
+
throw new ValidationError(
|
|
170
|
+
source === 'create'
|
|
171
|
+
? 'Pass either experimental.localTools or experimental.customTools, not both. experimental.customTools is a deprecated alias for experimental.localTools.'
|
|
172
|
+
: 'Pass either localTools or customTools, not both. customTools is a deprecated alias for localTools.'
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
if (options?.localToolkits !== undefined && options.customToolkits !== undefined) {
|
|
176
|
+
throw new ValidationError(
|
|
177
|
+
source === 'create'
|
|
178
|
+
? 'Pass either experimental.localToolkits or experimental.customToolkits, not both. experimental.customToolkits is a deprecated alias for experimental.localToolkits.'
|
|
179
|
+
: 'Pass either localToolkits or customToolkits, not both. customToolkits is a deprecated alias for localToolkits.'
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
tools: options?.localTools ?? options?.customTools,
|
|
184
|
+
toolkits: options?.localToolkits ?? options?.customToolkits,
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
|
|
148
188
|
export const transformToolRouterSandboxParams = (
|
|
149
189
|
params?: ParsedCreateSessionConfig['sandbox'] | ParsedCreateSessionConfig['workbench']
|
|
150
190
|
): NonNullable<SessionCreateParams['workbench']> | undefined => {
|
|
@@ -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,12 @@ 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, up to the timeout, and polls again. The client's retries can carry
|
|
68
|
+
* the wait past the timeout, because they aren't bound by it.
|
|
60
69
|
*
|
|
61
70
|
* @param {number} [timeout=60000] - Maximum time to wait in milliseconds before timing out (default: 60 seconds)
|
|
62
71
|
* @returns {Promise<ConnectedAccountRetrieveResponse>} The final connected account response when successful
|
|
@@ -104,49 +113,44 @@ export function createConnectionRequest(
|
|
|
104
113
|
}
|
|
105
114
|
};
|
|
106
115
|
|
|
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
|
-
}
|
|
116
|
+
const deadline = Date.now() + timeout;
|
|
117
|
+
let pollDelay = INITIAL_POLL_DELAY_MS;
|
|
128
118
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
while (Date.now() - start < timeout) {
|
|
119
|
+
while (true) {
|
|
120
|
+
let delay = pollDelay;
|
|
133
121
|
try {
|
|
134
122
|
const response = await client.connectedAccounts.retrieve(request.id);
|
|
135
|
-
|
|
136
123
|
request.status = response.status;
|
|
137
124
|
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
138
125
|
return transformConnectedAccountResponse(response);
|
|
139
126
|
}
|
|
140
|
-
|
|
141
127
|
failIfTerminal(response);
|
|
142
|
-
|
|
143
|
-
await new Promise(resolve => setTimeout(resolve, pollInterval));
|
|
144
128
|
} catch (error) {
|
|
145
|
-
|
|
129
|
+
if (error instanceof ComposioClient.NotFoundError) {
|
|
130
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
131
|
+
`Connected account with id ${request.id} not found`,
|
|
132
|
+
{
|
|
133
|
+
meta: {
|
|
134
|
+
connectedAccountId: request.id,
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (!isRateLimitResponse(error)) {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
delay = Math.max(delay, (getRetryAfterSeconds(error) ?? 0) * 1000);
|
|
146
143
|
}
|
|
147
|
-
}
|
|
148
144
|
|
|
149
|
-
|
|
145
|
+
const remaining = deadline - Date.now();
|
|
146
|
+
// Written so a NaN timeout times out rather than polling forever.
|
|
147
|
+
if (!(remaining > 0)) {
|
|
148
|
+
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${request.id}`);
|
|
149
|
+
}
|
|
150
|
+
// This delay stops at the deadline, so the last poll happens as the time runs out.
|
|
151
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(delay, remaining)));
|
|
152
|
+
pollDelay = Math.min(pollDelay * POLL_DELAY_GROWTH, MAX_POLL_DELAY_MS);
|
|
153
|
+
}
|
|
150
154
|
}
|
|
151
155
|
|
|
152
156
|
return request;
|
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
|
|
@@ -56,7 +56,7 @@ let _upsertDeprecationWarned = false;
|
|
|
56
56
|
* ```typescript
|
|
57
57
|
* const { slug } = await composio.experimental.customToolkits.create({
|
|
58
58
|
* name: 'My Toolkit',
|
|
59
|
-
*
|
|
59
|
+
* mcpUrl: 'https://mcp.example.com/mcp',
|
|
60
60
|
* authSchemes: [{ mode: 'DCR_OAUTH', discoveryUrl: 'https://mcp.example.com/.well-known/oauth-authorization-server' }],
|
|
61
61
|
* userId: 'all',
|
|
62
62
|
* });
|
|
@@ -76,7 +76,7 @@ export class CustomToolkits {
|
|
|
76
76
|
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
77
77
|
*
|
|
78
78
|
* 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. `
|
|
79
|
+
* project, or to a user ID to make it private to that user. `mcpUrl`,
|
|
80
80
|
* `authSchemes` and `userId` cannot change later: delete and re-create the
|
|
81
81
|
* toolkit instead. For a private toolkit, `connectLink` is where to send
|
|
82
82
|
* that user to connect.
|
|
@@ -89,7 +89,7 @@ export class CustomToolkits {
|
|
|
89
89
|
* ```typescript
|
|
90
90
|
* const { slug, connectLink } = await composio.experimental.customToolkits.create({
|
|
91
91
|
* name: 'Internal API',
|
|
92
|
-
*
|
|
92
|
+
* mcpUrl: 'https://mcp.internal.example.com/mcp',
|
|
93
93
|
* authSchemes: [
|
|
94
94
|
* { mode: 'API_KEY', headers: { Authorization: 'Bearer {{generic_api_key}}' } },
|
|
95
95
|
* ],
|
|
@@ -160,7 +160,7 @@ export class CustomToolkits {
|
|
|
160
160
|
* field copy) when the project already owns a toolkit with this slug.
|
|
161
161
|
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
162
162
|
*
|
|
163
|
-
* `
|
|
163
|
+
* `mcpUrl` and `authSchemes` cannot change on an existing toolkit:
|
|
164
164
|
* re-sending them unchanged is a no-op, and changing them fails with a 409.
|
|
165
165
|
* Delete and re-register the toolkit instead, which revokes its connections.
|
|
166
166
|
*
|
|
@@ -174,7 +174,7 @@ export class CustomToolkits {
|
|
|
174
174
|
* slug: 'INTERNAL_API',
|
|
175
175
|
* toolkitConfig: {
|
|
176
176
|
* name: 'Internal API',
|
|
177
|
-
*
|
|
177
|
+
* mcpUrl: 'https://mcp.internal.example.com/mcp',
|
|
178
178
|
* authSchemes: [
|
|
179
179
|
* { mode: 'API_KEY', headers: { Authorization: 'Bearer {{generic_api_key}}' } },
|
|
180
180
|
* ],
|
package/src/models/ToolRouter.ts
CHANGED
|
@@ -39,8 +39,8 @@ import {
|
|
|
39
39
|
SessionRetrieveResponse,
|
|
40
40
|
} from '@composio/client/resources/tool-router/session';
|
|
41
41
|
import type {
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
LocalTool,
|
|
43
|
+
LocalToolkit,
|
|
44
44
|
InlineCustomToolsWirePayload,
|
|
45
45
|
} from '../types/customTool.types';
|
|
46
46
|
import {
|
|
@@ -54,6 +54,8 @@ import {
|
|
|
54
54
|
transformToolRouterProxyExecuteParams,
|
|
55
55
|
transformToolRouterHooksParams,
|
|
56
56
|
resolveToolRouterSandboxConfig,
|
|
57
|
+
resolveLocalToolsOptions,
|
|
58
|
+
type LocalToolsOptions,
|
|
57
59
|
} from '../lib/toolRouterParams';
|
|
58
60
|
import { PRELOAD_TOOLS_ALL } from '../lib/toolRouterConstants';
|
|
59
61
|
import { buildMCPServerConfig } from '../lib/toolRouterMcp';
|
|
@@ -91,8 +93,8 @@ function preloadsAllCustomTools(preload?: { tools?: readonly string[] | string }
|
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
function prepareInlineCustomTools(options: {
|
|
94
|
-
customTools?:
|
|
95
|
-
customToolkits?:
|
|
96
|
+
customTools?: LocalTool[];
|
|
97
|
+
customToolkits?: LocalToolkit[];
|
|
96
98
|
defaultPreload?: boolean;
|
|
97
99
|
preloadTools?: readonly string[] | typeof PRELOAD_TOOLS_ALL;
|
|
98
100
|
}): InlineCustomToolsWirePayload | undefined {
|
|
@@ -181,6 +183,7 @@ export class ToolRouter<
|
|
|
181
183
|
* @param config {ToolRouterCreateSessionConfig} The config for the tool router session
|
|
182
184
|
* @returns {Promise<Session<TToolCollection, TTool, TProvider>>} The tool router session
|
|
183
185
|
* @throws {ComposioMCPDestinationError} When `mcp: true` is passed and the MCP URL is not on the API origin
|
|
186
|
+
* @throws {ValidationError} When a local tools option and its deprecated `custom*` alias are both passed
|
|
184
187
|
*
|
|
185
188
|
* @example
|
|
186
189
|
* ```typescript
|
|
@@ -192,8 +195,8 @@ export class ToolRouter<
|
|
|
192
195
|
* toolkits: ['gmail'],
|
|
193
196
|
* manageConnections: true,
|
|
194
197
|
* experimental: {
|
|
195
|
-
*
|
|
196
|
-
*
|
|
198
|
+
* localTools: [myLocalTool],
|
|
199
|
+
* localToolkits: [myLocalToolkit],
|
|
197
200
|
* },
|
|
198
201
|
* });
|
|
199
202
|
*
|
|
@@ -225,9 +228,10 @@ export class ToolRouter<
|
|
|
225
228
|
const routerConfig = parseSessionConfigInput(ToolRouterCreateSessionConfigSchema, config ?? {});
|
|
226
229
|
const isDirectToolsPreset = routerConfig.sessionPreset === SessionPreset.DIRECT_TOOLS;
|
|
227
230
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
+
const { tools: customTools, toolkits: customToolkits } = resolveLocalToolsOptions(
|
|
232
|
+
routerConfig.experimental,
|
|
233
|
+
'create'
|
|
234
|
+
);
|
|
231
235
|
const defaultCustomPreload = preloadsAllCustomTools(routerConfig.preload);
|
|
232
236
|
const inlineCustomToolsPayload = prepareInlineCustomTools({
|
|
233
237
|
customTools,
|
|
@@ -351,8 +355,12 @@ export class ToolRouter<
|
|
|
351
355
|
* origins is logged, so native tools keep working.
|
|
352
356
|
*
|
|
353
357
|
* @param id {string} The id of the session to use
|
|
358
|
+
* @param options {object} Optional session reuse options
|
|
359
|
+
* @param options.localTools Local tools to attach to the session; `customTools` is a deprecated alias.
|
|
360
|
+
* @param options.localToolkits Toolkits of local tools to attach; `customToolkits` is a deprecated alias.
|
|
354
361
|
* @returns {Promise<Session<TToolCollection, TTool, TProvider>>} The tool router session
|
|
355
362
|
* @throws {ComposioMCPDestinationError} When `mcp: true` is passed and the MCP URL is not on the API origin
|
|
363
|
+
* @throws {ValidationError} When a local tools option and its deprecated `custom*` alias are both passed
|
|
356
364
|
*
|
|
357
365
|
* @example
|
|
358
366
|
* ```typescript
|
|
@@ -370,21 +378,23 @@ export class ToolRouter<
|
|
|
370
378
|
// in the returned type. See https://docs.composio.dev/docs/sessions-via-mcp
|
|
371
379
|
async use(
|
|
372
380
|
id: string,
|
|
373
|
-
options:
|
|
381
|
+
options: LocalToolsOptions & { mcp: true },
|
|
374
382
|
requestOptions?: ComposioRequestOptions
|
|
375
383
|
): Promise<Session<TToolCollection, TTool, TProvider>>;
|
|
376
384
|
async use(
|
|
377
385
|
id: string,
|
|
378
|
-
options?:
|
|
386
|
+
options?: LocalToolsOptions & { mcp?: boolean },
|
|
379
387
|
requestOptions?: ComposioRequestOptions
|
|
380
388
|
): Promise<SessionWithoutMcp<TToolCollection, TTool, TProvider>>;
|
|
381
389
|
async use(
|
|
382
390
|
id: string,
|
|
383
|
-
options?:
|
|
391
|
+
options?: LocalToolsOptions & { mcp?: boolean },
|
|
384
392
|
requestOptions?: ComposioRequestOptions
|
|
385
393
|
): Promise<Session<TToolCollection, TTool, TProvider>> {
|
|
386
|
-
const customTools =
|
|
387
|
-
|
|
394
|
+
const { tools: customTools, toolkits: customToolkits } = resolveLocalToolsOptions(
|
|
395
|
+
options,
|
|
396
|
+
'use'
|
|
397
|
+
);
|
|
388
398
|
const hasCustoms = !!(customTools?.length || customToolkits?.length);
|
|
389
399
|
|
|
390
400
|
let session: SessionRetrieveResponse | SessionAttachResponse;
|
|
@@ -67,8 +67,8 @@ import type {
|
|
|
67
67
|
CustomToolsMap,
|
|
68
68
|
CustomToolsMapEntry,
|
|
69
69
|
SessionContext,
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
RegisteredLocalTool,
|
|
71
|
+
RegisteredLocalToolkit,
|
|
72
72
|
} from '../types/customTool.types';
|
|
73
73
|
import { ToolSchema, type Tool, type ToolExecuteResponse } from '../types/tool.types';
|
|
74
74
|
import type { SessionProxyExecuteParams } from '../types/toolRouter.types';
|
|
@@ -384,13 +384,13 @@ export class ToolRouterSession<
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
/**
|
|
387
|
-
* List all
|
|
387
|
+
* List all local tools registered in this session.
|
|
388
388
|
* Returns tools with their final slugs, schemas, and resolved toolkit.
|
|
389
389
|
*
|
|
390
390
|
* @param options.toolkit - Filter by toolkit slug (e.g. 'gmail', 'DEV_TOOLS')
|
|
391
|
-
* @returns Array of registered
|
|
391
|
+
* @returns Array of registered local tools
|
|
392
392
|
*/
|
|
393
|
-
|
|
393
|
+
localTools(options?: { toolkit?: string }): RegisteredLocalTool[] {
|
|
394
394
|
if (!this.customToolsMap) return [];
|
|
395
395
|
|
|
396
396
|
const entries = Array.from(this.customToolsMap.byFinalSlug.values());
|
|
@@ -409,12 +409,19 @@ export class ToolRouterSession<
|
|
|
409
409
|
}
|
|
410
410
|
|
|
411
411
|
/**
|
|
412
|
-
*
|
|
412
|
+
* @deprecated Use `localTools()` instead.
|
|
413
|
+
*/
|
|
414
|
+
customTools(options?: { toolkit?: string }): RegisteredLocalTool[] {
|
|
415
|
+
return this.localTools(options);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* List all toolkits of local tools registered in this session.
|
|
413
420
|
* Returns toolkits with their tools showing final slugs.
|
|
414
421
|
*
|
|
415
|
-
* @returns Array of registered
|
|
422
|
+
* @returns Array of registered toolkits of local tools
|
|
416
423
|
*/
|
|
417
|
-
|
|
424
|
+
localToolkits(): RegisteredLocalToolkit[] {
|
|
418
425
|
const toolkits = this.customToolsMap?.toolkits;
|
|
419
426
|
if (!toolkits?.length) return [];
|
|
420
427
|
|
|
@@ -444,6 +451,13 @@ export class ToolRouterSession<
|
|
|
444
451
|
}));
|
|
445
452
|
}
|
|
446
453
|
|
|
454
|
+
/**
|
|
455
|
+
* @deprecated Use `localToolkits()` instead.
|
|
456
|
+
*/
|
|
457
|
+
customToolkits(): RegisteredLocalToolkit[] {
|
|
458
|
+
return this.localToolkits();
|
|
459
|
+
}
|
|
460
|
+
|
|
447
461
|
/**
|
|
448
462
|
* Initiate an authorization flow for a toolkit.
|
|
449
463
|
* Returns a ConnectionRequest with a redirect URL for the user.
|