@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
package/src/models/Tools.ts
CHANGED
|
@@ -43,6 +43,7 @@ import { ExecuteToolFn, GlobalExecuteToolFn } from '../types/provider.types';
|
|
|
43
43
|
import {
|
|
44
44
|
ComposioInvalidModifierError,
|
|
45
45
|
ComposioToolFetchError,
|
|
46
|
+
ComposioToolFetchRateLimitError,
|
|
46
47
|
ComposioToolNotFoundError,
|
|
47
48
|
ComposioProviderNotDefinedError,
|
|
48
49
|
ComposioToolVersionRequiredError,
|
|
@@ -68,6 +69,7 @@ import {
|
|
|
68
69
|
transformExecuteResponse,
|
|
69
70
|
} from '../utils/transformers/toolRouterResponseTransform';
|
|
70
71
|
import { ComposioRequestCancelledError } from '../errors/SDKErrors';
|
|
72
|
+
import { isRateLimitResponse } from '../utils/rateLimit';
|
|
71
73
|
|
|
72
74
|
const TOOL_ROUTER_SESSION_TOOLS_PAGE_LIMIT = 500;
|
|
73
75
|
|
|
@@ -98,6 +100,13 @@ function normalizeRawToolParameters(
|
|
|
98
100
|
return params;
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
/** How long `execute()` reuses a schema fetched for `latest`, which can change at any release. */
|
|
104
|
+
const LATEST_TOOL_SCHEMA_TTL_MS = 5 * 60 * 1000;
|
|
105
|
+
/** How long `execute()` reuses a schema fetched for a pinned toolkit version. */
|
|
106
|
+
const PINNED_TOOL_SCHEMA_TTL_MS = 60 * 60 * 1000;
|
|
107
|
+
/** Most schemas `execute()` keeps per `Tools` instance; the oldest is dropped first. */
|
|
108
|
+
const MAX_CACHED_TOOL_SCHEMAS = 500;
|
|
109
|
+
|
|
101
110
|
/**
|
|
102
111
|
* This class is used to manage tools in the Composio SDK.
|
|
103
112
|
* It provides methods to list, get, and execute tools.
|
|
@@ -123,6 +132,12 @@ export class Tools<
|
|
|
123
132
|
* Scoped per-instance so a fresh `Composio` starts with a clean slate.
|
|
124
133
|
*/
|
|
125
134
|
private readonly warnedAutoUploadDisabledForTool = new Set<string>();
|
|
135
|
+
/**
|
|
136
|
+
* Schemas `execute()` already fetched, so repeated executions don't each spend a request.
|
|
137
|
+
* Holds what `getRawComposioToolBySlug` returned with no `modifySchema`, so a caller's schema
|
|
138
|
+
* modifiers never reach it.
|
|
139
|
+
*/
|
|
140
|
+
private readonly executeToolSchemas = new Map<string, { tool: Tool; expiresAt: number }>();
|
|
126
141
|
|
|
127
142
|
constructor(client: ComposioClient, config?: ComposioConfig<TProvider>) {
|
|
128
143
|
if (!client) {
|
|
@@ -409,9 +424,9 @@ export class Tools<
|
|
|
409
424
|
* Lists Composio API tools available to the SDK.
|
|
410
425
|
*
|
|
411
426
|
* This method fetches remote Composio tools from the API in raw format. The response can be
|
|
412
|
-
* filtered and modified as needed.
|
|
427
|
+
* filtered and modified as needed. Experimental local tools are session-scoped; attach
|
|
413
428
|
* them when creating or reusing a Tool Router session, then use `session.tools()`,
|
|
414
|
-
* `session.
|
|
429
|
+
* `session.localTools()`, or `session.execute()`.
|
|
415
430
|
* It provides access to the underlying tool data without provider-specific wrapping.
|
|
416
431
|
*
|
|
417
432
|
* @param {ToolListParams} query - Query parameters to filter the tools (required)
|
|
@@ -628,8 +643,8 @@ export class Tools<
|
|
|
628
643
|
* This method fetches a single tool in raw format without provider-specific wrapping,
|
|
629
644
|
* providing direct access to the tool's schema and metadata. Tool versions are controlled
|
|
630
645
|
* at the Composio SDK initialization level through the `toolkitVersions` configuration.
|
|
631
|
-
*
|
|
632
|
-
* Tool Router session, then use `session.tools()`, `session.
|
|
646
|
+
* Experimental local tools are session-scoped; attach them when creating or reusing a
|
|
647
|
+
* Tool Router session, then use `session.tools()`, `session.localTools()`, or
|
|
633
648
|
* `session.execute()`.
|
|
634
649
|
*
|
|
635
650
|
* @param {string} slug - The unique identifier of the tool (e.g., 'GITHUB_GET_REPOS')
|
|
@@ -692,6 +707,13 @@ export class Tools<
|
|
|
692
707
|
if (error instanceof ComposioRequestCancelledError) {
|
|
693
708
|
throw error;
|
|
694
709
|
}
|
|
710
|
+
if (isRateLimitResponse(error)) {
|
|
711
|
+
throw new ComposioToolFetchRateLimitError(
|
|
712
|
+
`Rate limited while retrieving tool with slug ${slug}`,
|
|
713
|
+
error,
|
|
714
|
+
{ slug }
|
|
715
|
+
);
|
|
716
|
+
}
|
|
695
717
|
// The tools endpoint reports an unknown slug as 404 (or 400 for a
|
|
696
718
|
// malformed one). Anything else (401, 5xx, network) is not "not found",
|
|
697
719
|
// so keep the client error reachable as `cause` under a generic error.
|
|
@@ -1153,16 +1175,40 @@ export class Tools<
|
|
|
1153
1175
|
const requestOptions: ComposioRequestOptions | undefined =
|
|
1154
1176
|
options?.signal != null ? { signal: options.signal } : undefined;
|
|
1155
1177
|
|
|
1156
|
-
const tool = await this.
|
|
1157
|
-
slug,
|
|
1158
|
-
{
|
|
1159
|
-
version: executeParams.version,
|
|
1160
|
-
},
|
|
1161
|
-
requestOptions
|
|
1162
|
-
);
|
|
1178
|
+
const tool = await this.getToolSchemaForExecute(slug, executeParams.version, requestOptions);
|
|
1163
1179
|
return this.executeWithTool(slug, executeParams, options, tool);
|
|
1164
1180
|
}
|
|
1165
1181
|
|
|
1182
|
+
/** The tool's schema for `execute()`, fetched only if no unexpired copy is cached. Failures aren't cached. */
|
|
1183
|
+
private async getToolSchemaForExecute(
|
|
1184
|
+
slug: string,
|
|
1185
|
+
version: string | undefined,
|
|
1186
|
+
requestOptions: ComposioRequestOptions | undefined
|
|
1187
|
+
): Promise<Tool> {
|
|
1188
|
+
const key = `${slug}\0${version ?? ''}`;
|
|
1189
|
+
const cached = this.executeToolSchemas.get(key);
|
|
1190
|
+
if (cached && cached.expiresAt > Date.now()) {
|
|
1191
|
+
return cached.tool;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
const tool = await this.getRawComposioToolBySlug(slug, { version }, requestOptions);
|
|
1195
|
+
|
|
1196
|
+
const resolvedVersion =
|
|
1197
|
+
version ?? getToolkitVersion(tool.toolkit?.slug ?? 'unknown', this.toolkitVersions);
|
|
1198
|
+
const ttlMs =
|
|
1199
|
+
resolvedVersion === 'latest' ? LATEST_TOOL_SCHEMA_TTL_MS : PINNED_TOOL_SCHEMA_TTL_MS;
|
|
1200
|
+
// Re-insert so a refreshed entry counts as the newest.
|
|
1201
|
+
this.executeToolSchemas.delete(key);
|
|
1202
|
+
if (this.executeToolSchemas.size >= MAX_CACHED_TOOL_SCHEMAS) {
|
|
1203
|
+
const oldestKey = this.executeToolSchemas.keys().next().value;
|
|
1204
|
+
if (oldestKey !== undefined) {
|
|
1205
|
+
this.executeToolSchemas.delete(oldestKey);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
this.executeToolSchemas.set(key, { tool, expiresAt: Date.now() + ttlMs });
|
|
1209
|
+
return tool;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1166
1212
|
/**
|
|
1167
1213
|
* Executes a tool based on a tool router session.
|
|
1168
1214
|
*
|
|
@@ -46,18 +46,21 @@ export interface SessionContext {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* Execute function for
|
|
49
|
+
* Execute function for local tools.
|
|
50
50
|
* Just return the result data, or throw an error. The SDK wraps it internally.
|
|
51
51
|
*
|
|
52
52
|
* Supports two call patterns:
|
|
53
53
|
* - `(input) => data` — for tools that don't need session context
|
|
54
54
|
* - `(input, ctx) => data` — for tools that need to call other tools or proxy APIs
|
|
55
55
|
*/
|
|
56
|
-
export type
|
|
56
|
+
export type LocalToolExecuteFn<T extends AnyZodSchema> = (
|
|
57
57
|
input: InferZodSchema<T>,
|
|
58
58
|
ctx: SessionContext
|
|
59
59
|
) => Promise<Record<string, unknown>>;
|
|
60
60
|
|
|
61
|
+
/** @deprecated Use `LocalToolExecuteFn` instead; local tools were previously called custom tools. */
|
|
62
|
+
export type CustomToolExecuteFn<T extends AnyZodSchema> = LocalToolExecuteFn<T>;
|
|
63
|
+
|
|
61
64
|
/**
|
|
62
65
|
* Zod schema for validating a custom tool slug.
|
|
63
66
|
* Alphanumeric, underscores, and hyphens only. No `LOCAL_` or `COMPOSIO_` prefix.
|
|
@@ -101,8 +104,8 @@ export const CreateCustomToolBaseSchema = z.object({
|
|
|
101
104
|
),
|
|
102
105
|
});
|
|
103
106
|
|
|
104
|
-
/** Options for creating
|
|
105
|
-
export type
|
|
107
|
+
/** Options for creating local tools via `experimental_createTool()`. */
|
|
108
|
+
export type CreateLocalToolParams<T extends AnyZodSchema> = z.infer<
|
|
106
109
|
typeof CreateCustomToolBaseSchema
|
|
107
110
|
> & {
|
|
108
111
|
/** Zod schema for input parameters */
|
|
@@ -110,14 +113,17 @@ export type CreateCustomToolParams<T extends AnyZodSchema> = z.infer<
|
|
|
110
113
|
/** Optional Zod schema for output parameters (sent to backend for documentation) */
|
|
111
114
|
outputParams?: AnyZodSchema;
|
|
112
115
|
/** The function that executes the tool */
|
|
113
|
-
execute:
|
|
116
|
+
execute: LocalToolExecuteFn<T>;
|
|
114
117
|
};
|
|
115
118
|
|
|
119
|
+
/** @deprecated Use `CreateLocalToolParams` instead; local tools were previously called custom tools. */
|
|
120
|
+
export type CreateCustomToolParams<T extends AnyZodSchema> = CreateLocalToolParams<T>;
|
|
121
|
+
|
|
116
122
|
/**
|
|
117
|
-
*
|
|
118
|
-
* Pass to `composio.create(userId, { experimental: {
|
|
123
|
+
* One of your local tools, returned from `experimental_createTool()`; it runs in your process.
|
|
124
|
+
* Pass to `composio.create(userId, { experimental: { localTools: [...] } })` to bind to a session.
|
|
119
125
|
*/
|
|
120
|
-
export interface
|
|
126
|
+
export interface LocalTool {
|
|
121
127
|
readonly slug: string;
|
|
122
128
|
readonly name: string;
|
|
123
129
|
readonly description: string;
|
|
@@ -138,9 +144,12 @@ export interface CustomTool {
|
|
|
138
144
|
/** @internal Original Zod schema — used for runtime input validation (defaults, coercions, transforms) */
|
|
139
145
|
readonly inputParams: AnyZodSchema;
|
|
140
146
|
/** Direct reference to the execute function — useful for testing */
|
|
141
|
-
readonly execute:
|
|
147
|
+
readonly execute: LocalToolExecuteFn<AnyZodSchema>;
|
|
142
148
|
}
|
|
143
149
|
|
|
150
|
+
/** @deprecated Use `LocalTool` instead; local tools were previously called custom tools. */
|
|
151
|
+
export type CustomTool = LocalTool;
|
|
152
|
+
|
|
144
153
|
/** Serialized tool definition sent to backend for search indexing. Uses official client type. */
|
|
145
154
|
export type CustomToolDefinition = NonNullable<
|
|
146
155
|
NonNullable<SessionCreateParams['experimental']>['custom_tools']
|
|
@@ -167,17 +176,20 @@ export const CreateCustomToolkitBaseSchema = z.object({
|
|
|
167
176
|
),
|
|
168
177
|
});
|
|
169
178
|
|
|
170
|
-
/** Options for
|
|
171
|
-
export type
|
|
179
|
+
/** Options for grouping local tools into a toolkit via `experimental_createToolkit()`. */
|
|
180
|
+
export type CreateLocalToolkitParams = z.infer<typeof CreateCustomToolkitBaseSchema> & {
|
|
172
181
|
/** Tools to include in this toolkit. Must not have `extendsToolkit` set. */
|
|
173
|
-
tools:
|
|
182
|
+
tools: LocalTool[];
|
|
174
183
|
};
|
|
175
184
|
|
|
185
|
+
/** @deprecated Use `CreateLocalToolkitParams` instead; local toolkits were previously called custom toolkits. */
|
|
186
|
+
export type CreateCustomToolkitParams = CreateLocalToolkitParams;
|
|
187
|
+
|
|
176
188
|
/**
|
|
177
|
-
*
|
|
178
|
-
* Pass to `composio.create(userId, { experimental: {
|
|
189
|
+
* A toolkit of local tools returned from `experimental_createToolkit()`.
|
|
190
|
+
* Pass to `composio.create(userId, { experimental: { localToolkits: [...] } })`.
|
|
179
191
|
*/
|
|
180
|
-
export interface
|
|
192
|
+
export interface LocalToolkit {
|
|
181
193
|
readonly slug: string;
|
|
182
194
|
readonly name: string;
|
|
183
195
|
readonly description: string;
|
|
@@ -186,9 +198,12 @@ export interface CustomToolkit {
|
|
|
186
198
|
* Tool-level preload values override this default.
|
|
187
199
|
*/
|
|
188
200
|
readonly preload?: boolean;
|
|
189
|
-
readonly tools: readonly
|
|
201
|
+
readonly tools: readonly LocalTool[];
|
|
190
202
|
}
|
|
191
203
|
|
|
204
|
+
/** @deprecated Use `LocalToolkit` instead; local toolkits were previously called custom toolkits. */
|
|
205
|
+
export type CustomToolkit = LocalToolkit;
|
|
206
|
+
|
|
192
207
|
/** Serialized toolkit definition sent to backend. Uses official client type. */
|
|
193
208
|
export type CustomToolkitDefinition = NonNullable<
|
|
194
209
|
NonNullable<NonNullable<SessionCreateParams['experimental']>['custom_toolkits']>[number]
|
|
@@ -207,7 +222,7 @@ export interface InlineCustomToolsWirePayload {
|
|
|
207
222
|
|
|
208
223
|
/** @internal Entry in the per-session custom tools routing map. */
|
|
209
224
|
export type CustomToolsMapEntry = {
|
|
210
|
-
handle:
|
|
225
|
+
handle: LocalTool;
|
|
211
226
|
/** @internal The final slug assigned by the prefixing rules (e.g. LOCAL_GREP, LOCAL_GMAIL_GET_EMAILS) */
|
|
212
227
|
finalSlug: string;
|
|
213
228
|
/** Resolved toolkit — from extendsToolkit, parent custom toolkit, or undefined for standalone */
|
|
@@ -224,36 +239,42 @@ export type CustomToolsMap = {
|
|
|
224
239
|
byToolkitAndOriginalSlug?: Map<string, CustomToolsMapEntry>;
|
|
225
240
|
/** Original slugs that appear in multiple toolkits and cannot be resolved safely without the final slug */
|
|
226
241
|
ambiguousOriginalSlugs?: Set<string>;
|
|
227
|
-
/** The original
|
|
228
|
-
toolkits?:
|
|
229
|
-
/** The original standalone
|
|
230
|
-
tools?:
|
|
242
|
+
/** The original local toolkits passed at session creation — used for session.localToolkits() */
|
|
243
|
+
toolkits?: LocalToolkit[];
|
|
244
|
+
/** The original standalone local tools passed at session creation — kept for inline re-injection on later requests. */
|
|
245
|
+
tools?: LocalTool[];
|
|
231
246
|
};
|
|
232
247
|
|
|
233
248
|
// ────────────────────────────────────────────────────────────────
|
|
234
|
-
// Registered
|
|
249
|
+
// Registered local tool types (returned by session.localTools())
|
|
235
250
|
// ────────────────────────────────────────────────────────────────
|
|
236
251
|
|
|
237
|
-
/**
|
|
238
|
-
export interface
|
|
252
|
+
/** One of your local tools as registered in a session, with its final resolved slug. */
|
|
253
|
+
export interface RegisteredLocalTool {
|
|
239
254
|
/** The final slug as registered with the backend (e.g. LOCAL_GREP, LOCAL_GMAIL_GET_EMAILS) */
|
|
240
255
|
slug: string;
|
|
241
256
|
name: string;
|
|
242
257
|
description: string;
|
|
243
|
-
/** Resolved toolkit — extendsToolkit value,
|
|
258
|
+
/** Resolved toolkit — extendsToolkit value, local toolkit slug, or undefined for standalone */
|
|
244
259
|
toolkit?: string;
|
|
245
260
|
inputSchema: Record<string, unknown>;
|
|
246
261
|
outputSchema?: Record<string, unknown>;
|
|
247
262
|
}
|
|
248
263
|
|
|
249
|
-
/** A
|
|
250
|
-
export interface
|
|
264
|
+
/** A toolkit of local tools as registered in a session, with final slugs on nested tools. */
|
|
265
|
+
export interface RegisteredLocalToolkit {
|
|
251
266
|
slug: string;
|
|
252
267
|
name: string;
|
|
253
268
|
description: string;
|
|
254
|
-
tools:
|
|
269
|
+
tools: RegisteredLocalTool[];
|
|
255
270
|
}
|
|
256
271
|
|
|
272
|
+
/** @deprecated Use `RegisteredLocalTool` instead; local tools were previously called custom tools. */
|
|
273
|
+
export type RegisteredCustomTool = RegisteredLocalTool;
|
|
274
|
+
|
|
275
|
+
/** @deprecated Use `RegisteredLocalToolkit` instead; local toolkits were previously called custom toolkits. */
|
|
276
|
+
export type RegisteredCustomToolkit = RegisteredLocalToolkit;
|
|
277
|
+
|
|
257
278
|
// ────────────────────────────────────────────────────────────────
|
|
258
279
|
// Response types from the backend (slug + original_slug mapping)
|
|
259
280
|
// ────────────────────────────────────────────────────────────────
|
|
@@ -57,7 +57,7 @@ export const CustomToolkitCreateParamsSchema = z.object({
|
|
|
57
57
|
/** Human-readable toolkit name. */
|
|
58
58
|
name: z.string().min(1).max(200),
|
|
59
59
|
/** The MCP server URL. Must use https. */
|
|
60
|
-
|
|
60
|
+
mcpUrl: z.string().url(),
|
|
61
61
|
/** Square PNG or JPEG logo (256-1024px, max 3MB), base64-encoded. Defaults to the MCP logo. */
|
|
62
62
|
logoFile: CustomToolkitLogoFileSchema.optional(),
|
|
63
63
|
/** At least one scheme. Cannot be changed after create. */
|
|
@@ -135,8 +135,8 @@ export const CustomToolkitUpsertParamsSchema = z.object({
|
|
|
135
135
|
toolkitConfig: z.object({
|
|
136
136
|
/** Human-readable toolkit name. */
|
|
137
137
|
name: z.string().min(1).max(200),
|
|
138
|
-
/** The
|
|
139
|
-
|
|
138
|
+
/** The MCP server URL. Must use https. */
|
|
139
|
+
mcpUrl: z.string().url(),
|
|
140
140
|
/** Square PNG or JPEG logo (256-1024px, max 3MB), base64-encoded. Defaults to the Composio logo. */
|
|
141
141
|
logoFile: CustomToolkitLogoFileSchema.optional(),
|
|
142
142
|
/** At least one scheme. The schemes cannot change once the toolkit exists. */
|
|
@@ -13,11 +13,11 @@ import type {
|
|
|
13
13
|
SessionExecuteParams,
|
|
14
14
|
} from '@composio/client/resources/tool-router/session';
|
|
15
15
|
import type {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
LocalTool,
|
|
17
|
+
LocalToolkit,
|
|
18
18
|
InlineCustomToolsWirePayload,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
RegisteredLocalTool,
|
|
20
|
+
RegisteredLocalToolkit,
|
|
21
21
|
} from './customTool.types';
|
|
22
22
|
import { PRELOAD_TOOLS_ALL } from '../lib/toolRouterConstants';
|
|
23
23
|
import { addSessionConfigConflictIssue } from '../lib/sessionConfigConflict';
|
|
@@ -517,24 +517,34 @@ const ToolRouterCreateSessionConfigBaseSchema = z
|
|
|
517
517
|
})
|
|
518
518
|
.optional()
|
|
519
519
|
.describe('Configuration for assistive prompt generation'),
|
|
520
|
-
|
|
521
|
-
.array(z.custom<
|
|
520
|
+
localTools: z
|
|
521
|
+
.array(z.custom<LocalTool>())
|
|
522
522
|
.optional()
|
|
523
523
|
.describe(
|
|
524
|
-
'
|
|
524
|
+
'Local tools to include in this session. They run in your process. Created via experimental_createTool() from @composio/core.'
|
|
525
525
|
),
|
|
526
|
-
|
|
527
|
-
.array(z.custom<
|
|
526
|
+
localToolkits: z
|
|
527
|
+
.array(z.custom<LocalToolkit>())
|
|
528
528
|
.optional()
|
|
529
529
|
.describe(
|
|
530
|
-
'
|
|
530
|
+
'Toolkits of local tools to include in this session. Created via experimental_createToolkit() from @composio/core.'
|
|
531
531
|
),
|
|
532
|
+
/** @deprecated Use `localTools` instead. */
|
|
533
|
+
customTools: z
|
|
534
|
+
.array(z.custom<LocalTool>())
|
|
535
|
+
.optional()
|
|
536
|
+
.describe('Deprecated alias for localTools. Accepted for backwards compatibility.'),
|
|
537
|
+
/** @deprecated Use `localToolkits` instead. */
|
|
538
|
+
customToolkits: z
|
|
539
|
+
.array(z.custom<LocalToolkit>())
|
|
540
|
+
.optional()
|
|
541
|
+
.describe('Deprecated alias for localToolkits. Accepted for backwards compatibility.'),
|
|
532
542
|
sessionConfigId: z
|
|
533
543
|
.string()
|
|
534
544
|
.min(1)
|
|
535
545
|
.optional()
|
|
536
546
|
.describe(
|
|
537
|
-
'ID of a saved Session config (`sc_…`) to apply when the session is created. Cannot be combined with toolkits, tools, tags,
|
|
547
|
+
'ID of a saved Session config (`sc_…`) to apply when the session is created. Cannot be combined with toolkits, tools, tags, localTools or localToolkits.'
|
|
538
548
|
),
|
|
539
549
|
/**
|
|
540
550
|
* What happens to a call that needs the user's approval when the
|
|
@@ -558,6 +568,8 @@ const ToolRouterCreateSessionConfigBaseSchema = z
|
|
|
558
568
|
config.tools !== undefined && 'tools',
|
|
559
569
|
config.tags !== undefined && 'tags',
|
|
560
570
|
config.hooks !== undefined && 'hooks',
|
|
571
|
+
config.experimental.localTools !== undefined && 'experimental.localTools',
|
|
572
|
+
config.experimental.localToolkits !== undefined && 'experimental.localToolkits',
|
|
561
573
|
config.experimental.customTools !== undefined && 'experimental.customTools',
|
|
562
574
|
config.experimental.customToolkits !== undefined && 'experimental.customToolkits',
|
|
563
575
|
].filter((field): field is string => field !== false)
|
|
@@ -626,7 +638,11 @@ export const ToolRouterCreateSessionConfigSchema = z
|
|
|
626
638
|
* @param {object} [preload] - Tools to preload into session.tools() and the MCP tool list
|
|
627
639
|
* @param {string[] | 'all'} [preload.tools] - Tool slugs to preload, or "all" to preload every app tool allowed by the session filters. "all" requires a positive filter such as toolkits, tools, or tags; the backend validates and caps the final tool set.
|
|
628
640
|
* @param {object} [experimental] - Experimental features configuration. Not stable; may change or be removed.
|
|
629
|
-
* @param {
|
|
641
|
+
* @param {LocalTool[]} [experimental.localTools] - Local tools to include in this session, created with `experimental_createTool()`. They run in your process.
|
|
642
|
+
* @param {LocalToolkit[]} [experimental.localToolkits] - Toolkits of local tools to include in this session, created with `experimental_createToolkit()`.
|
|
643
|
+
* @param {LocalTool[]} [experimental.customTools] - Deprecated alias for `experimental.localTools`.
|
|
644
|
+
* @param {LocalToolkit[]} [experimental.customToolkits] - Deprecated alias for `experimental.localToolkits`.
|
|
645
|
+
* @param {string} [experimental.sessionConfigId] - ID of a saved Session config (`sc_…`) to apply at creation; see `composio.sessionConfigs`. Cannot be combined with `toolkits`, `tools`, `tags`, `hooks`, `experimental.localTools` or `experimental.localToolkits` (or their deprecated aliases `experimental.customTools` / `experimental.customToolkits`). Per-session fields such as `authConfigs`, `connectedAccounts`, `manageConnections`, `sandbox`, `multiAccount` and `preload` stay allowed.
|
|
630
646
|
*/
|
|
631
647
|
export type ToolRouterCreateSessionConfig =
|
|
632
648
|
InlineAccessCreateSessionConfig | SavedConfigCreateSessionConfig;
|
|
@@ -652,9 +668,11 @@ type SavedConfigCreateSessionConfig = Omit<
|
|
|
652
668
|
hooks?: never;
|
|
653
669
|
experimental: Omit<
|
|
654
670
|
ParsedCreateSessionExperimental,
|
|
655
|
-
'sessionConfigId' | 'customTools' | 'customToolkits'
|
|
671
|
+
'sessionConfigId' | 'localTools' | 'localToolkits' | 'customTools' | 'customToolkits'
|
|
656
672
|
> & {
|
|
657
673
|
sessionConfigId: string;
|
|
674
|
+
localTools?: never;
|
|
675
|
+
localToolkits?: never;
|
|
658
676
|
customTools?: never;
|
|
659
677
|
customToolkits?: never;
|
|
660
678
|
};
|
|
@@ -1468,10 +1486,14 @@ export interface Session<
|
|
|
1468
1486
|
listConfigHistory: ToolRouterSessionListConfigHistoryFn;
|
|
1469
1487
|
/** Proxy an API call through Composio's auth layer using the session's connected account */
|
|
1470
1488
|
proxyExecute: ToolRouterSessionProxyExecuteFn;
|
|
1471
|
-
/** List
|
|
1472
|
-
|
|
1473
|
-
/** List
|
|
1474
|
-
|
|
1489
|
+
/** List local tools registered in this session, with their final slugs and schemas */
|
|
1490
|
+
localTools: (options?: { toolkit?: string }) => RegisteredLocalTool[];
|
|
1491
|
+
/** List toolkits of local tools registered in this session, with final slugs on nested tools */
|
|
1492
|
+
localToolkits: () => RegisteredLocalToolkit[];
|
|
1493
|
+
/** @deprecated Use `localTools()` instead. */
|
|
1494
|
+
customTools: (options?: { toolkit?: string }) => RegisteredLocalTool[];
|
|
1495
|
+
/** @deprecated Use `localToolkits()` instead. */
|
|
1496
|
+
customToolkits: () => RegisteredLocalToolkit[];
|
|
1475
1497
|
/** Experimental features (files, assistive prompt, etc.) */
|
|
1476
1498
|
experimental: SessionExperimental;
|
|
1477
1499
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { APIError } from '@composio/client';
|
|
2
|
+
|
|
3
|
+
/** Whether a client error is the API rejecting the request with a 429. */
|
|
4
|
+
export function isRateLimitResponse(error: unknown): error is APIError {
|
|
5
|
+
return error instanceof APIError && error.status === 429;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Seconds a 429 asks the caller to wait, from its `Retry-After` header (seconds or an HTTP date).
|
|
10
|
+
* Undefined when the header is missing or unreadable.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export function getRetryAfterSeconds(error: APIError): number | undefined {
|
|
15
|
+
const value = error.headers?.get('retry-after')?.trim();
|
|
16
|
+
if (!value) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const seconds = Number(value);
|
|
20
|
+
if (Number.isFinite(seconds)) {
|
|
21
|
+
return seconds >= 0 ? seconds : undefined;
|
|
22
|
+
}
|
|
23
|
+
const date = Date.parse(value);
|
|
24
|
+
return Number.isNaN(date) ? undefined : Math.max(0, (date - Date.now()) / 1000);
|
|
25
|
+
}
|
|
@@ -73,7 +73,7 @@ export const transformCustomToolkitCreateParams = (
|
|
|
73
73
|
params: CustomToolkitCreateParams
|
|
74
74
|
): RawCustomCreateToolkitParams => ({
|
|
75
75
|
name: params.name,
|
|
76
|
-
|
|
76
|
+
mcp_url: params.mcpUrl,
|
|
77
77
|
logo_file: transformCustomToolkitLogoFile(params.logoFile),
|
|
78
78
|
auth_schemes: params.authSchemes.map(transformCustomToolkitAuthScheme),
|
|
79
79
|
user_id: params.userId,
|
|
@@ -118,7 +118,7 @@ export const transformCustomToolkitUpsertParams = (
|
|
|
118
118
|
slug: params.slug,
|
|
119
119
|
toolkit_config: {
|
|
120
120
|
name: params.toolkitConfig.name,
|
|
121
|
-
|
|
121
|
+
mcp_url: params.toolkitConfig.mcpUrl,
|
|
122
122
|
logo_file: transformCustomToolkitLogoFile(params.toolkitConfig.logoFile),
|
|
123
123
|
auth_schemes: params.toolkitConfig.authSchemes.map(transformCustomToolkitAuthScheme),
|
|
124
124
|
},
|