Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Update toolkit model

haxzie9fc01ed6d6a7
diff --git a/README.md b/README.md
index ff78c94f6..9158648b5 100644
--- a/README.md
+++ b/README.md
@@ -139,6 +139,83 @@ const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
});
```
+## Connected Accounts
+
+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.
+
+### Creating a Connected Account
+
+```typescript
+import { Composio } from '@composio/core';
+
+const composio = new Composio({
+ apiKey: process.env.COMPOSIO_API_KEY,
+});
+
+// Create a connected account
+const connectionRequest = await composio.createConnectedAccount(
+ 'user123', // userId
+ 'HACKERNEWS', // authConfigId
+ {
+ redirectUrl: 'https://your-app.com/callback',
+ data: {
+ // Additional data for the connection
+ scope: ['read', 'write'],
+ },
+ }
+);
+
+// Wait for the connection to be established
+// Default timeout is 60 seconds
+const connectedAccount = await connectionRequest.waitForConnection();
+```
+
+### Managing Connected Accounts
+
+```typescript
+// List all connected accounts
+const accounts = await composio.connectedAccounts.list({
+ userId: 'user123',
+});
+
+// Get a specific connected account
+const account = await composio.connectedAccounts.get('account_id');
+
+// Enable/Disable a connected account
+await composio.connectedAccounts.enable('account_id');
+await composio.connectedAccounts.disable('account_id');
+
+// Refresh credentials
+await composio.connectedAccounts.refresh('account_id');
+
+// Delete a connected account
+await composio.connectedAccounts.delete('account_id');
+```
+
+### Connection Statuses
+
+Connected accounts can have the following statuses:
+
+- `ACTIVE`: Connection is established and working
+- `INACTIVE`: Connection is temporarily disabled
+- `PENDING`: Connection is being processed
+- `INITIATED`: Connection request has started
+- `EXPIRED`: Connection credentials have expired
+- `FAILED`: Connection attempt failed
+
+### Authentication Schemes
+
+Composio supports various authentication schemes:
+
+- OAuth2
+- OAuth1
+- OAuth1a
+- API Key
+- Basic Auth
+- Bearer Token
+- Google Service Account
+- And more...
+
## Development
### Creating Custom Toolsets
diff --git a/packages/core/src/models/ConnectedAccounts.ts b/packages/core/src/models/ConnectedAccounts.ts
index b1f3b7dfb..210c50510 100644
--- a/packages/core/src/models/ConnectedAccounts.ts
+++ b/packages/core/src/models/ConnectedAccounts.ts
@@ -20,7 +20,7 @@ import {
} from '@composio/client/resources/connected-accounts';
import {
CreateConnectedAccountOptions,
- CreateConnectedAccountParams,
+ CreateConnectedAccountParamsSchema,
} from '../types/connectedAccounts.types';
import { ConnectionRequest } from './ConnectionRequest';
@@ -69,8 +69,8 @@ export class ConnectedAccounts {
* @param {RequestOptions} options - Request options
* @returns {Promise<ConnectedAccountRetrieveResponse>} Connected account details
*/
- async get(nanoid: string, options?: RequestOptions): Promise<ConnectedAccountRetrieveResponse> {
- return this.client.connectedAccounts.retrieve(nanoid, options);
+ async get(nanoid: string): Promise<ConnectedAccountRetrieveResponse> {
+ return this.client.connectedAccounts.retrieve(nanoid);
}
/**
@@ -79,8 +79,8 @@ export class ConnectedAccounts {
* @param {RequestOptions} options - Request options
* @returns {Promise<ConnectedAccountDeleteResponse>} Response from deletion
*/
- async delete(nanoid: string, options?: RequestOptions): Promise<ConnectedAccountDeleteResponse> {
- return this.client.connectedAccounts.delete(nanoid, options);
+ async delete(nanoid: string): Promise<ConnectedAccountDeleteResponse> {
+ return this.client.connectedAccounts.delete(nanoid);
}
/**
@@ -93,7 +93,7 @@ export class ConnectedAccounts {
nanoid: string,
options?: RequestOptions
): Promise<ConnectedAccountRefreshResponse> {
- return this.client.connectedAccounts.refresh(nanoid, options);
+ return this.client.connectedAccounts.refresh(nanoid);
}
/**
@@ -108,7 +108,7 @@ export class ConnectedAccounts {
params: ConnectedAccountUpdateStatusParams,
options?: RequestOptions
): Promise<ConnectedAccountUpdateStatusResponse> {
- return this.client.connectedAccounts.updateStatus(nanoid, params, options);
+ return this.client.connectedAccounts.updateStatus(nanoid, params);
}
/**
@@ -121,7 +121,7 @@ export class ConnectedAccounts {
nanoid: string,
options?: RequestOptions
): Promise<ConnectedAccountUpdateStatusResponse> {
- return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true }, options);
+ return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true });
}
/**
@@ -134,7 +134,7 @@ export class ConnectedAccounts {
nanoid: string,
options?: RequestOptions
): Promise<ConnectedAccountUpdateStatusResponse> {
- return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false }, options);
+ return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
}
/**
diff --git a/packages/core/src/models/Toolkits.ts b/packages/core/src/models/Toolkits.ts
index b7ff85460..c089a349a 100644
--- a/packages/core/src/models/Toolkits.ts
+++ b/packages/core/src/models/Toolkits.ts
@@ -29,7 +29,7 @@ export class Toolkits {
* This method fetches the toolkits from the Composio API.
* @returns {Promise<Toolkit[]>} List of toolkits
*/
- async getToolkits(query: ToolkitListParams): Promise<ToolKitListResponse> {
+ private async getToolkits(query: ToolkitListParams): Promise<ToolKitListResponse> {
const parsedQuery = ToolkitsListParamsSchema.parse(query);
const result = await this.client.toolkits.list({
category: parsedQuery.category,
@@ -65,7 +65,7 @@ export class Toolkits {
* @param options - Request options
* @returns {Promise<ToolkitRetrieveResponse>} The toolkit object
*/
- async getToolkitBySlug(slug: string): Promise<ToolkitRetrieveResponse> {
+ private async getToolkitBySlug(slug: string): Promise<ToolkitRetrieveResponse> {
const result = await this.client.toolkits.retrieve(slug);
const parsedResult = ToolkitRetrieveResponseSchema.parse({
name: result.name,
@@ -78,6 +78,35 @@ export class Toolkits {
return parsedResult;
}
+ /**
+ * @overload
+ * Fetches a toolkit by its Slug or a list of toolkits.
+ * @param slug - The ID of the toolkit to be retrieved
+ * @returns {Promise<ToolkitRetrieveResponse>} The toolkit object
+ */
+ async get(slug: string): Promise<ToolkitRetrieveResponse>;
+ /**
+ * @overload
+ * Fetches a list of toolkits.
+ * @param query - The parameters to fetch the toolkits
+ * @returns {Promise<ToolKitListResponse>} The list of toolkits
+ */
+ async get(query: ToolkitListParams): Promise<ToolKitListResponse>;
+ /**
+ * Fetches a toolkit by its Slug or a list of toolkits.
+ * This method retrieves the toolkit from the Composio API.
+ * @param arg - The ID of the toolkit to be retrieved or a list of parameters
+ * @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit object or a list of toolkits
+ */
+ async get(
+ arg: string | ToolkitListParams
+ ): Promise<ToolkitRetrieveResponse | ToolKitListResponse> {
+ if (typeof arg === 'string') {
+ return this.getToolkitBySlug(arg);
+ }
+ return this.getToolkits(arg);
+ }
+
/**
* Fetches all categories available in the Composio SDK
*
diff --git a/packages/core/src/models/Tools.ts b/packages/core/src/models/Tools.ts
index 43092a7b3..bb52336e7 100644
--- a/packages/core/src/models/Tools.ts
+++ b/packages/core/src/models/Tools.ts
@@ -6,12 +6,12 @@ import {
ToolExecuteResponse,
ToolList,
ToolSchema,
+ ToolListParams,
ToolExecuteResponseSchema,
} from '../types/tool.types';
import {
ToolGetInputParams,
ToolGetInputResponse,
- ToolListParams,
ToolProxyParams,
ToolProxyResponse,
ToolRetrieveEnumResponse,
@@ -198,8 +198,8 @@ export class Tools<
important: queryParams.data.important,
limit: queryParams.data.limit,
search: queryParams.data.search,
- toolkit_slug: queryParams.data.toolkitSlug,
- tool_slugs: queryParams.data.toolSlugs?.join(','),
+ toolkit_slug: queryParams.data.toolkits,
+ tool_slugs: queryParams.data.tools?.join(','),
});
if (!tools) {
return [];
@@ -215,7 +215,7 @@ export class Tools<
// }
const customTools = await this.customTools.getCustomTools({
- toolSlugs: queryParams.data.toolSlugs,
+ toolSlugs: queryParams.data.tools,
});
let modifiedTools = [...caseTransformedTools, ...customTools];
diff --git a/packages/core/src/types/connectedAccounts.types.ts b/packages/core/src/types/connectedAccounts.types.ts
index 72dd02c98..65891eacc 100644
--- a/packages/core/src/types/connectedAccounts.types.ts
+++ b/packages/core/src/types/connectedAccounts.types.ts
@@ -33,6 +33,16 @@ export const CreateConnectedAccountParamsSchema = z.object({
userId: z.string().optional(),
}),
});
+export const DefaultCreateConnectedAccountParamsSchema = z.object({
+ auth_config: z.object({
+ id: z.string(),
+ }),
+ connection: z.object({
+ data: z.record(z.string(), z.unknown()).optional(),
+ redirect_uri: z.string().optional(),
+ user_id: z.string().optional(),
+ }),
+});
export const CreateConnectedAccountOptionsSchema = z.object({
redirectUrl: z.string().optional(),
data: z.record(z.string(), z.unknown()).optional(),
diff --git a/packages/core/src/types/tool.types.ts b/packages/core/src/types/tool.types.ts
index 0b5209862..56d847d84 100644
--- a/packages/core/src/types/tool.types.ts
+++ b/packages/core/src/types/tool.types.ts
@@ -60,8 +60,8 @@ export const ToolListParamsSchema = z.object({
important: z.string().optional(),
limit: z.string().optional(),
search: z.string().optional(),
- toolkitSlug: z.string().optional(),
- toolSlugs: z.array(z.string()).optional(),
+ toolkits: z.string().optional(),
+ tools: z.array(z.string()).optional(),
});
export type ToolListParams = z.infer<typeof ToolListParamsSchema>;
diff --git a/packages/core/src/types/toolkit.types.ts b/packages/core/src/types/toolkit.types.ts
index b27d35355..18518a9eb 100644
--- a/packages/core/src/types/toolkit.types.ts
+++ b/packages/core/src/types/toolkit.types.ts
@@ -6,105 +6,109 @@ import { z } from 'zod';
export const ToolkitMangedByEnumSchema = z.enum(['all', 'composio_managed', 'project_managed']);
export const ToolkitSortByEnumSchema = z.enum(['usage', 'alphabetically']);
export const ToolkitsListParamsSchema = z.object({
- category: z.string().optional(),
- isLocal: z.boolean().optional(),
- managedBy: ToolkitMangedByEnumSchema.optional(),
- sortBy: ToolkitSortByEnumSchema.optional(),
+ category: z.string().optional(),
+ isLocal: z.boolean().optional(),
+ managedBy: ToolkitMangedByEnumSchema.optional(),
+ sortBy: ToolkitSortByEnumSchema.optional(),
});
export type ToolkitMangedByEnum = z.infer<typeof ToolkitMangedByEnumSchema>;
export type ToolkitSortByEnum = z.infer<typeof ToolkitSortByEnumSchema>;
export type ToolkitListParams = z.infer<typeof ToolkitsListParamsSchema>;
-
/**
* Toolkits response
*/
export const ToolKitMetaSchema = z.object({
- categories: z.array(z.object({
- id: z.string(),
- name: z.string(),
- })),
- createdAt: z.string(),
- description: z.string(),
- logo: z.string(),
- toolsCount: z.number(),
- triggersCount: z.number(),
- updatedAt: z.string(),
+ categories: z.array(
+ z.object({
+ id: z.string(),
+ name: z.string(),
+ })
+ ),
+ createdAt: z.string(),
+ description: z.string(),
+ logo: z.string(),
+ toolsCount: z.number(),
+ triggersCount: z.number(),
+ updatedAt: z.string(),
});
export const ToolKitItemSchema = z.object({
- id: z.string(),
- name: z.string(),
- slug: z.string(),
- meta: ToolKitMetaSchema,
- isLocalToolkit: z.boolean(),
- authSchemes: z.array(z.string()).optional(),
- composioManagedAuthSchemes: z.array(z.string()).optional(),
- noAuth: z.boolean().optional(),
+ name: z.string(),
+ slug: z.string(),
+ meta: ToolKitMetaSchema,
+ isLocalToolkit: z.boolean(),
+ authSchemes: z.array(z.string()).optional(),
+ composioManagedAuthSchemes: z.array(z.string()).optional(),
+ noAuth: z.boolean().optional(),
});
+
export const ToolKitListResponseSchema = z.object({
- items: z.array(ToolKitItemSchema),
- nextCursor: z.string().nullable(),
- totalPages: z.number(),
+ items: z.array(ToolKitItemSchema),
+ nextCursor: z.string().nullable(),
+ totalPages: z.number(),
});
export type ToolKitMeta = z.infer<typeof ToolKitMetaSchema>;
export type ToolKitItem = z.infer<typeof ToolKitItemSchema>;
export type ToolKitListResponse = z.infer<typeof ToolKitListResponseSchema>;
-
/**
* Toolkit retrieve response
*/
export const ToolkitAuthFieldSchema = z.object({
- name: z.string(),
- displayName: z.string(),
- type: z.string(),
- default: z.string().nullable().optional(),
+ name: z.string(),
+ displayName: z.string(),
+ type: z.string(),
+ default: z.string().nullable().optional(),
});
export const ToolkitAuthConfigDetailsSchema = z.object({
- name: z.string(),
- mode: z.string(),
- fields: z.array(z.object({
- authConfigCreation: z.object({
- optional: z.array(ToolkitAuthFieldSchema),
- required: z.array(ToolkitAuthFieldSchema),
- }),
- connectedAccountInitiation: z.object({
- optional: z.array(ToolkitAuthFieldSchema),
- required: z.array(ToolkitAuthFieldSchema),
- }),
- })),
- proxy: z.object({
- baseUrul: z.string(),
+ name: z.string(),
+ mode: z.string(),
+ fields: z.array(
+ z.object({
+ authConfigCreation: z.object({
+ optional: z.array(ToolkitAuthFieldSchema),
+ required: z.array(ToolkitAuthFieldSchema),
+ }),
+ connectedAccountInitiation: z.object({
+ optional: z.array(ToolkitAuthFieldSchema),
+ required: z.array(ToolkitAuthFieldSchema),
+ }),
})
+ ),
+ proxy: z.object({
+ baseUrul: z.string(),
+ }),
});
+
export const ToolkitRetrieveResponseSchema = z.object({
- slug: z.string(),
- name: z.string(),
- meta: ToolKitMetaSchema,
- isLocalToolkit: z.boolean(),
- composioManagedAuthSchemes: z.array(z.string()).optional(),
- authConfigDetails: z.array(ToolkitAuthConfigDetailsSchema).optional()
+ name: z.string(),
+ slug: z.string(),
+ meta: ToolKitMetaSchema,
+ isLocalToolkit: z.boolean(),
+ composioManagedAuthSchemes: z.array(z.string()).optional(),
+ authConfigDetails: z.array(ToolkitAuthConfigDetailsSchema).optional(),
});
export type ToolkitAuthField = z.infer<typeof ToolkitAuthFieldSchema>;
export type ToolkitAuthConfigDetails = z.infer<typeof ToolkitAuthConfigDetailsSchema>;
export type ToolkitRetrieveResponse = z.infer<typeof ToolkitRetrieveResponseSchema>;
-
/**
* Toolkit categories response
*/
export const ToolkitCategorySchema = z.object({
- id: z.string(),
- name: z.string(),
+ id: z.string(),
+ name: z.string(),
});
export const ToolkitRetrieveCategoriesResponseSchema = z.object({
- items: z.array(ToolkitCategorySchema),
- nextCursor: z.string().nullable(),
- totalPages: z.number(),
+ items: z.array(ToolkitCategorySchema),
+ nextCursor: z.string().nullable(),
+ totalPages: z.number(),
});
export type ToolkitCategory = z.infer<typeof ToolkitCategorySchema>;
-export type ToolkitRetrieveCategoriesResponse = z.infer<typeof ToolkitRetrieveCategoriesResponseSchema>;
\ No newline at end of file
+export type ToolkitRetrieveCategoriesResponse = z.infer<
+ typeof ToolkitRetrieveCategoriesResponseSchema
+>;