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
Add experimental modifiers
haxzie committed
May 9, 2025 at 17:43 UTC
b416a818416b7c18252b80e58cd9f72838d0af6a
6 files changed
+47
-11
packages/core/src/composio.ts
+1
-3
@@ -36,8 +36,6 @@ export type ComposioConfig<TToolset extends BaseComposioToolset<unknown, unknown
36
*/
37
export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = OpenAIToolset> {
38
private readonly DEFAULT_USER_ID = 'default';
39
- readonly FILE_NAME = 'core/composio.ts';
40
-
39
/**
40
* The Composio API client.
41
* @type {ComposioClient}
@@ -81,7 +79,7 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
79
* @param {string} config.runtime The runtime for the Composio SDK.
80
* @param {boolean} config.allowTracking Whether to allow analytics / tracking. Defaults to true.
81
* @param {boolean} config.allowTracing Whether to allow tracing. Defaults to true.
84
- * @param {TS} config.toolset The toolset to use for this Composio instance.
82
+ * @param {TToolset} config.toolset The toolset to use for this Composio instance.
83
*/
84
constructor(config: ComposioConfig<TToolset>) {
85
const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getSDKConfig(
packages/core/src/models/AuthConfigs.ts
+7
@@ -1,3 +1,10 @@
1
+/**
2
+ * @fileoverview Auth configs class for Composio SDK, used to manage authentication configurations.
3
+ *
4
+ * @author Musthaq Ahamad <musthaq@composio.dev>
5
+ * @date 2025-05-05
6
+ * @module AuthConfigs
7
+ */
8
import ComposioClient from '@composio/client';
9
import { RequestOptions } from '@composio/client/internal/request-options';
10
import {
packages/core/src/models/ConnectedAccounts.ts
+7
@@ -1,3 +1,10 @@
1
+/**
2
+ * @fileoverview Connected accounts class for Composio SDK, used to manage connected accounts of a user.
3
+ *
4
+ * @author Musthaq Ahamad <musthaq@composio.dev>
5
+ * @date 2025-05-05
6
+ * @module ConnectedAccounts
7
+ */
8
import ComposioClient from '@composio/client';
9
import { RequestOptions } from '@composio/client/internal/request-options';
10
import {
packages/core/src/models/ConnectionRequest.ts
+11
-5
@@ -1,3 +1,10 @@
1
+/**
2
+ * @fileoverview Connection request class for Composio SDK, used to manage an initiated connection request.
3
+ *
4
+ * @author Musthaq Ahamad <musthaq@composio.dev>
5
+ * @date 2025-05-05
6
+ * @module ConnectionRequest
7
+ */
8
import ComposioClient from '@composio/client';
9
import {
10
ConnectedAccountStatus,
@@ -23,8 +30,8 @@ export class ConnectionRequest {
30
31
/**
32
* Transform the response from the Composio API to the SDK format
26
- * @param response
27
- * @returns
33
+ * @param response
34
+ * @returns
35
*/
36
private async transformResponse(
37
response: OriginalConnectedAccountResponse
@@ -47,10 +54,10 @@ export class ConnectionRequest {
54
}
55
56
/**
50
- * Wait for the connection to be established.
57
+ * Wait for the connection to be established.
58
* The function will poll the Composio API every second until the connection is established or the timeout is reached.
59
* @param {number} timeout - The time in milliseconds to wait for the connection to be established. Default is 30 seconds.
53
- * @returns
60
+ * @returns
61
*/
62
async waitForConnection(timeout: number = 60000): Promise<ConnectedAccountRetrieveResponse> {
63
if (this.connectedAccountStatus === ConnectedAccountStatuses.ACTIVE) {
@@ -78,5 +85,4 @@ export class ConnectionRequest {
85
}, timeout);
86
});
87
}
81
-
88
}
packages/core/src/models/CustomTools.ts
+17
-2
@@ -1,3 +1,10 @@
1
+/**
2
+ * @fileoverview Custom tools class for Composio SDK, used to manage custom tools created by users.
3
+ *
4
+ * @author Musthaq Ahamad <musthaq@composio.dev>
5
+ * @date 2025-05-05
6
+ * @module CustomTools
7
+ */
8
import ComposioClient from '@composio/client';
9
import {
10
CustomToolOptions,
@@ -96,10 +103,10 @@ export class CustomTools {
103
* @param {string} slug The slug of the tool to get
104
* @returns {Tool} The tool
105
*/
99
- async getCustomToolBySlug(slug: string): Promise<Tool> {
106
+ async getCustomToolBySlug(slug: string): Promise<Tool | null> {
107
const tool = this.customToolsRegistry.get(slug.toLowerCase());
108
if (!tool) {
102
- throw new Error(`Tool with slug ${slug} not found`);
109
+ return null;
110
}
111
return tool.schema;
112
}
@@ -125,6 +132,13 @@ export class CustomTools {
132
: connectedAccounts.items[0];
133
}
134
135
+ /**
136
+ * Execute a custom tool
137
+ * @param {slug} slug The slug of the tool to execute
138
+ * @param {Record<string, unknown>} inputParams The input parameters for the tool
139
+ * @param {ExecuteMetadata} metadata The metadata of the execution
140
+ * @returns {Promise<ToolExecuteResponse>} The response from the tool
141
+ */
142
async executeCustomTool(
143
slug: string,
144
inputParams: Record<string, unknown>,
@@ -137,6 +151,7 @@ export class CustomTools {
151
152
let authCredentials: Record<string, unknown> = {};
153
const { toolkitSlug, execute } = tool.options;
154
+ // if a toolkit is used, get the connected account, and auth credentials
155
if (toolkitSlug) {
156
const connectedAccount = await this.getConnectedAccount(toolkitSlug, metadata);
157
if (!connectedAccount) {
packages/core/src/models/Modifiers.ts
+4
-1
@@ -138,7 +138,10 @@ export class Modifiers {
138
}
139
140
/**
141
- * Function signature for modifying the tool schema.
141
+ * Function signatures for modifying the tool schema.
142
+ * We support two ways to register modifiers:
143
+ * 1. useTransformToolSchema(globalModifier: GlobalTransformToolSchemaModifier): void
144
+ * 2. useTransformToolSchema(toolSlug: string, modifier: TransformToolSchemaModifier): void
145
*/
146
useTransformToolSchema(globalModifier: GlobalTransformToolSchemaModifier): void;
147
useTransformToolSchema(toolSlug: string, modifier: TransformToolSchemaModifier): void;