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 { Command, Flag } from 'effect/cli'; |
| 2 | import { Effect, Option } from 'effect'; |
| 3 | import { |
| 4 | AGENT_CONFIG_FILE_NAME, |
| 5 | getCurrentLoggedInAgent, |
| 6 | removeStoredAgentIdentity, |
| 7 | } from 'src/services/agents'; |
| 8 | import { ComposioUserContext } from 'src/services/user-context'; |
| 9 | import { TerminalUI } from 'src/services/terminal-ui'; |
| 10 | import { clearApolloIdentityForAnalytics } from 'src/analytics/dispatch'; |
| 11 | import { commandInputError } from 'src/commands/errors'; |
| 12 | |
| 13 | // `--force` and `-f` predate `--yes` and keep working. |
| 14 | const yes = Flag.Boolean('yes').pipe( |
| 15 | Flag.withAlias('y'), |
| 16 | Flag.withAlias('force'), |
| 17 | Flag.withAlias('f'), |
| 18 | Flag.withDefault(false), |
| 19 | Flag.withDescription('Skip confirmation prompts') |
| 20 | ); |
| 21 | |
| 22 | /** Without a terminal to confirm on, an agent logout needs `--yes`. */ |
| 23 | const NEEDS_YES_MESSAGE = |
| 24 | '`composio logout` needs --yes when not running interactively: it removes the stored Composio agent key.'; |
| 25 | |
| 26 | /** |
| 27 | * CLI command to log out from the Composio CLI. An agent logout removes the stored agent key, so |
| 28 | * it asks first; without a terminal to ask on it needs `--yes` and otherwise fails with a |
| 29 | * `CommandInputError`. Declining the prompt logs nothing out and exits 0. |
| 30 | * |
| 31 | * @example |
| 32 | * ```bash |
| 33 | * composio logout |
| 34 | * ``` |
| 35 | */ |
| 36 | export const logoutCmd = Command.make('logout', { yes }, ({ yes }) => |
| 37 | Effect.gen(function* () { |
| 38 | const ui = yield* TerminalUI; |
| 39 | const ctx = yield* ComposioUserContext; |
| 40 | |
| 41 | if (!ctx.isLoggedIn()) { |
| 42 | yield* ui.log.warn('You are not logged in yet. Please run `composio login`.'); |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | const loggedInAgent = yield* getCurrentLoggedInAgent; |
| 47 | if (Option.isSome(loggedInAgent) && !yes) { |
| 48 | const { canPrompt } = yield* ui.capabilities; |
| 49 | if (!canPrompt) { |
| 50 | return yield* commandInputError('logout')(NEEDS_YES_MESSAGE, '--yes'); |
| 51 | } |
| 52 | yield* ui.note( |
| 53 | [ |
| 54 | `You are logged in as a Composio agent (${loggedInAgent.value.email ?? loggedInAgent.value.slug ?? 'unknown'}).`, |
| 55 | `Logging out will remove ~/.composio/${AGENT_CONFIG_FILE_NAME}, including the stored composio_agent_key.`, |
| 56 | 'Save that key before continuing if you may need this exact agent again.', |
| 57 | 'Without the key, you cannot run `composio agent login <composio_agent_key>` for this agent unless it has been claimed by a human admin.', |
| 58 | ].join('\n'), |
| 59 | 'Agent Logout Warning' |
| 60 | ); |
| 61 | |
| 62 | const confirmed = yield* ui.confirm('Remove the stored Composio agent key and log out?', { |
| 63 | defaultValue: false, |
| 64 | }); |
| 65 | if (!confirmed) { |
| 66 | yield* ui.log.warn('Agent logout cancelled. No credentials were removed.'); |
| 67 | return; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | yield* ctx.logout; |
| 72 | yield* clearApolloIdentityForAnalytics; |
| 73 | |
| 74 | if (Option.isSome(loggedInAgent)) { |
| 75 | yield* removeStoredAgentIdentity; |
| 76 | yield* ui.log.success('Logged out and removed stored Composio agent key.'); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | yield* ui.log.success('Logged out successfully.'); |
| 81 | }) |
| 82 | ).pipe(Command.withDescription('Log out from the Composio SDK.')); |