@composio/core 0.12.0 → 0.13.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/dist/BaseProvider-Brb3o86-.d.mts +29425 -0
- package/dist/{CustomTool-DEB4BQPl.mjs → CustomTool-D9qwyMrv.mjs} +1 -1
- package/dist/{CustomTool-DH18rVQu.d.mts → CustomTool-Dmi6ti3I.d.mts} +1 -1
- package/dist/CustomTool-DrJpOhY2.d.mts +74 -0
- package/dist/{composio-CHnEggnv.d.mts → composio-DHIKRdeG.d.mts} +253 -37
- package/dist/composio-vMwhASRc.d.mts +5698 -0
- package/dist/{customTool.types-DpIdOJjL.d.mts → customTool.types-CKH2R2ia.d.mts} +344 -25
- package/dist/customTool.types-DXin7Cfc.d.mts +2773 -0
- package/dist/docs/error-consistency.md +97 -0
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +306 -0
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +205 -0
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +488 -0
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +94 -0
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +67 -0
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +304 -0
- package/dist/docs/reference/sdk-reference/typescript/meta.json +17 -0
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +107 -0
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +163 -0
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +229 -0
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +131 -0
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +169 -0
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +453 -0
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +434 -0
- package/dist/{errors-D5f4pfvI.mjs → errors-DSIlYfl5.mjs} +2 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/index.d.mts +27 -4
- package/dist/index.mjs +423 -123
- package/dist/{jsonSchema-daqF3S3d.mjs → jsonSchema-CFKdONpP.mjs} +1 -1
- package/dist/{types-CaI5Z4PA.d.mts → types-D4Id3wXA.d.mts} +1 -1
- package/dist/types-qTbYYBJw.d.mts +12 -0
- 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.mjs +2 -2
- package/docs/error-consistency.md +97 -0
- package/package.json +4 -3
- package/src/composio.ts +509 -0
- package/src/errors/AuthConfigErrors.ts +23 -0
- package/src/errors/ComposioError.ts +408 -0
- package/src/errors/ConnectedAccountsErrors.ts +158 -0
- package/src/errors/ConnectionRequestErrors.ts +32 -0
- package/src/errors/FileModifierErrors.ts +100 -0
- package/src/errors/PusherErrors.ts +28 -0
- package/src/errors/RemoteFileErrors.ts +62 -0
- package/src/errors/SDKErrors.ts +92 -0
- package/src/errors/ToolErrors.ts +244 -0
- package/src/errors/ToolkitErrors.ts +39 -0
- package/src/errors/TriggerErrors.ts +120 -0
- package/src/errors/ValidationErrors.ts +99 -0
- package/src/errors/index.ts +41 -0
- package/src/experimental/index.ts +28 -0
- package/src/index.ts +64 -0
- package/src/lib/toolRouterConstants.ts +1 -0
- package/src/lib/toolRouterParams.ts +306 -0
- package/src/models/AuthConfigs.ts +398 -0
- package/src/models/AuthScheme.ts +206 -0
- package/src/models/ConnectedAccounts.ts +735 -0
- package/src/models/ConnectionRequest.ts +150 -0
- package/src/models/CustomTool.ts +676 -0
- package/src/models/Experimental.ts +202 -0
- package/src/models/Files.node.ts +93 -0
- package/src/models/Files.workerd.ts +49 -0
- package/src/models/MCP.ts +478 -0
- package/src/models/RemoteFile.ts +172 -0
- package/src/models/SessionContext.ts +147 -0
- package/src/models/Sessions.ts +21 -0
- package/src/models/ToolRouter.ts +391 -0
- package/src/models/ToolRouterSession.ts +827 -0
- package/src/models/ToolRouterSessionFileMount.ts +389 -0
- package/src/models/Toolkits.ts +412 -0
- package/src/models/Tools.ts +1260 -0
- package/src/models/Triggers.ts +1381 -0
- package/src/models/customToolExecution.ts +118 -0
- package/src/models/inlineCustomToolsPayload.ts +17 -0
- package/src/models/proxyParamsTransform.ts +26 -0
- package/src/provider/BaseProvider.ts +138 -0
- package/src/provider/ComposioProvider.ts +29 -0
- package/src/provider/OpenAIProvider.ts +547 -0
- package/src/services/internal/InternalService.ts +50 -0
- package/src/services/internal/InternalService.types.ts +14 -0
- package/src/services/pusher/Pusher.ts +230 -0
- package/src/services/telemetry/TelemetryService.ts +48 -0
- package/src/services/telemetry/TelemetryService.types.ts +67 -0
- package/src/telemetry/BatchProcessor.ts +77 -0
- package/src/telemetry/README.md +123 -0
- package/src/telemetry/Telemetry.ts +356 -0
- package/src/types/ToolRouterSessionFilesMount.types.ts +96 -0
- package/src/types/authConfigs.types.ts +174 -0
- package/src/types/composio.types.ts +1 -0
- package/src/types/connectedAccountAuthStates.types.ts +852 -0
- package/src/types/connectedAccounts.types.ts +395 -0
- package/src/types/connectionRequest.types.ts +16 -0
- package/src/types/customTool.types.ts +261 -0
- package/src/types/files.types.ts +15 -0
- package/src/types/mcp.experimental.types.ts +163 -0
- package/src/types/mcp.types.ts +362 -0
- package/src/types/modifiers.types.ts +663 -0
- package/src/types/org.types.ts +0 -0
- package/src/types/provider.types.ts +41 -0
- package/src/types/pusher.types.ts +18 -0
- package/src/types/requestOptions.types.ts +62 -0
- package/src/types/telemetry.types.ts +89 -0
- package/src/types/tool.types.ts +408 -0
- package/src/types/toolRouter.types.ts +761 -0
- package/src/types/toolkit.types.ts +130 -0
- package/src/types/triggers.types.ts +401 -0
- package/src/types/webhookEvents.types.ts +219 -0
- package/src/utils/buffer.ts +30 -0
- package/src/utils/cancellation.ts +22 -0
- package/src/utils/config-defaults/ConfigDefaults.node.ts +7 -0
- package/src/utils/config-defaults/ConfigDefaults.workerd.ts +10 -0
- package/src/utils/config-defaults/index.ts +1 -0
- package/src/utils/config-defaults/types.ts +14 -0
- package/src/utils/constants.ts +22 -0
- package/src/utils/crypto.ts +34 -0
- package/src/utils/env.ts +34 -0
- package/src/utils/fileDirs.ts +81 -0
- package/src/utils/fileUtils.node.ts +458 -0
- package/src/utils/json-schema.ts +1 -0
- package/src/utils/jsonSchema.ts +355 -0
- package/src/utils/logger.ts +99 -0
- package/src/utils/mime.ts +75 -0
- package/src/utils/modifiers/FileToolModifier.node.ts +477 -0
- package/src/utils/modifiers/FileToolModifier.utils.neutral.ts +132 -0
- package/src/utils/modifiers/FileToolModifier.workerd.ts +51 -0
- package/src/utils/pagination.ts +73 -0
- package/src/utils/pusher.ts +286 -0
- package/src/utils/schemaPropertyKeys.ts +433 -0
- package/src/utils/sdk.ts +110 -0
- package/src/utils/sensitiveFileUploadPaths.node.ts +105 -0
- package/src/utils/session.ts +114 -0
- package/src/utils/toolArguments.ts +73 -0
- package/src/utils/toolkitVersion.ts +26 -0
- package/src/utils/transform.ts +42 -0
- package/src/utils/transformers/authConfigs.ts +107 -0
- package/src/utils/transformers/connectedAccounts.ts +119 -0
- package/src/utils/transformers/mcp.ts +164 -0
- package/src/utils/transformers/toolRouterResponseTransform.ts +160 -0
- package/src/utils/transformers/toolkits.ts +100 -0
- package/src/utils/transformers/triggers.ts +118 -0
- package/src/utils/uploadDirAllowlist.node.ts +178 -0
- package/src/utils/uuid.ts +7 -0
- package/src/utils/version.ts +58 -0
- package/src/utils/zodSchema.ts +90 -0
|
@@ -0,0 +1,1260 @@
|
|
|
1
|
+
import ComposioClient from '@composio/client';
|
|
2
|
+
import { FileToolModifier } from '#file_tool_modifier';
|
|
3
|
+
import {
|
|
4
|
+
Tool,
|
|
5
|
+
ToolExecuteParams,
|
|
6
|
+
ToolListParamsSchema,
|
|
7
|
+
ToolExecuteResponse,
|
|
8
|
+
ToolList,
|
|
9
|
+
ToolSchema,
|
|
10
|
+
ToolListParams,
|
|
11
|
+
ToolExecuteResponseSchema,
|
|
12
|
+
ToolProxyParamsSchema,
|
|
13
|
+
ToolProxyParams,
|
|
14
|
+
ToolExecuteParamsSchema,
|
|
15
|
+
ToolkitVersionParam,
|
|
16
|
+
SchemaModifierOptions,
|
|
17
|
+
ToolRetrievalOptions,
|
|
18
|
+
ToolExecuteMetaParams,
|
|
19
|
+
ToolExecuteMetaParamsSchema,
|
|
20
|
+
} from '../types/tool.types';
|
|
21
|
+
import {
|
|
22
|
+
ToolGetInputParams,
|
|
23
|
+
ToolGetInputResponse,
|
|
24
|
+
ToolProxyParams as ComposioToolProxyParams,
|
|
25
|
+
ToolProxyResponse,
|
|
26
|
+
ToolRetrieveEnumResponse,
|
|
27
|
+
ToolRetrieveResponse,
|
|
28
|
+
ToolListResponse as ComposioToolListResponse,
|
|
29
|
+
ToolExecuteResponse as ComposioToolExecuteResponse,
|
|
30
|
+
ToolListParams as ComposioToolListParams,
|
|
31
|
+
ToolExecuteParams as ComposioToolExecuteParams,
|
|
32
|
+
} from '@composio/client/resources/tools';
|
|
33
|
+
import {
|
|
34
|
+
afterExecuteModifier,
|
|
35
|
+
ExecuteToolModifiers,
|
|
36
|
+
SessionExecuteMetaModifiers,
|
|
37
|
+
ProviderOptions,
|
|
38
|
+
TransformToolSchemaModifier,
|
|
39
|
+
} from '../types/modifiers.types';
|
|
40
|
+
import type { BaseComposioProvider } from '../provider/BaseProvider';
|
|
41
|
+
import logger from '../utils/logger';
|
|
42
|
+
import { ExecuteToolFn, GlobalExecuteToolFn } from '../types/provider.types';
|
|
43
|
+
import {
|
|
44
|
+
ComposioInvalidModifierError,
|
|
45
|
+
ComposioToolNotFoundError,
|
|
46
|
+
ComposioProviderNotDefinedError,
|
|
47
|
+
ComposioToolVersionRequiredError,
|
|
48
|
+
} from '../errors/ToolErrors';
|
|
49
|
+
import { ValidationError } from '../errors/ValidationErrors';
|
|
50
|
+
import { telemetry } from '../telemetry/Telemetry';
|
|
51
|
+
import type { ComposioConfig } from '../composio';
|
|
52
|
+
import { getToolkitVersion } from '../utils/toolkitVersion';
|
|
53
|
+
import { handleToolExecutionError } from '../errors/ToolErrors';
|
|
54
|
+
import type { SessionExecuteParams } from '@composio/client/resources/tool-router/session/session.mjs';
|
|
55
|
+
import { CONFIG_DEFAULTS } from '../utils/config-defaults';
|
|
56
|
+
import { resolveEffectiveUploadAllowlist } from '../utils/fileDirs';
|
|
57
|
+
import { schemaHasFileUploadable } from '../utils/modifiers/FileToolModifier.utils.neutral';
|
|
58
|
+
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
59
|
+
import { withCancellation } from '../utils/cancellation';
|
|
60
|
+
import { ComposioRequestCancelledError } from '../errors/SDKErrors';
|
|
61
|
+
|
|
62
|
+
const TOOL_ROUTER_SESSION_TOOLS_PAGE_LIMIT = 500;
|
|
63
|
+
|
|
64
|
+
type ToolRouterSessionExecuteOptions = {
|
|
65
|
+
experimental?: SessionExecuteParams.Experimental;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
type RawToolParameters =
|
|
69
|
+
| ToolRetrieveResponse['input_parameters']
|
|
70
|
+
| ComposioToolListResponse['items'][0]['input_parameters'];
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Normalize a raw `input_parameters` / `output_parameters` payload returned by
|
|
74
|
+
* the Composio API. Maps `null`, `undefined`, and empty `{}` — all of which
|
|
75
|
+
* mean "no declared schema" — to `undefined` so the strict `ParametersSchema`
|
|
76
|
+
* validator never sees them. Non-empty objects pass through unchanged and
|
|
77
|
+
* remain subject to strict Zod validation.
|
|
78
|
+
*
|
|
79
|
+
* MCP-backed toolkits (granola_mcp, apify_mcp, tavily_mcp, …) have no
|
|
80
|
+
* declared output schema and the API serializes that as `{}`, which would
|
|
81
|
+
* otherwise trip `ParametersSchema`. See
|
|
82
|
+
* https://github.com/ComposioHQ/composio/issues/3354.
|
|
83
|
+
*/
|
|
84
|
+
function normalizeRawToolParameters(
|
|
85
|
+
params: RawToolParameters | null | undefined
|
|
86
|
+
): RawToolParameters | undefined {
|
|
87
|
+
if (params == null || Object.keys(params).length === 0) return undefined;
|
|
88
|
+
return params;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* This class is used to manage tools in the Composio SDK.
|
|
93
|
+
* It provides methods to list, get, and execute tools.
|
|
94
|
+
*/
|
|
95
|
+
export class Tools<
|
|
96
|
+
TToolCollection,
|
|
97
|
+
TTool,
|
|
98
|
+
TProvider extends BaseComposioProvider<TToolCollection, TTool, unknown>,
|
|
99
|
+
> {
|
|
100
|
+
private client: ComposioClient;
|
|
101
|
+
private provider: TProvider;
|
|
102
|
+
private autoUploadDownloadFiles: boolean;
|
|
103
|
+
private toolkitVersions: ToolkitVersionParam;
|
|
104
|
+
private fileUploadPathOptions: {
|
|
105
|
+
sensitiveFileUploadProtection?: boolean;
|
|
106
|
+
fileUploadPathDenySegments?: string[];
|
|
107
|
+
fileUploadAllowlist?: string[];
|
|
108
|
+
fileDownloadDir?: string;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Tracks tool slugs we've already warned about to avoid spamming the log when
|
|
112
|
+
* the same file-input tool is executed repeatedly while auto-upload is off.
|
|
113
|
+
* Scoped per-instance so a fresh `Composio` starts with a clean slate.
|
|
114
|
+
*/
|
|
115
|
+
private readonly warnedAutoUploadDisabledForTool = new Set<string>();
|
|
116
|
+
|
|
117
|
+
constructor(client: ComposioClient, config?: ComposioConfig<TProvider>) {
|
|
118
|
+
if (!client) {
|
|
119
|
+
throw new Error('ComposioClient is required');
|
|
120
|
+
}
|
|
121
|
+
if (!config?.provider) {
|
|
122
|
+
throw new ComposioProviderNotDefinedError('Provider not passed into Tools instance');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.client = client;
|
|
126
|
+
this.provider = config.provider;
|
|
127
|
+
this.autoUploadDownloadFiles = config?.dangerouslyAllowAutoUploadDownloadFiles === true;
|
|
128
|
+
this.toolkitVersions = config?.toolkitVersions ?? CONFIG_DEFAULTS.toolkitVersions;
|
|
129
|
+
this.fileUploadPathOptions = {
|
|
130
|
+
sensitiveFileUploadProtection: config?.sensitiveFileUploadProtection,
|
|
131
|
+
fileUploadPathDenySegments: config?.fileUploadPathDenySegments,
|
|
132
|
+
// The allowlist is only enforced during automatic upload (see
|
|
133
|
+
// FileToolModifier). Manual `composio.files.upload()` calls don't see it.
|
|
134
|
+
fileUploadAllowlist: this.autoUploadDownloadFiles
|
|
135
|
+
? resolveEffectiveUploadAllowlist(config?.fileUploadDirs)
|
|
136
|
+
: undefined,
|
|
137
|
+
fileDownloadDir: config?.fileDownloadDir,
|
|
138
|
+
};
|
|
139
|
+
// Bind the execute method to ensure correct 'this' context
|
|
140
|
+
this.execute = this.execute.bind(this);
|
|
141
|
+
// Set the execute method for the provider.
|
|
142
|
+
this.provider._setExecuteToolFn(this.createExecuteFnForProviders());
|
|
143
|
+
this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
|
|
144
|
+
this.getRawComposioTools = this.getRawComposioTools.bind(this);
|
|
145
|
+
|
|
146
|
+
telemetry.instrument(this, 'Tools');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Transforms tool data from snake_case API format to camelCase for internal SDK use.
|
|
151
|
+
*
|
|
152
|
+
* This method standardizes the property naming convention for tools retrieved from the Composio API,
|
|
153
|
+
* making them more consistent with JavaScript/TypeScript conventions.
|
|
154
|
+
*
|
|
155
|
+
* @param {ToolRetrieveResponse | ComposioToolListResponse['items'][0]} tool - The tool object to transform
|
|
156
|
+
* @returns {Tool} The transformed tool with camelCase properties
|
|
157
|
+
*
|
|
158
|
+
* @private
|
|
159
|
+
*/
|
|
160
|
+
private transformToolCases(
|
|
161
|
+
tool: ToolRetrieveResponse | ComposioToolListResponse['items'][0]
|
|
162
|
+
): Tool {
|
|
163
|
+
return ToolSchema.parse({
|
|
164
|
+
...tool,
|
|
165
|
+
inputParameters: normalizeRawToolParameters(tool.input_parameters),
|
|
166
|
+
outputParameters: normalizeRawToolParameters(tool.output_parameters),
|
|
167
|
+
availableVersions: tool.available_versions,
|
|
168
|
+
isDeprecated: tool.deprecated?.is_deprecated ?? false,
|
|
169
|
+
isNoAuth: tool.no_auth,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Transforms tool execution response from snake_case API format to camelCase.
|
|
175
|
+
*
|
|
176
|
+
* This method converts the response received from the Composio API to a standardized format
|
|
177
|
+
* with consistent property naming that follows JavaScript/TypeScript conventions.
|
|
178
|
+
*
|
|
179
|
+
* @param {ComposioToolExecuteResponse} response - The raw API response to transform
|
|
180
|
+
* @returns {ToolExecuteResponse} The transformed response with camelCase properties
|
|
181
|
+
*
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
private transformToolExecuteResponse(response: ComposioToolExecuteResponse): ToolExecuteResponse {
|
|
185
|
+
return ToolExecuteResponseSchema.parse({
|
|
186
|
+
data: response.data,
|
|
187
|
+
error: response.error,
|
|
188
|
+
successful: response.successful,
|
|
189
|
+
logId: response.log_id,
|
|
190
|
+
sessionInfo: response.session_info,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Applies the default schema modifiers to the tools.
|
|
196
|
+
*
|
|
197
|
+
* The `file_uploadable` transform (collapsing the backend's internal
|
|
198
|
+
* `{ name, mimetype, s3key }` staging shape to `{ type: 'string',
|
|
199
|
+
* format: 'path' }`) is **gated on `dangerouslyAllowAutoUploadDownloadFiles`**
|
|
200
|
+
* — the collapsed shape is a promise that the SDK will stage local paths
|
|
201
|
+
* on your behalf at execute time, and that's only true when the flag is on.
|
|
202
|
+
*
|
|
203
|
+
* When the flag is off, the raw schema is returned unchanged; callers are
|
|
204
|
+
* expected to stage files themselves via `composio.files.upload()` and pass
|
|
205
|
+
* the resulting descriptor into `tools.execute`. If an LLM ends up calling
|
|
206
|
+
* a file-uploadable tool in this mode, the execute path emits a one-shot
|
|
207
|
+
* warning per tool slug (see `applyBeforeExecuteModifiers`).
|
|
208
|
+
*
|
|
209
|
+
* @param tools - The tools to apply the default schema modifiers to
|
|
210
|
+
* @returns The tools with the default schema modifiers applied
|
|
211
|
+
*/
|
|
212
|
+
private async applyDefaultSchemaModifiers(tools: Tool[]): Promise<Tool[]> {
|
|
213
|
+
if (!this.autoUploadDownloadFiles) {
|
|
214
|
+
return tools;
|
|
215
|
+
}
|
|
216
|
+
const fileToolModifier = new FileToolModifier(this.client, this.fileUploadPathOptions);
|
|
217
|
+
return await Promise.all(tools.map(tool => fileToolModifier.modifyToolSchema(tool)));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Applies the before execute modifiers to the tool execution params
|
|
222
|
+
* @param options.toolSlug - The slug of the tool
|
|
223
|
+
* @param options.toolkitSlug - The slug of the toolkit
|
|
224
|
+
* @param options.params - The params of the tool execution
|
|
225
|
+
* @param modifier - The modifier to apply
|
|
226
|
+
* @returns The modified params
|
|
227
|
+
*/
|
|
228
|
+
private async applyBeforeExecuteModifiers(
|
|
229
|
+
tool: Tool,
|
|
230
|
+
{
|
|
231
|
+
toolSlug,
|
|
232
|
+
toolkitSlug,
|
|
233
|
+
params,
|
|
234
|
+
}: {
|
|
235
|
+
toolSlug: string;
|
|
236
|
+
toolkitSlug: string;
|
|
237
|
+
params: ToolExecuteParams;
|
|
238
|
+
},
|
|
239
|
+
modifiers?: ExecuteToolModifiers,
|
|
240
|
+
requestOptions?: ComposioRequestOptions
|
|
241
|
+
): Promise<ToolExecuteParams> {
|
|
242
|
+
if (requestOptions?.signal?.aborted) {
|
|
243
|
+
throw new ComposioRequestCancelledError();
|
|
244
|
+
}
|
|
245
|
+
let modifiedParams = params;
|
|
246
|
+
// if auto upload download files is enabled, upload the files to the Composio API
|
|
247
|
+
if (this.autoUploadDownloadFiles) {
|
|
248
|
+
const fileToolModifier = new FileToolModifier(this.client, {
|
|
249
|
+
...this.fileUploadPathOptions,
|
|
250
|
+
beforeFileUpload: modifiers?.beforeFileUpload,
|
|
251
|
+
});
|
|
252
|
+
modifiedParams = await fileToolModifier.fileUploadModifier(tool, {
|
|
253
|
+
toolSlug,
|
|
254
|
+
toolkitSlug,
|
|
255
|
+
params: modifiedParams,
|
|
256
|
+
signal: requestOptions?.signal,
|
|
257
|
+
});
|
|
258
|
+
if (requestOptions?.signal?.aborted) {
|
|
259
|
+
throw new ComposioRequestCancelledError();
|
|
260
|
+
}
|
|
261
|
+
} else if (
|
|
262
|
+
schemaHasFileUploadable(tool.inputParameters) &&
|
|
263
|
+
!this.warnedAutoUploadDisabledForTool.has(toolSlug)
|
|
264
|
+
) {
|
|
265
|
+
// With auto-upload off, the raw `{ name, mimetype, s3key }` shape is
|
|
266
|
+
// what the LLM / caller sees on `tool.inputParameters`. LLMs can't
|
|
267
|
+
// produce a valid `s3key` and will hallucinate one, which then fails
|
|
268
|
+
// at the staging-lookup step on the backend. Nudge the caller toward
|
|
269
|
+
// manual staging or opting into auto-upload.
|
|
270
|
+
this.warnedAutoUploadDisabledForTool.add(toolSlug);
|
|
271
|
+
logger.warn(
|
|
272
|
+
`Tool "${toolSlug}" (toolkit "${toolkitSlug}") has a file-uploadable input, but ` +
|
|
273
|
+
`\`dangerouslyAllowAutoUploadDownloadFiles\` is disabled. The SDK will forward ` +
|
|
274
|
+
`the file argument as-is; if it isn't already a staged ` +
|
|
275
|
+
`{ name, mimetype, s3key } descriptor, the backend will reject the call. Either:\n` +
|
|
276
|
+
` 1) Stage the file yourself: \`const f = await composio.files.upload({ file, toolSlug, toolkitSlug }); ` +
|
|
277
|
+
`await composio.tools.execute('${toolSlug}', { userId, arguments: { <fileField>: f } })\`, or\n` +
|
|
278
|
+
` 2) Enable auto-upload with a scoped allowlist: ` +
|
|
279
|
+
`\`new Composio({ dangerouslyAllowAutoUploadDownloadFiles: true, fileUploadDirs: ['/safe/dir'] })\`.`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
// apply the before execute modifiers
|
|
283
|
+
if (modifiers?.beforeExecute) {
|
|
284
|
+
if (typeof modifiers.beforeExecute === 'function') {
|
|
285
|
+
modifiedParams = await modifiers.beforeExecute({
|
|
286
|
+
toolSlug,
|
|
287
|
+
toolkitSlug,
|
|
288
|
+
params: modifiedParams,
|
|
289
|
+
});
|
|
290
|
+
if (requestOptions?.signal?.aborted) {
|
|
291
|
+
throw new ComposioRequestCancelledError();
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
throw new ComposioInvalidModifierError('Invalid beforeExecute modifier. Not a function.');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return modifiedParams;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Applies the after execute modifiers to the tool execution result
|
|
302
|
+
* @param options.toolSlug - The slug of the tool
|
|
303
|
+
* @param options.toolkitSlug - The slug of the toolkit
|
|
304
|
+
* @param options.result - The result of the tool execution
|
|
305
|
+
* @param modifier - The modifier to apply
|
|
306
|
+
* @returns The modified result
|
|
307
|
+
*/
|
|
308
|
+
private async applyAfterExecuteModifiers(
|
|
309
|
+
tool: Tool,
|
|
310
|
+
{
|
|
311
|
+
toolSlug,
|
|
312
|
+
toolkitSlug,
|
|
313
|
+
result,
|
|
314
|
+
}: {
|
|
315
|
+
toolSlug: string;
|
|
316
|
+
toolkitSlug: string;
|
|
317
|
+
result: ToolExecuteResponse;
|
|
318
|
+
},
|
|
319
|
+
modifier?: afterExecuteModifier,
|
|
320
|
+
requestOptions?: ComposioRequestOptions
|
|
321
|
+
): Promise<ToolExecuteResponse> {
|
|
322
|
+
// The tool already executed and may have mutated external state, so a late
|
|
323
|
+
// abort does NOT short-circuit post-processing: skipping the caller's
|
|
324
|
+
// afterExecute modifier here would leave a half-finished pipeline that
|
|
325
|
+
// still looks like success-shaped data. Once the remote call has committed
|
|
326
|
+
// we run file download + afterExecute to completion. The signal is still
|
|
327
|
+
// forwarded to the download so a stuck transfer degrades gracefully
|
|
328
|
+
// (file_downloaded: false) rather than blocking, but it never skips
|
|
329
|
+
// afterExecute.
|
|
330
|
+
let modifiedResult = result;
|
|
331
|
+
// if auto upload download files is enabled, download the files from the Composio API
|
|
332
|
+
if (this.autoUploadDownloadFiles) {
|
|
333
|
+
const fileToolModifier = new FileToolModifier(this.client, this.fileUploadPathOptions);
|
|
334
|
+
modifiedResult = await fileToolModifier.fileDownloadModifier(tool, {
|
|
335
|
+
toolSlug,
|
|
336
|
+
toolkitSlug,
|
|
337
|
+
result: modifiedResult,
|
|
338
|
+
signal: requestOptions?.signal,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
// apply the after execute modifiers
|
|
342
|
+
if (modifier) {
|
|
343
|
+
if (typeof modifier === 'function') {
|
|
344
|
+
modifiedResult = await modifier({
|
|
345
|
+
toolSlug,
|
|
346
|
+
toolkitSlug,
|
|
347
|
+
result: modifiedResult,
|
|
348
|
+
});
|
|
349
|
+
} else {
|
|
350
|
+
throw new ComposioInvalidModifierError('Invalid afterExecute modifier. Not a function.');
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return modifiedResult;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Lists Composio API tools available to the SDK.
|
|
359
|
+
*
|
|
360
|
+
* This method fetches remote Composio tools from the API in raw format. The response can be
|
|
361
|
+
* filtered and modified as needed. Local experimental custom tools are session-scoped; attach
|
|
362
|
+
* them when creating or reusing a Tool Router session, then use `session.tools()`,
|
|
363
|
+
* `session.customTools()`, or `session.execute()`.
|
|
364
|
+
* It provides access to the underlying tool data without provider-specific wrapping.
|
|
365
|
+
*
|
|
366
|
+
* @param {ToolListParams} query - Query parameters to filter the tools (required)
|
|
367
|
+
* @param {GetRawComposioToolsOptions} [options] - Optional configuration for tool retrieval
|
|
368
|
+
* @param {TransformToolSchemaModifier} [options.modifySchema] - Function to transform tool schemas
|
|
369
|
+
* @returns {Promise<ToolList>} List of tools matching the query criteria
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```typescript
|
|
373
|
+
* // Get tools from specific toolkits
|
|
374
|
+
* const githubTools = await composio.tools.getRawComposioTools({
|
|
375
|
+
* toolkits: ['github'],
|
|
376
|
+
* limit: 10
|
|
377
|
+
* });
|
|
378
|
+
*
|
|
379
|
+
* // Get specific tools by slug
|
|
380
|
+
* const specificTools = await composio.tools.getRawComposioTools({
|
|
381
|
+
* tools: ['GITHUB_GET_REPOS', 'HACKERNEWS_GET_USER']
|
|
382
|
+
* });
|
|
383
|
+
*
|
|
384
|
+
* // Get tools from specific toolkits
|
|
385
|
+
* const githubTools = await composio.tools.getRawComposioTools({
|
|
386
|
+
* toolkits: ['github'],
|
|
387
|
+
* limit: 10
|
|
388
|
+
* });
|
|
389
|
+
*
|
|
390
|
+
* // Get tools with schema transformation
|
|
391
|
+
* const customizedTools = await composio.tools.getRawComposioTools({
|
|
392
|
+
* toolkits: ['github'],
|
|
393
|
+
* limit: 5
|
|
394
|
+
* }, {
|
|
395
|
+
* modifySchema: ({ toolSlug, toolkitSlug, schema }) => {
|
|
396
|
+
* // Add custom properties to tool schema
|
|
397
|
+
* return {
|
|
398
|
+
* ...schema,
|
|
399
|
+
* customProperty: `Modified ${toolSlug} from ${toolkitSlug}`,
|
|
400
|
+
* tags: [...(schema.tags || []), 'customized']
|
|
401
|
+
* };
|
|
402
|
+
* }
|
|
403
|
+
* });
|
|
404
|
+
*
|
|
405
|
+
* // Search for tools
|
|
406
|
+
* const searchResults = await composio.tools.getRawComposioTools({
|
|
407
|
+
* search: 'user management'
|
|
408
|
+
* });
|
|
409
|
+
*
|
|
410
|
+
* // Get tools by authentication config
|
|
411
|
+
* const authSpecificTools = await composio.tools.getRawComposioTools({
|
|
412
|
+
* authConfigIds: ['auth_config_123']
|
|
413
|
+
* });
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
async getRawComposioTools(
|
|
417
|
+
query: ToolListParams,
|
|
418
|
+
options?: SchemaModifierOptions,
|
|
419
|
+
requestOptions?: ComposioRequestOptions
|
|
420
|
+
): Promise<ToolList> {
|
|
421
|
+
if ('tools' in query && 'toolkits' in query) {
|
|
422
|
+
throw new ValidationError(
|
|
423
|
+
'Invalid tool list parameters. You should not use tools and toolkits filter together.'
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
428
|
+
if (queryParams.error) {
|
|
429
|
+
throw new ValidationError('Invalid tool list parameters', {
|
|
430
|
+
cause: queryParams.error,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const shouldAutoApplyImportant =
|
|
435
|
+
'toolkits' in queryParams.data &&
|
|
436
|
+
!('tools' in queryParams.data) &&
|
|
437
|
+
!('tags' in queryParams.data) &&
|
|
438
|
+
!('search' in queryParams.data) &&
|
|
439
|
+
// if the user provides a limit, do not apply the important flag
|
|
440
|
+
!('limit' in queryParams.data) &&
|
|
441
|
+
queryParams.data.important !== false;
|
|
442
|
+
|
|
443
|
+
const effectiveImportant =
|
|
444
|
+
'important' in queryParams.data ? queryParams.data.important : shouldAutoApplyImportant;
|
|
445
|
+
|
|
446
|
+
// check if the query params contains atleast one of the following: tools, toolkits, search, authConfigIds
|
|
447
|
+
if (
|
|
448
|
+
!(
|
|
449
|
+
'tools' in queryParams.data ||
|
|
450
|
+
'toolkits' in queryParams.data ||
|
|
451
|
+
'search' in queryParams.data ||
|
|
452
|
+
'authConfigIds' in queryParams.data
|
|
453
|
+
)
|
|
454
|
+
) {
|
|
455
|
+
throw new ValidationError(
|
|
456
|
+
'Invalid tool list parameters, atleast one of the following parameters is required: tools, toolkits, search, authConfigIds'
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// if tools are provided, set the limit to 9999 so that all tools are fetched
|
|
461
|
+
let limit = 'limit' in queryParams.data ? queryParams.data.limit : undefined;
|
|
462
|
+
if ('tools' in queryParams.data) {
|
|
463
|
+
limit = 9999;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const filters: ComposioToolListParams = {
|
|
467
|
+
...('tools' in queryParams.data ? { tool_slugs: queryParams.data.tools?.join(',') } : {}),
|
|
468
|
+
...('toolkits' in queryParams.data
|
|
469
|
+
? { toolkit_slug: queryParams.data.toolkits?.join(',') }
|
|
470
|
+
: {}),
|
|
471
|
+
...(limit ? { limit } : {}),
|
|
472
|
+
...('tags' in queryParams.data ? { tags: queryParams.data.tags } : {}),
|
|
473
|
+
...('scopes' in queryParams.data ? { scopes: queryParams.data.scopes } : {}),
|
|
474
|
+
...('search' in queryParams.data ? { search: queryParams.data.search } : {}),
|
|
475
|
+
...('authConfigIds' in queryParams.data
|
|
476
|
+
? { auth_config_ids: queryParams.data.authConfigIds }
|
|
477
|
+
: {}),
|
|
478
|
+
...(effectiveImportant ? { important: 'true' } : {}),
|
|
479
|
+
...{ toolkit_versions: this.toolkitVersions },
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
logger.debug(`Fetching tools with filters: ${JSON.stringify(filters, null, 2)}`);
|
|
483
|
+
|
|
484
|
+
const tools = await withCancellation(
|
|
485
|
+
() => this.client.tools.list(filters, requestOptions),
|
|
486
|
+
requestOptions?.signal
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
if (!tools) {
|
|
490
|
+
return [];
|
|
491
|
+
}
|
|
492
|
+
const caseTransformedTools = tools.items.map(tool => this.transformToolCases(tool));
|
|
493
|
+
|
|
494
|
+
let modifiedTools = await this.applyDefaultSchemaModifiers(caseTransformedTools);
|
|
495
|
+
|
|
496
|
+
// apply local modifiers if they are provided
|
|
497
|
+
if (options?.modifySchema) {
|
|
498
|
+
const modifier = options.modifySchema;
|
|
499
|
+
if (typeof modifier === 'function') {
|
|
500
|
+
const modifiedPromises = modifiedTools.map(tool =>
|
|
501
|
+
modifier({
|
|
502
|
+
toolSlug: tool.slug,
|
|
503
|
+
toolkitSlug: tool.toolkit?.slug ?? 'unknown',
|
|
504
|
+
schema: tool,
|
|
505
|
+
})
|
|
506
|
+
);
|
|
507
|
+
modifiedTools = await Promise.all(modifiedPromises);
|
|
508
|
+
} else {
|
|
509
|
+
throw new ComposioInvalidModifierError('Invalid schema modifier. Not a function.');
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
return modifiedTools;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Fetches tools exposed by a tool router session.
|
|
518
|
+
* This includes helper/meta tools plus any tools preloaded into the session.
|
|
519
|
+
* It provides access to the underlying tool data without provider-specific wrapping.
|
|
520
|
+
*
|
|
521
|
+
* @param sessionId {string} The session id to get tools for
|
|
522
|
+
* @param options {SchemaModifierOptions} Optional configuration for tool retrieval
|
|
523
|
+
* @param {TransformToolSchemaModifier} [options.modifySchema] - Function to transform the tool schema
|
|
524
|
+
* @returns {Promise<ToolList>} The list of session tools
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```typescript
|
|
528
|
+
* const sessionTools = await composio.tools.getRawToolRouterSessionTools('session_123');
|
|
529
|
+
* console.log(sessionTools);
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
async getRawToolRouterSessionTools(
|
|
533
|
+
sessionId: string,
|
|
534
|
+
options?: SchemaModifierOptions,
|
|
535
|
+
requestOptions?: ComposioRequestOptions
|
|
536
|
+
): Promise<ToolList> {
|
|
537
|
+
const tools: ToolList = [];
|
|
538
|
+
let cursor: string | null | undefined;
|
|
539
|
+
|
|
540
|
+
do {
|
|
541
|
+
const sessionToolsParams = {
|
|
542
|
+
limit: TOOL_ROUTER_SESSION_TOOLS_PAGE_LIMIT,
|
|
543
|
+
...(cursor ? { cursor } : {}),
|
|
544
|
+
};
|
|
545
|
+
const response = await withCancellation(
|
|
546
|
+
() => this.client.toolRouter.session.tools(sessionId, sessionToolsParams, requestOptions),
|
|
547
|
+
requestOptions?.signal
|
|
548
|
+
);
|
|
549
|
+
tools.push(...response.items.map(tool => this.transformToolCases(tool)));
|
|
550
|
+
cursor = response.next_cursor;
|
|
551
|
+
} while (cursor);
|
|
552
|
+
|
|
553
|
+
let modifiedTools = tools;
|
|
554
|
+
// apply local modifiers if they are provided
|
|
555
|
+
if (options?.modifySchema) {
|
|
556
|
+
const modifier = options.modifySchema;
|
|
557
|
+
if (typeof modifier === 'function') {
|
|
558
|
+
const modifiedPromises = modifiedTools.map(tool =>
|
|
559
|
+
modifier({
|
|
560
|
+
toolSlug: tool.slug,
|
|
561
|
+
toolkitSlug: tool.toolkit?.slug ?? 'unknown',
|
|
562
|
+
schema: tool,
|
|
563
|
+
})
|
|
564
|
+
);
|
|
565
|
+
modifiedTools = await Promise.all(modifiedPromises);
|
|
566
|
+
} else {
|
|
567
|
+
throw new ComposioInvalidModifierError('Invalid schema modifier. Not a function.');
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
return modifiedTools;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Retrieves a specific tool by its slug from the Composio API.
|
|
576
|
+
*
|
|
577
|
+
* This method fetches a single tool in raw format without provider-specific wrapping,
|
|
578
|
+
* providing direct access to the tool's schema and metadata. Tool versions are controlled
|
|
579
|
+
* at the Composio SDK initialization level through the `toolkitVersions` configuration.
|
|
580
|
+
* Local experimental custom tools are session-scoped; attach them when creating or reusing a
|
|
581
|
+
* Tool Router session, then use `session.tools()`, `session.customTools()`, or
|
|
582
|
+
* `session.execute()`.
|
|
583
|
+
*
|
|
584
|
+
* @param {string} slug - The unique identifier of the tool (e.g., 'GITHUB_GET_REPOS')
|
|
585
|
+
* @param {GetRawComposioToolBySlugOptions} [options] - Optional configuration for tool retrieval
|
|
586
|
+
* @param {TransformToolSchemaModifier} [options.modifySchema] - Function to transform the tool schema
|
|
587
|
+
* @returns {Promise<Tool>} The requested tool with its complete schema and metadata
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
* ```typescript
|
|
591
|
+
* // Get a tool by slug
|
|
592
|
+
* const tool = await composio.tools.getRawComposioToolBySlug('GITHUB_GET_REPOS');
|
|
593
|
+
* console.log(tool.name, tool.description);
|
|
594
|
+
*
|
|
595
|
+
* // Get a tool with schema transformation
|
|
596
|
+
* const customizedTool = await composio.tools.getRawComposioToolBySlug(
|
|
597
|
+
* 'SLACK_SEND_MESSAGE',
|
|
598
|
+
* {
|
|
599
|
+
* modifySchema: ({ toolSlug, toolkitSlug, schema }) => {
|
|
600
|
+
* return {
|
|
601
|
+
* ...schema,
|
|
602
|
+
* description: `Enhanced ${schema.description} with custom modifications`,
|
|
603
|
+
* customMetadata: {
|
|
604
|
+
* lastModified: new Date().toISOString(),
|
|
605
|
+
* toolkit: toolkitSlug
|
|
606
|
+
* }
|
|
607
|
+
* };
|
|
608
|
+
* }
|
|
609
|
+
* }
|
|
610
|
+
* );
|
|
611
|
+
*
|
|
612
|
+
* // Access tool properties
|
|
613
|
+
* const githubTool = await composio.tools.getRawComposioToolBySlug('GITHUB_CREATE_ISSUE');
|
|
614
|
+
* console.log({
|
|
615
|
+
* slug: githubTool.slug,
|
|
616
|
+
* name: githubTool.name,
|
|
617
|
+
* toolkit: githubTool.toolkit?.name,
|
|
618
|
+
* version: githubTool.version,
|
|
619
|
+
* availableVersions: githubTool.availableVersions,
|
|
620
|
+
* inputParameters: githubTool.inputParameters
|
|
621
|
+
* });
|
|
622
|
+
* ```
|
|
623
|
+
*/
|
|
624
|
+
async getRawComposioToolBySlug(
|
|
625
|
+
slug: string,
|
|
626
|
+
options?: ToolRetrievalOptions,
|
|
627
|
+
requestOptions?: ComposioRequestOptions
|
|
628
|
+
): Promise<Tool> {
|
|
629
|
+
let tool: ToolRetrieveResponse;
|
|
630
|
+
try {
|
|
631
|
+
// Build API call parameters based on version source
|
|
632
|
+
const retrieveParams = options?.version
|
|
633
|
+
? { version: options.version } // Explicit version → use 'version' param
|
|
634
|
+
: { toolkit_versions: this.toolkitVersions }; // SDK config → use 'toolkit_versions' param
|
|
635
|
+
|
|
636
|
+
tool = await withCancellation(
|
|
637
|
+
() => this.client.tools.retrieve(slug, retrieveParams, requestOptions),
|
|
638
|
+
requestOptions?.signal
|
|
639
|
+
);
|
|
640
|
+
} catch (error) {
|
|
641
|
+
if (error instanceof ComposioRequestCancelledError) {
|
|
642
|
+
throw error;
|
|
643
|
+
}
|
|
644
|
+
throw new ComposioToolNotFoundError(`Unable to retrieve tool with slug ${slug}`, {
|
|
645
|
+
cause: error,
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// change the case of the tool to camel case and apply default modifiers
|
|
650
|
+
let [modifiedTool] = await this.applyDefaultSchemaModifiers([this.transformToolCases(tool)]);
|
|
651
|
+
// apply local modifiers if they are provided
|
|
652
|
+
if (options?.modifySchema) {
|
|
653
|
+
const modifier = options.modifySchema;
|
|
654
|
+
if (typeof modifier === 'function') {
|
|
655
|
+
modifiedTool = await modifier({
|
|
656
|
+
toolSlug: slug,
|
|
657
|
+
toolkitSlug: modifiedTool.toolkit?.slug ?? 'unknown',
|
|
658
|
+
schema: modifiedTool,
|
|
659
|
+
});
|
|
660
|
+
} else {
|
|
661
|
+
throw new ComposioInvalidModifierError('Invalid schema modifier. Not a function.');
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
return modifiedTool;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Get a list of tools from Composio based on filters.
|
|
669
|
+
* This method fetches the tools from the Composio API and wraps them using the provider.
|
|
670
|
+
*
|
|
671
|
+
* @param {string} userId - The user id to get the tools for
|
|
672
|
+
* @param {ToolListParams} filters - The filters to apply when fetching tools
|
|
673
|
+
* @param {ProviderOptions<TProvider> & ComposioRequestOptions} [options] - Provider options, modifiers, and/or AbortSignal
|
|
674
|
+
* @returns {Promise<ReturnType<T['wrapTools']>>} The wrapped tools collection
|
|
675
|
+
*
|
|
676
|
+
* @example
|
|
677
|
+
* ```typescript
|
|
678
|
+
* // Get tools from the GitHub toolkit
|
|
679
|
+
* const tools = await composio.tools.get('default', {
|
|
680
|
+
* toolkits: ['github'],
|
|
681
|
+
* limit: 10
|
|
682
|
+
* });
|
|
683
|
+
*
|
|
684
|
+
* // Timeout a slow search after 5s
|
|
685
|
+
* const emailTools = await composio.tools.get('default', {
|
|
686
|
+
* search: 'send email',
|
|
687
|
+
* }, { signal: AbortSignal.timeout(5_000) });
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
690
|
+
async get<T extends TProvider>(
|
|
691
|
+
userId: string,
|
|
692
|
+
filters: ToolListParams,
|
|
693
|
+
options?: ProviderOptions<TProvider> & ComposioRequestOptions
|
|
694
|
+
): Promise<ReturnType<T['wrapTools']>>;
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Get a specific tool by its slug.
|
|
698
|
+
* This method fetches the tool from the Composio API and wraps it using the provider.
|
|
699
|
+
*
|
|
700
|
+
* @param {string} userId - The user id to get the tool for
|
|
701
|
+
* @param {string} slug - The slug of the tool to fetch
|
|
702
|
+
* @param {ProviderOptions<TProvider> & ComposioRequestOptions} [options] - Optional provider options including modifiers and signal
|
|
703
|
+
* @returns {Promise<ReturnType<T['wrapTools']>>} The wrapped tool
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* ```typescript
|
|
707
|
+
* // Get a specific tool by slug
|
|
708
|
+
* const hackerNewsUserTool = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
|
|
709
|
+
*
|
|
710
|
+
* // Get a tool with schema modifications
|
|
711
|
+
* const tool = await composio.tools.get('default', 'GITHUB_GET_REPOS', {
|
|
712
|
+
* modifySchema: (toolSlug, toolkitSlug, schema) => {
|
|
713
|
+
* // Customize the tool schema
|
|
714
|
+
* return {...schema, description: 'Custom description'};
|
|
715
|
+
* }
|
|
716
|
+
* });
|
|
717
|
+
*
|
|
718
|
+
* // Timeout after 5s
|
|
719
|
+
* const tools = await composio.tools.get('user_1', { search: 'email' }, {
|
|
720
|
+
* signal: AbortSignal.timeout(5_000)
|
|
721
|
+
* });
|
|
722
|
+
* ```
|
|
723
|
+
*/
|
|
724
|
+
async get<T extends TProvider>(
|
|
725
|
+
userId: string,
|
|
726
|
+
slug: string,
|
|
727
|
+
options?: ProviderOptions<TProvider> & ComposioRequestOptions
|
|
728
|
+
): Promise<ReturnType<T['wrapTools']>>;
|
|
729
|
+
|
|
730
|
+
async get(
|
|
731
|
+
userId: string,
|
|
732
|
+
arg2: ToolListParams | string,
|
|
733
|
+
arg3?: ProviderOptions<TProvider> & ComposioRequestOptions
|
|
734
|
+
): Promise<TToolCollection> {
|
|
735
|
+
const options = arg3;
|
|
736
|
+
const requestOptions: ComposioRequestOptions | undefined =
|
|
737
|
+
options?.signal != null ? { signal: options.signal } : undefined;
|
|
738
|
+
// Strip signal so it isn't captured in the provider execution closure —
|
|
739
|
+
// an expired AbortSignal.timeout() would poison every future tool call.
|
|
740
|
+
const { signal: _, ...modifiers } = options ?? {};
|
|
741
|
+
|
|
742
|
+
if (typeof arg2 === 'string') {
|
|
743
|
+
const tool = await this.getRawComposioToolBySlug(
|
|
744
|
+
arg2,
|
|
745
|
+
{
|
|
746
|
+
modifySchema: options?.modifySchema as TransformToolSchemaModifier,
|
|
747
|
+
},
|
|
748
|
+
requestOptions
|
|
749
|
+
);
|
|
750
|
+
return this.wrapToolsForProvider(
|
|
751
|
+
userId,
|
|
752
|
+
[tool],
|
|
753
|
+
modifiers as ExecuteToolModifiers
|
|
754
|
+
) as TToolCollection;
|
|
755
|
+
} else {
|
|
756
|
+
const tools = await this.getRawComposioTools(
|
|
757
|
+
arg2,
|
|
758
|
+
{
|
|
759
|
+
modifySchema: options?.modifySchema as TransformToolSchemaModifier,
|
|
760
|
+
},
|
|
761
|
+
requestOptions
|
|
762
|
+
);
|
|
763
|
+
return this.wrapToolsForProvider(
|
|
764
|
+
userId,
|
|
765
|
+
tools,
|
|
766
|
+
modifiers as ExecuteToolModifiers
|
|
767
|
+
) as TToolCollection;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* @internal
|
|
772
|
+
* Creates a global execute tool function.
|
|
773
|
+
* This function is used by providers to execute tools.
|
|
774
|
+
* It skips the version check for provider controlled execution.
|
|
775
|
+
* @returns {GlobalExecuteToolFn} The global execute tool function
|
|
776
|
+
*/
|
|
777
|
+
private createExecuteFnForProviders(): GlobalExecuteToolFn {
|
|
778
|
+
return async (slug: string, body: ToolExecuteParams, modifiers?: ExecuteToolModifiers) => {
|
|
779
|
+
return await this.execute(
|
|
780
|
+
slug,
|
|
781
|
+
{ ...body, dangerouslySkipVersionCheck: body.dangerouslySkipVersionCheck ?? true },
|
|
782
|
+
modifiers
|
|
783
|
+
);
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* @internal
|
|
789
|
+
* Utility to wrap a given set of tools in the format expected by the provider
|
|
790
|
+
*
|
|
791
|
+
* @param userId - The user id to get the tools for
|
|
792
|
+
* @param tools - The tools to wrap
|
|
793
|
+
* @param modifiers - The modifiers to be applied to the tools
|
|
794
|
+
* @returns The wrapped tools
|
|
795
|
+
*/
|
|
796
|
+
wrapToolsForProvider<T extends TProvider>(
|
|
797
|
+
userId: string,
|
|
798
|
+
tools: Tool[],
|
|
799
|
+
modifiers?: ExecuteToolModifiers
|
|
800
|
+
): ReturnType<T['wrapTools']> {
|
|
801
|
+
const executeToolFn = this.createExecuteToolFn(userId, modifiers);
|
|
802
|
+
return this.provider.wrapTools(tools, executeToolFn) as ReturnType<T['wrapTools']>;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* @internal
|
|
807
|
+
* Utility to wrap a given set of tools in the format expected by the tool router
|
|
808
|
+
*
|
|
809
|
+
* @param {string} sessionId - The session id to execute the tool for
|
|
810
|
+
* @param {Tool[]} tools - The tools to wrap
|
|
811
|
+
* @param {SessionExecuteMetaModifiers} modifiers - The modifiers to apply to the tool
|
|
812
|
+
* @returns {Tool[]} The wrapped tools
|
|
813
|
+
*/
|
|
814
|
+
wrapToolsForToolRouter(
|
|
815
|
+
sessionId: string,
|
|
816
|
+
tools: Tool[],
|
|
817
|
+
modifiers?: SessionExecuteMetaModifiers
|
|
818
|
+
): Tool[] {
|
|
819
|
+
const executeToolFn = this.createExecuteToolFnForToolRouter(sessionId, tools, modifiers);
|
|
820
|
+
return this.provider.wrapTools(tools, executeToolFn) as Tool[];
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* @internal
|
|
825
|
+
* @description
|
|
826
|
+
* Creates a function that executes a tool.
|
|
827
|
+
* This function is used by agentic providers to execute the tool
|
|
828
|
+
*
|
|
829
|
+
* @param {string} userId - The user id
|
|
830
|
+
* @param {ExecuteToolModifiers} modifiers - The modifiers to be applied to the tool
|
|
831
|
+
* @returns {ExecuteToolFn} The execute tool function
|
|
832
|
+
*/
|
|
833
|
+
private createExecuteToolFn(userId: string, modifiers?: ExecuteToolModifiers): ExecuteToolFn {
|
|
834
|
+
const executeToolFn = async (toolSlug: string, input: Record<string, unknown>) => {
|
|
835
|
+
return await this.execute(
|
|
836
|
+
toolSlug,
|
|
837
|
+
{
|
|
838
|
+
userId,
|
|
839
|
+
arguments: input,
|
|
840
|
+
// dangerously skip version check for agentic tool execution via providers
|
|
841
|
+
// this can be safe because most agentic flows users fetch latest version and then execute the tool
|
|
842
|
+
dangerouslySkipVersionCheck: true,
|
|
843
|
+
},
|
|
844
|
+
modifiers
|
|
845
|
+
);
|
|
846
|
+
};
|
|
847
|
+
return executeToolFn;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* @internal
|
|
852
|
+
* Creates a function that executes a tool for a tool router session
|
|
853
|
+
*
|
|
854
|
+
* @param {string} sessionId - The session id to execute the tool for
|
|
855
|
+
* @param {SessionExecuteMetaModifiers} modifiers - The modifiers to apply to the tool
|
|
856
|
+
* @returns {ExecuteToolFn} The execute tool function
|
|
857
|
+
*/
|
|
858
|
+
private createExecuteToolFnForToolRouter(
|
|
859
|
+
sessionId: string,
|
|
860
|
+
tools: Tool[],
|
|
861
|
+
modifiers?: SessionExecuteMetaModifiers
|
|
862
|
+
): ExecuteToolFn {
|
|
863
|
+
const toolBySlug = new Map(tools.map(tool => [tool.slug.toUpperCase(), tool]));
|
|
864
|
+
const executeToolFn = async (
|
|
865
|
+
toolSlug: string,
|
|
866
|
+
input: Record<string, unknown>
|
|
867
|
+
): Promise<ToolExecuteResponse> => {
|
|
868
|
+
return await this.executeSessionTool(
|
|
869
|
+
toolSlug,
|
|
870
|
+
{
|
|
871
|
+
sessionId,
|
|
872
|
+
arguments: input,
|
|
873
|
+
},
|
|
874
|
+
modifiers,
|
|
875
|
+
toolBySlug.get(toolSlug.toUpperCase())
|
|
876
|
+
);
|
|
877
|
+
};
|
|
878
|
+
return executeToolFn;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* @internal
|
|
883
|
+
* Executes a composio tool via API without modifiers
|
|
884
|
+
* @param tool - The tool to execute
|
|
885
|
+
* @param body - The body of the tool execution
|
|
886
|
+
* @returns The response from the tool execution
|
|
887
|
+
*/
|
|
888
|
+
private async executeComposioTool(
|
|
889
|
+
tool: Tool,
|
|
890
|
+
body: ToolExecuteParams,
|
|
891
|
+
requestOptions?: ComposioRequestOptions
|
|
892
|
+
): Promise<ToolExecuteResponse> {
|
|
893
|
+
const toolkitVersion =
|
|
894
|
+
body.version ?? getToolkitVersion(tool.toolkit?.slug ?? 'unknown', this.toolkitVersions);
|
|
895
|
+
// if the version is latest and dangerouslySkipVersionCheck is not true, throw an error
|
|
896
|
+
if (toolkitVersion === 'latest' && !body.dangerouslySkipVersionCheck) {
|
|
897
|
+
throw new ComposioToolVersionRequiredError();
|
|
898
|
+
}
|
|
899
|
+
try {
|
|
900
|
+
const executeBody: ComposioToolExecuteParams = {
|
|
901
|
+
allow_tracing: body.allowTracing,
|
|
902
|
+
connected_account_id: body.connectedAccountId,
|
|
903
|
+
custom_auth_params: body.customAuthParams
|
|
904
|
+
? {
|
|
905
|
+
base_url: body.customAuthParams.baseURL,
|
|
906
|
+
body: body.customAuthParams.body,
|
|
907
|
+
parameters: body.customAuthParams.parameters,
|
|
908
|
+
}
|
|
909
|
+
: undefined,
|
|
910
|
+
/**
|
|
911
|
+
* @deprecated The `customConnectionData` execute param is deprecated and will be
|
|
912
|
+
* removed in a future release. Use `customAuthParams` instead.
|
|
913
|
+
*/
|
|
914
|
+
custom_connection_data:
|
|
915
|
+
body.customConnectionData as ComposioToolExecuteParams['custom_connection_data'],
|
|
916
|
+
arguments: body.arguments,
|
|
917
|
+
user_id: body.userId,
|
|
918
|
+
version: toolkitVersion,
|
|
919
|
+
text: body.text,
|
|
920
|
+
};
|
|
921
|
+
const result = await withCancellation(
|
|
922
|
+
() => this.client.tools.execute(tool.slug, executeBody, requestOptions),
|
|
923
|
+
requestOptions?.signal
|
|
924
|
+
);
|
|
925
|
+
// transform the response to the ToolExecuteResponse format
|
|
926
|
+
return this.transformToolExecuteResponse(result);
|
|
927
|
+
} catch (error) {
|
|
928
|
+
if (error instanceof ComposioRequestCancelledError) {
|
|
929
|
+
throw error;
|
|
930
|
+
}
|
|
931
|
+
const toolError = handleToolExecutionError(tool.slug, error as Error);
|
|
932
|
+
throw toolError;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* Executes a given tool with the provided parameters.
|
|
938
|
+
*
|
|
939
|
+
* This method calls the Composio API to execute the tool and returns the response.
|
|
940
|
+
*
|
|
941
|
+
* **Version Control:**
|
|
942
|
+
* By default, manual tool execution requires a specific toolkit version. If the version resolves to "latest",
|
|
943
|
+
* the execution will throw a `ComposioToolVersionRequiredError` unless `dangerouslySkipVersionCheck` is set to `true`.
|
|
944
|
+
* This helps prevent unexpected behavior when new toolkit versions are released.
|
|
945
|
+
*
|
|
946
|
+
* @param {string} slug - The slug/ID of the tool to be executed
|
|
947
|
+
* @param {ToolExecuteParams} body - The parameters to be passed to the tool
|
|
948
|
+
* @param {string} [body.version] - The specific version of the tool to execute (e.g., "20250909_00")
|
|
949
|
+
* @param {boolean} [body.dangerouslySkipVersionCheck] - Skip version validation for "latest" version (use with caution)
|
|
950
|
+
* @param {string} [body.userId] - The user ID to execute the tool for
|
|
951
|
+
* @param {string} [body.connectedAccountId] - The connected account ID to use for authenticated tools
|
|
952
|
+
* @param {Record<string, unknown>} [body.arguments] - The arguments to pass to the tool
|
|
953
|
+
* @param {ExecuteToolModifiers & ComposioRequestOptions} [options] - Optional modifiers and request options
|
|
954
|
+
* @returns {Promise<ToolExecuteResponse>} The response from the tool execution
|
|
955
|
+
*
|
|
956
|
+
* @throws {ComposioConnectedAccountNotFoundError} If the connected account is not found
|
|
957
|
+
* @throws {ComposioToolNotFoundError} If the tool with the given slug is not found
|
|
958
|
+
* @throws {ComposioToolVersionRequiredError} If version resolves to "latest" and dangerouslySkipVersionCheck is not true
|
|
959
|
+
* @throws {ComposioToolExecutionError} If there is an error during tool execution
|
|
960
|
+
*
|
|
961
|
+
* @example Execute with a specific version (recommended for production)
|
|
962
|
+
* ```typescript
|
|
963
|
+
* const result = await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
964
|
+
* userId: 'default',
|
|
965
|
+
* version: '20250909_00',
|
|
966
|
+
* arguments: { owner: 'composio' }
|
|
967
|
+
* });
|
|
968
|
+
* ```
|
|
969
|
+
*
|
|
970
|
+
* @example Execute with dangerouslySkipVersionCheck (not recommended for production)
|
|
971
|
+
* ```typescript
|
|
972
|
+
* const result = await composio.tools.execute('HACKERNEWS_GET_USER', {
|
|
973
|
+
* userId: 'default',
|
|
974
|
+
* arguments: { userId: 'pg' },
|
|
975
|
+
* dangerouslySkipVersionCheck: true // Allows execution with "latest" version
|
|
976
|
+
* });
|
|
977
|
+
* ```
|
|
978
|
+
*
|
|
979
|
+
* @example Execute with SDK-level toolkit versions configuration
|
|
980
|
+
* ```typescript
|
|
981
|
+
* // If toolkitVersions are set during Composio initialization, no need to pass version
|
|
982
|
+
* const composio = new Composio({ toolkitVersions: { github: '20250909_00' } });
|
|
983
|
+
* const result = await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
984
|
+
* userId: 'default',
|
|
985
|
+
* arguments: { owner: 'composio' }
|
|
986
|
+
* });
|
|
987
|
+
* ```
|
|
988
|
+
*
|
|
989
|
+
* @example Execute with modifiers
|
|
990
|
+
* ```typescript
|
|
991
|
+
* const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
|
|
992
|
+
* userId: 'default',
|
|
993
|
+
* version: '20250909_00',
|
|
994
|
+
* arguments: { owner: 'composio', repo: 'sdk' }
|
|
995
|
+
* }, {
|
|
996
|
+
* beforeExecute: ({ toolSlug, toolkitSlug, params }) => {
|
|
997
|
+
* console.log(`Executing ${toolSlug} from ${toolkitSlug}`);
|
|
998
|
+
* return params;
|
|
999
|
+
* },
|
|
1000
|
+
* afterExecute: ({ toolSlug, toolkitSlug, result }) => {
|
|
1001
|
+
* console.log(`Completed ${toolSlug}`);
|
|
1002
|
+
* return result;
|
|
1003
|
+
* }
|
|
1004
|
+
* });
|
|
1005
|
+
* ```
|
|
1006
|
+
*
|
|
1007
|
+
* @example Execute with timeout
|
|
1008
|
+
* ```typescript
|
|
1009
|
+
* const result = await composio.tools.execute('HACKERNEWS_GET_FRONTPAGE', {
|
|
1010
|
+
* userId: 'default',
|
|
1011
|
+
* arguments: {},
|
|
1012
|
+
* dangerouslySkipVersionCheck: true,
|
|
1013
|
+
* }, { signal: AbortSignal.timeout(5_000) });
|
|
1014
|
+
* ```
|
|
1015
|
+
*/
|
|
1016
|
+
async execute(
|
|
1017
|
+
slug: string,
|
|
1018
|
+
body: ToolExecuteParams,
|
|
1019
|
+
options?: ExecuteToolModifiers & ComposioRequestOptions
|
|
1020
|
+
): Promise<ToolExecuteResponse> {
|
|
1021
|
+
const executeParams = ToolExecuteParamsSchema.safeParse(body);
|
|
1022
|
+
if (!executeParams.success) {
|
|
1023
|
+
throw new ValidationError('Invalid tool execute parameters', { cause: executeParams.error });
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
const requestOptions: ComposioRequestOptions | undefined =
|
|
1027
|
+
options?.signal != null ? { signal: options.signal } : undefined;
|
|
1028
|
+
const { signal: _, ...modifiers } = options ?? {};
|
|
1029
|
+
|
|
1030
|
+
const tool = await this.getRawComposioToolBySlug(
|
|
1031
|
+
slug,
|
|
1032
|
+
{
|
|
1033
|
+
version: body.version,
|
|
1034
|
+
},
|
|
1035
|
+
requestOptions
|
|
1036
|
+
);
|
|
1037
|
+
const toolkitSlug = tool.toolkit?.slug ?? 'unknown';
|
|
1038
|
+
|
|
1039
|
+
// Apply before execute modifiers
|
|
1040
|
+
const params = await this.applyBeforeExecuteModifiers(
|
|
1041
|
+
tool,
|
|
1042
|
+
{
|
|
1043
|
+
toolSlug: slug,
|
|
1044
|
+
toolkitSlug,
|
|
1045
|
+
params: executeParams.data,
|
|
1046
|
+
},
|
|
1047
|
+
modifiers as ExecuteToolModifiers,
|
|
1048
|
+
requestOptions
|
|
1049
|
+
);
|
|
1050
|
+
|
|
1051
|
+
let result = await this.executeComposioTool(tool, params, requestOptions);
|
|
1052
|
+
|
|
1053
|
+
// Apply after execute modifiers
|
|
1054
|
+
result = await this.applyAfterExecuteModifiers(
|
|
1055
|
+
tool,
|
|
1056
|
+
{
|
|
1057
|
+
toolSlug: slug,
|
|
1058
|
+
toolkitSlug,
|
|
1059
|
+
result,
|
|
1060
|
+
},
|
|
1061
|
+
(modifiers as ExecuteToolModifiers).afterExecute,
|
|
1062
|
+
requestOptions
|
|
1063
|
+
);
|
|
1064
|
+
|
|
1065
|
+
return result;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* Executes a tool based on a tool router session.
|
|
1070
|
+
*
|
|
1071
|
+
* @param {string} toolSlug - The slug of the tool to execute
|
|
1072
|
+
* @param {ToolExecuteMetaParams} body - The execution parameters
|
|
1073
|
+
* @param {string} body.sessionId - The session id to execute the tool for
|
|
1074
|
+
* @param {Record<string, unknown>} body.arguments - The input to pass to the tool
|
|
1075
|
+
* @param {SessionExecuteMetaModifiers} modifiers - The modifiers to apply to the tool
|
|
1076
|
+
* @param {Tool} tool - Optional tool schema used to resolve toolkit metadata for modifiers
|
|
1077
|
+
* @returns {Promise<ToolExecuteResponse>} The response from the tool execution
|
|
1078
|
+
*/
|
|
1079
|
+
async executeSessionTool(
|
|
1080
|
+
toolSlug: string,
|
|
1081
|
+
body: ToolExecuteMetaParams,
|
|
1082
|
+
modifiers?: SessionExecuteMetaModifiers,
|
|
1083
|
+
tool?: Tool,
|
|
1084
|
+
options?: ToolRouterSessionExecuteOptions,
|
|
1085
|
+
requestOptions?: ComposioRequestOptions
|
|
1086
|
+
): Promise<ToolExecuteResponse> {
|
|
1087
|
+
const executeParams = ToolExecuteMetaParamsSchema.safeParse(body);
|
|
1088
|
+
if (!executeParams.success) {
|
|
1089
|
+
throw new ValidationError('Invalid tool execute session parameters', {
|
|
1090
|
+
cause: executeParams.error,
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// Apply beforeExecute modifier if provided
|
|
1095
|
+
let modifiedParams = body.arguments ?? {};
|
|
1096
|
+
const toolkitSlug = tool?.toolkit?.slug ?? 'composio';
|
|
1097
|
+
if (modifiers?.beforeExecute) {
|
|
1098
|
+
modifiedParams = await modifiers.beforeExecute({
|
|
1099
|
+
toolSlug,
|
|
1100
|
+
toolkitSlug,
|
|
1101
|
+
sessionId: body.sessionId,
|
|
1102
|
+
params: modifiedParams,
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
const executePayload: SessionExecuteParams = {
|
|
1107
|
+
tool_slug: toolSlug,
|
|
1108
|
+
arguments: modifiedParams,
|
|
1109
|
+
// Provider-wrapped session tools are agentic calls, so they opt into
|
|
1110
|
+
// direct tool offload when the backend session workbench allows it.
|
|
1111
|
+
enable_auto_workbench_offload: true,
|
|
1112
|
+
};
|
|
1113
|
+
if (options?.experimental) {
|
|
1114
|
+
executePayload.experimental = options.experimental;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
const response = await withCancellation(
|
|
1118
|
+
() => this.client.toolRouter.session.execute(body.sessionId, executePayload, requestOptions),
|
|
1119
|
+
requestOptions?.signal
|
|
1120
|
+
);
|
|
1121
|
+
|
|
1122
|
+
// Prepare the result
|
|
1123
|
+
let result: ToolExecuteResponse = {
|
|
1124
|
+
data: response.data,
|
|
1125
|
+
error: response.error,
|
|
1126
|
+
successful: !response.error,
|
|
1127
|
+
logId: response.log_id,
|
|
1128
|
+
};
|
|
1129
|
+
|
|
1130
|
+
// Apply afterExecute modifier if provided
|
|
1131
|
+
if (modifiers?.afterExecute) {
|
|
1132
|
+
result = await modifiers.afterExecute({
|
|
1133
|
+
toolSlug,
|
|
1134
|
+
toolkitSlug,
|
|
1135
|
+
sessionId: body.sessionId,
|
|
1136
|
+
result,
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
return result;
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
/**
|
|
1144
|
+
* Fetches the list of all available tools in the Composio SDK.
|
|
1145
|
+
*
|
|
1146
|
+
* This method is mostly used by the CLI to get the list of tools.
|
|
1147
|
+
* No filtering is done on the tools, the list is cached in the backend, no further optimization is required.
|
|
1148
|
+
* @returns {Promise<ToolRetrieveEnumResponse>} The complete list of all available tools with their metadata
|
|
1149
|
+
*
|
|
1150
|
+
* @example
|
|
1151
|
+
* ```typescript
|
|
1152
|
+
* // Get all available tools as an enum
|
|
1153
|
+
* const toolsEnum = await composio.tools.getToolsEnum();
|
|
1154
|
+
* console.log(toolsEnum.items);
|
|
1155
|
+
* ```
|
|
1156
|
+
*/
|
|
1157
|
+
async getToolsEnum(requestOptions?: ComposioRequestOptions): Promise<ToolRetrieveEnumResponse> {
|
|
1158
|
+
return withCancellation(
|
|
1159
|
+
() => this.client.tools.retrieveEnum(requestOptions),
|
|
1160
|
+
requestOptions?.signal
|
|
1161
|
+
);
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
/**
|
|
1165
|
+
* Fetches the input parameters for a given tool.
|
|
1166
|
+
*
|
|
1167
|
+
* This method is used to get the input parameters for a tool before executing it.
|
|
1168
|
+
*
|
|
1169
|
+
* @param {string} slug - The ID of the tool to find input for
|
|
1170
|
+
* @param {ToolGetInputParams} body - The parameters to be passed to the tool
|
|
1171
|
+
* @returns {Promise<ToolGetInputResponse>} The input parameters schema for the specified tool
|
|
1172
|
+
*
|
|
1173
|
+
* @example
|
|
1174
|
+
* ```typescript
|
|
1175
|
+
* // Get input parameters for a specific tool
|
|
1176
|
+
* const inputParams = await composio.tools.getInput('GITHUB_CREATE_ISSUE', {
|
|
1177
|
+
* userId: 'default'
|
|
1178
|
+
* });
|
|
1179
|
+
* console.log(inputParams.schema);
|
|
1180
|
+
* ```
|
|
1181
|
+
*/
|
|
1182
|
+
async getInput(
|
|
1183
|
+
slug: string,
|
|
1184
|
+
body: ToolGetInputParams,
|
|
1185
|
+
requestOptions?: ComposioRequestOptions
|
|
1186
|
+
): Promise<ToolGetInputResponse> {
|
|
1187
|
+
return withCancellation(
|
|
1188
|
+
() => this.client.tools.getInput(slug, body, requestOptions),
|
|
1189
|
+
requestOptions?.signal
|
|
1190
|
+
);
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* Proxies a custom request to a toolkit/integration.
|
|
1195
|
+
*
|
|
1196
|
+
* This method allows sending custom requests to a specific toolkit or integration
|
|
1197
|
+
* when you need more flexibility than the standard tool execution methods provide.
|
|
1198
|
+
*
|
|
1199
|
+
* @param {ToolProxyParams} body - The parameters for the proxy request including toolkit slug and custom data
|
|
1200
|
+
* @returns {Promise<ToolProxyResponse>} The response from the proxied request
|
|
1201
|
+
*
|
|
1202
|
+
* @example
|
|
1203
|
+
* ```typescript
|
|
1204
|
+
* // Send a custom request to a toolkit
|
|
1205
|
+
* const response = await composio.tools.proxyExecute({
|
|
1206
|
+
* toolkitSlug: 'github',
|
|
1207
|
+
* userId: 'default',
|
|
1208
|
+
* data: {
|
|
1209
|
+
* endpoint: '/repos/owner/repo/issues',
|
|
1210
|
+
* method: 'GET'
|
|
1211
|
+
* }
|
|
1212
|
+
* });
|
|
1213
|
+
* console.log(response.data);
|
|
1214
|
+
* ```
|
|
1215
|
+
*/
|
|
1216
|
+
async proxyExecute(
|
|
1217
|
+
body: ToolProxyParams,
|
|
1218
|
+
requestOptions?: ComposioRequestOptions
|
|
1219
|
+
): Promise<ToolProxyResponse> {
|
|
1220
|
+
const toolProxyParams = ToolProxyParamsSchema.safeParse(body);
|
|
1221
|
+
if (!toolProxyParams.success) {
|
|
1222
|
+
throw new ValidationError('Invalid tool proxy parameters', { cause: toolProxyParams.error });
|
|
1223
|
+
}
|
|
1224
|
+
// convert the headers and query to the composio format
|
|
1225
|
+
// { name: string, type: 'header' | 'query', value: string }
|
|
1226
|
+
const parameters: ComposioToolProxyParams.Parameter[] = [];
|
|
1227
|
+
const parameterTypes = {
|
|
1228
|
+
header: 'header',
|
|
1229
|
+
query: 'query',
|
|
1230
|
+
} as const;
|
|
1231
|
+
|
|
1232
|
+
if (toolProxyParams.data.parameters) {
|
|
1233
|
+
parameters.push(
|
|
1234
|
+
...(toolProxyParams.data.parameters ?? []).map(value => ({
|
|
1235
|
+
name: value.name,
|
|
1236
|
+
type: value.in === 'header' ? parameterTypes.header : parameterTypes.query,
|
|
1237
|
+
value: value.value.toString(),
|
|
1238
|
+
}))
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
const proxyBody = {
|
|
1243
|
+
endpoint: toolProxyParams.data.endpoint,
|
|
1244
|
+
method: toolProxyParams.data.method,
|
|
1245
|
+
body: toolProxyParams.data.body,
|
|
1246
|
+
connected_account_id: toolProxyParams.data.connectedAccountId,
|
|
1247
|
+
parameters: parameters,
|
|
1248
|
+
/**
|
|
1249
|
+
* @deprecated The `customConnectionData` proxy param is deprecated and will be
|
|
1250
|
+
* removed in a future release. Use `customAuthParams` instead.
|
|
1251
|
+
*/
|
|
1252
|
+
// @ts-ignore
|
|
1253
|
+
custom_connection_data: toolProxyParams.data.customConnectionData,
|
|
1254
|
+
} as ComposioToolProxyParams;
|
|
1255
|
+
return withCancellation(
|
|
1256
|
+
() => this.client.tools.proxy(proxyBody, requestOptions),
|
|
1257
|
+
requestOptions?.signal
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1260
|
+
}
|