@devries-cameron20 / composio Mirror · read-only
Fork 0

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

next
ts 49 lines 1.97 KB
Raw
1 import { Data } from 'effect';
2 import { ExpectedFailure, isExpectedFailure } from 'src/effects/expected-failure';
3
4 /**
5 * A usage mistake the parser cannot see: a flag combination, a value that fails a business
6 * rule, a missing input, or an environment the command cannot run in. `effect/cli`'s
7 * `CliError.InvalidValue` is a fixed option-and-value struct built only by the parser, so
8 * handler-level validation raises this instead. The invocation (`src/invocation/invocation.ts`)
9 * prints `message` as one line and exits 1, with no defect banner.
10 */
11 export class CommandInputError extends Data.TaggedError('commands/CommandInputError')<{
12 /** The command path without `composio`, e.g. `login` or `dev triggers disable`. */
13 readonly command: string;
14 readonly message: string;
15 /** The flag or argument at fault, e.g. `--alias` or `<toolkit>`, when there is one. */
16 readonly option?: string | undefined;
17 }> {
18 get [ExpectedFailure]() {
19 return true;
20 }
21 }
22
23 /** The command needs a logged-in user and `~/.composio` holds no API key. */
24 export class NotLoggedInError extends Data.TaggedError('commands/NotLoggedInError')<{
25 readonly message: string;
26 }> {
27 get [ExpectedFailure]() {
28 return true;
29 }
30 }
31
32 export const notLoggedIn = (): NotLoggedInError =>
33 new NotLoggedInError({ message: 'You are not logged in yet. Please run `composio login`.' });
34
35 /**
36 * Failures the user fixes by changing the invocation or their setup, or that a remote service
37 * reported clearly, not defects: any error whose class declares `ExpectedFailure` (see
38 * `src/effects/expected-failure.ts`). The invocation prints the message on stderr and exits 1,
39 * with no defect banner.
40 */
41 export type UsageFailure = ExpectedFailure;
42
43 export const isUsageFailure = isExpectedFailure;
44
45 /** Builds the constructor a command uses for its own input errors. */
46 export const commandInputError =
47 (command: string) =>
48 (message: string, option?: string): CommandInputError =>
49 new CommandInputError({ command, message, option });