@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,412 @@
|
|
|
1
|
+
import ComposioClient from '@composio/client';
|
|
2
|
+
import {
|
|
3
|
+
ToolkitListParams,
|
|
4
|
+
ToolKitListResponse,
|
|
5
|
+
ToolkitRetrieveResponse,
|
|
6
|
+
ToolkitsListParamsSchema,
|
|
7
|
+
ToolkitRetrieveCategoriesResponse,
|
|
8
|
+
ToolkitAuthFieldsResponse,
|
|
9
|
+
} from '../types/toolkit.types';
|
|
10
|
+
import { ComposioToolkitFetchError, ComposioToolkitNotFoundError } from '../errors';
|
|
11
|
+
import { ValidationError } from '../errors/ValidationErrors';
|
|
12
|
+
import { AuthConfigs } from './AuthConfigs';
|
|
13
|
+
import { ComposioAuthConfigNotFoundError } from '../errors/AuthConfigErrors';
|
|
14
|
+
import { ConnectedAccounts } from './ConnectedAccounts';
|
|
15
|
+
import { ConnectionRequest } from '../types/connectionRequest.types';
|
|
16
|
+
import { telemetry } from '../telemetry/Telemetry';
|
|
17
|
+
import { AuthSchemeType } from '../types/authConfigs.types';
|
|
18
|
+
import logger from '../utils/logger';
|
|
19
|
+
import { APIError } from 'openai';
|
|
20
|
+
import {
|
|
21
|
+
transformToolkitListResponse,
|
|
22
|
+
transformToolkitRetrieveCategoriesResponse,
|
|
23
|
+
transformToolkitRetrieveResponse,
|
|
24
|
+
} from '../utils/transformers/toolkits';
|
|
25
|
+
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
26
|
+
import { withCancellation } from '../utils/cancellation';
|
|
27
|
+
import { ComposioRequestCancelledError } from '../errors/SDKErrors';
|
|
28
|
+
/**
|
|
29
|
+
* Toolkits class
|
|
30
|
+
*
|
|
31
|
+
* Toolkits are a collection of tools that can be used to perform various tasks.
|
|
32
|
+
* This is similar/replacement of `apps` in the Composio API.
|
|
33
|
+
*/
|
|
34
|
+
export class Toolkits {
|
|
35
|
+
private client: ComposioClient;
|
|
36
|
+
|
|
37
|
+
constructor(client: ComposioClient) {
|
|
38
|
+
this.client = client;
|
|
39
|
+
this.authorize = this.authorize.bind(this);
|
|
40
|
+
telemetry.instrument(this, 'Toolkits');
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves a list of toolkits based on the provided query parameters.
|
|
44
|
+
*
|
|
45
|
+
* This method fetches toolkits from the Composio API and transforms the response
|
|
46
|
+
* from snake_case to camelCase format for consistency with JavaScript/TypeScript conventions.
|
|
47
|
+
*
|
|
48
|
+
* @param {ToolkitListParams} query - The query parameters to filter toolkits
|
|
49
|
+
* @returns {Promise<ToolKitListResponse>} The transformed list of toolkits
|
|
50
|
+
*
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
private async getToolkits(
|
|
54
|
+
query: ToolkitListParams,
|
|
55
|
+
requestOptions?: ComposioRequestOptions
|
|
56
|
+
): Promise<ToolKitListResponse> {
|
|
57
|
+
try {
|
|
58
|
+
const parsedQuery = ToolkitsListParamsSchema.safeParse(query);
|
|
59
|
+
if (!parsedQuery.success) {
|
|
60
|
+
throw new ValidationError('Failed to parse toolkit list query', {
|
|
61
|
+
cause: parsedQuery.error,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const listParams = {
|
|
65
|
+
category: parsedQuery.data.category,
|
|
66
|
+
managed_by: parsedQuery.data.managedBy,
|
|
67
|
+
sort_by: parsedQuery.data.sortBy,
|
|
68
|
+
cursor: parsedQuery.data.cursor,
|
|
69
|
+
limit: parsedQuery.data.limit,
|
|
70
|
+
};
|
|
71
|
+
const result = await withCancellation(
|
|
72
|
+
() => this.client.toolkits.list(listParams, requestOptions),
|
|
73
|
+
requestOptions?.signal
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return transformToolkitListResponse(result);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error instanceof ComposioRequestCancelledError) {
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
throw new ComposioToolkitFetchError('Failed to fetch toolkits', {
|
|
82
|
+
cause: error,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Retrieves a specific toolkit by its slug identifier.
|
|
88
|
+
*
|
|
89
|
+
* This method fetches a single toolkit from the Composio API and transforms
|
|
90
|
+
* the response to use camelCase property naming consistent with JavaScript/TypeScript conventions.
|
|
91
|
+
*
|
|
92
|
+
* @param {string} slug - The unique slug identifier of the toolkit to retrieve
|
|
93
|
+
* @returns {Promise<ToolkitRetrieveResponse>} The transformed toolkit object
|
|
94
|
+
* @throws {ValidationError} If the response cannot be properly parsed
|
|
95
|
+
* @throws {ComposioToolNotFoundError} If no toolkit with the given slug exists
|
|
96
|
+
*
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
protected async getToolkitBySlug(
|
|
100
|
+
slug: string,
|
|
101
|
+
requestOptions?: ComposioRequestOptions
|
|
102
|
+
): Promise<ToolkitRetrieveResponse> {
|
|
103
|
+
try {
|
|
104
|
+
const result = await withCancellation(
|
|
105
|
+
() => this.client.toolkits.retrieve(slug, undefined, requestOptions),
|
|
106
|
+
requestOptions?.signal
|
|
107
|
+
);
|
|
108
|
+
return transformToolkitRetrieveResponse(result);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (error instanceof ComposioRequestCancelledError) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
if (error instanceof APIError && (error.status === 404 || error.status === 400)) {
|
|
114
|
+
throw new ComposioToolkitNotFoundError(`Toolkit with slug ${slug} not found`, {
|
|
115
|
+
meta: {
|
|
116
|
+
slug,
|
|
117
|
+
},
|
|
118
|
+
cause: error,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
throw new ComposioToolkitFetchError(`Couldn't fetch Toolkit with slug: ${slug}`, {
|
|
122
|
+
meta: {
|
|
123
|
+
slug,
|
|
124
|
+
},
|
|
125
|
+
cause: error,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Retrieves a specific toolkit by its slug identifier.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} slug - The unique slug identifier of the toolkit to retrieve
|
|
134
|
+
* @returns {Promise<ToolkitRetrieveResponse>} The toolkit object with detailed information
|
|
135
|
+
* @throws {ComposioToolNotFoundError} If no toolkit with the given slug exists
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // Get a specific toolkit
|
|
140
|
+
* const githubToolkit = await composio.toolkits.get('github');
|
|
141
|
+
* console.log(githubToolkit.name); // GitHub
|
|
142
|
+
* console.log(githubToolkit.authConfigDetails); // Authentication configuration details
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
async get(
|
|
146
|
+
slug: string,
|
|
147
|
+
requestOptions?: ComposioRequestOptions
|
|
148
|
+
): Promise<ToolkitRetrieveResponse>;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Retrieves a list of toolkits based on the provided query parameters.
|
|
152
|
+
*
|
|
153
|
+
* @param {ToolkitListParams} query - The query parameters to filter toolkits
|
|
154
|
+
* @returns {Promise<ToolKitListResponse>} A paginated list of toolkits matching the query criteria
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* // Get all toolkits
|
|
159
|
+
* const allToolkits = await composio.toolkits.get({});
|
|
160
|
+
*
|
|
161
|
+
* // Get toolkits by category
|
|
162
|
+
* const devToolkits = await composio.toolkits.get({
|
|
163
|
+
* category: 'developer-tools'
|
|
164
|
+
* });
|
|
165
|
+
*
|
|
166
|
+
* // Get local toolkits
|
|
167
|
+
* const localToolkits = await composio.toolkits.get({
|
|
168
|
+
* isLocal: true
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
async get(
|
|
173
|
+
query?: ToolkitListParams,
|
|
174
|
+
requestOptions?: ComposioRequestOptions
|
|
175
|
+
): Promise<ToolKitListResponse>;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Implementation method that handles both overloads for retrieving toolkits.
|
|
179
|
+
*
|
|
180
|
+
* @param {string | ToolkitListParams} arg - Either a toolkit slug or query parameters
|
|
181
|
+
* @param {ComposioRequestOptions} [requestOptions] - Per-request cancellation/timeout options
|
|
182
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit or list of toolkits
|
|
183
|
+
*/
|
|
184
|
+
async get(
|
|
185
|
+
arg?: string | ToolkitListParams,
|
|
186
|
+
requestOptions?: ComposioRequestOptions
|
|
187
|
+
): Promise<ToolkitRetrieveResponse | ToolKitListResponse> {
|
|
188
|
+
if (typeof arg === 'string') {
|
|
189
|
+
return this.getToolkitBySlug(arg, requestOptions);
|
|
190
|
+
}
|
|
191
|
+
return this.getToolkits(arg ?? {}, requestOptions);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private async getAuthConfigFields(
|
|
195
|
+
toolkitSlug: string,
|
|
196
|
+
authScheme: AuthSchemeType | null,
|
|
197
|
+
authConfigType: 'authConfigCreation' | 'connectedAccountInitiation',
|
|
198
|
+
requiredOnly: boolean
|
|
199
|
+
): Promise<ToolkitAuthFieldsResponse> {
|
|
200
|
+
const toolkit = await this.getToolkitBySlug(toolkitSlug);
|
|
201
|
+
if (!toolkit.authConfigDetails) {
|
|
202
|
+
throw new ComposioAuthConfigNotFoundError('No auth config found for toolkit', {
|
|
203
|
+
meta: {
|
|
204
|
+
toolkitSlug,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// if multiple auth configs are found, warn the user and select the first one
|
|
210
|
+
if (toolkit.authConfigDetails.length > 1 && !authScheme) {
|
|
211
|
+
logger.warn(
|
|
212
|
+
`Multiple auth configs found for ${toolkitSlug}, please specify the auth scheme to get details of specific auth scheme. Selecting the first scheme by default.`,
|
|
213
|
+
{
|
|
214
|
+
meta: {
|
|
215
|
+
toolkitSlug,
|
|
216
|
+
},
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// if authScheme is provided, find the auth config for the given auth scheme
|
|
222
|
+
// otherwise, use the first auth config
|
|
223
|
+
const authConfig = authScheme
|
|
224
|
+
? toolkit.authConfigDetails.find(authConfig => authConfig.mode === authScheme)
|
|
225
|
+
: toolkit.authConfigDetails[0];
|
|
226
|
+
|
|
227
|
+
if (!authConfig) {
|
|
228
|
+
throw new ComposioAuthConfigNotFoundError(
|
|
229
|
+
`Auth schema ${authScheme} not found for toolkit ${toolkitSlug} with auth scheme ${authScheme}`,
|
|
230
|
+
{
|
|
231
|
+
meta: {
|
|
232
|
+
toolkitSlug,
|
|
233
|
+
authScheme,
|
|
234
|
+
},
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const requiredFields = authConfig.fields[authConfigType].required.map(field => ({
|
|
240
|
+
...field,
|
|
241
|
+
required: true,
|
|
242
|
+
}));
|
|
243
|
+
if (requiredOnly) {
|
|
244
|
+
return requiredFields;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const optionalFields = authConfig.fields[authConfigType].optional.map(field => ({
|
|
248
|
+
...field,
|
|
249
|
+
required: false,
|
|
250
|
+
}));
|
|
251
|
+
|
|
252
|
+
return [...requiredFields, ...optionalFields];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Retrieves the fields required for creating an auth config for a toolkit.
|
|
257
|
+
* @param toolkitSlug - The slug of the toolkit to retrieve the fields for
|
|
258
|
+
* @param authScheme - The auth scheme to retrieve the fields for
|
|
259
|
+
* @param options.requiredOnly - Whether to only return the required fields
|
|
260
|
+
* @returns {Promise<ToolkitAuthFieldsResponse>} The fields required for creating an auth config
|
|
261
|
+
*/
|
|
262
|
+
async getAuthConfigCreationFields(
|
|
263
|
+
toolkitSlug: string,
|
|
264
|
+
authScheme: AuthSchemeType,
|
|
265
|
+
{ requiredOnly = false }: { requiredOnly?: boolean } = {}
|
|
266
|
+
): Promise<ToolkitAuthFieldsResponse> {
|
|
267
|
+
return this.getAuthConfigFields(
|
|
268
|
+
toolkitSlug,
|
|
269
|
+
authScheme ?? null,
|
|
270
|
+
'authConfigCreation',
|
|
271
|
+
requiredOnly
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Retrieves the fields required for initiating a connected account for a toolkit.
|
|
277
|
+
* @param toolkitSlug - The slug of the toolkit to retrieve the fields for
|
|
278
|
+
* @param authScheme - The auth scheme to retrieve the fields for
|
|
279
|
+
* @param options.requiredOnly - Whether to only return the required fields
|
|
280
|
+
* @returns {Promise<ToolkitAuthFieldsResponse>} The fields required for initiating a connected account
|
|
281
|
+
*/
|
|
282
|
+
async getConnectedAccountInitiationFields(
|
|
283
|
+
toolkitSlug: string,
|
|
284
|
+
authScheme: AuthSchemeType,
|
|
285
|
+
{ requiredOnly = false }: { requiredOnly?: boolean } = {}
|
|
286
|
+
): Promise<ToolkitAuthFieldsResponse> {
|
|
287
|
+
return this.getAuthConfigFields(
|
|
288
|
+
toolkitSlug,
|
|
289
|
+
authScheme ?? null,
|
|
290
|
+
'connectedAccountInitiation',
|
|
291
|
+
requiredOnly
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Retrieves all toolkit categories available in the Composio SDK.
|
|
297
|
+
*
|
|
298
|
+
* This method fetches the complete list of categories from the Composio API
|
|
299
|
+
* and transforms the response to use camelCase property naming.
|
|
300
|
+
*
|
|
301
|
+
* @returns {Promise<ToolkitRetrieveCategoriesResponse>} The list of toolkit categories
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* // Get all toolkit categories
|
|
306
|
+
* const categories = await composio.toolkits.listCategories();
|
|
307
|
+
* console.log(categories.items); // Array of category objects
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
async listCategories(
|
|
311
|
+
requestOptions?: ComposioRequestOptions
|
|
312
|
+
): Promise<ToolkitRetrieveCategoriesResponse> {
|
|
313
|
+
const result = await withCancellation(
|
|
314
|
+
() => this.client.toolkits.retrieveCategories(requestOptions),
|
|
315
|
+
requestOptions?.signal
|
|
316
|
+
);
|
|
317
|
+
return transformToolkitRetrieveCategoriesResponse(result);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Authorizes a user to use a toolkit.
|
|
322
|
+
* This method will create an auth config if one doesn't exist and initiate a connection request.
|
|
323
|
+
* @param {string} userId - The user id of the user to authorize
|
|
324
|
+
* @param {string} toolkitSlug - The slug of the toolkit to authorize
|
|
325
|
+
* @returns {Promise<ConnectionRequest>} The connection request object
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* const connectionRequest = await composio.toolkits.authorize(userId, 'github');
|
|
330
|
+
* ```
|
|
331
|
+
*
|
|
332
|
+
*/
|
|
333
|
+
async authorize(
|
|
334
|
+
userId: string,
|
|
335
|
+
toolkitSlug: string,
|
|
336
|
+
authConfigId?: string,
|
|
337
|
+
requestOptions?: ComposioRequestOptions
|
|
338
|
+
): Promise<ConnectionRequest> {
|
|
339
|
+
// High-level helper that fans out to 3-4 network calls (toolkit retrieve,
|
|
340
|
+
// optional authConfigs list, optional authConfigs create, then
|
|
341
|
+
// connectedAccounts.initiate). Forward the caller's signal to every
|
|
342
|
+
// underlying call so the whole composite is cancellable as a single unit.
|
|
343
|
+
const toolkit = await this.getToolkitBySlug(toolkitSlug, requestOptions);
|
|
344
|
+
const composioAuthConfig = new AuthConfigs(this.client);
|
|
345
|
+
let authConfigIdToUse: string | undefined = authConfigId;
|
|
346
|
+
|
|
347
|
+
if (!authConfigIdToUse) {
|
|
348
|
+
const authConfig = await composioAuthConfig.list(
|
|
349
|
+
{
|
|
350
|
+
toolkit: toolkitSlug,
|
|
351
|
+
},
|
|
352
|
+
requestOptions
|
|
353
|
+
);
|
|
354
|
+
// pick the first auth config if none is passed
|
|
355
|
+
authConfigIdToUse = authConfig.items[0]?.id;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// if no auth config is found, create one for the toolkit
|
|
359
|
+
if (!authConfigIdToUse) {
|
|
360
|
+
// create authConfig using composioManagedAuthSchemes
|
|
361
|
+
if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
|
|
362
|
+
try {
|
|
363
|
+
const authConfig = await composioAuthConfig.create(
|
|
364
|
+
toolkitSlug,
|
|
365
|
+
{
|
|
366
|
+
type: 'use_composio_managed_auth',
|
|
367
|
+
name: `${toolkit.name} Auth Config`,
|
|
368
|
+
},
|
|
369
|
+
requestOptions
|
|
370
|
+
);
|
|
371
|
+
authConfigIdToUse = authConfig.id;
|
|
372
|
+
} catch (error) {
|
|
373
|
+
if (error instanceof ComposioClient.APIError && error.status === 400) {
|
|
374
|
+
throw new ComposioAuthConfigNotFoundError(
|
|
375
|
+
`No Default auth config found for toolkit ${toolkitSlug}`,
|
|
376
|
+
{
|
|
377
|
+
meta: {
|
|
378
|
+
toolkitSlug,
|
|
379
|
+
},
|
|
380
|
+
cause: error,
|
|
381
|
+
possibleFixes: [
|
|
382
|
+
`Please Create an auth config for the toolkit ${toolkitSlug} via the dashboard`,
|
|
383
|
+
],
|
|
384
|
+
}
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
throw error;
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
throw new ComposioAuthConfigNotFoundError(
|
|
391
|
+
`No auth configs found for toolkit ${toolkitSlug}`,
|
|
392
|
+
{
|
|
393
|
+
meta: {
|
|
394
|
+
toolkitSlug,
|
|
395
|
+
},
|
|
396
|
+
}
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
// create the auth config
|
|
401
|
+
const composioConnectedAccount = new ConnectedAccounts(this.client);
|
|
402
|
+
return await composioConnectedAccount.initiate(
|
|
403
|
+
userId,
|
|
404
|
+
authConfigIdToUse,
|
|
405
|
+
{
|
|
406
|
+
// in this magic function we allow multiple connected accounts per user for an auth config
|
|
407
|
+
allowMultiple: true,
|
|
408
|
+
},
|
|
409
|
+
requestOptions
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
}
|