Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 23, 03:00 UTC
Update toolkit model
haxzie committed
May 15, 2025 at 16:03 UTC
9fc01ed6d6a730d907e7004fe8a5491f0d81f7db
7 files changed
+195
-75
README.md
+77
@@ -139,6 +139,83 @@ const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
139
});
140
```
141
142
+## Connected Accounts
143
+
144
+Composio SDK provides a powerful way to manage third-party service connections through Connected Accounts. This feature allows you to authenticate with various services and maintain those connections.
145
+
146
+### Creating a Connected Account
147
+
148
+```typescript
149
+import { Composio } from '@composio/core';
150
+
151
+const composio = new Composio({
152
+ apiKey: process.env.COMPOSIO_API_KEY,
153
+});
154
+
155
+// Create a connected account
156
+const connectionRequest = await composio.createConnectedAccount(
157
+ 'user123', // userId
158
+ 'HACKERNEWS', // authConfigId
159
+ {
160
+ redirectUrl: 'https://your-app.com/callback',
161
+ data: {
162
+ // Additional data for the connection
163
+ scope: ['read', 'write'],
164
+ },
165
+ }
166
+);
167
+
168
+// Wait for the connection to be established
169
+// Default timeout is 60 seconds
170
+const connectedAccount = await connectionRequest.waitForConnection();
171
+```
172
+
173
+### Managing Connected Accounts
174
+
175
+```typescript
176
+// List all connected accounts
177
+const accounts = await composio.connectedAccounts.list({
178
+ userId: 'user123',
179
+});
180
+
181
+// Get a specific connected account
182
+const account = await composio.connectedAccounts.get('account_id');
183
+
184
+// Enable/Disable a connected account
185
+await composio.connectedAccounts.enable('account_id');
186
+await composio.connectedAccounts.disable('account_id');
187
+
188
+// Refresh credentials
189
+await composio.connectedAccounts.refresh('account_id');
190
+
191
+// Delete a connected account
192
+await composio.connectedAccounts.delete('account_id');
193
+```
194
+
195
+### Connection Statuses
196
+
197
+Connected accounts can have the following statuses:
198
+
199
+- `ACTIVE`: Connection is established and working
200
+- `INACTIVE`: Connection is temporarily disabled
201
+- `PENDING`: Connection is being processed
202
+- `INITIATED`: Connection request has started
203
+- `EXPIRED`: Connection credentials have expired
204
+- `FAILED`: Connection attempt failed
205
+
206
+### Authentication Schemes
207
+
208
+Composio supports various authentication schemes:
209
+
210
+- OAuth2
211
+- OAuth1
212
+- OAuth1a
213
+- API Key
214
+- Basic Auth
215
+- Bearer Token
216
+- Google Service Account
217
+- And more...
218
+
219
## Development
220
221
### Creating Custom Toolsets
packages/core/src/models/ConnectedAccounts.ts
+9
-9
@@ -20,7 +20,7 @@ import {
20
} from '@composio/client/resources/connected-accounts';
21
import {
22
CreateConnectedAccountOptions,
23
- CreateConnectedAccountParams,
23
+ CreateConnectedAccountParamsSchema,
24
} from '../types/connectedAccounts.types';
25
import { ConnectionRequest } from './ConnectionRequest';
26
@@ -69,8 +69,8 @@ export class ConnectedAccounts {
69
* @param {RequestOptions} options - Request options
70
* @returns {Promise<ConnectedAccountRetrieveResponse>} Connected account details
71
*/
72
- async get(nanoid: string, options?: RequestOptions): Promise<ConnectedAccountRetrieveResponse> {
73
- return this.client.connectedAccounts.retrieve(nanoid, options);
72
+ async get(nanoid: string): Promise<ConnectedAccountRetrieveResponse> {
73
+ return this.client.connectedAccounts.retrieve(nanoid);
74
}
75
76
/**
@@ -79,8 +79,8 @@ export class ConnectedAccounts {
79
* @param {RequestOptions} options - Request options
80
* @returns {Promise<ConnectedAccountDeleteResponse>} Response from deletion
81
*/
82
- async delete(nanoid: string, options?: RequestOptions): Promise<ConnectedAccountDeleteResponse> {
83
- return this.client.connectedAccounts.delete(nanoid, options);
82
+ async delete(nanoid: string): Promise<ConnectedAccountDeleteResponse> {
83
+ return this.client.connectedAccounts.delete(nanoid);
84
}
85
86
/**
@@ -93,7 +93,7 @@ export class ConnectedAccounts {
93
nanoid: string,
94
options?: RequestOptions
95
): Promise<ConnectedAccountRefreshResponse> {
96
- return this.client.connectedAccounts.refresh(nanoid, options);
96
+ return this.client.connectedAccounts.refresh(nanoid);
97
}
98
99
/**
@@ -108,7 +108,7 @@ export class ConnectedAccounts {
108
params: ConnectedAccountUpdateStatusParams,
109
options?: RequestOptions
110
): Promise<ConnectedAccountUpdateStatusResponse> {
111
- return this.client.connectedAccounts.updateStatus(nanoid, params, options);
111
+ return this.client.connectedAccounts.updateStatus(nanoid, params);
112
}
113
114
/**
@@ -121,7 +121,7 @@ export class ConnectedAccounts {
121
nanoid: string,
122
options?: RequestOptions
123
): Promise<ConnectedAccountUpdateStatusResponse> {
124
- return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true }, options);
124
+ return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true });
125
}
126
127
/**
@@ -134,7 +134,7 @@ export class ConnectedAccounts {
134
nanoid: string,
135
options?: RequestOptions
136
): Promise<ConnectedAccountUpdateStatusResponse> {
137
- return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false }, options);
137
+ return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
138
}
139
140
/**
packages/core/src/models/Toolkits.ts
+31
-2
@@ -29,7 +29,7 @@ export class Toolkits {
29
* This method fetches the toolkits from the Composio API.
30
* @returns {Promise<Toolkit[]>} List of toolkits
31
*/
32
- async getToolkits(query: ToolkitListParams): Promise<ToolKitListResponse> {
32
+ private async getToolkits(query: ToolkitListParams): Promise<ToolKitListResponse> {
33
const parsedQuery = ToolkitsListParamsSchema.parse(query);
34
const result = await this.client.toolkits.list({
35
category: parsedQuery.category,
@@ -65,7 +65,7 @@ export class Toolkits {
65
* @param options - Request options
66
* @returns {Promise<ToolkitRetrieveResponse>} The toolkit object
67
*/
68
- async getToolkitBySlug(slug: string): Promise<ToolkitRetrieveResponse> {
68
+ private async getToolkitBySlug(slug: string): Promise<ToolkitRetrieveResponse> {
69
const result = await this.client.toolkits.retrieve(slug);
70
const parsedResult = ToolkitRetrieveResponseSchema.parse({
71
name: result.name,
@@ -78,6 +78,35 @@ export class Toolkits {
78
return parsedResult;
79
}
80
81
+ /**
82
+ * @overload
83
+ * Fetches a toolkit by its Slug or a list of toolkits.
84
+ * @param slug - The ID of the toolkit to be retrieved
85
+ * @returns {Promise<ToolkitRetrieveResponse>} The toolkit object
86
+ */
87
+ async get(slug: string): Promise<ToolkitRetrieveResponse>;
88
+ /**
89
+ * @overload
90
+ * Fetches a list of toolkits.
91
+ * @param query - The parameters to fetch the toolkits
92
+ * @returns {Promise<ToolKitListResponse>} The list of toolkits
93
+ */
94
+ async get(query: ToolkitListParams): Promise<ToolKitListResponse>;
95
+ /**
96
+ * Fetches a toolkit by its Slug or a list of toolkits.
97
+ * This method retrieves the toolkit from the Composio API.
98
+ * @param arg - The ID of the toolkit to be retrieved or a list of parameters
99
+ * @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit object or a list of toolkits
100
+ */
101
+ async get(
102
+ arg: string | ToolkitListParams
103
+ ): Promise<ToolkitRetrieveResponse | ToolKitListResponse> {
104
+ if (typeof arg === 'string') {
105
+ return this.getToolkitBySlug(arg);
106
+ }
107
+ return this.getToolkits(arg);
108
+ }
109
+
110
/**
111
* Fetches all categories available in the Composio SDK
112
*
packages/core/src/models/Tools.ts
+4
-4
@@ -6,12 +6,12 @@ import {
6
ToolExecuteResponse,
7
ToolList,
8
ToolSchema,
9
+ ToolListParams,
10
ToolExecuteResponseSchema,
11
} from '../types/tool.types';
12
import {
13
ToolGetInputParams,
14
ToolGetInputResponse,
14
- ToolListParams,
15
ToolProxyParams,
16
ToolProxyResponse,
17
ToolRetrieveEnumResponse,
@@ -198,8 +198,8 @@ export class Tools<
198
important: queryParams.data.important,
199
limit: queryParams.data.limit,
200
search: queryParams.data.search,
201
- toolkit_slug: queryParams.data.toolkitSlug,
202
- tool_slugs: queryParams.data.toolSlugs?.join(','),
201
+ toolkit_slug: queryParams.data.toolkits,
202
+ tool_slugs: queryParams.data.tools?.join(','),
203
});
204
if (!tools) {
205
return [];
@@ -215,7 +215,7 @@ export class Tools<
215
// }
216
217
const customTools = await this.customTools.getCustomTools({
218
- toolSlugs: queryParams.data.toolSlugs,
218
+ toolSlugs: queryParams.data.tools,
219
});
220
221
let modifiedTools = [...caseTransformedTools, ...customTools];
packages/core/src/types/connectedAccounts.types.ts
+10
@@ -33,6 +33,16 @@ export const CreateConnectedAccountParamsSchema = z.object({
33
userId: z.string().optional(),
34
}),
35
});
36
+export const DefaultCreateConnectedAccountParamsSchema = z.object({
37
+ auth_config: z.object({
38
+ id: z.string(),
39
+ }),
40
+ connection: z.object({
41
+ data: z.record(z.string(), z.unknown()).optional(),
42
+ redirect_uri: z.string().optional(),
43
+ user_id: z.string().optional(),
44
+ }),
45
+});
46
export const CreateConnectedAccountOptionsSchema = z.object({
47
redirectUrl: z.string().optional(),
48
data: z.record(z.string(), z.unknown()).optional(),
packages/core/src/types/tool.types.ts
+2
-2
@@ -60,8 +60,8 @@ export const ToolListParamsSchema = z.object({
60
important: z.string().optional(),
61
limit: z.string().optional(),
62
search: z.string().optional(),
63
- toolkitSlug: z.string().optional(),
64
- toolSlugs: z.array(z.string()).optional(),
63
+ toolkits: z.string().optional(),
64
+ tools: z.array(z.string()).optional(),
65
});
66
export type ToolListParams = z.infer<typeof ToolListParamsSchema>;
67
packages/core/src/types/toolkit.types.ts
+62
-58
@@ -6,105 +6,109 @@ import { z } from 'zod';
6
export const ToolkitMangedByEnumSchema = z.enum(['all', 'composio_managed', 'project_managed']);
7
export const ToolkitSortByEnumSchema = z.enum(['usage', 'alphabetically']);
8
export const ToolkitsListParamsSchema = z.object({
9
- category: z.string().optional(),
10
- isLocal: z.boolean().optional(),
11
- managedBy: ToolkitMangedByEnumSchema.optional(),
12
- sortBy: ToolkitSortByEnumSchema.optional(),
9
+ category: z.string().optional(),
10
+ isLocal: z.boolean().optional(),
11
+ managedBy: ToolkitMangedByEnumSchema.optional(),
12
+ sortBy: ToolkitSortByEnumSchema.optional(),
13
});
14
15
export type ToolkitMangedByEnum = z.infer<typeof ToolkitMangedByEnumSchema>;
16
export type ToolkitSortByEnum = z.infer<typeof ToolkitSortByEnumSchema>;
17
export type ToolkitListParams = z.infer<typeof ToolkitsListParamsSchema>;
18
19
-
19
/**
20
* Toolkits response
21
*/
22
export const ToolKitMetaSchema = z.object({
24
- categories: z.array(z.object({
25
- id: z.string(),
26
- name: z.string(),
27
- })),
28
- createdAt: z.string(),
29
- description: z.string(),
30
- logo: z.string(),
31
- toolsCount: z.number(),
32
- triggersCount: z.number(),
33
- updatedAt: z.string(),
23
+ categories: z.array(
24
+ z.object({
25
+ id: z.string(),
26
+ name: z.string(),
27
+ })
28
+ ),
29
+ createdAt: z.string(),
30
+ description: z.string(),
31
+ logo: z.string(),
32
+ toolsCount: z.number(),
33
+ triggersCount: z.number(),
34
+ updatedAt: z.string(),
35
});
36
export const ToolKitItemSchema = z.object({
36
- id: z.string(),
37
- name: z.string(),
38
- slug: z.string(),
39
- meta: ToolKitMetaSchema,
40
- isLocalToolkit: z.boolean(),
41
- authSchemes: z.array(z.string()).optional(),
42
- composioManagedAuthSchemes: z.array(z.string()).optional(),
43
- noAuth: z.boolean().optional(),
37
+ name: z.string(),
38
+ slug: z.string(),
39
+ meta: ToolKitMetaSchema,
40
+ isLocalToolkit: z.boolean(),
41
+ authSchemes: z.array(z.string()).optional(),
42
+ composioManagedAuthSchemes: z.array(z.string()).optional(),
43
+ noAuth: z.boolean().optional(),
44
});
45
+
46
export const ToolKitListResponseSchema = z.object({
46
- items: z.array(ToolKitItemSchema),
47
- nextCursor: z.string().nullable(),
48
- totalPages: z.number(),
47
+ items: z.array(ToolKitItemSchema),
48
+ nextCursor: z.string().nullable(),
49
+ totalPages: z.number(),
50
});
51
52
export type ToolKitMeta = z.infer<typeof ToolKitMetaSchema>;
53
export type ToolKitItem = z.infer<typeof ToolKitItemSchema>;
54
export type ToolKitListResponse = z.infer<typeof ToolKitListResponseSchema>;
55
55
-
56
/**
57
* Toolkit retrieve response
58
*/
59
export const ToolkitAuthFieldSchema = z.object({
60
- name: z.string(),
61
- displayName: z.string(),
62
- type: z.string(),
63
- default: z.string().nullable().optional(),
60
+ name: z.string(),
61
+ displayName: z.string(),
62
+ type: z.string(),
63
+ default: z.string().nullable().optional(),
64
});
65
export const ToolkitAuthConfigDetailsSchema = z.object({
66
- name: z.string(),
67
- mode: z.string(),
68
- fields: z.array(z.object({
69
- authConfigCreation: z.object({
70
- optional: z.array(ToolkitAuthFieldSchema),
71
- required: z.array(ToolkitAuthFieldSchema),
72
- }),
73
- connectedAccountInitiation: z.object({
74
- optional: z.array(ToolkitAuthFieldSchema),
75
- required: z.array(ToolkitAuthFieldSchema),
76
- }),
77
- })),
78
- proxy: z.object({
79
- baseUrul: z.string(),
66
+ name: z.string(),
67
+ mode: z.string(),
68
+ fields: z.array(
69
+ z.object({
70
+ authConfigCreation: z.object({
71
+ optional: z.array(ToolkitAuthFieldSchema),
72
+ required: z.array(ToolkitAuthFieldSchema),
73
+ }),
74
+ connectedAccountInitiation: z.object({
75
+ optional: z.array(ToolkitAuthFieldSchema),
76
+ required: z.array(ToolkitAuthFieldSchema),
77
+ }),
78
})
79
+ ),
80
+ proxy: z.object({
81
+ baseUrul: z.string(),
82
+ }),
83
});
84
+
85
export const ToolkitRetrieveResponseSchema = z.object({
83
- slug: z.string(),
84
- name: z.string(),
85
- meta: ToolKitMetaSchema,
86
- isLocalToolkit: z.boolean(),
87
- composioManagedAuthSchemes: z.array(z.string()).optional(),
88
- authConfigDetails: z.array(ToolkitAuthConfigDetailsSchema).optional()
86
+ name: z.string(),
87
+ slug: z.string(),
88
+ meta: ToolKitMetaSchema,
89
+ isLocalToolkit: z.boolean(),
90
+ composioManagedAuthSchemes: z.array(z.string()).optional(),
91
+ authConfigDetails: z.array(ToolkitAuthConfigDetailsSchema).optional(),
92
});
93
94
export type ToolkitAuthField = z.infer<typeof ToolkitAuthFieldSchema>;
95
export type ToolkitAuthConfigDetails = z.infer<typeof ToolkitAuthConfigDetailsSchema>;
96
export type ToolkitRetrieveResponse = z.infer<typeof ToolkitRetrieveResponseSchema>;
97
95
-
98
/**
99
* Toolkit categories response
100
*/
101
export const ToolkitCategorySchema = z.object({
100
- id: z.string(),
101
- name: z.string(),
102
+ id: z.string(),
103
+ name: z.string(),
104
});
105
export const ToolkitRetrieveCategoriesResponseSchema = z.object({
104
- items: z.array(ToolkitCategorySchema),
105
- nextCursor: z.string().nullable(),
106
- totalPages: z.number(),
106
+ items: z.array(ToolkitCategorySchema),
107
+ nextCursor: z.string().nullable(),
108
+ totalPages: z.number(),
109
});
110
111
export type ToolkitCategory = z.infer<typeof ToolkitCategorySchema>;
110
-export type ToolkitRetrieveCategoriesResponse = z.infer<typeof ToolkitRetrieveCategoriesResponseSchema>;
\ No newline at end of file
112
+export type ToolkitRetrieveCategoriesResponse = z.infer<
113
+ typeof ToolkitRetrieveCategoriesResponseSchema
114
+>;