Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Implement core models for the library
haxzie committed
Apr 15, 2025 at 19:01 UTC
5a926cde6d722a7332c731582f36b031bcb7d71d
16 files changed
+626
-86
README.md
new
+22
@@ -0,0 +1,22 @@
1
+# @composio/core
2
+
3
+The core Composio SDK which allows users to interact with the Composio Platform.
4
+
5
+## Core Features
6
+
7
+- **Tools**: Manage and execute tools within the Composio ecosystem. Includes functionality to list, retrieve, and execute tools.
8
+- **Toolkits**: Organize and manage collections of tools for specific use cases.
9
+- **Triggers**: Create and manage event triggers that can execute tools based on specific conditions. Includes support for different trigger types and status management.
10
+- **AuthConfigs**: Configure authentication providers and settings. Manage auth configs with features to create, update, enable/disable, and delete configurations.
11
+- **ConnectedAccounts**: Manage third-party service connections. Includes functionality to create, list, refresh, and manage the status of connected accounts.
12
+- **ActionExecution**: Track and manage the execution of actions within the platform.
13
+
14
+## Internal
15
+What's not included from @composio/client
16
+- Action Execution
17
+- Org/Project Mangement with API Keys
18
+- CLI
19
+- MCP
20
+- Team Members
21
+
22
+These models can be still be accessed via the SDK explicitly by using the `@composio/client`.
\ No newline at end of file
packages/core/src/composio.ts
+31
-10
@@ -2,10 +2,12 @@ import ComposioClient from "@composio/client";
2
import { Tools } from "./models/Tools";
3
import { Toolkits } from "./models/Toolkits";
4
import { Triggers } from "./models/Triggers";
5
-import { Org } from "./models/Org";
5
import { ComposioToolset } from "./toolset/ComposioToolset";
7
-import { Toolset } from "./types/Toolset.types.";
8
-import { Tool } from "./types/Tool.types";
6
+import { Toolset, WrappedTool } from "./types/toolset.types.";
7
+import { Tool } from "./types/tool.types";
8
+import { AuthConfigs } from "./models/AuthConfigs";
9
+import { ConnectedAccounts } from "./models/ConnectedAccounts";
10
+import { ActionExecutions } from "./models/ActionExecution";
11
12
export type ComposioConfig<
13
TTool extends Tool,
@@ -38,8 +40,10 @@ export class Composio<TTool extends Tool, TToolset extends Toolset<TTool>> {
40
tools: Tools<TTool, TToolset>;
41
toolkits: Toolkits;
42
triggers: Triggers;
41
- org: Org;
43
toolset: TToolset;
44
+ authConfigs: AuthConfigs;
45
+ connectedAccounts: ConnectedAccounts;
46
+ ActionExecution: ActionExecutions;
47
48
/**
49
* @param {Object} config Configuration for the Composio SDK.
@@ -58,21 +62,36 @@ export class Composio<TTool extends Tool, TToolset extends Toolset<TTool>> {
62
allowTracing?: boolean;
63
toolset?: TToolset;
64
}) {
65
+ /**
66
+ * Initialize the Composio SDK client.
67
+ * The client is used to make API calls to the Composio API.
68
+ */
69
this.client = new ComposioClient({
70
apiKey: config.apiKey,
71
baseURL: config.baseURL,
72
});
73
74
+ /**
75
+ * Keep a reference to the config object.
76
+ * This is useful for creating a builder pattern, debugging and logging.
77
+ */
78
this.config = config;
79
80
+ /**
81
+ * Set the default toolset, if not provided by the user.
82
+ */
83
const defaultToolset = new ComposioToolset();
84
this.toolset = config.toolset ?? (defaultToolset as unknown as TToolset);
85
71
- // Initialize models
86
+ /**
87
+ * Initialize all the models with composio client.
88
+ */
89
this.tools = new Tools(this.client, this.toolset);
90
this.toolkits = new Toolkits(this.client);
91
this.triggers = new Triggers(this.client);
75
- this.org = new Org(this.client);
92
+ this.authConfigs = new AuthConfigs(this.client);
93
+ this.connectedAccounts = new ConnectedAccounts(this.client);
94
+ this.ActionExecution = new ActionExecutions(this.client);
95
}
96
97
/**
@@ -92,10 +111,12 @@ export class Composio<TTool extends Tool, TToolset extends Toolset<TTool>> {
111
* Generic function to get all the tools
112
* @returns {Promise<T[]>} Promise with list of tools
113
*/
95
- getTools(): Promise<TTool[]> {
96
- console.log("Tools");
97
- return Promise.resolve([]);
98
- // return this.tools.get();
114
+ getTool(id: string): Promise<WrappedTool<TToolset>> {
115
+ return this.tools.get(id);
116
+ }
117
+
118
+ getTools(): Promise<WrappedTool<TToolset>[]> {
119
+ return this.tools.list();
120
}
121
122
getEntity(): Promise<void> {
packages/core/src/index.ts
+2
-2
@@ -1,7 +1,7 @@
1
import { Composio } from "./composio";
2
import type { ComposioToolset } from "./toolset/ComposioToolset";
3
import type { BaseComposioToolset } from "./toolset/BaseToolset";
4
-import type { Tool } from "./types/Tool.types";
5
-import type { Toolset } from "./types/Toolset.types.";
4
+import type { Tool } from "./types/tool.types";
5
+import type { Toolset } from "./types/toolset.types.";
6
7
export { Composio, ComposioToolset, BaseComposioToolset, Tool, Toolset };
packages/core/src/models/AuthConfigs.ts
new
+136
@@ -0,0 +1,136 @@
1
+import ComposioSDK from "@composio/client";
2
+import { RequestOptions } from "@composio/client/internal/request-options";
3
+import {
4
+ AuthConfigListParams,
5
+ AuthConfigListResponse,
6
+ AuthConfigCreateParams,
7
+ AuthConfigCreateResponse,
8
+ AuthConfigDeleteResponse,
9
+ AuthConfigRetrieveResponse,
10
+ AuthConfigUpdateParams,
11
+ AuthConfigUpdateResponse,
12
+ AuthConfigUpdateStatusParams,
13
+ AuthConfigUpdateStatusResponse,
14
+} from "@composio/client/resources/auth-configs";
15
+
16
+/**
17
+ * AuthConfigs class
18
+ *
19
+ * This class is used to manage authentication configurations in the Composio SDK.
20
+ * Auth configs are used to configure authentication providers and settings.
21
+ */
22
+export class AuthConfigs {
23
+ private client: ComposioSDK;
24
+
25
+ constructor(client: ComposioSDK) {
26
+ this.client = client;
27
+ }
28
+
29
+ /**
30
+ * List all auth configs
31
+ * @param {AuthConfigListParams} query - Query parameters for filtering auth configs
32
+ * @param {RequestOptions} options - Request options
33
+ * @returns {Promise<AuthConfigListResponse>} List of auth configs
34
+ */
35
+ async list(
36
+ query?: AuthConfigListParams,
37
+ options?: RequestOptions
38
+ ): Promise<AuthConfigListResponse> {
39
+ return this.client.authConfigs.list(query, options);
40
+ }
41
+
42
+ /**
43
+ * Create a new auth config
44
+ * @param {AuthConfigCreateParams} data - Data for creating a new auth config
45
+ * @param {RequestOptions} options - Request options
46
+ * @returns {Promise<AuthConfigCreateResponse>} Created auth config
47
+ */
48
+ async create(
49
+ data: AuthConfigCreateParams,
50
+ options?: RequestOptions
51
+ ): Promise<AuthConfigCreateResponse> {
52
+ return this.client.authConfigs.create(data, options);
53
+ }
54
+
55
+ /**
56
+ * Get an auth config by nanoid
57
+ * @param {string} nanoid - Unique identifier of the auth config
58
+ * @param {RequestOptions} options - Request options
59
+ * @returns {Promise<AuthConfigRetrieveResponse>} Auth config details
60
+ */
61
+ async get(
62
+ nanoid: string,
63
+ options?: RequestOptions
64
+ ): Promise<AuthConfigRetrieveResponse> {
65
+ return this.client.authConfigs.retrieve(nanoid, options);
66
+ }
67
+
68
+ /**
69
+ * Update an auth config
70
+ * @param {string} nanoid - Unique identifier of the auth config to update
71
+ * @param {AuthConfigUpdateParams} data - Data to update
72
+ * @param {RequestOptions} options - Request options
73
+ * @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
74
+ */
75
+ async update(
76
+ nanoid: string,
77
+ data: AuthConfigUpdateParams,
78
+ options?: RequestOptions
79
+ ): Promise<AuthConfigUpdateResponse> {
80
+ return this.client.authConfigs.update(nanoid, data, options);
81
+ }
82
+
83
+ /**
84
+ * Delete an auth config
85
+ * @param {string} nanoid - Unique identifier of the auth config to delete
86
+ * @param {RequestOptions} options - Request options
87
+ * @returns {Promise<AuthConfigDeleteResponse>} Response from deletion
88
+ */
89
+ async delete(
90
+ nanoid: string,
91
+ options?: RequestOptions
92
+ ): Promise<AuthConfigDeleteResponse> {
93
+ return this.client.authConfigs.delete(nanoid, options);
94
+ }
95
+
96
+ /**
97
+ * Update the status of an auth config
98
+ * @param {string} nanoid - Unique identifier of the auth config
99
+ * @param {AuthConfigUpdateStatusParams} params - Parameters for updating the status
100
+ * @param {RequestOptions} options - Request options
101
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
102
+ */
103
+ async updateStatus(
104
+ status: "ENABLED" | "DISABLED",
105
+ nanoid: string,
106
+ options?: RequestOptions
107
+ ): Promise<AuthConfigUpdateStatusResponse> {
108
+ return this.client.authConfigs.updateStatus(status, { nanoid }, options);
109
+ }
110
+
111
+ /**
112
+ * Enable an auth config
113
+ * @param {string} nanoid - Unique identifier of the auth config
114
+ * @param {RequestOptions} options - Request options
115
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
116
+ */
117
+ async enable(
118
+ nanoid: string,
119
+ options?: RequestOptions
120
+ ): Promise<AuthConfigUpdateStatusResponse> {
121
+ return this.client.authConfigs.updateStatus("ENABLED", { nanoid }, options);
122
+ }
123
+
124
+ /**
125
+ * Disable an auth config
126
+ * @param {string} nanoid - Unique identifier of the auth config
127
+ * @param {RequestOptions} options - Request options
128
+ * @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
129
+ */
130
+ async disable(
131
+ nanoid: string,
132
+ options?: RequestOptions
133
+ ): Promise<AuthConfigUpdateStatusResponse> {
134
+ return this.client.authConfigs.updateStatus("DISABLED", { nanoid }, options);
135
+ }
136
+}
\ No newline at end of file
packages/core/src/models/ConnectedAccounts.ts
new
+133
@@ -0,0 +1,133 @@
1
+import ComposioSDK from "@composio/client";
2
+import { RequestOptions } from "@composio/client/internal/request-options";
3
+import {
4
+ ConnectedAccountListParams,
5
+ ConnectedAccountListResponse,
6
+ ConnectedAccountCreateParams,
7
+ ConnectedAccountCreateResponse,
8
+ ConnectedAccountDeleteResponse,
9
+ ConnectedAccountRetrieveResponse,
10
+ ConnectedAccountRefreshResponse,
11
+ ConnectedAccountUpdateStatusParams,
12
+ ConnectedAccountUpdateStatusResponse,
13
+} from "@composio/client/resources/connected-accounts";
14
+
15
+/**
16
+ * ConnectedAccounts class
17
+ *
18
+ * This class is used to manage connected accounts in the Composio SDK.
19
+ * Connected accounts are used to authenticate with third-party services.
20
+ */
21
+export class ConnectedAccounts {
22
+ private client: ComposioSDK;
23
+
24
+ constructor(client: ComposioSDK) {
25
+ this.client = client;
26
+ }
27
+
28
+ /**
29
+ * List all connected accounts
30
+ * @param {ConnectedAccountListParams} query - Query parameters for filtering connected accounts
31
+ * @param {RequestOptions} options - Request options
32
+ * @returns {Promise<ConnectedAccountListResponse>} List of connected accounts
33
+ */
34
+ async list(
35
+ query?: ConnectedAccountListParams,
36
+ options?: RequestOptions
37
+ ): Promise<ConnectedAccountListResponse> {
38
+ return this.client.connectedAccounts.list(query, options);
39
+ }
40
+
41
+ /**
42
+ * Create a new connected account
43
+ * @param {ConnectedAccountCreateParams} data - Data for creating a new connected account
44
+ * @param {RequestOptions} options - Request options
45
+ * @returns {Promise<ConnectedAccountCreateResponse>} Created connected account
46
+ */
47
+ async create(
48
+ data: ConnectedAccountCreateParams,
49
+ options?: RequestOptions
50
+ ): Promise<ConnectedAccountCreateResponse> {
51
+ return this.client.connectedAccounts.create(data, options);
52
+ }
53
+
54
+ /**
55
+ * Get a connected account by nanoid
56
+ * @param {string} nanoid - Unique identifier of the connected account
57
+ * @param {RequestOptions} options - Request options
58
+ * @returns {Promise<ConnectedAccountRetrieveResponse>} Connected account details
59
+ */
60
+ async get(
61
+ nanoid: string,
62
+ options?: RequestOptions
63
+ ): Promise<ConnectedAccountRetrieveResponse> {
64
+ return this.client.connectedAccounts.retrieve(nanoid, options);
65
+ }
66
+
67
+ /**
68
+ * Delete a connected account
69
+ * @param {string} nanoid - Unique identifier of the connected account to delete
70
+ * @param {RequestOptions} options - Request options
71
+ * @returns {Promise<ConnectedAccountDeleteResponse>} Response from deletion
72
+ */
73
+ async delete(
74
+ nanoid: string,
75
+ options?: RequestOptions
76
+ ): Promise<ConnectedAccountDeleteResponse> {
77
+ return this.client.connectedAccounts.delete(nanoid, options);
78
+ }
79
+
80
+ /**
81
+ * Refresh a connected account's credentials
82
+ * @param {string} nanoid - Unique identifier of the connected account to refresh
83
+ * @param {RequestOptions} options - Request options
84
+ * @returns {Promise<ConnectedAccountRefreshResponse>} Refreshed connected account details
85
+ */
86
+ async refresh(
87
+ nanoid: string,
88
+ options?: RequestOptions
89
+ ): Promise<ConnectedAccountRefreshResponse> {
90
+ return this.client.connectedAccounts.refresh(nanoid, options);
91
+ }
92
+
93
+ /**
94
+ * Update the status of a connected account
95
+ * @param {string} nanoid - Unique identifier of the connected account
96
+ * @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status
97
+ * @param {RequestOptions} options - Request options
98
+ * @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
99
+ */
100
+ async updateStatus(
101
+ nanoid: string,
102
+ params: ConnectedAccountUpdateStatusParams,
103
+ options?: RequestOptions
104
+ ): Promise<ConnectedAccountUpdateStatusResponse> {
105
+ return this.client.connectedAccounts.updateStatus(nanoid, params, options);
106
+ }
107
+
108
+ /**
109
+ * Enable a connected account
110
+ * @param {string} nanoid - Unique identifier of the connected account
111
+ * @param {RequestOptions} options - Request options
112
+ * @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
113
+ */
114
+ async enable(
115
+ nanoid: string,
116
+ options?: RequestOptions
117
+ ): Promise<ConnectedAccountUpdateStatusResponse> {
118
+ return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true }, options);
119
+ }
120
+
121
+ /**
122
+ * Disable a connected account
123
+ * @param {string} nanoid - Unique identifier of the connected account
124
+ * @param {RequestOptions} options - Request options
125
+ * @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
126
+ */
127
+ async disable(
128
+ nanoid: string,
129
+ options?: RequestOptions
130
+ ): Promise<ConnectedAccountUpdateStatusResponse> {
131
+ return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false }, options);
132
+ }
133
+}
\ No newline at end of file
packages/core/src/models/Org.ts
deleted
-18
@@ -1,18 +0,0 @@
1
-import ComposioSDK from "@composio/client";
2
-
3
-export class Org {
4
- private client: ComposioSDK;
5
-
6
- constructor(client: any) {
7
- this.client = client;
8
- }
9
-
10
- async getAPIKey() {
11
- return this.client.org.apiKey.retrieve();
12
- }
13
-
14
- async reGenerateAPIKey() {
15
- return this.client.org.apiKey.regenerate();
16
- }
17
-
18
-}
\ No newline at end of file
packages/core/src/models/Toolkits.ts
+52
-15
@@ -1,21 +1,58 @@
1
import ComposioSDK from "@composio/client";
2
+import { RequestOptions } from "@composio/client/internal/request-options";
3
+import {
4
+ ToolkitListParams,
5
+ ToolkitListResponse,
6
+ ToolkitRetrieveCategoriesResponse,
7
+ ToolkitRetrieveResponse,
8
+} from "@composio/client/resources/toolkits";
9
10
+/**
11
+ * Toolkits class
12
+ *
13
+ * Toolkits are a collection of tools that can be used to perform various tasks.
14
+ * This is similar/replacement of `apps` in the Composio API.
15
+ */
16
export class Toolkits {
4
- private client: ComposioSDK;
17
+ private client: ComposioSDK;
18
6
- constructor(client: ComposioSDK) {
7
- this.client = client;
8
- }
19
+ constructor(client: ComposioSDK) {
20
+ this.client = client;
21
+ }
22
+ /**
23
+ * List all toolkits available in the Composio SDK.
24
+ * This method fetches the toolkits from the Composio API.
25
+ * @returns {Promise<Toolkit[]>} List of toolkits
26
+ */
27
+ async list(
28
+ query: ToolkitListParams,
29
+ options?: RequestOptions
30
+ ): Promise<ToolkitListResponse> {
31
+ return this.client.toolkits.list(query, options);
32
+ }
33
10
- async list() {
11
- return this.client.toolkits.list();
12
- }
34
+ /**
35
+ * Fetches a toolkit by its Slug.
36
+ * This method retrieves the toolkit from the Composio API.
37
+ * @param slug - The ID of the toolkit to be retrieved
38
+ * @param options - Request options
39
+ * @returns {Promise<ToolkitRetrieveResponse>} The toolkit object
40
+ */
41
+ async get(
42
+ slug: string,
43
+ options?: RequestOptions
44
+ ): Promise<ToolkitRetrieveResponse> {
45
+ return this.client.toolkits.retrieve(slug, options);
46
+ }
47
14
- async get(toolkitId: string) {
15
- return this.client.toolkits.retrieve(toolkitId);
16
- }
17
-
18
- async listCategories() {
19
- return this.client.toolkits.retrieveCategories();
20
- }
21
-}
\ No newline at end of file
48
+ /**
49
+ * Fetches all categories available in the Composio SDK
50
+ *
51
+ * @returns {Promise<ToolkitRetrieveCategoriesResponse>} List of categories
52
+ */
53
+ async listCategories(
54
+ options?: RequestOptions
55
+ ): Promise<ToolkitRetrieveCategoriesResponse> {
56
+ return this.client.toolkits.retrieveCategories(options);
57
+ }
58
+}
packages/core/src/models/Tools.ts
+89
-19
@@ -1,11 +1,21 @@
1
import ComposioSDK from "@composio/client";
2
-import { Tool } from "../types/Tool.types";
3
-import { Toolset } from "../types/Toolset.types.";
2
+import { Tool } from "../types/tool.types";
3
+import { Toolset, WrappedTool } from "../types/toolset.types.";
4
+import {
5
+ ToolExecuteParams,
6
+ ToolExecuteResponse,
7
+ ToolGetInputParams,
8
+ ToolGetInputResponse,
9
+ ToolListParams,
10
+ ToolRetrieveEnumResponse,
11
+} from "@composio/client/resources/tools";
12
5
-export class Tools<
6
- TTool extends Tool,
7
- TToolset extends Toolset<TTool>
8
-> {
13
+/**
14
+ * This class is used to manage tools in the Composio SDK.
15
+ * It provides methods to list, get, and execute tools.
16
+ * It also provides a method to wrap tools using the toolset.
17
+ */
18
+export class Tools<TTool extends Tool, TToolset extends Toolset<TTool>> {
19
private client: ComposioSDK;
20
private toolset: TToolset;
21
@@ -14,24 +24,84 @@ export class Tools<
24
this.toolset = toolset;
25
}
26
17
- async list() {
18
- return this.client.tools.list();
27
+ /**
28
+ * This method helps us to safely wrap the tool in the toolset.
29
+ *
30
+ * @param {Tool} tool Tool to be wrapped by the toolset
31
+ * @returns {ReturnType<WrappedTool<TToolset>>} Wrapped tool
32
+ */
33
+ private wrap(tool: Tool): WrappedTool<TToolset> {
34
+ return this.toolset._wrapTool(tool) as WrappedTool<TToolset>;
35
}
36
21
- async get(toolId: string): Promise<ReturnType<TToolset["_wrapTool"]>> {
22
- const tool: Tool = await this.client.tools.retrieve(toolId);
23
- return this.toolset._wrapTool(tool) as ReturnType<TToolset["_wrapTool"]>;
37
+ /**
38
+ * Lists all tools available in the Composio SDK.
39
+ * This method fetches the tools from the Composio API and wraps them using the toolset.
40
+ * @returns {Promise<WrappedTool<TToolset>[]>} List of tools
41
+ */
42
+ async list(query: ToolListParams = {}): Promise<WrappedTool<TToolset>[]> {
43
+ try {
44
+ const tools = await this.client.tools.list(query);
45
+ if (!tools) {
46
+ return [];
47
+ }
48
+ return tools.items.map((tool) => this.wrap(tool));
49
+ } catch (error) {
50
+ console.error("Error fetching tools:", error);
51
+ return [];
52
+ }
53
}
54
26
- async execute(tool: string, body: { [key: string]: any }) {
27
- return this.client.tools.execute(tool, body);
55
+ /**
56
+ * Retrieves a tool by its Slug.
57
+ * @param slug The ID of the tool to be retrieved
58
+ * @returns {Promise<WrappedTool<TToolset>>} The tool object wrapped by the toolset
59
+ */
60
+ async get(slug: string): Promise<WrappedTool<TToolset>> {
61
+ const tool = await this.client.tools.retrieve(slug);
62
+ return this.wrap(tool);
63
}
64
30
- async getToolsByEnum(toolEnum: string) {
31
- return this.client.tools.retrieveEnum({
32
- body: {
33
- toolEnum,
34
- },
35
- });
65
+ /**
66
+ * Exectes a given tool with the provided parameters.
67
+ *
68
+ * This method calls the Composio API to execute the tool and returns the response.
69
+ *
70
+ * @param {string} slug - The ID of the tool to be executed
71
+ * @param {ToolExecuteParams} body - The parameters to be passed to the tool
72
+ * @returns {Promise<ToolExecuteResponse>} - The response from the tool execution
73
+ */
74
+ async execute(
75
+ slug: string,
76
+ body: ToolExecuteParams
77
+ ): Promise<ToolExecuteResponse> {
78
+ return this.client.tools.execute(slug, body);
79
+ }
80
+
81
+ /**
82
+ * Fetches the list of all available tools in the Composio SDK.
83
+ *
84
+ * This method is mostly used by the CLI to get the list of tools.
85
+ * No filtering is done on the tools, the list is cached in the backend, no further optimization is required.
86
+ * @returns {string} - The list of all available tools as a string
87
+ */
88
+ async getToolsEnum(): Promise<ToolRetrieveEnumResponse> {
89
+ return this.client.tools.retrieveEnum();
90
+ }
91
+
92
+ /**
93
+ * Fetches the input parameters for a given tool.
94
+ *
95
+ * This method is used to get the input parameters for a tool before executing it.
96
+ *
97
+ * @param {string} slug - The ID of the tool to find input for
98
+ * @param {ToolGetInputParams} body - The parameters to be passed to the tool
99
+ * @returns
100
+ */
101
+ async getInput(
102
+ slug: string,
103
+ body: ToolGetInputParams
104
+ ): Promise<ToolGetInputResponse> {
105
+ return this.client.tools.getInput(slug, body);
106
}
107
}
packages/core/src/models/Triggers.ts
+142
-16
@@ -1,5 +1,23 @@
1
import ComposioSDK from "@composio/client";
2
+import { RequestOptions } from "@composio/client/internal/request-options";
3
+import {
4
+ TriggerInstanceListActiveParams,
5
+ TriggerInstanceRemoveUpsertResponse,
6
+ TriggerInstanceUpdateStatusParams,
7
+ TriggerInstanceUpsertParams,
8
+ TriggerInstanceUpsertResponse,
9
+ TriggersTypeListParams,
10
+ TriggersTypeListResponse,
11
+ TriggersTypeRetrieveEnumResponse,
12
+ TriggersTypeRetrieveResponse,
13
+} from "@composio/client/resources/index";
14
+import { TriggerStatusEnum } from "../types/triggers.types";
15
16
+/**
17
+ * Trigger (Instance) class
18
+ * /api/v3/trigger_instances
19
+ *
20
+ */
21
export class Triggers {
22
private client: ComposioSDK;
23
@@ -7,28 +25,136 @@ export class Triggers {
25
this.client = client;
26
}
27
10
- async list() {
11
- return this.client.triggerInstances.listActive();
28
+ /**
29
+ * Fetch list of all the active triggers
30
+ * @returns {Promise<TriggerInstance[]>} List of trigger instances
31
+ */
32
+ async list(
33
+ query?: TriggerInstanceListActiveParams,
34
+ options?: RequestOptions
35
+ ) {
36
+ return this.client.triggerInstances.listActive(query, options);
37
}
38
39
+ /**
40
+ * Create a new trigger instance
41
+ *
42
+ * @param {string} slug - The slug of the trigger instance
43
+ * @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
44
+ * @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
45
+ */
46
async create(
47
slug: string,
16
- {
17
- connectedAuthId,
18
- triggerConfig,
19
- }: {
20
- connectedAuthId: string;
21
- triggerConfig: { [key: string]: any };
22
- }
23
- ) {
24
- return this.client.triggerInstances.upsert(slug, {
25
- connectedAuthId,
26
- triggerConfig,
27
- });
48
+ body: TriggerInstanceUpsertParams,
49
+ options?: RequestOptions
50
+ ): Promise<TriggerInstanceUpsertResponse> {
51
+ return this.client.triggerInstances.upsert(slug, body, options);
52
+ }
53
+
54
+ /**
55
+ * Update an existing trigger instance
56
+ *
57
+ * @param {string} slug - The slug of the trigger instance
58
+ * @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
59
+ * @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
60
+ */
61
+ async update(
62
+ slug: string,
63
+ body: TriggerInstanceUpsertParams,
64
+ options?: RequestOptions
65
+ ): Promise<TriggerInstanceUpsertResponse> {
66
+ return this.client.triggerInstances.upsert(slug, body, options);
67
}
68
30
- async delete(slug: string) {
69
+ /**
70
+ * Delete a trigger instance
71
+ *
72
+ * @param {string} slug - The slug of the trigger instance
73
+ * @returns
74
+ */
75
+ async delete(slug: string): Promise<TriggerInstanceRemoveUpsertResponse> {
76
return this.client.triggerInstances.removeUpsert(slug);
77
}
33
-
78
+
79
+ /**
80
+ * Update the status of a trigger
81
+ *
82
+ * @param {TriggerStatusEnum} status - The new status of the trigger
83
+ * @param {TriggerInstanceUpdateStatusParams} params - The parameters to update the trigger instance
84
+ * @param {RequestOptions} options - Request options
85
+ * @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
86
+ */
87
+ async updateStatus(
88
+ status: TriggerStatusEnum,
89
+ params: TriggerInstanceUpdateStatusParams,
90
+ options?: RequestOptions
91
+ ) {
92
+ return this.client.triggerInstances.updateStatus(status, params, options);
93
+ }
94
+
95
+ /**
96
+ * Disable a trigger instance
97
+ *
98
+ * @param {string} slug - The slug of the trigger instance
99
+ * @param {RequestOptions options - Request options
100
+ * @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
101
+ */
102
+ async disable(slug: string, options?: RequestOptions) {
103
+ return this.client.triggerInstances.updateStatus(
104
+ "disable",
105
+ { slug },
106
+ options
107
+ );
108
+ }
109
+
110
+ /**
111
+ * Enable a trigger instance
112
+ *
113
+ * @param {string} slug - The slug of the trigger instance
114
+ * @param {RequestOptions options - Request options
115
+ * @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
116
+ */
117
+ async enable(slug: string, options?: RequestOptions) {
118
+ return this.client.triggerInstances.updateStatus(
119
+ "enable",
120
+ { slug },
121
+ options
122
+ );
123
+ }
124
+
125
+ /**
126
+ * @TODO Learn about trigger types
127
+ */
128
+ /**
129
+ * List all the trigger types
130
+ *
131
+ * @param {TriggersTypeListParams} query - The query parameters to filter the trigger types
132
+ * @param {RequestOptions} options - Request options
133
+ * @returns {Promise<TriggersTypeListResponse>} The list of trigger types
134
+ */
135
+ async listTypes(query?: TriggersTypeListParams, options?: RequestOptions): Promise<TriggersTypeListResponse> {
136
+ return this.client.triggersTypes.list(query, options);
137
+ }
138
+
139
+ /**
140
+ * Retrieve a trigger type by its slug
141
+ *
142
+ * @param {string} slug - The slug of the trigger type
143
+ * @param {RequestOptions} options - request options
144
+ * @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
145
+ */
146
+ async getType(slug: string, options?: RequestOptions): Promise<TriggersTypeRetrieveResponse> {
147
+ return this.client.triggersTypes.retrieve(slug, options);
148
+ }
149
+
150
+ /**
151
+ * Fetches the list of all the available trigger enums
152
+ *
153
+ * This method is used by the CLI where filters are not required.
154
+ * @param options
155
+ * @returns
156
+ */
157
+ async listEnum(options?: RequestOptions): Promise<TriggersTypeRetrieveEnumResponse> {
158
+ return this.client.triggersTypes.retrieveEnum(options);
159
+ }
160
}
packages/core/src/toolset/BaseToolset.ts
+2
-2
@@ -1,5 +1,5 @@
1
-import { Toolset } from "../types/Toolset.types.";
2
-import { Tool } from "../types/Tool.types";
1
+import { Toolset } from "../types/toolset.types.";
2
+import { Tool } from "../types/tool.types";
3
4
/**
5
* Base toolset implementation with proper generic defaults
packages/core/src/toolset/ComposioToolset.ts
+1
-1
@@ -1,4 +1,4 @@
1
-import { Tool } from "../types/Tool.types";
1
+import { Tool } from "../types/tool.types";
2
import { BaseComposioToolset } from "./BaseToolset";
3
4
/**
packages/core/src/types/Tool.types.ts
+2
-2
@@ -1,3 +1,3 @@
1
-import { ToolRetrieveResponse } from "@composio/client/resources/tools";
1
+import { ToolListResponse, ToolRetrieveResponse } from "@composio/client/resources/tools";
2
3
-export type Tool = ToolRetrieveResponse;
3
+export type Tool = ToolRetrieveResponse | ToolListResponse.Item;
\ No newline at end of file
packages/core/src/types/Toolset.types..ts
+10
-1
@@ -1,4 +1,4 @@
1
-import { Tool } from "./Tool.types";
1
+import { Tool } from "./tool.types";
2
3
/**
4
* Base toolset implementation, which needs to be implemented by the extended class.
@@ -7,3 +7,12 @@ import { Tool } from "./Tool.types";
7
export interface Toolset<TTool extends Tool> {
8
_wrapTool: (tool: Tool) => TTool;
9
}
10
+
11
+
12
+/**
13
+ * This type is used to infer the wrapped tool type from the toolset.
14
+ * It checks if the toolset has a method `_wrapTool` and infers the return type.
15
+ */
16
+export type WrappedTool<TToolset> = TToolset extends {
17
+ _wrapTool: (tool: Tool) => infer TTool;
18
+} ? TTool : never;
\ No newline at end of file
packages/core/src/types/org.types.ts
packages/core/src/types/triggers.types.ts
new
+1
@@ -0,0 +1 @@
1
+export type TriggerStatusEnum = "enable" | "disable";
\ No newline at end of file
packages/examples/sample/src/index.ts
+3
@@ -12,6 +12,9 @@ async function constructorExample() {
12
13
const tool = await composio.tools.get("HACKERNEWS_SEARCH_POSTS");
14
15
+ const sampleTool = await composio.getTool("HACKERNEWS_SEARCH_POSTS");
16
+ sampleTool.execute({});
17
+
18
composio.toolset.handleToolCall(tool);
19
20
tool.execute({});