Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 76 lines 2.64 KB
Raw
1 import { Effect, Option } from 'effect';
2 import { commandInputError } from 'src/commands/errors';
3 import { CommandSurface } from 'src/commands/surface';
4 import { handleClientApiError } from 'src/effects/handle-http-error';
5 import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors';
6 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
7 import { TerminalUI } from 'src/services/terminal-ui';
8 import { formatTriggerTypeInfo } from '../format';
9
10 export type TriggersInfoParams = {
11 readonly slug: Option.Option<string>;
12 };
13
14 /** The commands the hints name, on the tree the command runs in. */
15 const triggersInfoHints = Effect.map(CommandSurface, ({ tree }) =>
16 tree === 'dev'
17 ? {
18 command: 'dev triggers info',
19 listCommand: 'composio dev triggers list',
20 listCommandPlaceholder: 'composio dev triggers list "<toolkit>"',
21 }
22 : {
23 command: 'triggers info',
24 listCommand: 'composio triggers list',
25 listCommandPlaceholder: 'composio triggers list "<toolkit>"',
26 }
27 );
28
29 /**
30 * View details of a specific trigger type including config and payload schemas. A missing
31 * `<slug>` fails with a `CommandInputError` before any request; an API failure is reported with
32 * a hint and exits 1.
33 *
34 * @example
35 * ```bash
36 * composio dev triggers info "GMAIL_NEW_GMAIL_MESSAGE"
37 * ```
38 */
39 export const runTriggersInfo = ({ slug }: TriggersInfoParams) =>
40 Effect.gen(function* () {
41 const ui = yield* TerminalUI;
42 const { command, listCommand, listCommandPlaceholder } = yield* triggersInfoHints;
43 const repo = yield* ComposioToolkitsRepository;
44
45 if (Option.isNone(slug)) {
46 return yield* commandInputError(command)(
47 `Missing required argument: <slug>\nTry specifying a trigger slug, e.g.:\n> composio ${command} "GMAIL_NEW_GMAIL_MESSAGE"`,
48 '<slug>'
49 );
50 }
51
52 const slugValue = slug.value;
53
54 const triggerType = yield* ui
55 .withSpinner('Fetching trigger type details...', repo.getTriggerTypeDetailed(slugValue))
56 .pipe(
57 Effect.catchTag(
58 CLIENT_API_ERROR_TAGS,
59 handleClientApiError(ui, {
60 fallbackMessage: `Trigger "${slugValue}" not found.`,
61 hint: `Browse available trigger types:\n> ${listCommandPlaceholder}`,
62 })
63 )
64 );
65
66 yield* ui.note(formatTriggerTypeInfo(triggerType), `Trigger: ${triggerType.name}`);
67
68 const toolkitSlug = triggerType.toolkit?.slug?.toLowerCase();
69 if (toolkitSlug) {
70 yield* ui.log.step(
71 `To list more trigger types in this toolkit:\n> ${listCommand} "${toolkitSlug}"`
72 );
73 }
74
75 yield* ui.output(JSON.stringify(triggerType, null, 2));
76 });