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 { handleAgentAuthError } from 'src/effects/handle-agent-auth-error'; |
| 3 | import { |
| 4 | AGENT_SUMMARY_NOTE_TITLE, |
| 5 | agentSummaryLines, |
| 6 | ensureAgentSignupAllowed, |
| 7 | getOrSignupReadyAgent, |
| 8 | loginWithAgentIdentity, |
| 9 | safeAgentSummary, |
| 10 | signupAgent, |
| 11 | } from 'src/services/agents'; |
| 12 | import { TerminalUI } from 'src/services/terminal-ui'; |
| 13 | |
| 14 | /** The flags `composio signup` and `composio agent signup` share. */ |
| 15 | export type AgentSignupFlowParams = { |
| 16 | readonly noWait: boolean; |
| 17 | readonly noLogin: boolean; |
| 18 | readonly force: boolean; |
| 19 | /** The command the intro and the info line name. */ |
| 20 | readonly commandLabel?: string; |
| 21 | }; |
| 22 | |
| 23 | /** |
| 24 | * Signs up (or reuses) a Composio agent identity and, unless `noWait` or `noLogin`, logs the |
| 25 | * CLI in with it. Shared by `composio signup` and `composio agent signup`, which differ only in |
| 26 | * `commandLabel`. |
| 27 | */ |
| 28 | export const runAgentSignupFlow = (params: AgentSignupFlowParams) => |
| 29 | handleAgentAuthError( |
| 30 | Effect.gen(function* () { |
| 31 | const ui = yield* TerminalUI; |
| 32 | const commandLabel = params.commandLabel ?? 'composio signup'; |
| 33 | |
| 34 | yield* ensureAgentSignupAllowed; |
| 35 | yield* ui.intro(commandLabel); |
| 36 | yield* ui.log.info( |
| 37 | `${commandLabel} signs you up as a Composio agent. This flow is fully non-interactive and does not open a browser.` |
| 38 | ); |
| 39 | |
| 40 | const identity = yield* params.noWait |
| 41 | ? signupAgent({ wait: false }) |
| 42 | : getOrSignupReadyAgent({ force: params.force }); |
| 43 | const summary = safeAgentSummary(identity); |
| 44 | |
| 45 | yield* ui.note( |
| 46 | [...agentSummaryLines(summary), `Agent key: stored in ~/.composio/agent.json`].join('\n'), |
| 47 | AGENT_SUMMARY_NOTE_TITLE |
| 48 | ); |
| 49 | |
| 50 | if (!params.noWait && !params.noLogin) { |
| 51 | yield* loginWithAgentIdentity(identity); |
| 52 | yield* ui.log.success('Logged in with the Composio agent identity.'); |
| 53 | } else if (params.noWait) { |
| 54 | yield* ui.log.info('Signup is pending. Run `composio agent whoami` to poll status.'); |
| 55 | } |
| 56 | |
| 57 | yield* ui.output( |
| 58 | JSON.stringify({ ...summary, logged_in: !params.noWait && !params.noLogin }) |
| 59 | ); |
| 60 | yield* ui.outro('Agent setup complete.'); |
| 61 | }) |
| 62 | ); |