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 } from 'effect'; |
| 2 | import { completeAgentLogin } from 'src/effects/complete-agent-login'; |
| 3 | import { handleAgentAuthError } from 'src/effects/handle-agent-auth-error'; |
| 4 | import { |
| 5 | ensureAgentSignupAllowed, |
| 6 | fetchAgentWhoami, |
| 7 | writeStoredAgentIdentity, |
| 8 | } from 'src/services/agents'; |
| 9 | |
| 10 | /** The argument of `composio agent login`. */ |
| 11 | export type AgentLoginParams = { |
| 12 | readonly composioAgentKey: string; |
| 13 | }; |
| 14 | |
| 15 | /** |
| 16 | * Looks the key up with the agents API, stores the identity, and logs the CLI in with it. A |
| 17 | * human login, or an identity without credentials yet, is reported by `handleAgentAuthError` |
| 18 | * and exits 1. |
| 19 | */ |
| 20 | export const runAgentLogin = ({ composioAgentKey }: AgentLoginParams) => |
| 21 | handleAgentAuthError( |
| 22 | Effect.gen(function* () { |
| 23 | yield* ensureAgentSignupAllowed; |
| 24 | const identity = yield* fetchAgentWhoami(composioAgentKey); |
| 25 | const saved = yield* writeStoredAgentIdentity(identity); |
| 26 | yield* completeAgentLogin(saved); |
| 27 | }) |
| 28 | ); |