Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
feat(cli): download trigger types with payload
jkomyno committed
Jul 28, 2025 at 22:36 UTC
4c0c17e8de6f4026517766fa739fdb7481a8087f
7 files changed
+330
-39
ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
+8
-4
@@ -116,18 +116,22 @@ export function generateTypescriptTypeStubs({
116
// Fetch data from Composio API
117
yield* Console.log('Fetching latest data from Composio API...');
118
119
- const [toolkits, tools, triggerTypes] = yield* Effect.all(
119
+ const triggerTypesAsEnums = yield* Effect.logDebug('Fetching trigger types...').pipe(
120
+ Effect.flatMap(() => client.getTriggerTypesAsEnums())
121
+ );
122
+
123
+ const [toolkits, tools, _triggerTypes] = yield* Effect.all(
124
[
125
Effect.logDebug('Fetching toolkits...').pipe(Effect.flatMap(() => client.getToolkits())),
126
Effect.logDebug('Fetching tools...').pipe(Effect.flatMap(() => client.getTools())),
123
- Effect.logDebug('Fetching trigger types...').pipe(
124
- Effect.flatMap(() => client.getTriggerTypes())
127
+ Effect.logDebug('Fetching trigger types payloads...').pipe(
128
+ Effect.flatMap(() => client.getTriggerTypes(triggerTypesAsEnums.length))
129
),
130
],
131
{ concurrency: 'unbounded' }
132
);
133
130
- const index = createToolkitIndex({ toolkits, tools, triggerTypes });
134
+ const index = createToolkitIndex({ toolkits, tools, triggerTypes: triggerTypesAsEnums });
135
136
// Generate TypeScript sources
137
const sources = generateTypeScriptSources({
ts/packages/cli/src/generation/create-toolkit-index.ts
+2
-2
@@ -2,7 +2,7 @@ import { pipe, String, Record } from 'effect';
2
import type { Simplify } from 'effect/Types';
3
import { Toolkit, Toolkits, ToolkitName } from 'src/models/toolkits';
4
import { Tools } from 'src/models/tools';
5
-import { TriggerTypes } from 'src/models/trigger-types';
5
+import { TriggerTypesAsEnums } from 'src/models/trigger-types';
6
7
const startsWith =
8
<const P extends string>(prefix: P) =>
@@ -12,7 +12,7 @@ const startsWith =
12
interface CreateToolkitIndexInput {
13
toolkits: Toolkits; // e.g., [ { slug: 'gmail', }]
14
tools: Tools; // e.g., [ 'GMAIL_SEND_EMAIL' ]
15
- triggerTypes: TriggerTypes; // e.g., [ 'GMAIL_NEW_EMAIL' ]
15
+ triggerTypes: TriggerTypesAsEnums; // e.g., [ 'GMAIL_NEW_EMAIL' ]
16
}
17
18
export type ToolkitIndexData = Simplify<{
ts/packages/cli/src/models/trigger-types.ts
+73
-7
@@ -1,23 +1,89 @@
1
import { Brand, Schema } from 'effect';
2
import { JSONTransformSchema } from './utils/json-transform-schema';
3
import { extractActual } from './utils/extract-actual';
4
+import { Toolkit } from './toolkits';
5
5
-export const TriggerType = Schema.String.annotations({ identifier: 'TriggerType' });
6
-export type TriggerType = Schema.Schema.Type<typeof TriggerType>;
6
+/**
7
+ * TriggerType as Enums
8
+ */
9
8
-export const TriggerTypes = Schema.Array(TriggerType).annotations({
9
- identifier: 'Array<TriggerType>',
10
- title: 'TriggerTypes',
10
+export const TriggerTypeAsEnum = Schema.String.annotations({ identifier: 'TriggerType' });
11
+export type TriggerTypeAsEnum = Schema.Schema.Type<typeof TriggerTypeAsEnum>;
12
+
13
+export const TriggerTypesAsEnums = Schema.Array(TriggerTypeAsEnum).annotations({
14
+ identifier: 'Array<TriggerTypeAsEnum>',
15
+ title: 'TriggerTypesAsEnums',
16
message: issue => ({
17
message: `Expected an array of strings, got ${extractActual(issue)}`,
18
override: true,
19
}),
20
});
21
+export type TriggerTypesAsEnums = Schema.Schema.Type<typeof TriggerTypesAsEnums>;
22
+
23
+export const TriggerTypesAsEnumsJSON = JSONTransformSchema(TriggerTypesAsEnums);
24
+export const TriggerTypesAsEnumsFromJSON = Schema.decode(TriggerTypesAsEnumsJSON);
25
+export const TriggerTypesAsEnumsToJSON = Schema.encode(TriggerTypesAsEnumsJSON);
26
+
27
+/**
28
+ * TriggerType with payload
29
+ */
30
+
31
+export const TriggerType = Schema.Struct({
32
+ /**
33
+ * Configuration schema required to set up this trigger
34
+ */
35
+ config: Schema.Record({ key: Schema.String, value: Schema.Unknown }),
36
+
37
+ /**
38
+ * Detailed description of what the trigger does
39
+ */
40
+ description: Schema.String,
41
+
42
+ /**
43
+ * Step-by-step instructions on how to set up and use this trigger
44
+ */
45
+ instructions: Schema.String,
46
+
47
+ /**
48
+ * Human-readable name of the trigger
49
+ */
50
+ name: TriggerTypeAsEnum,
51
+
52
+ /**
53
+ * Schema of the data payload this trigger will deliver when it fires
54
+ */
55
+ payload: Schema.Record({ key: Schema.String, value: Schema.Unknown }),
56
+
57
+ /**
58
+ * Unique identifier for the trigger type
59
+ */
60
+ slug: Schema.String,
61
+
62
+ /**
63
+ * Information about the toolkit that provides this trigger
64
+ */
65
+ // toolkit: Toolkit,
66
+
67
+ /**
68
+ * The trigger mechanism - either webhook (event-based) or poll (scheduled check)
69
+ */
70
+ type: Schema.Literal('webhook', 'poll'),
71
+}).annotations({ identifier: 'TriggerType' });
72
+export type TriggerType = Schema.Schema.Type<typeof TriggerType>;
73
+
74
+export const TriggerTypeJSON = JSONTransformSchema(TriggerType);
75
+export const TriggerTypeFromJSON = Schema.decode(TriggerTypeJSON);
76
+export const TriggerTypeToJSON = Schema.encode(TriggerTypeJSON);
77
+
78
+export const TriggerTypes = Schema.Array(TriggerType).annotations({
79
+ identifier: 'Array<TriggerType>',
80
+ title: 'TriggerTypes',
81
+});
82
export type TriggerTypes = Schema.Schema.Type<typeof TriggerTypes>;
83
84
export const TriggerTypesJSON = JSONTransformSchema(TriggerTypes);
19
-export const triggerTypesFromJSON = Schema.decode(TriggerTypesJSON);
20
-export const triggerTypesToJSON = Schema.encode(TriggerTypesJSON);
85
+export const TriggerTypesFromJSON = Schema.decode(TriggerTypesJSON);
86
+export const TriggerTypesToJSON = Schema.encode(TriggerTypesJSON);
87
88
// E.g., `NEW_EMAIL`
89
export type TriggerTypeName = string & Brand.Brand<'TriggerTypeName'>;
ts/packages/cli/src/services/composio-clients.ts
+40
-8
@@ -3,7 +3,7 @@ import { Composio as _RawComposioClient } from '@composio/client';
3
import { Toolkit, Toolkits } from 'src/models/toolkits';
4
import { Tools } from 'src/models/tools';
5
import { LinkedSession, Session, RetrievedSession } from 'src/models/session';
6
-import { TriggerTypes } from 'src/models/trigger-types';
6
+import { TriggerType, TriggerTypes, TriggerTypesAsEnums } from 'src/models/trigger-types';
7
import { ComposioUserContext, ComposioUserContextLive } from './user-context';
8
import type { NoSuchElementException } from 'effect/Cause';
9
import { renderPrettyError } from './utils/pretty-error';
@@ -51,8 +51,14 @@ export type ToolkitsResponse = Schema.Schema.Type<typeof ToolkitsResponse>;
51
export const ToolsResponse = Tools;
52
export type ToolsResponse = Schema.Schema.Type<typeof ToolsResponse>;
53
54
-export const TriggerTypesResponse = TriggerTypes;
55
-export type TriggerResponse = Schema.Schema.Type<typeof TriggerTypesResponse>;
54
+export const TriggerTypesAsEnumsResponse = TriggerTypesAsEnums;
55
+export type TriggerTypesAsEnumsResponse = Schema.Schema.Type<typeof TriggerTypesAsEnumsResponse>;
56
+
57
+export const TriggerTypesResponse = Schema.Struct({
58
+ items: TriggerTypes,
59
+ total_pages: Schema.Int,
60
+ next_cursor: Schema.NullOr(Schema.Int),
61
+}).annotations({ identifier: 'TriggerTypesResponse' });
62
63
/**
64
* Error response schemas
@@ -189,6 +195,16 @@ export class ComposioClientLive extends Effect.Service<ComposioClientLive>()(
195
callClient(
196
clientSingleton,
197
client => client.triggersTypes.retrieveEnum(),
198
+ TriggerTypesAsEnumsResponse
199
+ ),
200
+ /**
201
+ * Retrieve a list of $limit trigger types, containing their payload.
202
+ * Usually, you would call this with a limit matching the length of the list returned by `retrieveEnum`.
203
+ */
204
+ list: (params: { limit: number }) =>
205
+ callClient(
206
+ clientSingleton,
207
+ client => client.triggersTypes.list(params),
208
TriggerTypesResponse
209
),
210
},
@@ -239,16 +255,32 @@ export class ComposioToolkitsRepository extends Effect.Service<ComposioToolkitsR
255
getToolkits: () =>
256
client.toolkits.list().pipe(
257
Effect.map(response => response.items),
242
- Effect.flatMap(toolkits =>
243
- Effect.gen(function* () {
244
- // Sort apps by slug
258
+ Effect.tap(Effect.logDebug),
259
+ Effect.flatMap(
260
+ Effect.fn(function* (toolkits) {
261
+ // Sort apps by slug.
262
+ // TODO: make sure this happens on the server-side.
263
const orderBySlug = Order.mapInput(Order.string, (app: Toolkit) => app.slug);
264
return Array.sort(toolkits, orderBySlug);
265
})
266
)
267
),
250
- getTools: () => client.tools.retrieveEnum(),
251
- getTriggerTypes: () => client.triggersTypes.retrieveEnum(),
268
+ getTools: () => client.tools.retrieveEnum().pipe(Effect.tap(Effect.logDebug)),
269
+ getTriggerTypesAsEnums: () =>
270
+ client.triggersTypes.retrieveEnum().pipe(Effect.tap(Effect.logDebug)),
271
+ getTriggerTypes: (limit: number) =>
272
+ client.triggersTypes.list({ limit }).pipe(
273
+ Effect.map(response => response.items),
274
+ Effect.tap(Effect.logDebug),
275
+ Effect.flatMap(
276
+ Effect.fn(function* (triggerTypes) {
277
+ // Sort apps by slug.
278
+ // TODO: make sure this happens on the server-side.
279
+ const orderBySlug = Order.mapInput(Order.string, (app: TriggerType) => app.slug);
280
+ return Array.sort(triggerTypes, orderBySlug);
281
+ })
282
+ )
283
+ ),
284
};
285
}),
286
dependencies: [ComposioClientLive.Default],
ts/packages/cli/test/__utils__/models/toolkits.ts
+12
-1
@@ -4,7 +4,7 @@ import { Toolkit } from 'src/models/toolkits';
4
const ToolkitArbitary = Arbitrary.make(Toolkit);
5
6
/**
7
- * Creates test toolkit instances by merging arbitrary generated toolkit data with provided subset values.
7
+ * Creates multiple test toolkit instances by merging arbitrary generated toolkit data with the provided subset values.
8
* Useful for generating test data that maintains consistent identifiers while having realistic randomized properties.
9
*/
10
export function makeTestToolkits(inputs: Array<Pick<Toolkit, 'name' | 'slug'>>) {
@@ -15,3 +15,14 @@ export function makeTestToolkits(inputs: Array<Pick<Toolkit, 'name' | 'slug'>>)
15
const testToolkits = samples.map((sample, i) => ({ ...sample, ...inputs[i] }));
16
return testToolkits;
17
}
18
+
19
+/**
20
+ * Creates a single test toolkit instance by merging arbitrary generated toolkit data with the provided subset values.
21
+ * Useful for generating test data that maintains consistent identifiers while having realistic randomized properties.
22
+ */
23
+export function makeTestToolkit(input: Pick<Toolkit, 'name' | 'slug'>) {
24
+ const samples = FastCheck.sample(ToolkitArbitary, { numRuns: 1 });
25
+
26
+ const testToolkits = samples.map((sample, i) => ({ ...sample, ...input }));
27
+ return testToolkits[0];
28
+}
ts/packages/cli/test/__utils__/services/test-layer.ts
+6
-3
@@ -25,12 +25,12 @@ import {
25
import { EnvLangDetector } from 'src/services/env-lang-detector';
26
import { JsPackageManagerDetector } from 'src/services/js-package-manager-detector';
27
import type { Tools } from 'src/models/tools';
28
-import type { TriggerTypes } from 'src/models/trigger-types';
28
+import type { TriggerTypes, TriggerTypesAsEnums } from 'src/models/trigger-types';
29
import { ComposioUserContextLive } from 'src/services/user-context';
30
import { UpgradeBinary } from 'src/services/upgrade-binary';
31
import { NodeOs } from 'src/services/node-os';
32
33
-interface TestLiveInput {
33
+export interface TestLiveInput {
34
/**
35
* Base config provider to use in test.
36
* If not provided, the default `ConfigProvider.fromMap(new Map([]))` is used.
@@ -49,6 +49,7 @@ interface TestLiveInput {
49
toolkitsData?: {
50
toolkits?: Toolkits;
51
tools?: Tools;
52
+ triggerTypesAsEnums?: TriggerTypesAsEnums;
53
triggerTypes?: TriggerTypes;
54
};
55
}
@@ -74,6 +75,7 @@ export const TestLayer = (input?: TestLiveInput) =>
75
const defaultAppClientData = {
76
toolkits: [],
77
tools: [],
78
+ triggerTypesAsEnums: [],
79
triggerTypes: [],
80
} satisfies TestLiveInput['toolkitsData'];
81
const { fixture, toolkitsData } = Object.assign(
@@ -89,7 +91,8 @@ export const TestLayer = (input?: TestLiveInput) =>
91
new ComposioToolkitsRepository({
92
getToolkits: () => Effect.succeed(toolkitsData.toolkits),
93
getTools: () => Effect.succeed(toolkitsData.tools),
92
- getTriggerTypes: () => Effect.succeed(toolkitsData.triggerTypes),
94
+ getTriggerTypesAsEnums: () => Effect.succeed(toolkitsData.triggerTypesAsEnums),
95
+ getTriggerTypes: limit => Effect.succeed(toolkitsData.triggerTypes.slice(0, limit)),
96
})
97
);
98
ts/packages/cli/test/src/commands/ts/ts.generate.cmd.test.ts
+189
-14
@@ -1,31 +1,206 @@
1
import path from 'node:path';
2
import { describe, expect, layer } from '@effect/vitest';
3
-import { Effect, Stream, String } from 'effect';
4
-import { Command, FileSystem } from '@effect/platform';
3
+import { Effect } from 'effect';
4
+import { FileSystem } from '@effect/platform';
5
import { cli, TestLive } from 'test/__utils__';
6
-import { makeTestToolkits } from 'test/__utils__/models/toolkits';
6
+import { makeTestToolkit } from 'test/__utils__/models/toolkits';
7
import { NodeProcess } from 'src/services/node-process';
8
import {
9
assertTranspiledTypeScriptIsValid,
10
assertTypeScriptIsValid,
11
} from 'test/__utils__/typescript-compiler';
12
import { ComposioCorePkgNotFound } from 'src/effects/find-composio-core-generated';
13
+import type { TestLiveInput } from 'test/__utils__/services/test-layer';
14
15
describe('CLI: composio ts generate', () => {
16
+ const TOOLKIT_GMAIL = makeTestToolkit({
17
+ name: 'Gmail',
18
+ slug: 'gmail',
19
+ });
20
+ const TOOLKIT_SLACK = makeTestToolkit({
21
+ name: 'Slack',
22
+ slug: 'slack',
23
+ });
24
+
25
const appClientData = {
16
- toolkits: makeTestToolkits([
17
- {
18
- name: 'Gmail',
19
- slug: 'gmail',
20
- },
26
+ toolkits: [TOOLKIT_GMAIL, TOOLKIT_SLACK],
27
+ tools: ['GMAIL_CREATE_EMAIL_DRAFT', 'GMAIL_DELETE_MESSAGE', 'GMAIL_FETCH_EMAILS'],
28
+ triggerTypesAsEnums: ['GMAIL_NEW_GMAIL_MESSAGE'],
29
+ triggerTypes: [
30
{
22
- name: 'Slack',
23
- slug: 'slack',
31
+ config: {
32
+ properties: {
33
+ interval: {
34
+ default: 1,
35
+ description: 'Periodic Interval to Check for Updates & Send a Trigger in Minutes',
36
+ title: 'Interval',
37
+ type: 'number',
38
+ },
39
+ labelIds: {
40
+ default: 'INBOX',
41
+ description:
42
+ "Filter messages by a single label ID. Labels identify the status or category of messages. Supported labels include 'INBOX', 'SPAM', 'TRASH', 'UNREAD', 'STARRED', 'IMPORTANT', 'CATEGORY_PERSONAL', 'CATEGORY_SOCIAL', 'CATEGORY_PROMOTIONS', 'CATEGORY_UPDATES', and 'CATEGORY_FORUMS'. For complex label filtering, use the 'query' parameter instead.",
43
+ examples: ['INBOX', 'UNREAD', 'STARRED'],
44
+ title: 'Labelids',
45
+ type: 'string',
46
+ },
47
+ query: {
48
+ default: '',
49
+ description:
50
+ "Advanced Gmail search using the same syntax as Gmail's search box. Use 'AND' for messages that match all conditions, 'OR' for any condition. Search by sender (from:email@domain.com), labels (label:inbox), status (is:unread), attachments (has:attachment), dates (after:2023/1/1), and more. If specified, this takes precedence over labelIds.",
51
+ examples: [
52
+ 'label:inbox OR label:sent',
53
+ 'from:example@gmail.com is:unread',
54
+ 'has:attachment after:2023/1/1',
55
+ 'is:important is:unread',
56
+ ],
57
+ title: 'Query',
58
+ type: 'string',
59
+ },
60
+ userId: {
61
+ default: 'me',
62
+ description: "The user's email address or 'me' for the authenticated user.",
63
+ examples: ['me'],
64
+ title: 'Userid',
65
+ type: 'string',
66
+ },
67
+ },
68
+ title: 'NewMessageConfig',
69
+ type: 'object',
70
+ },
71
+ description: 'Triggers when a new message is received in Gmail.',
72
+ instructions:
73
+ "\n **Instructions for Setting Up the Trigger:**\n\n - Ensure that the Gmail API is enabled for your Google account.\n - Provide the user ID (usually 'me' for the authenticated user).\n - Optionally, provide label IDs to filter messages.\n ",
74
+ name: 'New Gmail Message Received Trigger',
75
+ payload: {
76
+ properties: {
77
+ attachment_list: {
78
+ anyOf: [
79
+ {
80
+ items: {},
81
+ type: 'array',
82
+ },
83
+ {
84
+ type: 'null',
85
+ },
86
+ ],
87
+ default: null,
88
+ description: 'The list of attachments in the message',
89
+ title: 'Attachment List',
90
+ },
91
+ message_id: {
92
+ anyOf: [
93
+ {
94
+ type: 'string',
95
+ },
96
+ {
97
+ type: 'null',
98
+ },
99
+ ],
100
+ default: null,
101
+ description: 'The message ID of the message',
102
+ title: 'Message ID',
103
+ },
104
+ message_text: {
105
+ anyOf: [
106
+ {
107
+ type: 'string',
108
+ },
109
+ {
110
+ type: 'null',
111
+ },
112
+ ],
113
+ default: null,
114
+ description: 'The text of the message',
115
+ title: 'Message Text',
116
+ },
117
+ message_timestamp: {
118
+ anyOf: [
119
+ {
120
+ type: 'string',
121
+ },
122
+ {
123
+ type: 'null',
124
+ },
125
+ ],
126
+ default: null,
127
+ description: 'The timestamp of the message',
128
+ title: 'Message Timestamp',
129
+ },
130
+ payload: {
131
+ anyOf: [
132
+ {
133
+ type: 'object',
134
+ },
135
+ {
136
+ type: 'null',
137
+ },
138
+ ],
139
+ default: null,
140
+ description: 'The payload of the message',
141
+ title: 'Payload',
142
+ },
143
+ sender: {
144
+ anyOf: [
145
+ {
146
+ type: 'string',
147
+ },
148
+ {
149
+ type: 'null',
150
+ },
151
+ ],
152
+ default: null,
153
+ description: 'The sender of the message',
154
+ title: 'Sender',
155
+ },
156
+ subject: {
157
+ anyOf: [
158
+ {
159
+ type: 'string',
160
+ },
161
+ {
162
+ type: 'null',
163
+ },
164
+ ],
165
+ default: null,
166
+ description: 'The subject of the message',
167
+ title: 'Subject',
168
+ },
169
+ thread_id: {
170
+ anyOf: [
171
+ {
172
+ type: 'string',
173
+ },
174
+ {
175
+ type: 'null',
176
+ },
177
+ ],
178
+ default: null,
179
+ description: 'The thread ID of the message',
180
+ title: 'Thread ID',
181
+ },
182
+ to: {
183
+ anyOf: [
184
+ {
185
+ type: 'string',
186
+ },
187
+ {
188
+ type: 'null',
189
+ },
190
+ ],
191
+ default: null,
192
+ description: 'The recipient of the message',
193
+ title: 'To',
194
+ },
195
+ },
196
+ title: 'NewMessagePayload',
197
+ type: 'object',
198
+ },
199
+ slug: 'GMAIL_NEW_GMAIL_MESSAGE',
200
+ type: 'poll',
201
},
25
- ]),
26
- tools: ['GMAIL_CREATE_EMAIL_DRAFT', 'GMAIL_DELETE_MESSAGE', 'GMAIL_FETCH_EMAILS'],
27
- triggerTypes: ['GMAIL_NEW_GMAIL_MESSAGE'],
28
- };
202
+ ],
203
+ } satisfies TestLiveInput['toolkitsData'];
204
205
describe('[Given] valid fetched app data', () => {
206
layer(