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.

Stable version with any

haxziee650c3b13498
diff --git a/packages/core/src/composio.ts b/packages/core/src/composio.ts
index b4407042b..25b10d8ac 100644
--- a/packages/core/src/composio.ts
+++ b/packages/core/src/composio.ts
@@ -9,33 +9,27 @@ import { AuthConfigs } from "./models/AuthConfigs";
import { ConnectedAccounts } from "./models/ConnectedAccounts";
import { ToolListParams } from "@composio/client/resources/tools";
-export type ComposioConfig<
- TTool,
- TToolset extends Toolset<TTool>
-> = {
+export type ComposioConfig<T extends Toolset<any>> = {
apiKey?: string;
baseURL?: string;
runtime?: string;
allowTracking?: boolean;
allowTracing?: boolean;
- toolset?: TToolset;
+ toolset?: T;
};
/**
* This is the core class for Composio.
* It is used to initialize the Composio SDK and provide a global configuration.
*/
-export class Composio<
- TTool,
- TToolset extends Toolset<TTool> = Toolset<TTool>
-> {
+export class Composio<T extends Toolset<any>> {
/**
* The Composio API client.
* @type {ComposioClient}
*/
private client: ComposioClient;
- private config: ComposioConfig<TTool, TToolset>;
+ private config: ComposioConfig<T>;
/**
* Core models for Composio.
@@ -43,7 +37,7 @@ export class Composio<
tools: Tools;
toolkits: Toolkits;
triggers: Triggers;
- toolset: TToolset;
+ toolset: T;
authConfigs: AuthConfigs;
connectedAccounts: ConnectedAccounts;
@@ -56,14 +50,7 @@ export class Composio<
* @param {boolean} config.allowTracing Whether to allow tracing. Defaults to true.
* @param {TS} config.toolset The toolset to use for this Composio instance.
*/
- constructor(config: {
- apiKey?: string;
- baseURL?: string;
- runtime?: string;
- allowTracking?: boolean;
- allowTracing?: boolean;
- toolset?: TToolset;
- }) {
+ constructor(config: ComposioConfig<T>) {
/**
* Initialize the Composio SDK client.
* The client is used to make API calls to the Composio API.
@@ -83,7 +70,7 @@ export class Composio<
* Set the default toolset, if not provided by the user.
*/
const defaultToolset = new ComposioToolset();
- this.toolset = config.toolset ?? (defaultToolset as unknown as TToolset);
+ this.toolset = config.toolset ?? (defaultToolset as unknown as T);
this.toolset.setClient(this);
/**
@@ -113,9 +100,9 @@ export class Composio<
* Generic function to get all the tools
* @returns {Promise<T[]>} Promise with list of tools
*/
- async getTool(id: string): Promise<WrappedTool<TToolset>> {
+ async getTool(id: string): Promise<WrappedTool<T>> {
const tool = await this.tools.get(id);
- return this.toolset._wrapTool(tool) as WrappedTool<TToolset>;
+ return this.toolset._wrapTool(tool) as WrappedTool<T>;
}
/**
@@ -123,8 +110,8 @@ export class Composio<
* @param query - Query parameters for the tools
* @returns {Promise<T[]>} Promise with list of tools
*/
- async getTools(query?: ToolListParams): Promise<WrappedTool<TToolset>[]> {
+ async getTools(query?: ToolListParams): Promise<WrappedTool<T>[]> {
const tools = await this.tools.list(query);
- return tools.items.map((tool) => this.toolset._wrapTool(tool as Tool)) as WrappedTool<TToolset>[];
+ return tools.items.map((tool) => this.toolset._wrapTool(tool as Tool)) as WrappedTool<T>[];
}
}
diff --git a/packages/core/src/toolset/BaseToolset.ts b/packages/core/src/toolset/BaseToolset.ts
index a011d6a01..6a219fd84 100644
--- a/packages/core/src/toolset/BaseToolset.ts
+++ b/packages/core/src/toolset/BaseToolset.ts
@@ -18,20 +18,17 @@ import { Composio } from "../composio";
* ```
*/
export abstract class BaseComposioToolset<TTool> implements Toolset<TTool> {
+ protected client: Composio<Toolset<TTool>> | undefined;
- /**
- * Sets the client for the toolset
- * @param client
- */
- abstract setClient(client: Composio<TTool, Toolset<TTool>>): void;
+ setClient(client: Composio<Toolset<TTool>>): void {
+ this.client = client;
+ }
- /**
- * Wraps the tool to a specific type
- * This method should be implemented by the extended class to wrap the tool to a specific type.
- * @param tool The tool to wrap (This will be the tool retrieved from the API)
- * @returns The wrapped tool
- */
- abstract _wrapTool: (tool: Tool) => TTool;
+ abstract _wrapTool(tool: Tool): TTool;
- // @TODO add pre-process and post-process methods
+ protected ensureClient(): void {
+ if (!this.client) {
+ throw new Error('Client not initialized. Make sure the toolset is properly initialized with Composio.');
+ }
+ }
}
\ No newline at end of file
diff --git a/packages/core/src/toolset/ComposioToolset.ts b/packages/core/src/toolset/ComposioToolset.ts
index b978e5ca5..a4ac7e220 100644
--- a/packages/core/src/toolset/ComposioToolset.ts
+++ b/packages/core/src/toolset/ComposioToolset.ts
@@ -1,7 +1,6 @@
import { Composio } from "../composio";
import { Tool } from "../types/tool.types";
import { BaseComposioToolset } from "./BaseToolset";
-import { Toolset } from "../types/toolset.types.";
/**
* This is a default toolset implementation for Composio.
@@ -10,24 +9,20 @@ import { Toolset } from "../types/toolset.types.";
* This class shouldn't be used directly or to be extended.
*/
-interface CustomTool {
- name: string;
-}
-export class ComposioToolset extends BaseComposioToolset<CustomTool> {
- private client: Composio<CustomTool, Toolset<CustomTool>> | undefined;
-
- setClient(client: Composio<CustomTool, Toolset<CustomTool>>) {
- this.client = client;
- }
+export class ComposioToolset extends BaseComposioToolset<Tool> {
- _wrapTool = (tool: Tool): CustomTool => {
- return tool as unknown as CustomTool;
+ _wrapTool = (tool: Tool): Tool => {
+ return tool as Tool;
};
+
+ async test() {}
}
+
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
toolset: new ComposioToolset(),
});
-
+composio.toolset.test();
+composio.getTool("123");
\ No newline at end of file
diff --git a/packages/core/src/types/Toolset.types..ts b/packages/core/src/types/Toolset.types..ts
index 7115ab2d9..44d1ba636 100644
--- a/packages/core/src/types/Toolset.types..ts
+++ b/packages/core/src/types/Toolset.types..ts
@@ -7,7 +7,7 @@ import { Tool } from "./tool.types";
*/
export interface Toolset<TTool> {
_wrapTool: (tool: Tool) => TTool;
- setClient: (client: Composio<TTool, Toolset<TTool>>) => void;
+ setClient<T extends Toolset<TTool>>(client: Composio<T>): void;
}
diff --git a/packages/core/src/types/toolset.types.ts b/packages/core/src/types/toolset.types.ts
new file mode 100644
index 000000000..cd58dd0be
--- /dev/null
+++ b/packages/core/src/types/toolset.types.ts
@@ -0,0 +1,9 @@
+import { Tool } from "./tool.types";
+import { Composio } from "../composio";
+
+export interface Toolset<TTool> {
+ _wrapTool(tool: Tool): TTool;
+ setClient(client: Composio<Toolset<TTool>>): void;
+}
+
+export type WrappedTool<T> = T extends Toolset<infer U> ? U : never;
\ No newline at end of file