Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { Effect, Option } from 'effect'; |
| 2 | import { commandInputError } from 'src/commands/errors'; |
| 3 | import { resolveDeveloperResourceProject } from 'src/commands/surface'; |
| 4 | import { handleClientApiError } from 'src/effects/handle-http-error'; |
| 5 | import { ComposioToolkitsRepository } from 'src/services/composio-clients'; |
| 6 | import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors'; |
| 7 | import { TerminalUI } from 'src/services/terminal-ui'; |
| 8 | |
| 9 | export type TriggersEnableParams = { |
| 10 | readonly id: Option.Option<string>; |
| 11 | }; |
| 12 | |
| 13 | const invalidInput = commandInputError('dev triggers enable'); |
| 14 | |
| 15 | /** |
| 16 | * Enable an existing trigger instance of the developer project. A missing `<id>` fails with a |
| 17 | * `CommandInputError` before any request, and a developer project that cannot be found with |
| 18 | * `ProjectResolutionError`; an API failure is reported with a hint and exits 1. |
| 19 | * |
| 20 | * @example |
| 21 | * ```bash |
| 22 | * composio dev triggers enable "trg_123" |
| 23 | * ``` |
| 24 | */ |
| 25 | export const runTriggersEnable = ({ id }: TriggersEnableParams) => |
| 26 | Effect.gen(function* () { |
| 27 | const ui = yield* TerminalUI; |
| 28 | const repo = yield* ComposioToolkitsRepository; |
| 29 | |
| 30 | if (Option.isNone(id)) { |
| 31 | return yield* invalidInput( |
| 32 | 'Missing required argument: <id>\nTry specifying a trigger ID, e.g.:\n> composio dev triggers enable "trg_123"\n\nTo find trigger IDs:\n> composio dev triggers status --show-disabled', |
| 33 | '<id>' |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | const idValue = id.value; |
| 38 | const project = yield* resolveDeveloperResourceProject; |
| 39 | yield* ui |
| 40 | .withSpinner(`Enabling trigger "${idValue}"...`, repo.enableTrigger(project, idValue)) |
| 41 | .pipe( |
| 42 | Effect.catchTag( |
| 43 | CLIENT_API_ERROR_TAGS, |
| 44 | handleClientApiError(ui, { |
| 45 | fallbackMessage: `Failed to enable trigger "${idValue}".`, |
| 46 | hint: 'Browse available triggers:\n> composio dev triggers status --show-disabled', |
| 47 | }) |
| 48 | ) |
| 49 | ); |
| 50 | |
| 51 | yield* ui.log.success(`Trigger "${idValue}" enabled.`); |
| 52 | }); |