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
Fix eslint rules
haxzie committed
Apr 23, 2025 at 14:04 UTC
d0fad6cf06d3b7f0b68ce49f2e2af8fe25f116c3
3 files changed
+101
-122
eslint.config.mjs
+3
-3
@@ -7,18 +7,18 @@ export default [
7
{
8
ignores: ["packages/**/dist/**", "packages/**/node_modules/**", "node_modules/**", "examples/"]
9
},
10
- {files: ["packages/**/*.{ts}"]},
10
+ {files: ["packages/**/*.ts"]},
11
{languageOptions: { globals: globals.browser }},
12
...tseslint.configs.recommended,
13
{
14
rules: {
15
- "@typescript-eslint/no-var-requires": "off",
15
+ // "@typescript-eslint/no-var-requires": "off",
16
"@typescript-eslint/no-require-imports": "warn",
17
"@typescript-eslint/no-unsafe-function-type": "off",
18
"no-prototype-builtins": "off",
19
"max-lines-per-function": ["error", 250],
20
"no-unused-vars": "off",
21
- "@typescript-eslint/ban-ts-comment": "off",
21
+ "@typescript-eslint/ban-ts-comment": "warn",
22
"no-constant-condition": "off",
23
"no-ex-assign": "off",
24
"no-constant-binary-expression": "off",
packages/core/src/models/Triggers.ts
+31
-53
@@ -1,5 +1,5 @@
1
-import ComposioClient from "@composio/client";
2
-import { RequestOptions } from "@composio/client/internal/request-options";
1
+import ComposioClient from '@composio/client';
2
+import { RequestOptions } from '@composio/client/internal/request-options';
3
import {
4
TriggerInstanceListActiveParams,
5
TriggerInstanceRemoveUpsertResponse,
@@ -10,15 +10,12 @@ import {
10
TriggersTypeListResponse,
11
TriggersTypeRetrieveEnumResponse,
12
TriggersTypeRetrieveResponse,
13
-} from "@composio/client/resources/index";
14
-import { TriggerStatusEnum, TriggerSubscribeParams } from "../types/triggers.types";
15
-import { InstrumentedInstance } from "../types/telemetry.types";
16
-import { PusherUtils, TriggerData } from "../utils/pusher";
17
-import logger from "../utils/logger";
18
-import { Session } from "./Session";
19
-
20
-
21
-
13
+} from '@composio/client/resources/index';
14
+import { TriggerStatusEnum, TriggerSubscribeParams } from '../types/triggers.types';
15
+import { InstrumentedInstance } from '../types/telemetry.types';
16
+import { PusherUtils, TriggerData } from '../utils/pusher';
17
+import logger from '../utils/logger';
18
+import { Session } from './Session';
19
20
/**
21
* Trigger (Instance) class
@@ -26,7 +23,7 @@ import { Session } from "./Session";
23
*
24
*/
25
export class Triggers implements InstrumentedInstance {
29
- readonly FILE_NAME: string = "core/models/Triggers.ts";
26
+ readonly FILE_NAME: string = 'core/models/Triggers.ts';
27
private client: ComposioClient;
28
29
constructor(client: ComposioClient) {
@@ -37,10 +34,7 @@ export class Triggers implements InstrumentedInstance {
34
* Fetch list of all the active triggers
35
* @returns {Promise<TriggerInstance[]>} List of trigger instances
36
*/
40
- async list(
41
- query?: TriggerInstanceListActiveParams,
42
- options?: RequestOptions
43
- ) {
37
+ async list(query?: TriggerInstanceListActiveParams, options?: RequestOptions) {
38
return this.client.triggerInstances.listActive(query, options);
39
}
40
@@ -108,11 +102,7 @@ export class Triggers implements InstrumentedInstance {
102
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
103
*/
104
async disable(slug: string, options?: RequestOptions) {
111
- return this.client.triggerInstances.updateStatus(
112
- "disable",
113
- { slug },
114
- options
115
- );
105
+ return this.client.triggerInstances.updateStatus('disable', { slug }, options);
106
}
107
108
/**
@@ -123,11 +113,7 @@ export class Triggers implements InstrumentedInstance {
113
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
114
*/
115
async enable(slug: string, options?: RequestOptions) {
126
- return this.client.triggerInstances.updateStatus(
127
- "enable",
128
- { slug },
129
- options
130
- );
116
+ return this.client.triggerInstances.updateStatus('enable', { slug }, options);
117
}
118
119
/**
@@ -135,18 +121,21 @@ export class Triggers implements InstrumentedInstance {
121
*/
122
/**
123
* List all the trigger types
138
- *
124
+ *
125
* @param {TriggersTypeListParams} query - The query parameters to filter the trigger types
126
* @param {RequestOptions} options - Request options
127
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
128
*/
143
- async listTypes(query?: TriggersTypeListParams, options?: RequestOptions): Promise<TriggersTypeListResponse> {
129
+ async listTypes(
130
+ query?: TriggersTypeListParams,
131
+ options?: RequestOptions
132
+ ): Promise<TriggersTypeListResponse> {
133
return this.client.triggersTypes.list(query, options);
134
}
135
136
/**
137
* Retrieve a trigger type by its slug
149
- *
138
+ *
139
* @param {string} slug - The slug of the trigger type
140
* @param {RequestOptions} options - request options
141
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
@@ -157,49 +146,38 @@ export class Triggers implements InstrumentedInstance {
146
147
/**
148
* Fetches the list of all the available trigger enums
160
- *
149
+ *
150
* This method is used by the CLI where filters are not required.
162
- * @param options
163
- * @returns
151
+ * @param options
152
+ * @returns
153
*/
154
async listEnum(options?: RequestOptions): Promise<TriggersTypeRetrieveEnumResponse> {
155
return this.client.triggersTypes.retrieveEnum(options);
156
}
157
169
- async subscribe(
170
- fn: (data: TriggerData) => void,
171
- filters: TriggerSubscribeParams = {}
172
- ) {
173
-
174
- if (!fn) throw new Error("Function is required for trigger subscription");
158
+ async subscribe(fn: (_data: TriggerData) => void, filters: TriggerSubscribeParams = {}) {
159
+ if (!fn) throw new Error('Function is required for trigger subscription');
160
161
// @TODO: Get the client id from the backend
162
const session = new Session(this.client);
163
const sessionInfo = await session.getInfo();
164
const clientId = sessionInfo.project?.id;
165
181
- if (!clientId) throw new Error("Client ID not found");
166
+ if (!clientId) throw new Error('Client ID not found');
167
183
- await PusherUtils.getPusherClient(
184
- this.client.baseURL,
185
- this.client.apiKey
186
- );
168
+ await PusherUtils.getPusherClient(this.client.baseURL, this.client.apiKey);
169
170
const shouldSendTrigger = (data: TriggerData) => {
171
if (Object.keys(filters).length === 0) return true;
172
else {
173
return (
192
- (!filters.appName ||
193
- data.appName.toLowerCase() === filters.appName.toLowerCase()) &&
174
+ (!filters.appName || data.appName.toLowerCase() === filters.appName.toLowerCase()) &&
175
(!filters.triggerId ||
195
- data.metadata.id.toLowerCase() ===
196
- filters.triggerId.toLowerCase()) &&
176
+ data.metadata.id.toLowerCase() === filters.triggerId.toLowerCase()) &&
177
(!filters.connectionId ||
198
- data.metadata.connectionId.toLowerCase() ===
199
- filters.connectionId.toLowerCase()) &&
178
+ data.metadata.connectionId.toLowerCase() === filters.connectionId.toLowerCase()) &&
179
(!filters.triggerName ||
201
- data.metadata.triggerName.toLowerCase() ===
202
- filters.triggerName.toLowerCase()) &&
180
+ data.metadata.triggerName.toLowerCase() === filters.triggerName.toLowerCase()) &&
181
(!filters.entityId ||
182
data.metadata.connection.clientUniqueUserId.toLowerCase() ===
183
filters.entityId.toLowerCase()) &&
@@ -210,7 +188,7 @@ export class Triggers implements InstrumentedInstance {
188
}
189
};
190
213
- logger.debug("Subscribing to triggers", filters);
191
+ logger.debug('Subscribing to triggers', filters);
192
PusherUtils.triggerSubscribe(clientId, (data: TriggerData) => {
193
if (shouldSendTrigger(data)) {
194
fn(data);
@@ -223,7 +201,7 @@ export class Triggers implements InstrumentedInstance {
201
const sessionInfo = await session.getInfo();
202
const clientId = sessionInfo.project?.id;
203
226
- if (!clientId) throw new Error("Client ID not found");
204
+ if (!clientId) throw new Error('Client ID not found');
205
206
PusherUtils.triggerUnsubscribe(clientId);
207
}
packages/toolsets/vercel/src/index.ts
+67
-66
@@ -1,84 +1,85 @@
1
/**
2
- * Vercel AI Toolset
2
+ * Vercel AI Toolset
3
* To be used with the Vercel AI SDK
4
- *
4
+ *
5
* Author: @haxzie
6
* Legacy Reference: https://github.com/ComposioHQ/composio/blob/master/js/src/frameworks/vercel.ts
7
- *
7
+ *
8
* This toolset provides a set of tools for interacting with Vercel AI SDK.
9
- *
9
+ *
10
* @packageDocumentation
11
* @module toolsets/vercel
12
*/
13
-import { BaseComposioToolset, Tool as ComposioTool, ToolListParams } from "@composio/core";
14
-import type { Tool as VercelTool } from "ai";
15
-import { jsonSchema, tool } from "ai";
13
+import { BaseComposioToolset, Tool as ComposioTool, ToolListParams } from '@composio/core';
14
+import type { Tool as VercelTool } from 'ai';
15
+import { jsonSchema, tool } from 'ai';
16
17
type VercelToolCollection = Record<string, VercelTool>;
18
export class VercelToolset extends BaseComposioToolset<VercelToolCollection, VercelTool> {
19
+ readonly FILE_NAME = 'toolsets/vercel/src/index.ts';
20
+ static readonly FRAMEWORK_NAME = 'vercel';
21
20
- readonly FILE_NAME = "toolsets/vercel/src/index.ts";
21
- static readonly FRAMEWORK_NAME = "vercel";
22
+ /**
23
+ * Get all the tools from the client.
24
+ * Override the default implementation to return a record of tools.
25
+ *
26
+ * @param params - The parameters for the tool list.
27
+ * @returns The tools.
28
+ */
29
+ override async getTools(params?: ToolListParams): Promise<VercelToolCollection> {
30
+ if (!this.client) {
31
+ throw new Error('Client not initialized');
32
+ }
33
+ const tools = await this.client.tools.list(params);
34
+ return tools.items.reduce(
35
+ (tools, tool) => ({
36
+ ...tools,
37
+ [tool.slug]: this._wrapTool(tool as ComposioTool),
38
+ }),
39
+ {}
40
+ );
41
+ }
42
23
- /**
24
- * Get all the tools from the client.
25
- * Override the default implementation to return a record of tools.
26
- *
27
- * @param params - The parameters for the tool list.
28
- * @returns The tools.
29
- */
30
- override async getTools(params?: ToolListParams): Promise<VercelToolCollection> {
31
- if (!this.client) {
32
- throw new Error("Client not initialized");
33
- }
34
- const tools = await this.client.tools.list(params);
35
- return tools.items.reduce((tools, tool) => ({
36
- ...tools,
37
- [tool.slug]: this._wrapTool(tool as ComposioTool)
38
- }), {});
43
+ /**
44
+ * Execute a tool call.
45
+ * @param tool - The tool to execute.
46
+ * @param userId - The user id.
47
+ * @returns {Promise<string>} The result of the tool call.
48
+ */
49
+ async executeToolCall(
50
+ tool: { name: string; arguments: unknown },
51
+ userId?: string
52
+ ): Promise<string> {
53
+ if (!this.client) {
54
+ throw new Error('Client not initialized');
55
}
40
-
41
- /**
42
- * Execute a tool call.
43
- * @param tool - The tool to execute.
44
- * @param userId - The user id.
45
- * @returns {Promise<string>} The result of the tool call.
46
- */
47
- async executeToolCall(
48
- tool: { name: string; arguments: unknown },
49
- userId?: string
50
- ): Promise<string> {
51
- if (!this.client) {
52
- throw new Error("Client not initialized");
53
- }
56
55
- const toolSchema = await this.client.tools.get(tool.name);
56
- const appName = toolSchema?.name.toLowerCase();
57
- const args = typeof tool.arguments === "string" ? JSON.parse(tool.arguments) : tool.arguments;
57
+ const toolSchema = await this.client.tools.get(tool.name);
58
+ const appName = toolSchema?.name.toLowerCase();
59
+ const args = typeof tool.arguments === 'string' ? JSON.parse(tool.arguments) : tool.arguments;
60
59
- const results = await this.client.tools.execute(toolSchema.slug, {
60
- arguments: args,
61
- entity_id: userId ?? this.client.userId,
62
- connected_account_id: this.client.getConnectedAccountId(appName)
63
- });
61
+ const results = await this.client.tools.execute(toolSchema.slug, {
62
+ arguments: args,
63
+ entity_id: userId ?? this.client.userId,
64
+ connected_account_id: this.client.getConnectedAccountId(appName),
65
+ });
66
65
- return JSON.stringify(results);
66
- }
67
+ return JSON.stringify(results);
68
+ }
69
68
- _wrapTool(composioTool: ComposioTool): VercelTool {
69
- return tool({
70
- description: composioTool.description,
71
- // @ts-ignore the type are JSONSchemV7. Internally it's resolved
72
- parameters: jsonSchema(composioTool.input_parameters),
73
- execute: async (params) => {
74
- return await this.executeToolCall(
75
- {
76
- name: composioTool.slug,
77
- arguments: JSON.stringify(params),
78
- },
79
- this.client?.userId
80
- );
81
- },
82
- });
83
- }
84
-}
\ No newline at end of file
70
+ _wrapTool(composioTool: ComposioTool): VercelTool {
71
+ return tool({
72
+ description: composioTool.description,
73
+ parameters: jsonSchema(composioTool.input_parameters),
74
+ execute: async params => {
75
+ return await this.executeToolCall(
76
+ {
77
+ name: composioTool.slug,
78
+ arguments: JSON.stringify(params),
79
+ },
80
+ this.client?.userId
81
+ );
82
+ },
83
+ });
84
+ }
85
+}