@composio/core 0.12.0 → 0.13.1
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-BBnsv9kS.d.mts → BaseProvider-Brb3o86-.d.mts} +80 -80
- package/dist/{CustomTool-DEB4BQPl.mjs → CustomTool-D9qwyMrv.mjs} +1 -1
- package/dist/{CustomTool-DH18rVQu.d.mts → CustomTool-DLf7JeKt.d.mts} +1 -1
- package/dist/CustomTool-NpHpqdnU.d.mts +74 -0
- package/dist/{composio-CHnEggnv.d.mts → composio-BHSQwOUz.d.mts} +503 -319
- package/dist/composio-DfPD7BAi.d.mts +5666 -0
- package/dist/{customTool.types-DpIdOJjL.d.mts → customTool.types-9yFqPjdw.d.mts} +448 -76
- package/dist/customTool.types-D-6YqFdW.d.mts +2826 -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 +252 -0
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +155 -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 +36 -6
- package/dist/index.mjs +455 -123
- package/dist/{jsonSchema-daqF3S3d.mjs → jsonSchema-CFKdONpP.mjs} +1 -1
- package/dist/{types-CaI5Z4PA.d.mts → types-BJLCRj9q.d.mts} +2 -2
- package/dist/types-CCh8qvui.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.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +2 -2
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- 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/lib/toolRouterSessionDelete.ts +30 -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 +406 -0
- package/src/models/ToolRouterSession.ts +839 -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 +774 -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,663 @@
|
|
|
1
|
+
import { BaseAgenticProvider, BaseComposioProvider } from '../provider/BaseProvider';
|
|
2
|
+
import { ToolExecuteParams, ToolExecuteResponse, Tool, ToolExecuteMetaParams } from './tool.types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Modifier for altering the tool execute parameters before execution.
|
|
6
|
+
*
|
|
7
|
+
* This function allows you to intercept and modify the parameters being passed to a tool
|
|
8
|
+
* before the actual execution happens. Common use cases include:
|
|
9
|
+
* - Adding or modifying authentication parameters
|
|
10
|
+
* - Transforming input data to match expected formats
|
|
11
|
+
* - Adding contextual information to the request
|
|
12
|
+
* - Implementing request validation or normalization
|
|
13
|
+
*
|
|
14
|
+
* @param {string} toolSlug - The slug identifier of the tool being executed
|
|
15
|
+
* @param {string} toolkitSlug - The slug identifier of the toolkit containing the tool
|
|
16
|
+
* @param {ToolExecuteParams} toolExecuteParams - The original execution parameters
|
|
17
|
+
* @returns {ToolExecuteParams} The modified execution parameters
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // Example 1: Add authentication headers to all tool requests
|
|
22
|
+
* const beforeExecute = ({ params, toolSlug, toolkitSlug }) => {
|
|
23
|
+
* // Log the execution attempt
|
|
24
|
+
* console.log(`Executing ${toolSlug} from toolkit ${toolkitSlug}`);
|
|
25
|
+
*
|
|
26
|
+
* // Add authentication and tracking headers
|
|
27
|
+
* return {
|
|
28
|
+
* ...params,
|
|
29
|
+
* customAuthParams: {
|
|
30
|
+
* ...params.customAuthParams,
|
|
31
|
+
* headers: {
|
|
32
|
+
* ...params.customAuthParams?.headers,
|
|
33
|
+
* 'X-API-Key': 'my-api-key',
|
|
34
|
+
* 'X-Request-ID': generateRequestId(),
|
|
35
|
+
* 'X-Toolkit': toolkitSlug
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* };
|
|
39
|
+
* };
|
|
40
|
+
*
|
|
41
|
+
* // Example 2: Transform input parameters for specific tools with validation
|
|
42
|
+
* const beforeExecute = ({ params, toolSlug, toolkitSlug }) => {
|
|
43
|
+
* // Handle different tools
|
|
44
|
+
* switch (toolSlug) {
|
|
45
|
+
* case 'GITHUB_SEARCH_REPOS':
|
|
46
|
+
* // Enhance search query with additional filters
|
|
47
|
+
* return {
|
|
48
|
+
* ...params,
|
|
49
|
+
* arguments: {
|
|
50
|
+
* ...params.arguments,
|
|
51
|
+
* q: `${params.arguments.query} in:name,description language:typescript stars:>100`,
|
|
52
|
+
* sort: 'stars',
|
|
53
|
+
* order: 'desc'
|
|
54
|
+
* }
|
|
55
|
+
* };
|
|
56
|
+
*
|
|
57
|
+
* case 'NPM_PACKAGE_INFO':
|
|
58
|
+
* // Validate and normalize package name
|
|
59
|
+
* const pkgName = params.arguments.packageName.trim().toLowerCase();
|
|
60
|
+
* if (!pkgName) {
|
|
61
|
+
* throw new Error('Package name is required');
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* return {
|
|
65
|
+
* ...params,
|
|
66
|
+
* arguments: {
|
|
67
|
+
* ...params.arguments,
|
|
68
|
+
* packageName: pkgName,
|
|
69
|
+
* includeVersions: true
|
|
70
|
+
* }
|
|
71
|
+
* };
|
|
72
|
+
*
|
|
73
|
+
* default:
|
|
74
|
+
* return params;
|
|
75
|
+
* }
|
|
76
|
+
* };
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export type beforeExecuteModifier = (context: {
|
|
80
|
+
toolSlug: string;
|
|
81
|
+
toolkitSlug: string;
|
|
82
|
+
params: ToolExecuteParams;
|
|
83
|
+
}) => Promise<ToolExecuteParams> | ToolExecuteParams;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Modifier for altering the tool execution response after execution completes.
|
|
87
|
+
*
|
|
88
|
+
* This function allows you to intercept and modify the response returned from a tool
|
|
89
|
+
* after its execution has completed. Common use cases include:
|
|
90
|
+
* - Transforming response data into a more convenient format
|
|
91
|
+
* - Handling or enhancing error responses
|
|
92
|
+
* - Adding additional context or derived data to successful responses
|
|
93
|
+
* - Implementing cross-cutting concerns like logging or analytics
|
|
94
|
+
*
|
|
95
|
+
* @param {string} toolSlug - The slug identifier of the tool that was executed
|
|
96
|
+
* @param {string} toolkitSlug - The slug identifier of the toolkit containing the tool
|
|
97
|
+
* @param {ToolExecuteResponse} toolExecuteResponse - The original execution response
|
|
98
|
+
* @returns {ToolExecuteResponse} The modified execution response
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // Example 1: Transform and enrich response data
|
|
103
|
+
* const afterExecute = ({ result, toolSlug, toolkitSlug }) => {
|
|
104
|
+
* // Handle successful GitHub repository listing
|
|
105
|
+
* if (toolSlug === 'GITHUB_LIST_REPOS' && result.successful) {
|
|
106
|
+
* // Transform the returned repos into a more useful format
|
|
107
|
+
* const repositories = result.data.items.map(repo => ({
|
|
108
|
+
* name: repo.name,
|
|
109
|
+
* url: repo.html_url,
|
|
110
|
+
* stars: repo.stargazers_count,
|
|
111
|
+
* // Add derived and computed fields
|
|
112
|
+
* isPopular: repo.stargazers_count > 1000,
|
|
113
|
+
* lastUpdated: new Date(repo.updated_at).toLocaleDateString(),
|
|
114
|
+
* topics: repo.topics || [],
|
|
115
|
+
* license: repo.license?.spdx_id || 'No License'
|
|
116
|
+
* }));
|
|
117
|
+
*
|
|
118
|
+
* // Add metadata about the response
|
|
119
|
+
* return {
|
|
120
|
+
* ...result,
|
|
121
|
+
* data: {
|
|
122
|
+
* repositories,
|
|
123
|
+
* totalCount: result.data.total_count,
|
|
124
|
+
* metadata: {
|
|
125
|
+
* queryTime: new Date().toISOString(),
|
|
126
|
+
* toolkit: toolkitSlug,
|
|
127
|
+
* filterApplied: true
|
|
128
|
+
* }
|
|
129
|
+
* }
|
|
130
|
+
* };
|
|
131
|
+
* }
|
|
132
|
+
*
|
|
133
|
+
* return result;
|
|
134
|
+
* };
|
|
135
|
+
*
|
|
136
|
+
* // Example 2: Comprehensive error handling and logging
|
|
137
|
+
* const afterExecute = ({ result, toolSlug, toolkitSlug }) => {
|
|
138
|
+
* // Log all executions for monitoring
|
|
139
|
+
* logToolExecution(toolSlug, toolkitSlug, result.successful);
|
|
140
|
+
*
|
|
141
|
+
* if (!result.successful) {
|
|
142
|
+
* // Get error details
|
|
143
|
+
* const errorCode = result.error?.code || 'UNKNOWN_ERROR';
|
|
144
|
+
* const errorMessage = result.error?.message || 'An unknown error occurred';
|
|
145
|
+
*
|
|
146
|
+
* // Handle specific error cases
|
|
147
|
+
* switch (errorCode) {
|
|
148
|
+
* case 'RATE_LIMIT_EXCEEDED':
|
|
149
|
+
* notifyRateLimitExceeded(toolkitSlug);
|
|
150
|
+
* break;
|
|
151
|
+
* case 'AUTHENTICATION_FAILED':
|
|
152
|
+
* refreshAuthToken(toolkitSlug);
|
|
153
|
+
* break;
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* // Return enhanced error response
|
|
157
|
+
* return {
|
|
158
|
+
* ...result,
|
|
159
|
+
* error: {
|
|
160
|
+
* message: `Error using ${toolSlug}: ${errorMessage}`,
|
|
161
|
+
* code: errorCode,
|
|
162
|
+
* timestamp: new Date().toISOString(),
|
|
163
|
+
* context: {
|
|
164
|
+
* toolkit: toolkitSlug,
|
|
165
|
+
* severity: getSeverityLevel(errorCode),
|
|
166
|
+
* retryable: isRetryableError(errorCode)
|
|
167
|
+
* }
|
|
168
|
+
* }
|
|
169
|
+
* };
|
|
170
|
+
* }
|
|
171
|
+
*
|
|
172
|
+
* return result;
|
|
173
|
+
* };
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export type afterExecuteModifier = (context: {
|
|
177
|
+
toolSlug: string;
|
|
178
|
+
toolkitSlug: string;
|
|
179
|
+
result: ToolExecuteResponse;
|
|
180
|
+
}) => Promise<ToolExecuteResponse> | ToolExecuteResponse;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Discriminates what kind of input the hook is seeing:
|
|
184
|
+
*
|
|
185
|
+
* - `'path'` — a local filesystem path string.
|
|
186
|
+
* - `'url'` — an `http(s)://...` URL string.
|
|
187
|
+
* - `'file'` — a `File` object; `path` holds `file.name` (a filename, NOT a
|
|
188
|
+
* filesystem path). Returning a string from the hook in this case replaces
|
|
189
|
+
* the `File` with a local-path upload.
|
|
190
|
+
*/
|
|
191
|
+
export type BeforeFileUploadSource = 'path' | 'url' | 'file';
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Called for each `file_uploadable` value before the SDK reads the file and
|
|
195
|
+
* uploads to storage.
|
|
196
|
+
*
|
|
197
|
+
* - `context.path` holds the local path, the URL, or the `File`'s name
|
|
198
|
+
* depending on `context.source`.
|
|
199
|
+
* - Return a string to replace the input (e.g. rewrite the path, redirect a
|
|
200
|
+
* URL, or swap a `File` for a filesystem path).
|
|
201
|
+
* - Return `false` to abort the upload with `ComposioFileUploadAbortedError`.
|
|
202
|
+
* - Throwing an error also aborts.
|
|
203
|
+
*/
|
|
204
|
+
export type beforeFileUploadModifier = (context: {
|
|
205
|
+
path: string;
|
|
206
|
+
source: BeforeFileUploadSource;
|
|
207
|
+
toolSlug: string;
|
|
208
|
+
toolkitSlug: string;
|
|
209
|
+
}) => Promise<string | false> | string | false;
|
|
210
|
+
|
|
211
|
+
type BeforeFileUploadHook = { beforeFileUpload?: beforeFileUploadModifier };
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Modifier for altering the tool schema before it's exposed to consumers.
|
|
215
|
+
*
|
|
216
|
+
* This function allows you to customize the metadata, parameters, and behavior definitions
|
|
217
|
+
* of tools before they are used. Common use cases include:
|
|
218
|
+
* - Customizing input parameter definitions or descriptions
|
|
219
|
+
* - Adding, removing, or modifying parameters to match your application's needs
|
|
220
|
+
* - Changing the name or description of tools to better fit your context
|
|
221
|
+
* - Implementing versioning or feature flagging for tool schemas
|
|
222
|
+
*
|
|
223
|
+
* @param {string} toolSlug - The slug identifier of the tool being modified
|
|
224
|
+
* @param {string} toolkitSlug - The slug identifier of the toolkit containing the tool
|
|
225
|
+
* @param {Tool} toolSchema - The original tool schema
|
|
226
|
+
* @returns {Tool} The modified tool schema
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* // Example 1: Comprehensive schema modification with validation
|
|
231
|
+
* const modifySchema = ({ schema, toolSlug, toolkitSlug }) => {
|
|
232
|
+
* // Handle specific tools
|
|
233
|
+
* if (toolSlug === 'HACKERNEWS_GET_USER') {
|
|
234
|
+
* return {
|
|
235
|
+
* ...schema,
|
|
236
|
+
* name: 'Get HackerNews User Profile',
|
|
237
|
+
* description: 'Retrieve detailed user information from HackerNews',
|
|
238
|
+
* version: '2.0.0',
|
|
239
|
+
* inputParameters: {
|
|
240
|
+
* ...schema.inputParameters,
|
|
241
|
+
* userId: {
|
|
242
|
+
* type: 'string',
|
|
243
|
+
* description: 'The HackerNews username to retrieve information for',
|
|
244
|
+
* required: true,
|
|
245
|
+
* minLength: 2,
|
|
246
|
+
* maxLength: 15,
|
|
247
|
+
* pattern: '^[a-zA-Z0-9_-]+$'
|
|
248
|
+
* },
|
|
249
|
+
* includeSubmissions: {
|
|
250
|
+
* type: 'boolean',
|
|
251
|
+
* description: 'Include user submissions in the response',
|
|
252
|
+
* default: false
|
|
253
|
+
* },
|
|
254
|
+
* submissionLimit: {
|
|
255
|
+
* type: 'number',
|
|
256
|
+
* description: 'Maximum number of submissions to return',
|
|
257
|
+
* default: 10,
|
|
258
|
+
* minimum: 1,
|
|
259
|
+
* maximum: 100
|
|
260
|
+
* }
|
|
261
|
+
* },
|
|
262
|
+
* outputSchema: {
|
|
263
|
+
* type: 'object',
|
|
264
|
+
* properties: {
|
|
265
|
+
* user: {
|
|
266
|
+
* type: 'object',
|
|
267
|
+
* properties: {
|
|
268
|
+
* id: { type: 'string' },
|
|
269
|
+
* karma: { type: 'number' },
|
|
270
|
+
* created: { type: 'string', format: 'date-time' },
|
|
271
|
+
* submissions: { type: 'array', items: { type: 'object' } }
|
|
272
|
+
* }
|
|
273
|
+
* }
|
|
274
|
+
* }
|
|
275
|
+
* }
|
|
276
|
+
* };
|
|
277
|
+
* }
|
|
278
|
+
*
|
|
279
|
+
* return schema;
|
|
280
|
+
* };
|
|
281
|
+
*
|
|
282
|
+
* // Example 2: Add organization-specific customizations
|
|
283
|
+
* const modifySchema = ({ schema, toolSlug, toolkitSlug }) => {
|
|
284
|
+
* // Add organization prefix to all GitHub tools
|
|
285
|
+
* if (toolkitSlug === 'github') {
|
|
286
|
+
* const enhancedSchema = {
|
|
287
|
+
* ...schema,
|
|
288
|
+
* name: `Acme Corp - ${schema.name}`,
|
|
289
|
+
* description: `Company GitHub tool: ${schema.description}`,
|
|
290
|
+
* category: 'Internal Tools',
|
|
291
|
+
* tags: [...(schema.tags || []), 'acme-corp', 'internal'],
|
|
292
|
+
* metadata: {
|
|
293
|
+
* ...(schema.metadata || {}),
|
|
294
|
+
* organization: 'acme-corp',
|
|
295
|
+
* department: 'engineering',
|
|
296
|
+
* supportContact: 'tools@acme-corp.com'
|
|
297
|
+
* },
|
|
298
|
+
* authentication: {
|
|
299
|
+
* type: 'oauth2',
|
|
300
|
+
* scopes: ['repo', 'user'],
|
|
301
|
+
* enterpriseServer: 'github.acme-corp.com'
|
|
302
|
+
* }
|
|
303
|
+
* };
|
|
304
|
+
*
|
|
305
|
+
* // Add rate limiting metadata
|
|
306
|
+
* if (schema.rateLimit) {
|
|
307
|
+
* enhancedSchema.rateLimit = {
|
|
308
|
+
* ...schema.rateLimit,
|
|
309
|
+
* enterprise: {
|
|
310
|
+
* requests: 5000,
|
|
311
|
+
* per: '1 hour'
|
|
312
|
+
* }
|
|
313
|
+
* };
|
|
314
|
+
* }
|
|
315
|
+
*
|
|
316
|
+
* return enhancedSchema;
|
|
317
|
+
* }
|
|
318
|
+
*
|
|
319
|
+
* return schema;
|
|
320
|
+
* };
|
|
321
|
+
*
|
|
322
|
+
* // Example 3: Simplify schemas for external consumers
|
|
323
|
+
* const modifySchema = ({ schema }) => {
|
|
324
|
+
* // Remove internal or complex parameters
|
|
325
|
+
* const {
|
|
326
|
+
* debugMode,
|
|
327
|
+
* internalFlags,
|
|
328
|
+
* experimentalFeatures,
|
|
329
|
+
* ...simpleInputParams
|
|
330
|
+
* } = schema.inputParameters;
|
|
331
|
+
*
|
|
332
|
+
* // Simplify authentication requirements
|
|
333
|
+
* const { oauth2, apiKey, ...simpleAuth } = schema.authentication || {};
|
|
334
|
+
*
|
|
335
|
+
* return {
|
|
336
|
+
* ...schema,
|
|
337
|
+
* inputParameters: simpleInputParams,
|
|
338
|
+
* authentication: {
|
|
339
|
+
* type: 'apiKey',
|
|
340
|
+
* in: 'header',
|
|
341
|
+
* name: 'X-API-Key'
|
|
342
|
+
* },
|
|
343
|
+
* // Remove internal metadata
|
|
344
|
+
* metadata: {
|
|
345
|
+
* isPublic: true,
|
|
346
|
+
* version: schema.metadata?.version
|
|
347
|
+
* }
|
|
348
|
+
* };
|
|
349
|
+
* };
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
export type TransformToolSchemaModifier = (context: {
|
|
353
|
+
toolSlug: string;
|
|
354
|
+
toolkitSlug: string;
|
|
355
|
+
schema: Tool;
|
|
356
|
+
}) => Tool | Promise<Tool>;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Options for non-agentic tool configuration.
|
|
360
|
+
*
|
|
361
|
+
* These options are used when working with non-agentic tool providers to
|
|
362
|
+
* customize the behavior of tools through schema transformation.
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* // Configure tools with schema modification
|
|
367
|
+
* const tools = await composio.tools.get('default', {
|
|
368
|
+
* toolkits: ['github']
|
|
369
|
+
* }, {
|
|
370
|
+
* modifySchema: (context) => {
|
|
371
|
+
* // Custom schema modifications
|
|
372
|
+
* return context.schema;
|
|
373
|
+
* }
|
|
374
|
+
* });
|
|
375
|
+
* ```
|
|
376
|
+
*/
|
|
377
|
+
export type ToolOptions = {
|
|
378
|
+
/**
|
|
379
|
+
* Function to transform tool schemas before they're exposed to consumers.
|
|
380
|
+
* This allows customizing input/output parameters, descriptions, and other metadata.
|
|
381
|
+
*/
|
|
382
|
+
modifySchema?: TransformToolSchemaModifier;
|
|
383
|
+
} & BeforeFileUploadHook;
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Options for configuring tool execution behavior.
|
|
387
|
+
*
|
|
388
|
+
* These modifiers allow you to intercept and modify tool execution at both
|
|
389
|
+
* the request and response stages, enabling custom behavior, data transformation,
|
|
390
|
+
* error handling, and more.
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* ```typescript
|
|
394
|
+
* // Execute a tool with request and response modifications
|
|
395
|
+
* const result = await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
396
|
+
* userId: 'default',
|
|
397
|
+
* arguments: { owner: 'composio' }
|
|
398
|
+
* }, {
|
|
399
|
+
* beforeExecute: (context) => {
|
|
400
|
+
* console.log(`Executing ${context.toolSlug} from ${context.toolkitSlug}`);
|
|
401
|
+
* return context.params;
|
|
402
|
+
* },
|
|
403
|
+
* afterExecute: (context) => {
|
|
404
|
+
* if (context.result.successful) {
|
|
405
|
+
* console.log(`Successfully executed ${context.toolSlug}`);
|
|
406
|
+
* }
|
|
407
|
+
* return context.result;
|
|
408
|
+
* }
|
|
409
|
+
* });
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
export type ExecuteToolModifiers = {
|
|
413
|
+
/**
|
|
414
|
+
* Function to intercept and modify tool execution parameters before the tool is executed.
|
|
415
|
+
* This allows customizing the request based on tool-specific needs.
|
|
416
|
+
*/
|
|
417
|
+
beforeExecute?: beforeExecuteModifier;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Function to intercept and modify tool execution responses after the tool has executed.
|
|
421
|
+
* This allows transforming the response or implementing custom error handling.
|
|
422
|
+
*/
|
|
423
|
+
afterExecute?: afterExecuteModifier;
|
|
424
|
+
} & BeforeFileUploadHook;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Type alias for session tool execution arguments.
|
|
428
|
+
* Represents the arguments passed to a tool during session execution.
|
|
429
|
+
* This is derived from ToolExecuteMetaParams but guaranteed to be non-null.
|
|
430
|
+
*/
|
|
431
|
+
export type MetaToolArguments = NonNullable<ToolExecuteMetaParams['arguments']>;
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Modifier for altering tool execute parameters before execution in a session context.
|
|
435
|
+
*
|
|
436
|
+
* This function is specifically designed for tools executed within a tool router session,
|
|
437
|
+
* allowing you to intercept and modify the parameters before execution. Helper tools use
|
|
438
|
+
* the 'composio' toolkit slug; preloaded app tools use their own toolkit slug when available.
|
|
439
|
+
*
|
|
440
|
+
* @param {string} toolSlug - The slug identifier of the tool being executed
|
|
441
|
+
* @param {string} toolkitSlug - The toolkit slug for this tool
|
|
442
|
+
* @param {string} sessionId - The session ID for the tool router context
|
|
443
|
+
* @param {MetaToolArguments} params - The parameters being passed to the tool
|
|
444
|
+
* @returns {MetaToolArguments} The modified parameters
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* ```typescript
|
|
448
|
+
* const beforeExecuteMeta = ({ toolSlug, toolkitSlug, sessionId, params }) => {
|
|
449
|
+
* console.log(`Executing ${toolkitSlug} tool ${toolSlug} in session ${sessionId}`);
|
|
450
|
+
*
|
|
451
|
+
* // Add or modify parameters
|
|
452
|
+
* return {
|
|
453
|
+
* ...params,
|
|
454
|
+
* timestamp: new Date().toISOString()
|
|
455
|
+
* };
|
|
456
|
+
* };
|
|
457
|
+
* ```
|
|
458
|
+
*/
|
|
459
|
+
export type beforeExecuteMetaModifier = (context: {
|
|
460
|
+
toolSlug: string;
|
|
461
|
+
toolkitSlug: string;
|
|
462
|
+
sessionId: string;
|
|
463
|
+
params: MetaToolArguments;
|
|
464
|
+
}) => Promise<MetaToolArguments> | MetaToolArguments;
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Modifier for altering a tool execution response after execution completes in a session context.
|
|
468
|
+
*
|
|
469
|
+
* This function is specifically designed for tools executed within a tool router session,
|
|
470
|
+
* allowing you to intercept and modify the response after execution. This is useful for
|
|
471
|
+
* session-specific transformations, logging, or error handling.
|
|
472
|
+
*
|
|
473
|
+
* @param {string} toolSlug - The slug identifier of the tool that was executed
|
|
474
|
+
* @param {string} toolkitSlug - The toolkit slug for this tool
|
|
475
|
+
* @param {string} sessionId - The session ID for the tool router context
|
|
476
|
+
* @param {ToolExecuteResponse} result - The original execution response
|
|
477
|
+
* @returns {ToolExecuteResponse} The modified execution response
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```typescript
|
|
481
|
+
* const afterExecuteMeta = ({ toolSlug, toolkitSlug, sessionId, result }) => {
|
|
482
|
+
* // Log session-specific execution
|
|
483
|
+
* console.log(`${toolkitSlug} tool ${toolSlug} completed in session ${sessionId}`);
|
|
484
|
+
*
|
|
485
|
+
* if (!result.successful) {
|
|
486
|
+
* console.error(`Session ${sessionId} error:`, result.error);
|
|
487
|
+
* }
|
|
488
|
+
*
|
|
489
|
+
* return result;
|
|
490
|
+
* };
|
|
491
|
+
* ```
|
|
492
|
+
*/
|
|
493
|
+
export type afterExecuteMetaModifier = (context: {
|
|
494
|
+
toolSlug: string;
|
|
495
|
+
toolkitSlug: string;
|
|
496
|
+
sessionId: string;
|
|
497
|
+
result: ToolExecuteResponse;
|
|
498
|
+
}) => Promise<ToolExecuteResponse> | ToolExecuteResponse;
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Modifiers specifically for tool execution within a session context.
|
|
502
|
+
*
|
|
503
|
+
* These modifiers are designed for tool router session-based execution,
|
|
504
|
+
* providing hooks to intercept and modify both the request and response of helper
|
|
505
|
+
* tools and preloaded app tools.
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```typescript
|
|
509
|
+
* const sessionModifiers: SessionExecuteMetaModifiers = {
|
|
510
|
+
* beforeExecute: ({ toolSlug, toolkitSlug, sessionId, params }) => {
|
|
511
|
+
* // Add session tracking
|
|
512
|
+
* console.log(`Executing ${toolkitSlug}/${toolSlug}`);
|
|
513
|
+
* return {
|
|
514
|
+
* ...params,
|
|
515
|
+
* sessionMetadata: {
|
|
516
|
+
* startTime: Date.now(),
|
|
517
|
+
* sessionId
|
|
518
|
+
* }
|
|
519
|
+
* };
|
|
520
|
+
* },
|
|
521
|
+
*
|
|
522
|
+
* afterExecute: ({ toolSlug, toolkitSlug, sessionId, result }) => {
|
|
523
|
+
* // Transform session results
|
|
524
|
+
* return {
|
|
525
|
+
* ...result,
|
|
526
|
+
* sessionInfo: {
|
|
527
|
+
* sessionId,
|
|
528
|
+
* toolSlug,
|
|
529
|
+
* toolkitSlug,
|
|
530
|
+
* completedAt: new Date().toISOString()
|
|
531
|
+
* }
|
|
532
|
+
* };
|
|
533
|
+
* }
|
|
534
|
+
* };
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
export type SessionExecuteMetaModifiers = {
|
|
538
|
+
/**
|
|
539
|
+
* Function to intercept and modify session tool execution parameters before the tool is executed.
|
|
540
|
+
* This allows customizing the request based on session-specific needs.
|
|
541
|
+
*/
|
|
542
|
+
beforeExecute?: beforeExecuteMetaModifier;
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Function to intercept and modify session tool execution responses after the tool has executed.
|
|
546
|
+
* This allows transforming the response or implementing custom session-specific handling.
|
|
547
|
+
*/
|
|
548
|
+
afterExecute?: afterExecuteMetaModifier;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Options for agentic tool configuration.
|
|
553
|
+
*
|
|
554
|
+
* These options combine schema modification capabilities with execution behavior
|
|
555
|
+
* customization, providing full control over both the definition and execution
|
|
556
|
+
* of tools in agentic contexts (like LLM providers).
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```typescript
|
|
560
|
+
* // Configure agentic tools with schema and execution modifications
|
|
561
|
+
* const agenticTools = await vercel.tools.get('default', 'GITHUB_GET_REPOS', {
|
|
562
|
+
* modifySchema: (context) => {
|
|
563
|
+
* return {
|
|
564
|
+
* ...context.schema,
|
|
565
|
+
* description: `Enhanced ${context.toolSlug} for better context`
|
|
566
|
+
* };
|
|
567
|
+
* },
|
|
568
|
+
*
|
|
569
|
+
* // Intercept before execution
|
|
570
|
+
* beforeExecute: (context) => {
|
|
571
|
+
* // Add analytics tracking
|
|
572
|
+
* trackToolUsage(context.toolSlug);
|
|
573
|
+
* return context.params;
|
|
574
|
+
* },
|
|
575
|
+
*
|
|
576
|
+
* // Transform after execution
|
|
577
|
+
* afterExecute: (context) => {
|
|
578
|
+
* // Log results and handle errors
|
|
579
|
+
* if (!context.result.successful) {
|
|
580
|
+
* logToolError(context.toolSlug, context.result.error);
|
|
581
|
+
* }
|
|
582
|
+
* return context.result;
|
|
583
|
+
* }
|
|
584
|
+
* });
|
|
585
|
+
* ```
|
|
586
|
+
*/
|
|
587
|
+
export type AgenticToolOptions = ToolOptions & ExecuteToolModifiers;
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Options for session-based tool configuration in tool router contexts.
|
|
591
|
+
*
|
|
592
|
+
* These options combine schema modification capabilities with session-specific execution
|
|
593
|
+
* behavior customization, providing control over both the definition and execution
|
|
594
|
+
* of tools within a tool router session.
|
|
595
|
+
*
|
|
596
|
+
* @example
|
|
597
|
+
* ```typescript
|
|
598
|
+
* // Configure session tools with schema and session-specific execution modifications
|
|
599
|
+
* const sessionTools = await toolRouter.getTools(sessionId, {
|
|
600
|
+
* modifySchema: (context) => {
|
|
601
|
+
* return {
|
|
602
|
+
* ...context.schema,
|
|
603
|
+
* description: `Session-specific ${context.toolSlug}`
|
|
604
|
+
* };
|
|
605
|
+
* },
|
|
606
|
+
*
|
|
607
|
+
* // Intercept before session tool execution
|
|
608
|
+
* beforeExecute: ({ toolSlug, toolkitSlug, sessionId, params }) => {
|
|
609
|
+
* // Add session tracking
|
|
610
|
+
* console.log(`Executing ${toolkitSlug}/${toolSlug}`);
|
|
611
|
+
* return {
|
|
612
|
+
* ...params,
|
|
613
|
+
* sessionMetadata: { sessionId, timestamp: Date.now() }
|
|
614
|
+
* };
|
|
615
|
+
* },
|
|
616
|
+
*
|
|
617
|
+
* // Transform after session tool execution
|
|
618
|
+
* afterExecute: ({ toolSlug, toolkitSlug, sessionId, result }) => {
|
|
619
|
+
* // Log session results
|
|
620
|
+
* if (!result.successful) {
|
|
621
|
+
* logSessionError(sessionId, toolkitSlug, toolSlug, result.error);
|
|
622
|
+
* }
|
|
623
|
+
* return result;
|
|
624
|
+
* }
|
|
625
|
+
* });
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
export type SessionMetaToolOptions = ToolOptions & SessionExecuteMetaModifiers;
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Provider-specific options determined by the type of provider being used.
|
|
632
|
+
*
|
|
633
|
+
* This type automatically resolves to either AgenticToolOptions or ToolOptions
|
|
634
|
+
* based on whether the provider is agentic (like OpenAI or Vercel) or non-agentic.
|
|
635
|
+
*
|
|
636
|
+
* @template T - The provider type
|
|
637
|
+
*
|
|
638
|
+
* @example
|
|
639
|
+
* ```typescript
|
|
640
|
+
* // With standard provider (non-agentic)
|
|
641
|
+
* const tools = await composio.tools.get('default', 'GITHUB_GET_REPOS', {
|
|
642
|
+
* modifySchema: (context) => context.schema
|
|
643
|
+
* });
|
|
644
|
+
*
|
|
645
|
+
* // With agentic provider (e.g., VercelProvider)
|
|
646
|
+
* const vercel = new Composio({
|
|
647
|
+
* apiKey: process.env.COMPOSIO_API_KEY,
|
|
648
|
+
* provider: new VercelProvider()
|
|
649
|
+
* });
|
|
650
|
+
*
|
|
651
|
+
* const agenticTools = await vercel.tools.get('default', 'GITHUB_GET_REPOS', {
|
|
652
|
+
* modifySchema: (context) => context.schema,
|
|
653
|
+
* beforeExecute: (context) => context.params,
|
|
654
|
+
* afterExecute: (context) => context.result
|
|
655
|
+
* });
|
|
656
|
+
* ```
|
|
657
|
+
*/
|
|
658
|
+
export type ProviderOptions<TProvider> =
|
|
659
|
+
TProvider extends BaseComposioProvider<infer TToolCollection, infer TTool, infer TMcpResponse>
|
|
660
|
+
? TProvider extends BaseAgenticProvider<TToolCollection, TTool, TMcpResponse>
|
|
661
|
+
? AgenticToolOptions
|
|
662
|
+
: ToolOptions
|
|
663
|
+
: never;
|
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ExecuteToolModifiers } from './modifiers.types';
|
|
2
|
+
import {
|
|
3
|
+
CustomAuthParams,
|
|
4
|
+
Tool,
|
|
5
|
+
ToolExecuteParams,
|
|
6
|
+
ToolExecuteResponse,
|
|
7
|
+
ToolkitVersion,
|
|
8
|
+
ToolListParams,
|
|
9
|
+
} from './tool.types';
|
|
10
|
+
import { CustomConnectionData } from './connectedAccountAuthStates.types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Base provider implementation, which needs to be implemented by the extended class.
|
|
14
|
+
* This class is used to create a base provider by implementing this class.
|
|
15
|
+
* This class also extends InstrumentedInstance, so that the telemetry can be instrumented for the provider.
|
|
16
|
+
*/
|
|
17
|
+
export interface Provider<TTool, TToolCollection> {
|
|
18
|
+
wrapTool: (tool: Tool) => TTool;
|
|
19
|
+
getTools: (params?: ToolListParams) => Promise<TToolCollection>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type ExecuteToolFnOptions = {
|
|
23
|
+
connectedAccountId?: string;
|
|
24
|
+
customAuthParams?: CustomAuthParams;
|
|
25
|
+
customConnectionData?: CustomConnectionData;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* This type is used to infer the wrapped tool type from the provider.
|
|
30
|
+
* It checks if the provider has a method `_wrapTool` and infers the return type.
|
|
31
|
+
*/
|
|
32
|
+
export type ExecuteToolFn = (
|
|
33
|
+
toolSlug: string,
|
|
34
|
+
input: Record<string, unknown>
|
|
35
|
+
) => Promise<ToolExecuteResponse>;
|
|
36
|
+
|
|
37
|
+
export type GlobalExecuteToolFn = (
|
|
38
|
+
slug: string,
|
|
39
|
+
body: ToolExecuteParams,
|
|
40
|
+
modifiers?: ExecuteToolModifiers
|
|
41
|
+
) => Promise<ToolExecuteResponse>;
|