@composio/core 0.29.0 → 0.31.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 +23 -0
- package/dist/{CustomTool-Bd1KdWvo.mjs → CustomTool-9Vlb4XaS.mjs} +4 -7
- package/dist/{CustomTool-CMW-d2ZN.d.mts → CustomTool-Ds5aLDth.d.mts} +2 -4
- 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-D5UV5HXN.d.mts → composio-Ba89XGHL.d.mts} +310 -222
- package/dist/{customTool.types-B9fs34dv.d.mts → customTool.types-DHxXBU6E.d.mts} +205 -268
- package/dist/docs/error-consistency.md +3 -3
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +9 -0
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +1 -0
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +6 -11
- 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/mcp.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +2 -2
- package/dist/{errors-BK6Xc7Ia.mjs → errors-xC13uvaA.mjs} +56 -139
- package/dist/experimental/index.d.mts +16 -2
- 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 +37 -72
- package/dist/index.mjs +339 -254
- package/dist/{cancellation-BoJjs34Y.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-CaP2SytR.d.mts → types-DcdZy5Nc.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 +107 -30
- package/src/errors/apiErrorDetails.ts +40 -0
- package/src/models/AuthConfigs.ts +9 -0
- package/src/models/ConnectionRequest.ts +12 -4
- package/src/models/CustomToolkits.ts +11 -17
- package/src/models/Experimental.ts +2 -7
- package/src/models/Files.node.ts +68 -37
- package/src/models/MCP.ts +2 -2
- package/src/models/RemoteFile.ts +22 -16
- package/src/models/SessionContext.ts +6 -7
- package/src/models/ToolRouterSession.ts +16 -23
- package/src/models/Tools.ts +220 -22
- package/src/models/Triggers.ts +8 -2
- package/src/types/authConfigs.types.ts +14 -0
- package/src/types/customToolkits.types.ts +4 -9
- package/src/types/tool.types.ts +1 -1
- package/src/types/toolkit.types.ts +21 -0
- package/src/utils/cancellation.ts +5 -1
- package/src/utils/transformers/authConfigs.ts +6 -2
- package/src/utils/transformers/toolkits.ts +7 -0
- 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,
|
|
@@ -46,6 +47,7 @@ import {
|
|
|
46
47
|
ComposioToolFetchRateLimitError,
|
|
47
48
|
ComposioToolNotFoundError,
|
|
48
49
|
ComposioProviderNotDefinedError,
|
|
50
|
+
ComposioToolSchemaInvalidError,
|
|
49
51
|
ComposioToolVersionRequiredError,
|
|
50
52
|
} from '../errors/ToolErrors';
|
|
51
53
|
import { ValidationError } from '../errors/ValidationErrors';
|
|
@@ -53,6 +55,7 @@ import { telemetry } from '../telemetry/Telemetry';
|
|
|
53
55
|
import type { ComposioConfig } from '../composio';
|
|
54
56
|
import { getToolkitVersion } from '../utils/toolkitVersion';
|
|
55
57
|
import { handleToolExecutionError } from '../errors/ToolErrors';
|
|
58
|
+
import { apiErrorSuggestedFixes, withApiErrorMessage } from '../errors/apiErrorDetails';
|
|
56
59
|
import type { SessionExecuteParams } from '@composio/client/resources/tool-router/session';
|
|
57
60
|
import { CONFIG_DEFAULTS } from '../utils/config-defaults';
|
|
58
61
|
import { resolveEffectiveUploadAllowlist } from '../utils/fileDirs';
|
|
@@ -81,23 +84,121 @@ type RawToolParameters =
|
|
|
81
84
|
| ToolRetrieveResponse['input_parameters']
|
|
82
85
|
| ComposioToolListResponse['items'][0]['input_parameters'];
|
|
83
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
|
+
|
|
84
169
|
/**
|
|
85
170
|
* Normalize a raw `input_parameters` / `output_parameters` payload returned by
|
|
86
171
|
* the Composio API. Maps `null`, `undefined`, and empty `{}` — all of which
|
|
87
172
|
* mean "no declared schema" — to `undefined` so the strict `ParametersSchema`
|
|
88
|
-
* validator never sees them
|
|
89
|
-
*
|
|
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.
|
|
90
176
|
*
|
|
91
177
|
* MCP-backed toolkits (granola_mcp, apify_mcp, tavily_mcp, …) have no
|
|
92
178
|
* declared output schema and the API serializes that as `{}`, which would
|
|
93
179
|
* otherwise trip `ParametersSchema`. See
|
|
94
|
-
* 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.
|
|
95
183
|
*/
|
|
96
184
|
function normalizeRawToolParameters(
|
|
97
185
|
params: RawToolParameters | null | undefined
|
|
98
186
|
): RawToolParameters | undefined {
|
|
99
187
|
if (params == null || Object.keys(params).length === 0) return undefined;
|
|
100
|
-
|
|
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;
|
|
101
202
|
}
|
|
102
203
|
|
|
103
204
|
/** How long `execute()` reuses a schema fetched for `latest`, which can change at any release. */
|
|
@@ -132,6 +233,9 @@ export class Tools<
|
|
|
132
233
|
* Scoped per-instance so a fresh `Composio` starts with a clean slate.
|
|
133
234
|
*/
|
|
134
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
|
+
|
|
135
239
|
/**
|
|
136
240
|
* Schemas `execute()` already fetched, so repeated executions don't each spend a request.
|
|
137
241
|
* Holds what `getRawComposioToolBySlug` returned with no `modifySchema`, so a caller's schema
|
|
@@ -178,21 +282,79 @@ export class Tools<
|
|
|
178
282
|
* making them more consistent with JavaScript/TypeScript conventions.
|
|
179
283
|
*
|
|
180
284
|
* @param {ToolRetrieveResponse | ComposioToolListResponse['items'][0]} tool - The tool object to transform
|
|
181
|
-
* @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
|
|
182
287
|
*
|
|
183
288
|
* @private
|
|
184
289
|
*/
|
|
185
290
|
private transformToolCases(
|
|
186
291
|
tool: ToolRetrieveResponse | ComposioToolListResponse['items'][0]
|
|
187
|
-
): Tool {
|
|
188
|
-
|
|
292
|
+
): Tool | undefined {
|
|
293
|
+
const candidate = {
|
|
189
294
|
...tool,
|
|
190
295
|
inputParameters: normalizeRawToolParameters(tool.input_parameters),
|
|
191
296
|
outputParameters: normalizeRawToolParameters(tool.output_parameters),
|
|
192
297
|
availableVersions: tool.available_versions,
|
|
193
298
|
isDeprecated: tool.deprecated?.is_deprecated ?? false,
|
|
194
299
|
isNoAuth: tool.no_auth,
|
|
195
|
-
}
|
|
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
|
+
);
|
|
196
358
|
}
|
|
197
359
|
|
|
198
360
|
/**
|
|
@@ -555,7 +717,9 @@ export class Tools<
|
|
|
555
717
|
if (!tools) {
|
|
556
718
|
return [];
|
|
557
719
|
}
|
|
558
|
-
const caseTransformedTools = tools.items
|
|
720
|
+
const caseTransformedTools = tools.items
|
|
721
|
+
.map(tool => this.transformToolCases(tool))
|
|
722
|
+
.filter((tool): tool is Tool => tool !== undefined);
|
|
559
723
|
|
|
560
724
|
let modifiedTools = await this.applyDefaultSchemaModifiers(caseTransformedTools);
|
|
561
725
|
|
|
@@ -612,7 +776,11 @@ export class Tools<
|
|
|
612
776
|
() => this.client.toolRouter.session.tools(sessionId, sessionToolsParams, requestOptions),
|
|
613
777
|
requestOptions?.signal
|
|
614
778
|
);
|
|
615
|
-
tools.push(
|
|
779
|
+
tools.push(
|
|
780
|
+
...response.items
|
|
781
|
+
.map(tool => this.transformToolCases(tool))
|
|
782
|
+
.filter((tool): tool is Tool => tool !== undefined)
|
|
783
|
+
);
|
|
616
784
|
cursor = response.next_cursor;
|
|
617
785
|
} while (cursor);
|
|
618
786
|
|
|
@@ -676,7 +844,7 @@ export class Tools<
|
|
|
676
844
|
* );
|
|
677
845
|
*
|
|
678
846
|
* // Access tool properties
|
|
679
|
-
* const githubTool = await composio.tools.getRawComposioToolBySlug('
|
|
847
|
+
* const githubTool = await composio.tools.getRawComposioToolBySlug('GITHUB_CREATE_AN_ISSUE');
|
|
680
848
|
* console.log({
|
|
681
849
|
* slug: githubTool.slug,
|
|
682
850
|
* name: githubTool.name,
|
|
@@ -709,7 +877,10 @@ export class Tools<
|
|
|
709
877
|
}
|
|
710
878
|
if (isRateLimitResponse(error)) {
|
|
711
879
|
throw new ComposioToolFetchRateLimitError(
|
|
712
|
-
|
|
880
|
+
withApiErrorMessage(
|
|
881
|
+
`Rate limited while retrieving tool with slug ${slug}`,
|
|
882
|
+
error.details
|
|
883
|
+
),
|
|
713
884
|
error,
|
|
714
885
|
{ slug }
|
|
715
886
|
);
|
|
@@ -718,19 +889,44 @@ export class Tools<
|
|
|
718
889
|
// malformed one). Anything else (401, 5xx, network) is not "not found",
|
|
719
890
|
// so keep the client error reachable as `cause` under a generic error.
|
|
720
891
|
if (error instanceof APIError && (error.status === 404 || error.status === 400)) {
|
|
721
|
-
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
|
+
{
|
|
722
911
|
meta: { slug },
|
|
723
912
|
cause: error,
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
meta: { slug },
|
|
728
|
-
cause: error,
|
|
729
|
-
});
|
|
913
|
+
possibleFixes: apiErrorSuggestedFixes(details),
|
|
914
|
+
}
|
|
915
|
+
);
|
|
730
916
|
}
|
|
731
917
|
|
|
732
918
|
// change the case of the tool to camel case and apply default modifiers
|
|
733
|
-
|
|
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]);
|
|
734
930
|
// apply local modifiers if they are provided
|
|
735
931
|
if (options?.modifySchema) {
|
|
736
932
|
const modifier = options.modifySchema;
|
|
@@ -1282,7 +1478,9 @@ export class Tools<
|
|
|
1282
1478
|
withoutRetries(requestOptions)
|
|
1283
1479
|
),
|
|
1284
1480
|
requestOptions?.signal
|
|
1285
|
-
)
|
|
1481
|
+
).catch((error: unknown) => {
|
|
1482
|
+
throw handleToolExecutionError(toolSlug, error as Error);
|
|
1483
|
+
});
|
|
1286
1484
|
|
|
1287
1485
|
const { data, error, logId, resultType, instantCharge } = transformExecuteResponse(
|
|
1288
1486
|
response,
|
|
@@ -1346,7 +1544,7 @@ export class Tools<
|
|
|
1346
1544
|
*
|
|
1347
1545
|
* @example
|
|
1348
1546
|
* ```typescript
|
|
1349
|
-
* const { arguments: args, error } = await composio.tools.getInput('
|
|
1547
|
+
* const { arguments: args, error } = await composio.tools.getInput('GITHUB_CREATE_AN_ISSUE', {
|
|
1350
1548
|
* text: 'Open an issue in composiohq/composio titled "Docs typo" describing the broken link',
|
|
1351
1549
|
* version: '20250909_00',
|
|
1352
1550
|
* });
|
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',
|
|
@@ -78,6 +78,11 @@ export const CreateComposioManagedAuthConfigParamsSchema = z.object({
|
|
|
78
78
|
.optional(),
|
|
79
79
|
toolAccessConfig: AuthConfigCreationToolAccessConfigSchema.optional(),
|
|
80
80
|
isEnabledForToolRouter: z.boolean().optional(),
|
|
81
|
+
/**
|
|
82
|
+
* The Composio-managed app to use, as `composioManagedAuth[].managedAppId`
|
|
83
|
+
* from `composio.toolkits.get(slug)`. Omit to use the toolkit's default app.
|
|
84
|
+
*/
|
|
85
|
+
managedAppId: z.string().optional(),
|
|
81
86
|
});
|
|
82
87
|
|
|
83
88
|
/**
|
|
@@ -90,11 +95,19 @@ export const CreateAuthConfigParamsSchema = z.discriminatedUnion('type', [
|
|
|
90
95
|
|
|
91
96
|
export type CreateAuthConfigParams = z.infer<typeof CreateAuthConfigParamsSchema>;
|
|
92
97
|
|
|
98
|
+
/**
|
|
99
|
+
* The Composio-managed app an auth config uses, as
|
|
100
|
+
* `composioManagedAuth[].managedAppId` from `composio.toolkits.get(slug)`.
|
|
101
|
+
* `null` when the auth config is not linked to a managed app.
|
|
102
|
+
*/
|
|
103
|
+
const AuthConfigManagedAppIdSchema = z.string().nullable();
|
|
104
|
+
|
|
93
105
|
export const CreateAuthConfigResponseSchema = z.object({
|
|
94
106
|
id: z.string(),
|
|
95
107
|
authScheme: z.string(),
|
|
96
108
|
isComposioManaged: z.boolean(),
|
|
97
109
|
toolkit: z.string(),
|
|
110
|
+
managedAppId: AuthConfigManagedAppIdSchema,
|
|
98
111
|
});
|
|
99
112
|
export type CreateAuthConfigResponse = z.infer<typeof CreateAuthConfigResponseSchema>;
|
|
100
113
|
|
|
@@ -120,6 +133,7 @@ export const AuthConfigRetrieveResponseSchema = z.object({
|
|
|
120
133
|
createdAt: z.string().optional(),
|
|
121
134
|
lastUpdatedAt: z.string().optional(),
|
|
122
135
|
toolAccessConfig: AuthConfigToolAccessConfigSchema.optional(),
|
|
136
|
+
managedAppId: AuthConfigManagedAppIdSchema,
|
|
123
137
|
});
|
|
124
138
|
export type AuthConfigRetrieveResponse = z.infer<typeof AuthConfigRetrieveResponseSchema>;
|
|
125
139
|
|
|
@@ -8,7 +8,6 @@ export type CustomToolkitApiKeyField = z.infer<typeof CustomToolkitApiKeyFieldSc
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* How end users authenticate to a custom toolkit.
|
|
11
|
-
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
12
11
|
*/
|
|
13
12
|
export const CustomToolkitAuthSchemeSchema = z.discriminatedUnion('mode', [
|
|
14
13
|
z.object({ mode: z.literal('NO_AUTH') }),
|
|
@@ -50,8 +49,7 @@ const CustomToolkitLogoFileSchema = z.object({
|
|
|
50
49
|
export type CustomToolkitLogoFile = z.infer<typeof CustomToolkitLogoFileSchema>;
|
|
51
50
|
|
|
52
51
|
/**
|
|
53
|
-
* Params for `composio.
|
|
54
|
-
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
52
|
+
* Params for `composio.customToolkits.create()`.
|
|
55
53
|
*/
|
|
56
54
|
export const CustomToolkitCreateParamsSchema = z.object({
|
|
57
55
|
/** Human-readable toolkit name. */
|
|
@@ -90,8 +88,7 @@ export const CustomToolkitCreateResponseSchema = z.object({
|
|
|
90
88
|
export type CustomToolkitCreateResponse = z.infer<typeof CustomToolkitCreateResponseSchema>;
|
|
91
89
|
|
|
92
90
|
/**
|
|
93
|
-
* Params for `composio.
|
|
94
|
-
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
91
|
+
* Params for `composio.customToolkits.update()`.
|
|
95
92
|
*/
|
|
96
93
|
export const CustomToolkitUpdateParamsSchema = z
|
|
97
94
|
.object({
|
|
@@ -117,8 +114,7 @@ export const CustomToolkitUpdateResponseSchema = z.object({
|
|
|
117
114
|
export type CustomToolkitUpdateResponse = z.infer<typeof CustomToolkitUpdateResponseSchema>;
|
|
118
115
|
|
|
119
116
|
/**
|
|
120
|
-
* Params for `composio.
|
|
121
|
-
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
117
|
+
* Params for `composio.customToolkits.upsert()`.
|
|
122
118
|
*
|
|
123
119
|
* @deprecated Use `CustomToolkitCreateParams` with `create()`.
|
|
124
120
|
*/
|
|
@@ -152,8 +148,7 @@ export const CustomToolkitUpsertResponseSchema = z.object({
|
|
|
152
148
|
export type CustomToolkitUpsertResponse = z.infer<typeof CustomToolkitUpsertResponseSchema>;
|
|
153
149
|
|
|
154
150
|
/**
|
|
155
|
-
* Params for `composio.
|
|
156
|
-
* **Experimental — custom toolkits are in pilot; shape may change.**
|
|
151
|
+
* Params for `composio.customToolkits.sync()`.
|
|
157
152
|
*/
|
|
158
153
|
export const CustomToolkitSyncParamsSchema = z.object({
|
|
159
154
|
/** Connected account to use when fetching the remote tool definitions. */
|
package/src/types/tool.types.ts
CHANGED
|
@@ -459,7 +459,7 @@ export type ToolRetrievalOptions = {
|
|
|
459
459
|
*
|
|
460
460
|
* @example Override with specific version
|
|
461
461
|
* ```typescript
|
|
462
|
-
* const tool = await tools.getRawComposioToolBySlug('
|
|
462
|
+
* const tool = await tools.getRawComposioToolBySlug('GITHUB_CREATE_AN_ISSUE', {
|
|
463
463
|
* version: '20250909_00'
|
|
464
464
|
* });
|
|
465
465
|
* ```
|
|
@@ -125,12 +125,32 @@ export const ToolkitAuthConfigDetailsSchema = z.object({
|
|
|
125
125
|
.optional(),
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
+
const ToolkitManagedAuthScopesSchema = z.object({
|
|
129
|
+
available: z.array(z.string()),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A Composio-managed app for a toolkit. Pass `managedAppId` to
|
|
134
|
+
* `composio.authConfigs.create` to create an auth config on this app.
|
|
135
|
+
*/
|
|
136
|
+
export const ToolkitComposioManagedAuthSchema = z.object({
|
|
137
|
+
managedAppId: z.string(),
|
|
138
|
+
/** Whether this is the app used when `managedAppId` is omitted. */
|
|
139
|
+
isDefault: z.boolean(),
|
|
140
|
+
mode: z.string(),
|
|
141
|
+
scopes: ToolkitManagedAuthScopesSchema,
|
|
142
|
+
/** Present only for Slack. */
|
|
143
|
+
userScopes: ToolkitManagedAuthScopesSchema.optional(),
|
|
144
|
+
});
|
|
145
|
+
|
|
128
146
|
export const ToolkitRetrieveResponseSchema = z.object({
|
|
129
147
|
name: z.string(),
|
|
130
148
|
slug: z.string(),
|
|
131
149
|
meta: ToolKitMetaSchema,
|
|
132
150
|
isLocalToolkit: z.boolean(),
|
|
133
151
|
composioManagedAuthSchemes: z.array(z.string()).optional(),
|
|
152
|
+
/** One entry per Composio-managed app, the default first. */
|
|
153
|
+
composioManagedAuth: z.array(ToolkitComposioManagedAuthSchema).optional(),
|
|
134
154
|
authConfigDetails: z.array(ToolkitAuthConfigDetailsSchema).optional(),
|
|
135
155
|
baseUrl: z.string().optional(),
|
|
136
156
|
getCurrentUserEndpoint: z.string().optional(),
|
|
@@ -139,6 +159,7 @@ export const ToolkitRetrieveResponseSchema = z.object({
|
|
|
139
159
|
|
|
140
160
|
export type ToolkitAuthField = z.infer<typeof ToolkitAuthFieldSchema>;
|
|
141
161
|
export type ToolkitAuthConfigDetails = z.infer<typeof ToolkitAuthConfigDetailsSchema>;
|
|
162
|
+
export type ToolkitComposioManagedAuth = z.infer<typeof ToolkitComposioManagedAuthSchema>;
|
|
142
163
|
export type ToolkitRetrieveResponse = z.infer<typeof ToolkitRetrieveResponseSchema>;
|
|
143
164
|
|
|
144
165
|
/**
|
|
@@ -8,7 +8,11 @@ export async function withCancellation<T>(
|
|
|
8
8
|
try {
|
|
9
9
|
return await call();
|
|
10
10
|
} catch (error) {
|
|
11
|
-
|
|
11
|
+
// A raw `fetch` rejects with the signal's reason, so an `AbortSignal.timeout()`
|
|
12
|
+
// surfaces as a `TimeoutError` (or a custom reason passed to `abort()`) that is
|
|
13
|
+
// not abort-shaped. Matching the reason itself still excludes an unrelated
|
|
14
|
+
// failure that merely coincides with a late abort.
|
|
15
|
+
if (signal?.aborted && (isRequestAbortError(error) || error === signal.reason)) {
|
|
12
16
|
const underlyingMessage = error instanceof Error ? error.message : '';
|
|
13
17
|
const message = underlyingMessage
|
|
14
18
|
? `Request was cancelled by the caller: ${underlyingMessage}`
|
|
@@ -15,19 +15,21 @@ import {
|
|
|
15
15
|
} from '@composio/client/resources/auth-configs';
|
|
16
16
|
import { transform } from '../transform';
|
|
17
17
|
|
|
18
|
+
type RawAuthConfig = RawAuthConfigRetrieveResponse | RawAuthConfigListResponse['items'][number];
|
|
19
|
+
|
|
18
20
|
/**
|
|
19
21
|
* Transforms an auth config response from API format to SDK format.
|
|
20
22
|
*
|
|
21
23
|
* This method converts property names from snake_case to camelCase and reorganizes
|
|
22
24
|
* the data structure to match the SDK's standardized format for auth configurations.
|
|
23
25
|
*
|
|
24
|
-
* @param {
|
|
26
|
+
* @param {RawAuthConfig} authConfig - The raw retrieve response or list item to transform
|
|
25
27
|
* @returns {AuthConfigRetrieveResponse} The transformed auth config data
|
|
26
28
|
*
|
|
27
29
|
* @private
|
|
28
30
|
*/
|
|
29
31
|
export function transformAuthConfigRetrieveResponse(
|
|
30
|
-
authConfig:
|
|
32
|
+
authConfig: RawAuthConfig
|
|
31
33
|
): AuthConfigRetrieveResponse {
|
|
32
34
|
return transform(authConfig)
|
|
33
35
|
.with(AuthConfigRetrieveResponseSchema)
|
|
@@ -56,6 +58,7 @@ export function transformAuthConfigRetrieveResponse(
|
|
|
56
58
|
authConfig.tool_access_config.tools_for_connected_account_creation,
|
|
57
59
|
}
|
|
58
60
|
: undefined,
|
|
61
|
+
managedAppId: authConfig.managed_app_id,
|
|
59
62
|
}));
|
|
60
63
|
}
|
|
61
64
|
|
|
@@ -103,5 +106,6 @@ export function transformCreateAuthConfigResponse(
|
|
|
103
106
|
authScheme: response.auth_config.auth_scheme,
|
|
104
107
|
isComposioManaged: response.auth_config.is_composio_managed,
|
|
105
108
|
toolkit: response.toolkit.slug,
|
|
109
|
+
managedAppId: response.auth_config.managed_app_id,
|
|
106
110
|
}));
|
|
107
111
|
}
|
|
@@ -156,6 +156,13 @@ export const transformToolkitRetrieveResponse = (
|
|
|
156
156
|
},
|
|
157
157
|
isLocalToolkit: response.is_local_toolkit,
|
|
158
158
|
composioManagedAuthSchemes: response.composio_managed_auth_schemes,
|
|
159
|
+
composioManagedAuth: response.composio_managed_auth?.map(app => ({
|
|
160
|
+
managedAppId: app.managed_app_id,
|
|
161
|
+
isDefault: app.is_default,
|
|
162
|
+
mode: app.mode,
|
|
163
|
+
scopes: app.scopes,
|
|
164
|
+
...(app.user_scopes != null && { userScopes: app.user_scopes }),
|
|
165
|
+
})),
|
|
159
166
|
authConfigDetails: response.auth_config_details?.map(authConfig => ({
|
|
160
167
|
name: authConfig.name,
|
|
161
168
|
mode: authConfig.mode,
|