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 21, 04:45 UTC
| 1 | import { Effect } from 'effect'; |
| 2 | import { commandInputError } from 'src/commands/errors'; |
| 3 | import { CommandSurface } from 'src/commands/surface'; |
| 4 | import { commandHintStep } from 'src/services/command-hints'; |
| 5 | import { ComposioToolkitsRepository } from 'src/services/composio-clients'; |
| 6 | import { TerminalUI } from 'src/services/terminal-ui'; |
| 7 | import { clampLimit } from 'src/ui/clamp-limit'; |
| 8 | import { formatTriggerTypesJson, formatTriggerTypesTable } from '../format'; |
| 9 | |
| 10 | export type TriggersListParams = { |
| 11 | readonly toolkit: string; |
| 12 | readonly limit: number; |
| 13 | }; |
| 14 | |
| 15 | const invalidToolkit = commandInputError('triggers list'); |
| 16 | |
| 17 | const findToolkitHint = commandHintStep('Find the toolkit for a task with', 'root.search', { |
| 18 | query: '<what you want to do>', |
| 19 | }); |
| 20 | |
| 21 | /** |
| 22 | * The hints, on the tree the command runs in. Toolkits are listed only under `dev`, so the root |
| 23 | * tree finds a toolkit through `composio search` instead. |
| 24 | */ |
| 25 | const triggersListHints = Effect.map(CommandSurface, ({ tree }) => |
| 26 | tree === 'dev' |
| 27 | ? { |
| 28 | invalidToolkitHint: commandHintStep('List valid toolkits with', 'dev.toolkits.list'), |
| 29 | noResultsHint: commandHintStep('Verify the toolkit slug with', 'dev.toolkits.list'), |
| 30 | infoCommand: 'composio dev triggers info', |
| 31 | } |
| 32 | : { |
| 33 | invalidToolkitHint: findToolkitHint, |
| 34 | noResultsHint: findToolkitHint, |
| 35 | infoCommand: 'composio triggers info', |
| 36 | } |
| 37 | ); |
| 38 | |
| 39 | /** |
| 40 | * List available trigger types with optional toolkit filters. |
| 41 | * |
| 42 | * @example |
| 43 | * ```bash |
| 44 | * composio dev triggers list gmail |
| 45 | * composio dev triggers list slack --limit 10 |
| 46 | * ``` |
| 47 | */ |
| 48 | export const runTriggersList = ({ toolkit, limit }: TriggersListParams) => |
| 49 | Effect.gen(function* () { |
| 50 | const ui = yield* TerminalUI; |
| 51 | const { invalidToolkitHint, noResultsHint, infoCommand } = yield* triggersListHints; |
| 52 | const repo = yield* ComposioToolkitsRepository; |
| 53 | const clampedLimit = clampLimit(limit); |
| 54 | |
| 55 | yield* repo.validateToolkits([toolkit]).pipe( |
| 56 | Effect.catchTag('services/InvalidToolkitsError', error => |
| 57 | Effect.gen(function* () { |
| 58 | const availableExample = error.availableToolkits.slice(0, 8).join(', '); |
| 59 | yield* ui.log.step(invalidToolkitHint); |
| 60 | return yield* Effect.fail( |
| 61 | invalidToolkit( |
| 62 | `Toolkit "${toolkit}" is not available. ${availableExample ? `Examples: ${availableExample}` : ''}`, |
| 63 | '<toolkit>' |
| 64 | ) |
| 65 | ); |
| 66 | }) |
| 67 | ) |
| 68 | ); |
| 69 | |
| 70 | const allTriggerTypes = yield* ui.withSpinner( |
| 71 | 'Fetching trigger types...', |
| 72 | repo.getTriggerTypes([toolkit]) |
| 73 | ); |
| 74 | const triggerTypes = allTriggerTypes.slice(0, clampedLimit); |
| 75 | |
| 76 | if (triggerTypes.length === 0) { |
| 77 | yield* ui.log.warn(`No trigger types found in toolkit "${toolkit}". ${noResultsHint}`); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | const count = triggerTypes.length; |
| 82 | yield* ui.note( |
| 83 | formatTriggerTypesTable(triggerTypes), |
| 84 | `Listing ${count} trigger type${count === 1 ? '' : 's'}` |
| 85 | ); |
| 86 | |
| 87 | const firstSlug = triggerTypes[0]?.slug; |
| 88 | if (firstSlug) { |
| 89 | yield* ui.log.step(`To view details of a trigger type:\n> ${infoCommand} "${firstSlug}"`); |
| 90 | } |
| 91 | |
| 92 | yield* ui.output(formatTriggerTypesJson(triggerTypes)); |
| 93 | }); |