@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
package/src/models/Tools.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ComposioClient, { APIError } from '@composio/client';
|
|
2
2
|
import { FileToolModifier } from '#file_tool_modifier';
|
|
3
|
+
import { z } from 'zod/v3';
|
|
3
4
|
import {
|
|
4
5
|
Tool,
|
|
5
6
|
ToolExecuteParams,
|
|
@@ -43,8 +44,10 @@ import { ExecuteToolFn, GlobalExecuteToolFn } from '../types/provider.types';
|
|
|
43
44
|
import {
|
|
44
45
|
ComposioInvalidModifierError,
|
|
45
46
|
ComposioToolFetchError,
|
|
47
|
+
ComposioToolFetchRateLimitError,
|
|
46
48
|
ComposioToolNotFoundError,
|
|
47
49
|
ComposioProviderNotDefinedError,
|
|
50
|
+
ComposioToolSchemaInvalidError,
|
|
48
51
|
ComposioToolVersionRequiredError,
|
|
49
52
|
} from '../errors/ToolErrors';
|
|
50
53
|
import { ValidationError } from '../errors/ValidationErrors';
|
|
@@ -52,6 +55,7 @@ import { telemetry } from '../telemetry/Telemetry';
|
|
|
52
55
|
import type { ComposioConfig } from '../composio';
|
|
53
56
|
import { getToolkitVersion } from '../utils/toolkitVersion';
|
|
54
57
|
import { handleToolExecutionError } from '../errors/ToolErrors';
|
|
58
|
+
import { apiErrorSuggestedFixes, withApiErrorMessage } from '../errors/apiErrorDetails';
|
|
55
59
|
import type { SessionExecuteParams } from '@composio/client/resources/tool-router/session';
|
|
56
60
|
import { CONFIG_DEFAULTS } from '../utils/config-defaults';
|
|
57
61
|
import { resolveEffectiveUploadAllowlist } from '../utils/fileDirs';
|
|
@@ -68,6 +72,7 @@ import {
|
|
|
68
72
|
transformExecuteResponse,
|
|
69
73
|
} from '../utils/transformers/toolRouterResponseTransform';
|
|
70
74
|
import { ComposioRequestCancelledError } from '../errors/SDKErrors';
|
|
75
|
+
import { isRateLimitResponse } from '../utils/rateLimit';
|
|
71
76
|
|
|
72
77
|
const TOOL_ROUTER_SESSION_TOOLS_PAGE_LIMIT = 500;
|
|
73
78
|
|
|
@@ -79,25 +84,130 @@ type RawToolParameters =
|
|
|
79
84
|
| ToolRetrieveResponse['input_parameters']
|
|
80
85
|
| ComposioToolListResponse['items'][0]['input_parameters'];
|
|
81
86
|
|
|
87
|
+
type JsonSchemaNode = Record<string, unknown>;
|
|
88
|
+
|
|
89
|
+
const isSchemaRecord = (value: unknown): value is JsonSchemaNode =>
|
|
90
|
+
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Flatten a value for interpolation into a log line.
|
|
94
|
+
*
|
|
95
|
+
* The logger writes straight to the console sink, and the slug and the zod
|
|
96
|
+
* issue paths here are built from property names a remote toolkit controls. A
|
|
97
|
+
* name carrying a newline could otherwise forge or erase a line in the host's
|
|
98
|
+
* log, and an ANSI clear-line sequence could hide what came before it.
|
|
99
|
+
*/
|
|
100
|
+
const sanitizeForLog = (value: string): string =>
|
|
101
|
+
// eslint-disable-next-line no-control-regex
|
|
102
|
+
value.replace(/[\u0000-\u001F\u007F-\u009F]/g, ' ');
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Rewrite one JSON-Schema node into the strict subset `ParametersSchema`
|
|
106
|
+
* accepts, preserving its meaning:
|
|
107
|
+
*
|
|
108
|
+
* - boolean nodes (`items: true` / `items: false`) become `{}` / `{ not: {} }`
|
|
109
|
+
* — the strict subset's way to express "anything" and "nothing", so the
|
|
110
|
+
* meaning survives; booleans are still valid JSON Schema (draft-04 style)
|
|
111
|
+
* that MCP toolkits emit;
|
|
112
|
+
* - draft-04 boolean `exclusiveMinimum`/`exclusiveMaximum` (paired with
|
|
113
|
+
* `minimum`/`maximum`) become the numeric form draft-07+ uses;
|
|
114
|
+
*
|
|
115
|
+
* Children are rewritten recursively. `additionalProperties` legitimately
|
|
116
|
+
* accepts a boolean, so it is only recursed into when it is a schema.
|
|
117
|
+
*/
|
|
118
|
+
function sanitizeJsonSchemaNode(node: unknown): unknown {
|
|
119
|
+
// Boolean JSON-Schema nodes (draft-04 style, still emitted by MCP toolkits):
|
|
120
|
+
// `true` accepts anything, which `{}` also expresses; `false` accepts
|
|
121
|
+
// nothing, which the strict subset (an object node) expresses as `not: {}`.
|
|
122
|
+
// Coercing `false` to `{}` would invert the schema's meaning.
|
|
123
|
+
if (typeof node === 'boolean') return node ? {} : { not: {} };
|
|
124
|
+
if (Array.isArray(node)) return node.map(sanitizeJsonSchemaNode);
|
|
125
|
+
if (!isSchemaRecord(node)) return node;
|
|
126
|
+
|
|
127
|
+
const schema: JsonSchemaNode = { ...node };
|
|
128
|
+
|
|
129
|
+
for (const [bound, limit] of [
|
|
130
|
+
['exclusiveMinimum', 'minimum'],
|
|
131
|
+
['exclusiveMaximum', 'maximum'],
|
|
132
|
+
] as const) {
|
|
133
|
+
if (typeof schema[bound] !== 'boolean') continue;
|
|
134
|
+
if (schema[bound] && typeof schema[limit] === 'number') {
|
|
135
|
+
schema[bound] = schema[limit];
|
|
136
|
+
} else {
|
|
137
|
+
delete schema[bound];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
for (const key of ['items', 'not', 'if', 'then', 'else', 'additionalProperties'] as const) {
|
|
142
|
+
const child = schema[key];
|
|
143
|
+
if (child === undefined) continue;
|
|
144
|
+
// Every keyword here takes a schema node except `additionalProperties`,
|
|
145
|
+
// which also accepts a boolean; the sanitizer coerces boolean nodes.
|
|
146
|
+
if (key === 'additionalProperties' && typeof child === 'boolean') continue;
|
|
147
|
+
schema[key] = sanitizeJsonSchemaNode(child);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
for (const key of ['anyOf', 'oneOf', 'allOf'] as const) {
|
|
151
|
+
if (Array.isArray(schema[key])) {
|
|
152
|
+
schema[key] = sanitizeJsonSchemaNode(schema[key]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
for (const key of ['properties', 'patternProperties', '$defs', 'definitions'] as const) {
|
|
157
|
+
const children = schema[key];
|
|
158
|
+
if (!isSchemaRecord(children)) continue;
|
|
159
|
+
const mapped: JsonSchemaNode = {};
|
|
160
|
+
for (const [name, child] of Object.entries(children)) {
|
|
161
|
+
mapped[name] = sanitizeJsonSchemaNode(child);
|
|
162
|
+
}
|
|
163
|
+
schema[key] = mapped;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return schema;
|
|
167
|
+
}
|
|
168
|
+
|
|
82
169
|
/**
|
|
83
170
|
* Normalize a raw `input_parameters` / `output_parameters` payload returned by
|
|
84
171
|
* the Composio API. Maps `null`, `undefined`, and empty `{}` — all of which
|
|
85
172
|
* mean "no declared schema" — to `undefined` so the strict `ParametersSchema`
|
|
86
|
-
* validator never sees them
|
|
87
|
-
*
|
|
173
|
+
* validator never sees them, and rewrites the valid-but-unusual JSON Schema
|
|
174
|
+
* shapes MCP toolkits ship (boolean nodes, draft-04 boolean bounds, a bare
|
|
175
|
+
* combinator root) into the strict subset.
|
|
88
176
|
*
|
|
89
177
|
* MCP-backed toolkits (granola_mcp, apify_mcp, tavily_mcp, …) have no
|
|
90
178
|
* declared output schema and the API serializes that as `{}`, which would
|
|
91
179
|
* otherwise trip `ParametersSchema`. See
|
|
92
|
-
* https://github.com/ComposioHQ/composio/issues/3354.
|
|
180
|
+
* https://github.com/ComposioHQ/composio/issues/3354. The malformed-shape
|
|
181
|
+
* handling covers the toolkits listed in
|
|
182
|
+
* https://github.com/ComposioHQ/composio/issues/4757.
|
|
93
183
|
*/
|
|
94
184
|
function normalizeRawToolParameters(
|
|
95
185
|
params: RawToolParameters | null | undefined
|
|
96
186
|
): RawToolParameters | undefined {
|
|
97
187
|
if (params == null || Object.keys(params).length === 0) return undefined;
|
|
98
|
-
|
|
188
|
+
const sanitized = sanitizeJsonSchemaNode(params);
|
|
189
|
+
// A parameters root is a tool's named-argument object, so a bare combinator
|
|
190
|
+
// root (`oneOf`/`anyOf`/`allOf` with no `type`) still needs `type: "object"`
|
|
191
|
+
// to satisfy the strict schema.
|
|
192
|
+
if (
|
|
193
|
+
isSchemaRecord(sanitized) &&
|
|
194
|
+
sanitized.type === undefined &&
|
|
195
|
+
(Array.isArray(sanitized.anyOf) ||
|
|
196
|
+
Array.isArray(sanitized.oneOf) ||
|
|
197
|
+
Array.isArray(sanitized.allOf))
|
|
198
|
+
) {
|
|
199
|
+
return { ...sanitized, type: 'object' } as RawToolParameters;
|
|
200
|
+
}
|
|
201
|
+
return sanitized as RawToolParameters;
|
|
99
202
|
}
|
|
100
203
|
|
|
204
|
+
/** How long `execute()` reuses a schema fetched for `latest`, which can change at any release. */
|
|
205
|
+
const LATEST_TOOL_SCHEMA_TTL_MS = 5 * 60 * 1000;
|
|
206
|
+
/** How long `execute()` reuses a schema fetched for a pinned toolkit version. */
|
|
207
|
+
const PINNED_TOOL_SCHEMA_TTL_MS = 60 * 60 * 1000;
|
|
208
|
+
/** Most schemas `execute()` keeps per `Tools` instance; the oldest is dropped first. */
|
|
209
|
+
const MAX_CACHED_TOOL_SCHEMAS = 500;
|
|
210
|
+
|
|
101
211
|
/**
|
|
102
212
|
* This class is used to manage tools in the Composio SDK.
|
|
103
213
|
* It provides methods to list, get, and execute tools.
|
|
@@ -123,6 +233,15 @@ export class Tools<
|
|
|
123
233
|
* Scoped per-instance so a fresh `Composio` starts with a clean slate.
|
|
124
234
|
*/
|
|
125
235
|
private readonly warnedAutoUploadDisabledForTool = new Set<string>();
|
|
236
|
+
/** Tools whose parameters were dropped by `transformToolCases`; warn once each. */
|
|
237
|
+
private readonly warnedMalformedToolParametersSlugs = new Set<string>();
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Schemas `execute()` already fetched, so repeated executions don't each spend a request.
|
|
241
|
+
* Holds what `getRawComposioToolBySlug` returned with no `modifySchema`, so a caller's schema
|
|
242
|
+
* modifiers never reach it.
|
|
243
|
+
*/
|
|
244
|
+
private readonly executeToolSchemas = new Map<string, { tool: Tool; expiresAt: number }>();
|
|
126
245
|
|
|
127
246
|
constructor(client: ComposioClient, config?: ComposioConfig<TProvider>) {
|
|
128
247
|
if (!client) {
|
|
@@ -163,21 +282,79 @@ export class Tools<
|
|
|
163
282
|
* making them more consistent with JavaScript/TypeScript conventions.
|
|
164
283
|
*
|
|
165
284
|
* @param {ToolRetrieveResponse | ComposioToolListResponse['items'][0]} tool - The tool object to transform
|
|
166
|
-
* @returns {Tool} The transformed tool with camelCase properties
|
|
285
|
+
* @returns {Tool} The transformed tool with camelCase properties, or
|
|
286
|
+
* `undefined` when its input schema is unrepairable and the tool is skipped
|
|
167
287
|
*
|
|
168
288
|
* @private
|
|
169
289
|
*/
|
|
170
290
|
private transformToolCases(
|
|
171
291
|
tool: ToolRetrieveResponse | ComposioToolListResponse['items'][0]
|
|
172
|
-
): Tool {
|
|
173
|
-
|
|
292
|
+
): Tool | undefined {
|
|
293
|
+
const candidate = {
|
|
174
294
|
...tool,
|
|
175
295
|
inputParameters: normalizeRawToolParameters(tool.input_parameters),
|
|
176
296
|
outputParameters: normalizeRawToolParameters(tool.output_parameters),
|
|
177
297
|
availableVersions: tool.available_versions,
|
|
178
298
|
isDeprecated: tool.deprecated?.is_deprecated ?? false,
|
|
179
299
|
isNoAuth: tool.no_auth,
|
|
180
|
-
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const parsed = ToolSchema.safeParse(candidate);
|
|
303
|
+
if (parsed.success) return parsed.data;
|
|
304
|
+
|
|
305
|
+
// One malformed schema must not take down a whole toolkit's tool list
|
|
306
|
+
// (#4757). The output side degrades to "no schema"; the input side cannot,
|
|
307
|
+
// because providers build their call schema from it and a tool without one
|
|
308
|
+
// is not callable — @composio/langchain's wrapTool throws
|
|
309
|
+
// "Tool input parameters are not defined", so an unrepairable input schema
|
|
310
|
+
// would fail the provider's whole wrapTools pass one layer later. Such a
|
|
311
|
+
// tool is skipped instead, with the same warning. A failure outside the
|
|
312
|
+
// parameters is genuinely broken data and stays loud — including alongside
|
|
313
|
+
// a parameter failure, where skipping the tool would otherwise hide it.
|
|
314
|
+
const failingSides = new Set<'inputParameters' | 'outputParameters'>();
|
|
315
|
+
let hasNonParameterIssue = false;
|
|
316
|
+
for (const issue of parsed.error.issues) {
|
|
317
|
+
const root = issue.path[0];
|
|
318
|
+
if (root === 'inputParameters' || root === 'outputParameters') {
|
|
319
|
+
failingSides.add(root);
|
|
320
|
+
} else {
|
|
321
|
+
hasNonParameterIssue = true;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (hasNonParameterIssue || failingSides.size === 0) throw parsed.error;
|
|
325
|
+
|
|
326
|
+
this.warnMalformedToolParameters(tool, parsed.error, [...failingSides]);
|
|
327
|
+
if (failingSides.has('inputParameters')) return undefined;
|
|
328
|
+
const degradedCandidate = { ...candidate };
|
|
329
|
+
for (const side of failingSides) {
|
|
330
|
+
degradedCandidate[side] = undefined;
|
|
331
|
+
}
|
|
332
|
+
const degraded = ToolSchema.safeParse(degradedCandidate);
|
|
333
|
+
if (degraded.success) return degraded.data;
|
|
334
|
+
throw parsed.error;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Warn once per tool that its declared parameters could not be parsed and
|
|
339
|
+
* were dropped, so a caller sees why a tool carries no schema instead of a
|
|
340
|
+
* bare TypeError from deep inside Zod.
|
|
341
|
+
*/
|
|
342
|
+
private warnMalformedToolParameters(
|
|
343
|
+
tool: ToolRetrieveResponse | ComposioToolListResponse['items'][0],
|
|
344
|
+
error: z.ZodError,
|
|
345
|
+
droppedSides: Array<'inputParameters' | 'outputParameters'>
|
|
346
|
+
): void {
|
|
347
|
+
const slug = String((tool as { slug?: unknown }).slug ?? '');
|
|
348
|
+
if (slug && this.warnedMalformedToolParametersSlugs.has(slug)) return;
|
|
349
|
+
if (slug) this.warnedMalformedToolParametersSlugs.add(slug);
|
|
350
|
+
const inputFailed = droppedSides.includes('inputParameters');
|
|
351
|
+
logger.warn(
|
|
352
|
+
`Tool "${sanitizeForLog(slug) || '(unknown slug)'}" has ${droppedSides.join(' and ')} that do not ` +
|
|
353
|
+
`match the expected schema, so the tool was ` +
|
|
354
|
+
`${inputFailed ? 'skipped' : 'returned without those parameters'}. ` +
|
|
355
|
+
`${inputFailed ? 'It cannot be offered without an input schema.' : 'The tool still executes, but LLM callers will not see those parameters.'} ` +
|
|
356
|
+
`Issues: ${error.issues.map(issue => `${sanitizeForLog(issue.path.join('.'))}: ${sanitizeForLog(issue.message)}`).join('; ')}`
|
|
357
|
+
);
|
|
181
358
|
}
|
|
182
359
|
|
|
183
360
|
/**
|
|
@@ -409,9 +586,9 @@ export class Tools<
|
|
|
409
586
|
* Lists Composio API tools available to the SDK.
|
|
410
587
|
*
|
|
411
588
|
* This method fetches remote Composio tools from the API in raw format. The response can be
|
|
412
|
-
* filtered and modified as needed.
|
|
589
|
+
* filtered and modified as needed. Experimental local tools are session-scoped; attach
|
|
413
590
|
* them when creating or reusing a Tool Router session, then use `session.tools()`,
|
|
414
|
-
* `session.
|
|
591
|
+
* `session.localTools()`, or `session.execute()`.
|
|
415
592
|
* It provides access to the underlying tool data without provider-specific wrapping.
|
|
416
593
|
*
|
|
417
594
|
* @param {ToolListParams} query - Query parameters to filter the tools (required)
|
|
@@ -540,7 +717,9 @@ export class Tools<
|
|
|
540
717
|
if (!tools) {
|
|
541
718
|
return [];
|
|
542
719
|
}
|
|
543
|
-
const caseTransformedTools = tools.items
|
|
720
|
+
const caseTransformedTools = tools.items
|
|
721
|
+
.map(tool => this.transformToolCases(tool))
|
|
722
|
+
.filter((tool): tool is Tool => tool !== undefined);
|
|
544
723
|
|
|
545
724
|
let modifiedTools = await this.applyDefaultSchemaModifiers(caseTransformedTools);
|
|
546
725
|
|
|
@@ -597,7 +776,11 @@ export class Tools<
|
|
|
597
776
|
() => this.client.toolRouter.session.tools(sessionId, sessionToolsParams, requestOptions),
|
|
598
777
|
requestOptions?.signal
|
|
599
778
|
);
|
|
600
|
-
tools.push(
|
|
779
|
+
tools.push(
|
|
780
|
+
...response.items
|
|
781
|
+
.map(tool => this.transformToolCases(tool))
|
|
782
|
+
.filter((tool): tool is Tool => tool !== undefined)
|
|
783
|
+
);
|
|
601
784
|
cursor = response.next_cursor;
|
|
602
785
|
} while (cursor);
|
|
603
786
|
|
|
@@ -628,8 +811,8 @@ export class Tools<
|
|
|
628
811
|
* This method fetches a single tool in raw format without provider-specific wrapping,
|
|
629
812
|
* providing direct access to the tool's schema and metadata. Tool versions are controlled
|
|
630
813
|
* at the Composio SDK initialization level through the `toolkitVersions` configuration.
|
|
631
|
-
*
|
|
632
|
-
* Tool Router session, then use `session.tools()`, `session.
|
|
814
|
+
* Experimental local tools are session-scoped; attach them when creating or reusing a
|
|
815
|
+
* Tool Router session, then use `session.tools()`, `session.localTools()`, or
|
|
633
816
|
* `session.execute()`.
|
|
634
817
|
*
|
|
635
818
|
* @param {string} slug - The unique identifier of the tool (e.g., 'GITHUB_GET_REPOS')
|
|
@@ -692,23 +875,58 @@ export class Tools<
|
|
|
692
875
|
if (error instanceof ComposioRequestCancelledError) {
|
|
693
876
|
throw error;
|
|
694
877
|
}
|
|
878
|
+
if (isRateLimitResponse(error)) {
|
|
879
|
+
throw new ComposioToolFetchRateLimitError(
|
|
880
|
+
withApiErrorMessage(
|
|
881
|
+
`Rate limited while retrieving tool with slug ${slug}`,
|
|
882
|
+
error.details
|
|
883
|
+
),
|
|
884
|
+
error,
|
|
885
|
+
{ slug }
|
|
886
|
+
);
|
|
887
|
+
}
|
|
695
888
|
// The tools endpoint reports an unknown slug as 404 (or 400 for a
|
|
696
889
|
// malformed one). Anything else (401, 5xx, network) is not "not found",
|
|
697
890
|
// so keep the client error reachable as `cause` under a generic error.
|
|
698
891
|
if (error instanceof APIError && (error.status === 404 || error.status === 400)) {
|
|
699
|
-
throw new ComposioToolNotFoundError(
|
|
892
|
+
throw new ComposioToolNotFoundError(
|
|
893
|
+
withApiErrorMessage(`Tool with slug ${slug} not found`, error.details),
|
|
894
|
+
{
|
|
895
|
+
meta: { slug },
|
|
896
|
+
cause: error,
|
|
897
|
+
possibleFixes: apiErrorSuggestedFixes(error.details),
|
|
898
|
+
}
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
const details = error instanceof APIError ? error.details : undefined;
|
|
902
|
+
const originalMessage =
|
|
903
|
+
error instanceof APIError && error.status !== undefined
|
|
904
|
+
? undefined
|
|
905
|
+
: error instanceof Error
|
|
906
|
+
? error.message
|
|
907
|
+
: undefined;
|
|
908
|
+
throw new ComposioToolFetchError(
|
|
909
|
+
withApiErrorMessage(`Unable to retrieve tool with slug ${slug}`, details, originalMessage),
|
|
910
|
+
{
|
|
700
911
|
meta: { slug },
|
|
701
912
|
cause: error,
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
meta: { slug },
|
|
706
|
-
cause: error,
|
|
707
|
-
});
|
|
913
|
+
possibleFixes: apiErrorSuggestedFixes(details),
|
|
914
|
+
}
|
|
915
|
+
);
|
|
708
916
|
}
|
|
709
917
|
|
|
710
918
|
// change the case of the tool to camel case and apply default modifiers
|
|
711
|
-
|
|
919
|
+
const transformedTool = this.transformToolCases(tool);
|
|
920
|
+
if (transformedTool === undefined) {
|
|
921
|
+
// The tool exists; its schema is what could not be parsed. Reporting that
|
|
922
|
+
// as TOOL_NOT_FOUND makes a caller that treats the code as "no such tool"
|
|
923
|
+
// hide a real one.
|
|
924
|
+
throw new ComposioToolSchemaInvalidError(
|
|
925
|
+
`Tool with slug ${slug} has an unusable input schema`,
|
|
926
|
+
{ meta: { slug } }
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
let [modifiedTool] = await this.applyDefaultSchemaModifiers([transformedTool]);
|
|
712
930
|
// apply local modifiers if they are provided
|
|
713
931
|
if (options?.modifySchema) {
|
|
714
932
|
const modifier = options.modifySchema;
|
|
@@ -1153,16 +1371,40 @@ export class Tools<
|
|
|
1153
1371
|
const requestOptions: ComposioRequestOptions | undefined =
|
|
1154
1372
|
options?.signal != null ? { signal: options.signal } : undefined;
|
|
1155
1373
|
|
|
1156
|
-
const tool = await this.
|
|
1157
|
-
slug,
|
|
1158
|
-
{
|
|
1159
|
-
version: executeParams.version,
|
|
1160
|
-
},
|
|
1161
|
-
requestOptions
|
|
1162
|
-
);
|
|
1374
|
+
const tool = await this.getToolSchemaForExecute(slug, executeParams.version, requestOptions);
|
|
1163
1375
|
return this.executeWithTool(slug, executeParams, options, tool);
|
|
1164
1376
|
}
|
|
1165
1377
|
|
|
1378
|
+
/** The tool's schema for `execute()`, fetched only if no unexpired copy is cached. Failures aren't cached. */
|
|
1379
|
+
private async getToolSchemaForExecute(
|
|
1380
|
+
slug: string,
|
|
1381
|
+
version: string | undefined,
|
|
1382
|
+
requestOptions: ComposioRequestOptions | undefined
|
|
1383
|
+
): Promise<Tool> {
|
|
1384
|
+
const key = `${slug}\0${version ?? ''}`;
|
|
1385
|
+
const cached = this.executeToolSchemas.get(key);
|
|
1386
|
+
if (cached && cached.expiresAt > Date.now()) {
|
|
1387
|
+
return cached.tool;
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
const tool = await this.getRawComposioToolBySlug(slug, { version }, requestOptions);
|
|
1391
|
+
|
|
1392
|
+
const resolvedVersion =
|
|
1393
|
+
version ?? getToolkitVersion(tool.toolkit?.slug ?? 'unknown', this.toolkitVersions);
|
|
1394
|
+
const ttlMs =
|
|
1395
|
+
resolvedVersion === 'latest' ? LATEST_TOOL_SCHEMA_TTL_MS : PINNED_TOOL_SCHEMA_TTL_MS;
|
|
1396
|
+
// Re-insert so a refreshed entry counts as the newest.
|
|
1397
|
+
this.executeToolSchemas.delete(key);
|
|
1398
|
+
if (this.executeToolSchemas.size >= MAX_CACHED_TOOL_SCHEMAS) {
|
|
1399
|
+
const oldestKey = this.executeToolSchemas.keys().next().value;
|
|
1400
|
+
if (oldestKey !== undefined) {
|
|
1401
|
+
this.executeToolSchemas.delete(oldestKey);
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
this.executeToolSchemas.set(key, { tool, expiresAt: Date.now() + ttlMs });
|
|
1405
|
+
return tool;
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1166
1408
|
/**
|
|
1167
1409
|
* Executes a tool based on a tool router session.
|
|
1168
1410
|
*
|
|
@@ -1236,7 +1478,9 @@ export class Tools<
|
|
|
1236
1478
|
withoutRetries(requestOptions)
|
|
1237
1479
|
),
|
|
1238
1480
|
requestOptions?.signal
|
|
1239
|
-
)
|
|
1481
|
+
).catch((error: unknown) => {
|
|
1482
|
+
throw handleToolExecutionError(toolSlug, error as Error);
|
|
1483
|
+
});
|
|
1240
1484
|
|
|
1241
1485
|
const { data, error, logId, resultType, instantCharge } = transformExecuteResponse(
|
|
1242
1486
|
response,
|
package/src/models/Triggers.ts
CHANGED
|
@@ -451,12 +451,18 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
451
451
|
filters: TriggerSubscribeParams,
|
|
452
452
|
data: IncomingTriggerPayload
|
|
453
453
|
): boolean {
|
|
454
|
-
// Check if toolkits filter is provided and matches
|
|
454
|
+
// Check if toolkits filter is provided and matches.
|
|
455
|
+
// Payloads don't carry the toolkit slug, so `data.toolkitSlug` is the trigger slug's
|
|
456
|
+
// first `_` segment, which is wrong for toolkits whose slug contains an underscore
|
|
457
|
+
// (`ONE_DRIVE_FILE_CREATED_TRIGGER` gives `ONE`). Trigger slugs start with
|
|
458
|
+
// `<TOOLKIT>_`, so a filter also matches on that prefix.
|
|
459
|
+
const toolkitSlug = data.toolkitSlug.toLowerCase();
|
|
460
|
+
const triggerSlug = data.triggerSlug.toLowerCase();
|
|
455
461
|
if (
|
|
456
462
|
filters.toolkits?.length &&
|
|
457
463
|
!filters.toolkits
|
|
458
464
|
.map(toolkit => toolkit.toLowerCase())
|
|
459
|
-
.
|
|
465
|
+
.some(toolkit => toolkit === toolkitSlug || triggerSlug.startsWith(`${toolkit}_`))
|
|
460
466
|
) {
|
|
461
467
|
logger.debug(
|
|
462
468
|
'Trigger does not match toolkits filter',
|
|
@@ -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
|
// ────────────────────────────────────────────────────────────────
|