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.

feat(cli): download trigger types with payload

jkomyno4c0c17e8de6f
diff --git a/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts b/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
index 2bacfc2b3..62714f1af 100644
--- a/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
+++ b/ts/packages/cli/src/commands/ts/commands/ts.generate.cmd.ts
@@ -116,18 +116,22 @@ export function generateTypescriptTypeStubs({
// Fetch data from Composio API
yield* Console.log('Fetching latest data from Composio API...');
- const [toolkits, tools, triggerTypes] = yield* Effect.all(
+ const triggerTypesAsEnums = yield* Effect.logDebug('Fetching trigger types...').pipe(
+ Effect.flatMap(() => client.getTriggerTypesAsEnums())
+ );
+
+ const [toolkits, tools, _triggerTypes] = yield* Effect.all(
[
Effect.logDebug('Fetching toolkits...').pipe(Effect.flatMap(() => client.getToolkits())),
Effect.logDebug('Fetching tools...').pipe(Effect.flatMap(() => client.getTools())),
- Effect.logDebug('Fetching trigger types...').pipe(
- Effect.flatMap(() => client.getTriggerTypes())
+ Effect.logDebug('Fetching trigger types payloads...').pipe(
+ Effect.flatMap(() => client.getTriggerTypes(triggerTypesAsEnums.length))
),
],
{ concurrency: 'unbounded' }
);
- const index = createToolkitIndex({ toolkits, tools, triggerTypes });
+ const index = createToolkitIndex({ toolkits, tools, triggerTypes: triggerTypesAsEnums });
// Generate TypeScript sources
const sources = generateTypeScriptSources({
diff --git a/ts/packages/cli/src/generation/create-toolkit-index.ts b/ts/packages/cli/src/generation/create-toolkit-index.ts
index 5a4dd1714..e9b347f89 100644
--- a/ts/packages/cli/src/generation/create-toolkit-index.ts
+++ b/ts/packages/cli/src/generation/create-toolkit-index.ts
@@ -2,7 +2,7 @@ import { pipe, String, Record } from 'effect';
import type { Simplify } from 'effect/Types';
import { Toolkit, Toolkits, ToolkitName } from 'src/models/toolkits';
import { Tools } from 'src/models/tools';
-import { TriggerTypes } from 'src/models/trigger-types';
+import { TriggerTypesAsEnums } from 'src/models/trigger-types';
const startsWith =
<const P extends string>(prefix: P) =>
@@ -12,7 +12,7 @@ const startsWith =
interface CreateToolkitIndexInput {
toolkits: Toolkits; // e.g., [ { slug: 'gmail', }]
tools: Tools; // e.g., [ 'GMAIL_SEND_EMAIL' ]
- triggerTypes: TriggerTypes; // e.g., [ 'GMAIL_NEW_EMAIL' ]
+ triggerTypes: TriggerTypesAsEnums; // e.g., [ 'GMAIL_NEW_EMAIL' ]
}
export type ToolkitIndexData = Simplify<{
diff --git a/ts/packages/cli/src/models/trigger-types.ts b/ts/packages/cli/src/models/trigger-types.ts
index a25023161..5b5ec99e7 100644
--- a/ts/packages/cli/src/models/trigger-types.ts
+++ b/ts/packages/cli/src/models/trigger-types.ts
@@ -1,23 +1,89 @@
import { Brand, Schema } from 'effect';
import { JSONTransformSchema } from './utils/json-transform-schema';
import { extractActual } from './utils/extract-actual';
+import { Toolkit } from './toolkits';
-export const TriggerType = Schema.String.annotations({ identifier: 'TriggerType' });
-export type TriggerType = Schema.Schema.Type<typeof TriggerType>;
+/**
+ * TriggerType as Enums
+ */
-export const TriggerTypes = Schema.Array(TriggerType).annotations({
- identifier: 'Array<TriggerType>',
- title: 'TriggerTypes',
+export const TriggerTypeAsEnum = Schema.String.annotations({ identifier: 'TriggerType' });
+export type TriggerTypeAsEnum = Schema.Schema.Type<typeof TriggerTypeAsEnum>;
+
+export const TriggerTypesAsEnums = Schema.Array(TriggerTypeAsEnum).annotations({
+ identifier: 'Array<TriggerTypeAsEnum>',
+ title: 'TriggerTypesAsEnums',
message: issue => ({
message: `Expected an array of strings, got ${extractActual(issue)}`,
override: true,
}),
});
+export type TriggerTypesAsEnums = Schema.Schema.Type<typeof TriggerTypesAsEnums>;
+
+export const TriggerTypesAsEnumsJSON = JSONTransformSchema(TriggerTypesAsEnums);
+export const TriggerTypesAsEnumsFromJSON = Schema.decode(TriggerTypesAsEnumsJSON);
+export const TriggerTypesAsEnumsToJSON = Schema.encode(TriggerTypesAsEnumsJSON);
+
+/**
+ * TriggerType with payload
+ */
+
+export const TriggerType = Schema.Struct({
+ /**
+ * Configuration schema required to set up this trigger
+ */
+ config: Schema.Record({ key: Schema.String, value: Schema.Unknown }),
+
+ /**
+ * Detailed description of what the trigger does
+ */
+ description: Schema.String,
+
+ /**
+ * Step-by-step instructions on how to set up and use this trigger
+ */
+ instructions: Schema.String,
+
+ /**
+ * Human-readable name of the trigger
+ */
+ name: TriggerTypeAsEnum,
+
+ /**
+ * Schema of the data payload this trigger will deliver when it fires
+ */
+ payload: Schema.Record({ key: Schema.String, value: Schema.Unknown }),
+
+ /**
+ * Unique identifier for the trigger type
+ */
+ slug: Schema.String,
+
+ /**
+ * Information about the toolkit that provides this trigger
+ */
+ // toolkit: Toolkit,
+
+ /**
+ * The trigger mechanism - either webhook (event-based) or poll (scheduled check)
+ */
+ type: Schema.Literal('webhook', 'poll'),
+}).annotations({ identifier: 'TriggerType' });
+export type TriggerType = Schema.Schema.Type<typeof TriggerType>;
+
+export const TriggerTypeJSON = JSONTransformSchema(TriggerType);
+export const TriggerTypeFromJSON = Schema.decode(TriggerTypeJSON);
+export const TriggerTypeToJSON = Schema.encode(TriggerTypeJSON);
+
+export const TriggerTypes = Schema.Array(TriggerType).annotations({
+ identifier: 'Array<TriggerType>',
+ title: 'TriggerTypes',
+});
export type TriggerTypes = Schema.Schema.Type<typeof TriggerTypes>;
export const TriggerTypesJSON = JSONTransformSchema(TriggerTypes);
-export const triggerTypesFromJSON = Schema.decode(TriggerTypesJSON);
-export const triggerTypesToJSON = Schema.encode(TriggerTypesJSON);
+export const TriggerTypesFromJSON = Schema.decode(TriggerTypesJSON);
+export const TriggerTypesToJSON = Schema.encode(TriggerTypesJSON);
// E.g., `NEW_EMAIL`
export type TriggerTypeName = string & Brand.Brand<'TriggerTypeName'>;
diff --git a/ts/packages/cli/src/services/composio-clients.ts b/ts/packages/cli/src/services/composio-clients.ts
index 5f0dc127c..e953a1bd6 100644
--- a/ts/packages/cli/src/services/composio-clients.ts
+++ b/ts/packages/cli/src/services/composio-clients.ts
@@ -3,7 +3,7 @@ import { Composio as _RawComposioClient } from '@composio/client';
import { Toolkit, Toolkits } from 'src/models/toolkits';
import { Tools } from 'src/models/tools';
import { LinkedSession, Session, RetrievedSession } from 'src/models/session';
-import { TriggerTypes } from 'src/models/trigger-types';
+import { TriggerType, TriggerTypes, TriggerTypesAsEnums } from 'src/models/trigger-types';
import { ComposioUserContext, ComposioUserContextLive } from './user-context';
import type { NoSuchElementException } from 'effect/Cause';
import { renderPrettyError } from './utils/pretty-error';
@@ -51,8 +51,14 @@ export type ToolkitsResponse = Schema.Schema.Type<typeof ToolkitsResponse>;
export const ToolsResponse = Tools;
export type ToolsResponse = Schema.Schema.Type<typeof ToolsResponse>;
-export const TriggerTypesResponse = TriggerTypes;
-export type TriggerResponse = Schema.Schema.Type<typeof TriggerTypesResponse>;
+export const TriggerTypesAsEnumsResponse = TriggerTypesAsEnums;
+export type TriggerTypesAsEnumsResponse = Schema.Schema.Type<typeof TriggerTypesAsEnumsResponse>;
+
+export const TriggerTypesResponse = Schema.Struct({
+ items: TriggerTypes,
+ total_pages: Schema.Int,
+ next_cursor: Schema.NullOr(Schema.Int),
+}).annotations({ identifier: 'TriggerTypesResponse' });
/**
* Error response schemas
@@ -189,6 +195,16 @@ export class ComposioClientLive extends Effect.Service<ComposioClientLive>()(
callClient(
clientSingleton,
client => client.triggersTypes.retrieveEnum(),
+ TriggerTypesAsEnumsResponse
+ ),
+ /**
+ * Retrieve a list of $limit trigger types, containing their payload.
+ * Usually, you would call this with a limit matching the length of the list returned by `retrieveEnum`.
+ */
+ list: (params: { limit: number }) =>
+ callClient(
+ clientSingleton,
+ client => client.triggersTypes.list(params),
TriggerTypesResponse
),
},
@@ -239,16 +255,32 @@ export class ComposioToolkitsRepository extends Effect.Service<ComposioToolkitsR
getToolkits: () =>
client.toolkits.list().pipe(
Effect.map(response => response.items),
- Effect.flatMap(toolkits =>
- Effect.gen(function* () {
- // Sort apps by slug
+ Effect.tap(Effect.logDebug),
+ Effect.flatMap(
+ Effect.fn(function* (toolkits) {
+ // Sort apps by slug.
+ // TODO: make sure this happens on the server-side.
const orderBySlug = Order.mapInput(Order.string, (app: Toolkit) => app.slug);
return Array.sort(toolkits, orderBySlug);
})
)
),
- getTools: () => client.tools.retrieveEnum(),
- getTriggerTypes: () => client.triggersTypes.retrieveEnum(),
+ getTools: () => client.tools.retrieveEnum().pipe(Effect.tap(Effect.logDebug)),
+ getTriggerTypesAsEnums: () =>
+ client.triggersTypes.retrieveEnum().pipe(Effect.tap(Effect.logDebug)),
+ getTriggerTypes: (limit: number) =>
+ client.triggersTypes.list({ limit }).pipe(
+ Effect.map(response => response.items),
+ Effect.tap(Effect.logDebug),
+ Effect.flatMap(
+ Effect.fn(function* (triggerTypes) {
+ // Sort apps by slug.
+ // TODO: make sure this happens on the server-side.
+ const orderBySlug = Order.mapInput(Order.string, (app: TriggerType) => app.slug);
+ return Array.sort(triggerTypes, orderBySlug);
+ })
+ )
+ ),
};
}),
dependencies: [ComposioClientLive.Default],
diff --git a/ts/packages/cli/test/__utils__/models/toolkits.ts b/ts/packages/cli/test/__utils__/models/toolkits.ts
index bfee182fc..fb88b357f 100644
--- a/ts/packages/cli/test/__utils__/models/toolkits.ts
+++ b/ts/packages/cli/test/__utils__/models/toolkits.ts
@@ -4,7 +4,7 @@ import { Toolkit } from 'src/models/toolkits';
const ToolkitArbitary = Arbitrary.make(Toolkit);
/**
- * Creates test toolkit instances by merging arbitrary generated toolkit data with provided subset values.
+ * Creates multiple test toolkit instances by merging arbitrary generated toolkit data with the provided subset values.
* Useful for generating test data that maintains consistent identifiers while having realistic randomized properties.
*/
export function makeTestToolkits(inputs: Array<Pick<Toolkit, 'name' | 'slug'>>) {
@@ -15,3 +15,14 @@ export function makeTestToolkits(inputs: Array<Pick<Toolkit, 'name' | 'slug'>>)
const testToolkits = samples.map((sample, i) => ({ ...sample, ...inputs[i] }));
return testToolkits;
}
+
+/**
+ * Creates a single test toolkit instance by merging arbitrary generated toolkit data with the provided subset values.
+ * Useful for generating test data that maintains consistent identifiers while having realistic randomized properties.
+ */
+export function makeTestToolkit(input: Pick<Toolkit, 'name' | 'slug'>) {
+ const samples = FastCheck.sample(ToolkitArbitary, { numRuns: 1 });
+
+ const testToolkits = samples.map((sample, i) => ({ ...sample, ...input }));
+ return testToolkits[0];
+}
diff --git a/ts/packages/cli/test/__utils__/services/test-layer.ts b/ts/packages/cli/test/__utils__/services/test-layer.ts
index 4b91a02bf..b7bae3dad 100644
--- a/ts/packages/cli/test/__utils__/services/test-layer.ts
+++ b/ts/packages/cli/test/__utils__/services/test-layer.ts
@@ -25,12 +25,12 @@ import {
import { EnvLangDetector } from 'src/services/env-lang-detector';
import { JsPackageManagerDetector } from 'src/services/js-package-manager-detector';
import type { Tools } from 'src/models/tools';
-import type { TriggerTypes } from 'src/models/trigger-types';
+import type { TriggerTypes, TriggerTypesAsEnums } from 'src/models/trigger-types';
import { ComposioUserContextLive } from 'src/services/user-context';
import { UpgradeBinary } from 'src/services/upgrade-binary';
import { NodeOs } from 'src/services/node-os';
-interface TestLiveInput {
+export interface TestLiveInput {
/**
* Base config provider to use in test.
* If not provided, the default `ConfigProvider.fromMap(new Map([]))` is used.
@@ -49,6 +49,7 @@ interface TestLiveInput {
toolkitsData?: {
toolkits?: Toolkits;
tools?: Tools;
+ triggerTypesAsEnums?: TriggerTypesAsEnums;
triggerTypes?: TriggerTypes;
};
}
@@ -74,6 +75,7 @@ export const TestLayer = (input?: TestLiveInput) =>
const defaultAppClientData = {
toolkits: [],
tools: [],
+ triggerTypesAsEnums: [],
triggerTypes: [],
} satisfies TestLiveInput['toolkitsData'];
const { fixture, toolkitsData } = Object.assign(
@@ -89,7 +91,8 @@ export const TestLayer = (input?: TestLiveInput) =>
new ComposioToolkitsRepository({
getToolkits: () => Effect.succeed(toolkitsData.toolkits),
getTools: () => Effect.succeed(toolkitsData.tools),
- getTriggerTypes: () => Effect.succeed(toolkitsData.triggerTypes),
+ getTriggerTypesAsEnums: () => Effect.succeed(toolkitsData.triggerTypesAsEnums),
+ getTriggerTypes: limit => Effect.succeed(toolkitsData.triggerTypes.slice(0, limit)),
})
);
diff --git a/ts/packages/cli/test/src/commands/ts/ts.generate.cmd.test.ts b/ts/packages/cli/test/src/commands/ts/ts.generate.cmd.test.ts
index 3442636bc..bbab87232 100644
--- a/ts/packages/cli/test/src/commands/ts/ts.generate.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/ts/ts.generate.cmd.test.ts
@@ -1,31 +1,206 @@
import path from 'node:path';
import { describe, expect, layer } from '@effect/vitest';
-import { Effect, Stream, String } from 'effect';
-import { Command, FileSystem } from '@effect/platform';
+import { Effect } from 'effect';
+import { FileSystem } from '@effect/platform';
import { cli, TestLive } from 'test/__utils__';
-import { makeTestToolkits } from 'test/__utils__/models/toolkits';
+import { makeTestToolkit } from 'test/__utils__/models/toolkits';
import { NodeProcess } from 'src/services/node-process';
import {
assertTranspiledTypeScriptIsValid,
assertTypeScriptIsValid,
} from 'test/__utils__/typescript-compiler';
import { ComposioCorePkgNotFound } from 'src/effects/find-composio-core-generated';
+import type { TestLiveInput } from 'test/__utils__/services/test-layer';
describe('CLI: composio ts generate', () => {
+ const TOOLKIT_GMAIL = makeTestToolkit({
+ name: 'Gmail',
+ slug: 'gmail',
+ });
+ const TOOLKIT_SLACK = makeTestToolkit({
+ name: 'Slack',
+ slug: 'slack',
+ });
+
const appClientData = {
- toolkits: makeTestToolkits([
- {
- name: 'Gmail',
- slug: 'gmail',
- },
+ toolkits: [TOOLKIT_GMAIL, TOOLKIT_SLACK],
+ tools: ['GMAIL_CREATE_EMAIL_DRAFT', 'GMAIL_DELETE_MESSAGE', 'GMAIL_FETCH_EMAILS'],
+ triggerTypesAsEnums: ['GMAIL_NEW_GMAIL_MESSAGE'],
+ triggerTypes: [
{
- name: 'Slack',
- slug: 'slack',
+ config: {
+ properties: {
+ interval: {
+ default: 1,
+ description: 'Periodic Interval to Check for Updates & Send a Trigger in Minutes',
+ title: 'Interval',
+ type: 'number',
+ },
+ labelIds: {
+ default: 'INBOX',
+ description:
+ "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.",
+ examples: ['INBOX', 'UNREAD', 'STARRED'],
+ title: 'Labelids',
+ type: 'string',
+ },
+ query: {
+ default: '',
+ description:
+ "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 protected]), labels (label:inbox), status (is:unread), attachments (has:attachment), dates (after:2023/1/1), and more. If specified, this takes precedence over labelIds.",
+ examples: [
+ 'label:inbox OR label:sent',
+ 'from:[email protected] is:unread',
+ 'has:attachment after:2023/1/1',
+ 'is:important is:unread',
+ ],
+ title: 'Query',
+ type: 'string',
+ },
+ userId: {
+ default: 'me',
+ description: "The user's email address or 'me' for the authenticated user.",
+ examples: ['me'],
+ title: 'Userid',
+ type: 'string',
+ },
+ },
+ title: 'NewMessageConfig',
+ type: 'object',
+ },
+ description: 'Triggers when a new message is received in Gmail.',
+ instructions:
+ "\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 ",
+ name: 'New Gmail Message Received Trigger',
+ payload: {
+ properties: {
+ attachment_list: {
+ anyOf: [
+ {
+ items: {},
+ type: 'array',
+ },
+ {
+ type: 'null',
+ },
+ ],
+ default: null,
+ description: 'The list of attachments in the message',
+ title: 'Attachment List',
+ },
+ message_id: {
+ anyOf: [
+ {
+ type: 'string',
+ },
+ {
+ type: 'null',
+ },
+ ],
+ default: null,
+ description: 'The message ID of the message',
+ title: 'Message ID',
+ },
+ message_text: {
+ anyOf: [
+ {
+ type: 'string',
+ },
+ {
+ type: 'null',
+ },
+ ],
+ default: null,
+ description: 'The text of the message',
+ title: 'Message Text',
+ },
+ message_timestamp: {
+ anyOf: [
+ {
+ type: 'string',
+ },
+ {
+ type: 'null',
+ },
+ ],
+ default: null,
+ description: 'The timestamp of the message',
+ title: 'Message Timestamp',
+ },
+ payload: {
+ anyOf: [
+ {
+ type: 'object',
+ },
+ {
+ type: 'null',
+ },
+ ],
+ default: null,
+ description: 'The payload of the message',
+ title: 'Payload',
+ },
+ sender: {
+ anyOf: [
+ {
+ type: 'string',
+ },
+ {
+ type: 'null',
+ },
+ ],
+ default: null,
+ description: 'The sender of the message',
+ title: 'Sender',
+ },
+ subject: {
+ anyOf: [
+ {
+ type: 'string',
+ },
+ {
+ type: 'null',
+ },
+ ],
+ default: null,
+ description: 'The subject of the message',
+ title: 'Subject',
+ },
+ thread_id: {
+ anyOf: [
+ {
+ type: 'string',
+ },
+ {
+ type: 'null',
+ },
+ ],
+ default: null,
+ description: 'The thread ID of the message',
+ title: 'Thread ID',
+ },
+ to: {
+ anyOf: [
+ {
+ type: 'string',
+ },
+ {
+ type: 'null',
+ },
+ ],
+ default: null,
+ description: 'The recipient of the message',
+ title: 'To',
+ },
+ },
+ title: 'NewMessagePayload',
+ type: 'object',
+ },
+ slug: 'GMAIL_NEW_GMAIL_MESSAGE',
+ type: 'poll',
},
- ]),
- tools: ['GMAIL_CREATE_EMAIL_DRAFT', 'GMAIL_DELETE_MESSAGE', 'GMAIL_FETCH_EMAILS'],
- triggerTypes: ['GMAIL_NEW_GMAIL_MESSAGE'],
- };
+ ],
+ } satisfies TestLiveInput['toolkitsData'];
describe('[Given] valid fetched app data', () => {
layer(