Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 52 lines 1.8 KB
Raw
1 import { LogLevel, type Option } from 'effect';
2 import { Command, Flag } from 'effect/cli';
3 import { setMinimumLogLevel } from 'src/effects/with-log-level';
4
5 const logLevel = Flag.Literals('log-level', LogLevel.values).pipe(
6 Flag.withDescription('Define log level'),
7 Flag.optional
8 );
9
10 /**
11 * CLI entry point for the Composio CLI.
12 *
13 * `--log-level` is a shared flag: v4 only applies a plain root flag when no
14 * subcommand is selected, so `composio --log-level Debug version` needs the
15 * flag to be inherited by every subcommand. The minimum log level is applied by
16 * `withRootLogLevel` once the subcommand tree is attached, because
17 * `Command.provide` wraps only the handler that exists when it is called.
18 *
19 * @example
20 * ```bash
21 * composio <subcommand>
22 * ```
23 */
24 export const $defaultCmd = Command.make('composio').pipe(
25 Command.withSharedFlags({ logLevel }),
26 Command.withDescription(
27 `Connect AI agents to external tools. Start with search, execute, and link.`
28 ),
29 Command.withExamples([
30 { command: 'composio search "send an email"', description: 'Find tools for a task.' },
31 { command: 'composio link gmail', description: 'Connect an app account.' },
32 {
33 command: 'composio execute GMAIL_SEND_EMAIL --get-schema',
34 description: 'Inspect tool inputs.',
35 },
36 ])
37 );
38
39 /**
40 * Applies `--log-level` (falling back to `COMPOSIO_LOG_LEVEL`) to the root handler and every
41 * subcommand it dispatches to. Call it on the fully assembled root command, after
42 * `Command.withSubcommands`.
43 */
44 export const withRootLogLevel = <
45 const Name extends string,
46 Input extends { readonly logLevel: Option.Option<LogLevel.LogLevel> },
47 ContextInput,
48 E,
49 R,
50 >(
51 root: Command.Command<Name, Input, ContextInput, E, R>
52 ) => root.pipe(Command.provide(({ logLevel }: Input) => setMinimumLogLevel(logLevel)));