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, 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 { ComposioCliUserConfig } from 'src/services/cli-user-config'; |
| 6 | import { ComposioToolkitsRepository } from 'src/services/composio-clients'; |
| 7 | import { CLIENT_API_ERROR_TAGS } from 'src/services/composio-errors'; |
| 8 | import { TerminalUI } from 'src/services/terminal-ui'; |
| 9 | |
| 10 | export type TriggersDisableParams = { |
| 11 | readonly id: Option.Option<string>; |
| 12 | readonly dangerouslyAllow: boolean; |
| 13 | }; |
| 14 | |
| 15 | const invalidInput = commandInputError('dev triggers disable'); |
| 16 | |
| 17 | /** |
| 18 | * Disable an existing trigger instance of the developer project. A developer-destructive command: |
| 19 | * it runs only when `developer.destructive_actions` is enabled and `--dangerously-allow` is passed. |
| 20 | * A missing `<id>` fails with a `CommandInputError` before any request, and a developer project that cannot be found with `ProjectResolutionError`; an API failure is reported with a hint and exits 1. |
| 21 | * |
| 22 | * @example |
| 23 | * ```bash |
| 24 | * composio dev triggers disable "trg_123" --dangerously-allow |
| 25 | * ``` |
| 26 | */ |
| 27 | export const runTriggersDisable = ({ id, dangerouslyAllow }: TriggersDisableParams) => |
| 28 | Effect.gen(function* () { |
| 29 | const config = yield* ComposioCliUserConfig; |
| 30 | if (!config.areDeveloperDangerousCommandsEnabled()) { |
| 31 | return yield* invalidInput( |
| 32 | 'This developer command is disabled by config. Set developer.destructive_actions to true in ~/.composio/config.json to allow it.' |
| 33 | ); |
| 34 | } |
| 35 | if (!dangerouslyAllow) { |
| 36 | return yield* invalidInput( |
| 37 | 'This developer command requires explicit acknowledgement. Re-run with --dangerously-allow.', |
| 38 | '--dangerously-allow' |
| 39 | ); |
| 40 | } |
| 41 | const ui = yield* TerminalUI; |
| 42 | const repo = yield* ComposioToolkitsRepository; |
| 43 | |
| 44 | if (Option.isNone(id)) { |
| 45 | return yield* invalidInput( |
| 46 | 'Missing required argument: <id>\nTry specifying a trigger ID, e.g.:\n> composio dev triggers disable "trg_123"\n\nTo find trigger IDs:\n> composio dev triggers status', |
| 47 | '<id>' |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | const idValue = id.value; |
| 52 | const project = yield* resolveDeveloperResourceProject; |
| 53 | yield* ui |
| 54 | .withSpinner(`Disabling trigger "${idValue}"...`, repo.disableTrigger(project, idValue)) |
| 55 | .pipe( |
| 56 | Effect.catchTag( |
| 57 | CLIENT_API_ERROR_TAGS, |
| 58 | handleClientApiError(ui, { |
| 59 | fallbackMessage: `Failed to disable trigger "${idValue}".`, |
| 60 | hint: 'Browse available triggers:\n> composio dev triggers status', |
| 61 | }) |
| 62 | ) |
| 63 | ); |
| 64 | |
| 65 | yield* ui.log.success(`Trigger "${idValue}" disabled.`); |
| 66 | }); |